Skip to contentSkip to conversation

kobject: Improve doc clarity kobject_init_and_add()

PATCH In review Tobin C. Harding 2 participants 2 messages Apr 27, 2019 – Apr 29, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kobject: Improve doc clarity kobject_init_and_add()

Function kobject_init_and_add() is currently misused in a number of places in the kernel. On error return kobject_put() must be called but is at times not.

Make the function documentation more explicit about calling kobject_put() in the error path.

---
 lib/kobject.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
lib/kobject.c +6 -3
index aa89edcd2b63..58d1d7a64203 100644
@@ -437,9 +437,12 @@ EXPORT_SYMBOL(kobject_add);
  * @parent: pointer to the parent of this kobject.
  * @fmt: the name of the kobject.
  *
- * This function combines the call to kobject_init() and
- * kobject_add().  The same type of error handling after a call to
- * kobject_add() and kobject lifetime rules are the same here.
+ * This function combines the call to kobject_init() and kobject_add().
+ *
+ * If this function returns an error, kobject_put() must be called to
+ * properly clean up the memory associated with the object.  This is the
+ * same type of error handling after a call to kobject_add() and kobject
+ * lifetime rules are the same here.
  */
 int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype,
 			 struct kobject *parent, const char *fmt, ...)
Signature · 1 line
2.21.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Tobin C. Harding

Function kobject_init_and_add() is currently misused in a number of places in the kernel. On error return kobject_put() must be called but is at times not.

Make the function documentation more explicit about calling kobject_put() in the error path.

Quoted 27 lines
---
 lib/kobject.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
lib/kobject.c +6 -4
index aa89edcd2b63..58d1d7a64203 100644
@@ -437,9 +437,12 @@ EXPORT_SYMBOL(kobject_add);
  * @parent: pointer to the parent of this kobject.
  * @fmt: the name of the kobject.
  *
- * This function combines the call to kobject_init() and
- * kobject_add().  The same type of error handling after a call to
- * kobject_add() and kobject lifetime rules are the same here.
+ * This function combines the call to kobject_init() and kobject_add().
+ *
+ * If this function returns an error, kobject_put() must be called to
+ * properly clean up the memory associated with the object.  This is the
+ * same type of error handling after a call to kobject_add() and kobject
+ * lifetime rules are the same here.
  */
 int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype,
                         struct kobject *parent, const char *fmt, ...)
--

2.21.0