blob: b5b190d736b3b92e5aa877c2149b7b9f3d40b044 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
---
lib/kobject.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -191,6 +191,41 @@ void kobject_init(struct kobject * kobj)
INIT_LIST_HEAD(&kobj->entry);
}
+/**
+ * kobject_init - initialize a kobject structure
+ * @kobj: pointer to the kobject to initialize
+ * @ktype: pointer to the ktype for this kobject.
+ * @fmt: the name of the kobject
+ *
+ * This function will properly initialize a kobject such that it can then
+ * be passed to the kobject_add() call.
+ *
+ * If the function returns an error, the memory allocated by the kobject
+ * can be safely freed, no other functions need to be called.
+ */
+int kobject_i(struct kobject *kobj, struct kobj_type *ktype, const char *fmt, ...)
+{
+ va_list args;
+ int retval;
+
+ if (!kobj)
+ return -EINVAL;
+
+ if (!ktype)
+ return -EINVAL;
+
+ WARN_ON(atomic_read(&kobj->kref.refcount));
+ kref_init(&kobj->kref);
+ INIT_LIST_HEAD(&kobj->entry);
+ kobj->ktype = ktype;
+
+ va_start(args, fmt);
+ retval = kobject_set_name_vargs(kobj, fmt, args);
+ va_end(args);
+
+ return retval;
+}
+
/**
* unlink - remove kobject from kset list.
|