Skip to contentSkip to conversation

driver core: platform: document registration-failure requirement

PATCH Superseded Johan Hovold 1 participant 2 messages Dec 22, 2021 Driver core

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Johan Hovold

author maintainer
#0 lore raw

PATCH 1/1 driver core: platform: document registration-failure requirement

Add an explicit comment to document that the reference initialised by platform_device_register() needs to be released by a call to platform_device_put() also when registration fails (cf. device_register()).

---
 drivers/base/platform.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/base/platform.c +4 -0
index 598acf93a360..38fdcbdba4a4 100644
@@ -762,6 +762,10 @@ EXPORT_SYMBOL_GPL(platform_device_del);
 /**
  * platform_device_register - add a platform-level device
  * @pdev: platform device we're adding
+ *
+ * NOTE: _Never_ directly free @pdev after calling this function, even if it
+ * returned an error! Always use platform_put_device() to give up the
+ * reference initialised in this function instead.
  */
 int platform_device_register(struct platform_device *pdev)
 {
Signature · 1 line
2.32.0
author maintainer
#1 lore raw
Quoted 15 lines · Johan Hovold

Add an explicit comment to document that the reference initialised by platform_device_register() needs to be released by a call to platform_device_put() also when registration fails (cf. device_register()).

---
 drivers/base/platform.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/base/platform.c +0 -0
index 598acf93a360..38fdcbdba4a4 100644

drivers/base/platform.c EXPORT_SYMBOL_GPL(platform_device_del); · line 767

Quoted 6 lines
drivers/base/platform.c +3 -0
@@ -762,6 +762,10 @@ EXPORT_SYMBOL_GPL(platform_device_del);
 /**
  * platform_device_register - add a platform-level device
  * @pdev: platform device we're adding
+ *
+ * NOTE: _Never_ directly free @pdev after calling this function, even if it
+ * returned an error! Always use platform_put_device() to give up the

This should have been platform_device_put().

Greg, I'll send a v2 for you to consider since this documents the current behaviour even if you wanted to look into ways to change this.

drivers/base/platform.c EXPORT_SYMBOL_GPL(platform_device_del); · line 771

Quoted 4 lines
drivers/base/platform.c +1 -0
+ * reference initialised in this function instead.
  */
 int platform_device_register(struct platform_device *pdev)
 {

Johan