Skip to contentSkip to conversation

backports: fix device_release_driver

PATCH Applied Johannes Berg 2 participants 2 messages Aug 7, 2013 – Aug 13, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 backports: fix device_release_driver

From: Johannes Berg <[email protected]>

The new macro, introduced by

commit 9f5876fa9cfb8cd6f450c200043ca7e31915f976

Author: Luis R. Rodriguez <[email protected]>
Date:   Thu Jul 18 16:40:55 2013 -0700

backports: backport drvdata = NULL core driver fixes

evaluates its argument multiple times, causing crashes as there are potential side-effects of the called code and/or the arguments.

Fix this by converting it to static inlines.

Also remove the driver_probe_device() macro that has the same issue, but tries to wrap a function that isn't even available outside the driver core code in any kernel.

---
 backport/backport-include/linux/device.h | 25 +++++++++----------------
 1 file changed, 9 insertions(+), 16 deletions(-)
backport/backport-include/linux/device.h +9 -16
index ba55d0e..909a534 100644
@@ -177,22 +177,15 @@ extern int dev_set_name(struct device *dev, const char *name, ...)
 #endif
 
 #if LINUX_VERSION_CODE <= KERNEL_VERSION(3,6,0)
-#define driver_probe_device(__drv, __dev)		\
-({							\
- 	int ret;					\
- 	ret = (driver_probe_device)(__drv, __dev);	\
- 	if (ret)					\
-		dev_set_drvdata(__dev, NULL);		\
- 	return ret;					\
-})
-
-#define device_release_driver(__dev)			\
-({							\
- 	(device_release_driver)(__dev);			\
- 	device_lock(__dev);				\
- 	dev_set_drvdata(__dev, NULL);			\
- 	device_unlock(__dev);				\
-})
+static inline void
+backport_device_release_driver(struct device *dev)
+{
+	device_release_driver(dev);
+	device_lock(dev);
+	dev_set_drvdata(dev, NULL);
+	device_unlock(dev);
+}
+#define device_release_driver LINUX_BACKPORT(device_release_driver)
 #endif /* LINUX_VERSION_CODE <= KERNEL_VERSION(3,6,0) */
 
 #endif /* __BACKPORT_DEVICE_H */
Signature · 1 line
1.8.0
#1 lore raw
Quoted 14 lines · Johannes Berg

From: Johannes Berg <[email protected]>

The new macro, introduced by

commit 9f5876fa9cfb8cd6f450c200043ca7e31915f976

Author: Luis R. Rodriguez <[email protected]>
Date:   Thu Jul 18 16:40:55 2013 -0700

backports: backport drvdata = NULL core driver fixes

evaluates its argument multiple times, causing crashes as there are potential side-effects of the called code and/or the arguments.

Quoted 7 lines

Fix this by converting it to static inlines.

Also remove the driver_probe_device() macro that has the same issue, but tries to wrap a function that isn't even available outside the driver core code in any kernel.

Thanks, applied and pushed!

Luis