# 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/br-sparc64-full-2016.08-613-ge98b4dd/bin/sparc64-linux-gcc --version # < /opt/cross/kisskb/br-sparc64-full-2016.08-613-ge98b4dd/bin/sparc64-linux-ld --version # < git log --format=%s --max-count=1 e3a36eb6dfaeea8175c05d5915dcf0b939be6dab # < make -s -j 32 ARCH=sparc64 O=/kisskb/build/linus_sparc64-allmodconfig_sparc64 CROSS_COMPILE=/opt/cross/kisskb/br-sparc64-full-2016.08-613-ge98b4dd/bin/sparc64-linux- allmodconfig # Added to kconfig CONFIG_BUILD_DOCSRC=n # Added to kconfig CONFIG_HAVE_FTRACE_MCOUNT_RECORD=n # Added to kconfig CONFIG_SAMPLES=n # Added to kconfig CONFIG_MODULE_SIG=n # < make -s -j 32 ARCH=sparc64 O=/kisskb/build/linus_sparc64-allmodconfig_sparc64 CROSS_COMPILE=/opt/cross/kisskb/br-sparc64-full-2016.08-613-ge98b4dd/bin/sparc64-linux- help # make -s -j 32 ARCH=sparc64 O=/kisskb/build/linus_sparc64-allmodconfig_sparc64 CROSS_COMPILE=/opt/cross/kisskb/br-sparc64-full-2016.08-613-ge98b4dd/bin/sparc64-linux- olddefconfig # make -s -j 32 ARCH=sparc64 O=/kisskb/build/linus_sparc64-allmodconfig_sparc64 CROSS_COMPILE=/opt/cross/kisskb/br-sparc64-full-2016.08-613-ge98b4dd/bin/sparc64-linux- :1511:2: warning: #warning syscall clone3 not implemented [-Wcpp] /kisskb/src/fs/cifs/smb2pdu.c: In function 'SMB2_ioctl_init': /kisskb/src/fs/cifs/smb2pdu.c:2845:19: warning: 'in_data_buf' may be used uninitialized in this function [-Wmaybe-uninitialized] iov[1].iov_base = in_data_buf; ^ In file included from /kisskb/src/include/linux/rwsem.h:16:0, from /kisskb/src/include/linux/notifier.h:15, from /kisskb/src/include/linux/clk.h:14, from /kisskb/src/drivers/tty/serial/sh-sci.c:20: /kisskb/src/drivers/tty/serial/sh-sci.c: In function 'sci_dma_rx_submit': /kisskb/src/include/linux/spinlock.h:288:3: warning: 'flags' may be used uninitialized in this function [-Wmaybe-uninitialized] _raw_spin_unlock_irqrestore(lock, flags); \ ^ /kisskb/src/drivers/tty/serial/sh-sci.c:1348:16: note: 'flags' was declared here unsigned long flags; ^ /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 [-Wmaybe-uninitialized] pd->msg->buf[real_pos] = data; ^ /kisskb/src/drivers/i2c/busses/i2c-sh_mobile.c:372:16: note: 'data' was declared here unsigned char data; ^ /kisskb/src/drivers/input/joystick/analog.c:160:2: warning: #warning Precise timer not defined for this architecture. [-Wcpp] #warning Precise timer not defined for this architecture. ^ In file included from /kisskb/src/include/linux/wait.h:9:0, from /kisskb/src/include/linux/net.h:19, from /kisskb/src/drivers/infiniband/sw/siw/siw_qp_rx.c:8: /kisskb/src/drivers/infiniband/sw/siw/siw_qp_rx.c: In function 'siw_proc_send': /kisskb/src/include/linux/spinlock.h:288:3: warning: 'flags' may be used uninitialized in this function [-Wmaybe-uninitialized] _raw_spin_unlock_irqrestore(lock, flags); \ ^ /kisskb/src/drivers/infiniband/sw/siw/siw_qp_rx.c:335:16: note: 'flags' was declared here unsigned long flags; ^ kernel: arch/sparc/boot/image is ready kernel: arch/sparc/boot/zImage is ready warning: same module names found: drivers/char/adi.ko drivers/input/joystick/adi.ko Completed OK # rm -rf /kisskb/build/linus_sparc64-allmodconfig_sparc64 # Build took: 0:15:27.457391