# git rev-parse -q --verify e3a36eb6dfaeea8175c05d5915dcf0b939be6dab^{commit} e3a36eb6dfaeea8175c05d5915dcf0b939be6dab already have revision, skipping fetch # git checkout -q -f -B kisskb e3a36eb6dfaeea8175c05d5915dcf0b939be6dab # git clean -qxdf # < git log -1 # commit e3a36eb6dfaeea8175c05d5915dcf0b939be6dab # Author: Christoph Hellwig # Date: Wed Mar 11 17:07:10 2020 +0100 # # driver code: clarify and fix platform device DMA mask allocation # # This does three inter-related things to clarify the usage of the # platform device dma_mask field. In the process, fix the bug introduced # by cdfee5623290 ("driver core: initialize a default DMA mask for # platform device") that caused Artem Tashkinov's laptop to not boot with # newer Fedora kernels. # # This does: # # - First off, rename the field to "platform_dma_mask" to make it # greppable. # # We have way too many different random fields called "dma_mask" in # various data structures, where some of them are actual masks, and # some of them are just pointers to the mask. And the structures all # have pointers to each other, or embed each other inside themselves, # and "pdev" sometimes means "platform device" and sometimes it means # "PCI device". # # So to make it clear in the code when you actually use this new field, # give it a unique name (it really should be something even more unique # like "platform_device_dma_mask", since it's per platform device, not # per platform, but that gets old really fast, and this is unique # enough in context). # # To further clarify when the field gets used, initialize it when we # actually start using it with the default value. # # - Then, use this field instead of the random one-off allocation in # platform_device_register_full() that is now unnecessary since we now # already have a perfectly fine allocation for it in the platform # device structure. # # - The above then allows us to fix the actual bug, where the error path # of platform_device_register_full() would unconditionally free the # platform device DMA allocation with 'kfree()'. # # That kfree() was dont regardless of whether the allocation had been # done earlier with the (now removed) kmalloc, or whether # setup_pdev_dma_masks() had already been used and the dma_mask pointer # pointed to the mask that was part of the platform device. # # It seems most people never triggered the error path, or only triggered # it from a call chain that set an explicit pdevinfo->dma_mask value (and # thus caused the unnecessary allocation that was "cleaned up" in the # error path) before calling platform_device_register_full(). # # Robin Murphy points out that in Artem's case the wdat_wdt driver failed # in platform_device_add(), and that was the one that had called # platform_device_register_full() with pdevinfo.dma_mask = 0, and would # have caused that kfree() of pdev.dma_mask corrupting the heap. # # A later unrelated kmalloc() then oopsed due to the heap corruption. # # Fixes: cdfee5623290 ("driver core: initialize a default DMA mask for platform device") # Reported-bisected-and-tested-by: Artem S. Tashkinov # Reviewed-by: Robin Murphy # Cc: Greg Kroah-Hartman # Signed-off-by: Christoph Hellwig # Signed-off-by: Linus Torvalds # < /opt/cross/kisskb/gcc-4.6.3-nolibc/sh4-linux/bin/sh4-linux-gcc --version # < /opt/cross/kisskb/gcc-4.6.3-nolibc/sh4-linux/bin/sh4-linux-ld --version # < git log --format=%s --max-count=1 e3a36eb6dfaeea8175c05d5915dcf0b939be6dab # < make -s -j 48 ARCH=sh O=/kisskb/build/linus_se7724_defconfig_sh4-gcc4.6 CROSS_COMPILE=/opt/cross/kisskb/gcc-4.6.3-nolibc/sh4-linux/bin/sh4-linux- se7724_defconfig # < make -s -j 48 ARCH=sh O=/kisskb/build/linus_se7724_defconfig_sh4-gcc4.6 CROSS_COMPILE=/opt/cross/kisskb/gcc-4.6.3-nolibc/sh4-linux/bin/sh4-linux- help # make -s -j 48 ARCH=sh O=/kisskb/build/linus_se7724_defconfig_sh4-gcc4.6 CROSS_COMPILE=/opt/cross/kisskb/gcc-4.6.3-nolibc/sh4-linux/bin/sh4-linux- olddefconfig # make -s -j 48 ARCH=sh O=/kisskb/build/linus_se7724_defconfig_sh4-gcc4.6 CROSS_COMPILE=/opt/cross/kisskb/gcc-4.6.3-nolibc/sh4-linux/bin/sh4-linux- Generating include/generated/machtypes.h :1511:2: warning: #warning syscall clone3 not implemented [-Wcpp] /kisskb/src/arch/sh/kernel/cpu/sh4/../sh3/../../entry-common.S: Assembler messages: /kisskb/src/arch/sh/kernel/cpu/sh4/../sh3/../../entry-common.S:385: Warning: overflow in branch to syscall_exit_work; converted into longer instruction sequence /kisskb/src/arch/sh/kernel/cpu/sh4/../sh3/../../entry-common.S:388: Warning: overflow in branch to syscall_exit_work; converted into longer instruction sequence /kisskb/src/kernel/printk/printk.c: In function 'devkmsg_sysctl_set_loglvl': /kisskb/src/kernel/printk/printk.c:204:16: warning: 'old' may be used uninitialized in this function [-Wuninitialized] /kisskb/src/fs/proc/inode.c: In function 'proc_reg_open': /kisskb/src/include/linux/list.h:72:12: warning: 'pdeo' may be used uninitialized in this function [-Wuninitialized] /kisskb/src/fs/proc/inode.c:338:21: note: 'pdeo' was declared here /kisskb/src/drivers/base/regmap/regmap.c: In function 'regmap_raw_read': /kisskb/src/drivers/base/regmap/regmap.c:2598:6: warning: 'ret' may be used uninitialized in this function [-Wuninitialized] /kisskb/src/drivers/base/regmap/regmap.c: In function '_regmap_raw_write': /kisskb/src/drivers/base/regmap/regmap.c:1859:6: warning: 'ret' may be used uninitialized in this function [-Wuninitialized] /kisskb/src/fs/ext4/extents.c: In function 'ext4_convert_unwritten_io_end_vec': /kisskb/src/fs/ext4/extents.c:5009:23: warning: 'ret' may be used uninitialized in this function [-Wuninitialized] /kisskb/src/drivers/i2c/busses/i2c-sh_mobile.c: In function 'sh_mobile_i2c_isr': /kisskb/src/drivers/i2c/busses/i2c-sh_mobile.c:399:26: warning: 'data' may be used uninitialized in this function [-Wuninitialized] /kisskb/src/drivers/i2c/busses/i2c-sh_mobile.c:372:16: note: 'data' was declared here /kisskb/src/drivers/usb/core/devio.c: In function 'async_completed': /kisskb/src/drivers/usb/core/devio.c:625:23: warning: 'errno' may be used uninitialized in this function [-Wuninitialized] /kisskb/src/drivers/sh/clk/cpg.c: In function 'r8': /kisskb/src/drivers/sh/clk/cpg.c:41:2: warning: passing argument 1 of 'ioread8' discards 'const' qualifier from pointer target type [enabled by default] /kisskb/src/include/asm-generic/iomap.h:29:21: note: expected 'void *' but argument is of type 'const void *' /kisskb/src/drivers/sh/clk/cpg.c: In function 'r16': /kisskb/src/drivers/sh/clk/cpg.c:46:2: warning: passing argument 1 of 'ioread16' discards 'const' qualifier from pointer target type [enabled by default] /kisskb/src/include/asm-generic/iomap.h:30:21: note: expected 'void *' but argument is of type 'const void *' /kisskb/src/drivers/sh/clk/cpg.c: In function 'r32': /kisskb/src/drivers/sh/clk/cpg.c:51:2: warning: passing argument 1 of 'ioread32' discards 'const' qualifier from pointer target type [enabled by default] /kisskb/src/include/asm-generic/iomap.h:32:21: note: expected 'void *' but argument is of type 'const void *' /kisskb/src/fs/io_uring.c: In function '__io_sqe_files_update': /kisskb/src/fs/io_uring.c:5845:13: warning: 'err' may be used uninitialized in this function [-Wuninitialized] Image Name: Linux-5.6.0-rc5+ Created: Thu Mar 12 05:35:45 2020 Image Type: SuperH Linux Kernel Image (gzip compressed) Data Size: 3464128 Bytes = 3382.94 KiB = 3.30 MiB Load Address: 88001000 Entry Point: 88002000 Image arch/sh/boot/uImage is ready Completed OK # rm -rf /kisskb/build/linus_se7724_defconfig_sh4-gcc4.6 # Build took: 0:00:50.562024