diff options
author | Marek Szyprowski <m.szyprowski@samsung.com> | 2020-11-24 14:15:23 +0100 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2020-11-24 14:14:39 +0000 |
commit | a6f483b2e4415bca7af90346204f93f63b90acdd (patch) | |
tree | c43fed048c1eeea4a5dbdfb4f78015bbb577c206 /drivers/spi/spi.c | |
parent | 2ed6e3bac15242c18bef5af12547a13b25b65ac8 (diff) |
spi: Fix potential NULL pointer dereference in spi_shutdown()
Shutdown bus function might be called on the unbound device, so add a
check if there is a driver before calling its shutdown function.
This fixes following kernel panic obserbed during system reboot:
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000018
...
Call trace:
spi_shutdown+0x10/0x38
kernel_restart_prepare+0x34/0x40
kernel_restart+0x14/0x88
__do_sys_reboot+0x148/0x248
__arm64_sys_reboot+0x1c/0x28
el0_svc_common.constprop.3+0x74/0x198
do_el0_svc+0x20/0x98
el0_sync_handler+0x140/0x1a8
el0_sync+0x140/0x180
Code: f9403402 d1008041 f100005f 9a9f1021 (f9400c21)
---[ end trace 266c07205a2d632e ]---
Fixes: 9db34ee64ce4 (spi: Use bus_type functions for probe, remove and shutdown)
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Link: https://lore.kernel.org/r/20201124131523.32287-1-m.szyprowski@samsung.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/spi/spi.c')
-rw-r--r-- | drivers/spi/spi.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 6ee0f66ddef1..1564914930d8 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -426,10 +426,12 @@ static int spi_remove(struct device *dev) static void spi_shutdown(struct device *dev) { - const struct spi_driver *sdrv = to_spi_driver(dev->driver); + if (dev->driver) { + const struct spi_driver *sdrv = to_spi_driver(dev->driver); - if (sdrv->shutdown) - sdrv->shutdown(to_spi_device(dev)); + if (sdrv->shutdown) + sdrv->shutdown(to_spi_device(dev)); + } } struct bus_type spi_bus_type = { |