Skip to contentSkip to conversation

driver core: Clarify which counterparts to use to device_add()

PATCH In review Borislav Petkov 2 participants 2 messages Apr 18, 2019 Driver core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 driver core: Clarify which counterparts to use to device_add()

From: Borislav Petkov <[email protected]>

It is not absolutely clear from the docs how the cleanup path after device_add() should look like so spell it out explicitly.

No functional changes, just documentation.

Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
---
 drivers/base/core.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/base/core.c +5 -0
index 4aeaa0c92bda..fd7511e04e62 100644
@@ -1999,6 +1999,11 @@ static int device_private_init(struct device *dev)
  * NOTE: _Never_ directly free @dev after calling this function, even
  * if it returned an error! Always use put_device() to give up your
  * reference instead.
+ *
+ * Rule of thumb is: if device_add() succeeds, you should call
+ * device_del() when you want to get rid of it. If device_add() has
+ * *not* succeeded, use *only* put_device() to drop the reference
+ * count.
  */
 int device_add(struct device *dev)
 {
Signature · 1 line
2.21.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Borislav Petkov

From: Borislav Petkov <[email protected]>

It is not absolutely clear from the docs how the cleanup path after device_add() should look like so spell it out explicitly.

No functional changes, just documentation.

Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Quoted 23 lines
---
 drivers/base/core.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/base/core.c +5 -1
index 4aeaa0c92bda..fd7511e04e62 100644
@@ -1999,6 +1999,11 @@ static int device_private_init(struct device *dev)
  * NOTE: _Never_ directly free @dev after calling this function, even
  * if it returned an error! Always use put_device() to give up your
  * reference instead.
+ *
+ * Rule of thumb is: if device_add() succeeds, you should call
+ * device_del() when you want to get rid of it. If device_add() has
+ * *not* succeeded, use *only* put_device() to drop the reference
+ * count.
  */
 int device_add(struct device *dev)
 {
--

2.21.0