[<prev] [next>] [day] [month] [year] [list]
Message-ID: <CAN2+FELU6ZprSLOU5GYXHq1-jQDHBKaDC98fRuqBWwQkPXmtwA@mail.gmail.com>
Date: Sun, 5 Oct 2014 18:14:52 -0400
From: Jason Noakes <jjnoakes@...il.com>
To: Greg KH <gregkh@...uxfoundation.org>
Cc: linux-kernel <linux-kernel@...r.kernel.org>
Subject: [PATCH] Add zero-object requirement to kobject documentation
Explicitly document the requirement that the memory passed to
kobject_init() must be zero-initialized beforehand.
Signed-off-by: Jason J. Noakes <jjnoakes@...il.com>
diff --git a/Documentation/kobject.txt b/Documentation/kobject.txt
index f87241d..1b38727 100644
--- a/Documentation/kobject.txt
+++ b/Documentation/kobject.txt
@@ -113,8 +113,14 @@ question. That macro is subsequently invoked with:
Initialization of kobjects
-Code which creates a kobject must, of course, initialize that object. Some
-of the internal fields are setup with a (mandatory) call to kobject_init():
+Code which creates a kobject must, of course, initialize that object.
+
+First, ensure the memory for the kobject is initialized to zero; this is
+typically accomplished by obtaining the memory for the kobject (and the
+structure it is embedded in) from a call to kzalloc().
+
+Then, some of the internal fields must be setup with a (mandatory) call
+to kobject_init():
void kobject_init(struct kobject *kobj, struct kobj_type *ktype);
diff --git a/lib/kobject.c b/lib/kobject.c
index 58751bb..46fc865 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -307,6 +307,8 @@ EXPORT_SYMBOL(kobject_set_name);
* This function will properly initialize a kobject such that it can then
* be passed to the kobject_add() call.
*
+ * The kobject must be initialized to zero prior to calling this function.
+ *
* After this function is called, the kobject MUST be cleaned up by a call
* to kobject_put(), not by a call to kfree directly to ensure that all of
* the memory is cleaned up properly.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists