Skip to contentSkip to conversation

driver core: platform: don't oops in platform_shutdown() on unbound devices

PATCH In review Dmitry Baryshkov 3 participants 3 messages Dec 12, 2020 – Dec 13, 2020 Driver core

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 driver core: platform: don't oops in platform_shutdown() on unbound devices

On shutdown the driver core calls the bus' shutdown callback also for unbound devices. A driver's shutdown callback however is only called for devices bound to this driver. Commit 9c30921fe799 ("driver core:
platform: use bus_type functions") changed the platform bus from driver callbacks to bus callbacks, so the shutdown function must be prepared to be called without a driver. Add the corresponding check in the shutdown function.

Fixes 9c30921fe799 ("driver core: platform: use bus_type functions")
---
 drivers/base/platform.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/base/platform.c +5 -1
index 0358dc3ea3ad..e9477e0bbca5 100644
@@ -1351,9 +1351,13 @@ static int platform_remove(struct device *_dev)
 
 static void platform_shutdown(struct device *_dev)
 {
-	struct platform_driver *drv = to_platform_driver(_dev->driver);
 	struct platform_device *dev = to_platform_device(_dev);
+	struct platform_driver *drv;
+
+	if (!_dev->driver)
+		return;
 
+	drv = to_platform_driver(_dev->driver);
 	if (drv->shutdown)
 		drv->shutdown(dev);
 }
Signature · 1 line
2.29.2
Tested-by on v3 1/1
#1 lore raw
Quoted 10 lines · Dmitry Baryshkov

On shutdown the driver core calls the bus' shutdown callback also for unbound devices. A driver's shutdown callback however is only called for devices bound to this driver. Commit 9c30921fe799 ("driver core:
platform: use bus_type functions") changed the platform bus from driver callbacks to bus callbacks, so the shutdown function must be prepared to be called without a driver. Add the corresponding check in the shutdown function.

Fixes 9c30921fe799 ("driver core: platform: use bus_type functions")
Quoted 26 lines
---
 drivers/base/platform.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/base/platform.c +5 -1
index 0358dc3ea3ad..e9477e0bbca5 100644
@@ -1351,9 +1351,13 @@ static int platform_remove(struct device *_dev)
 
 static void platform_shutdown(struct device *_dev)
 {
-	struct platform_driver *drv = to_platform_driver(_dev->driver);
 	struct platform_device *dev = to_platform_device(_dev);
+	struct platform_driver *drv;
+
+	if (!_dev->driver)
+		return;
 
+	drv = to_platform_driver(_dev->driver);
 	if (drv->shutdown)
 		drv->shutdown(dev);
 }
Signature · 1 line
2.29.2
Reviewed-by on v3 1/1
#2 lore raw
In reply to Dmitry Baryshkov
Quoted 10 lines · Dmitry Baryshkov

On shutdown the driver core calls the bus' shutdown callback also for unbound devices. A driver's shutdown callback however is only called for devices bound to this driver. Commit 9c30921fe799 ("driver core:
platform: use bus_type functions") changed the platform bus from driver callbacks to bus callbacks, so the shutdown function must be prepared to be called without a driver. Add the corresponding check in the shutdown function.

Fixes 9c30921fe799 ("driver core: platform: use bus_type functions")

nice commit log :-)

Thanks
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |