return error;
}
-
static inline struct kobject * to_kobj(struct list_head * entry)
{
return container_of(entry,struct kobject,entry);
}
-
-#ifdef CONFIG_HOTPLUG
static int get_kobj_path_length(struct kset *kset, struct kobject *kobj)
{
int length = 1;
pr_debug("%s: path = '%s'\n",__FUNCTION__,path);
}
+/**
+ * kobject_get_path - generate and return the path associated with a given kobj
+ * and kset pair. The result must be freed by the caller with kfree().
+ *
+ * @kset: kset in question, with which to build the path
+ * @kobj: kobject in question, with which to build the path
+ * @gfp_mask: the allocation type used to allocate the path
+ */
+char * kobject_get_path(struct kset *kset, struct kobject *kobj, int gfp_mask)
+{
+ char *path;
+ int len;
+
+ len = get_kobj_path_length(kset, kobj);
+ path = kmalloc(len, gfp_mask);
+ if (!path)
+ return NULL;
+ memset(path, 0x00, len);
+ fill_kobj_path(kset, kobj, path, len);
+
+ return path;
+}
+
+#ifdef CONFIG_HOTPLUG
+
#define BUFFER_SIZE 1024 /* should be enough memory for the env */
#define NUM_ENVP 32 /* number of env pointers */
static unsigned long sequence_num;
char *scratch;
int i = 0;
int retval;
- int kobj_path_length;
char *kobj_path = NULL;
char *name = NULL;
unsigned long seq;
envp [i++] = scratch;
scratch += sprintf(scratch, "SEQNUM=%ld", seq) + 1;
- kobj_path_length = get_kobj_path_length (kset, kobj);
- kobj_path = kmalloc (kobj_path_length, GFP_KERNEL);
+ kobj_path = kobject_get_path(kset, kobj, GFP_KERNEL);
if (!kobj_path)
goto exit;
- memset (kobj_path, 0x00, kobj_path_length);
- fill_kobj_path (kset, kobj, kobj_path, kobj_path_length);
envp [i++] = scratch;
scratch += sprintf (scratch, "DEVPATH=%s", kobj_path) + 1;
* kobject_init - initialize object.
* @kobj: object in question.
*/
-
void kobject_init(struct kobject * kobj)
{
- atomic_set(&kobj->refcount,1);
+ kref_init(&kobj->kref);
INIT_LIST_HEAD(&kobj->entry);
kobj->kset = kset_get(kobj->kset);
}
* @kobj: object.
* @name: name.
*
- * If strlen(name) < KOBJ_NAME_LEN, then use a dynamically allocated
+ * If strlen(name) >= KOBJ_NAME_LEN, then use a dynamically allocated
* string that @kobj->k_name points to. Otherwise, use the static
* @kobj->name array.
*/
struct kobject * kobject_get(struct kobject * kobj)
{
- if (kobj) {
- WARN_ON(!atomic_read(&kobj->refcount));
- atomic_inc(&kobj->refcount);
- }
+ if (kobj)
+ kref_get(&kobj->kref);
return kobj;
}
kobject_put(parent);
}
+static void kobject_release(struct kref *kref)
+{
+ kobject_cleanup(container_of(kref, struct kobject, kref));
+}
+
/**
* kobject_put - decrement refcount for object.
* @kobj: object.
*
* Decrement the refcount, and if 0, call kobject_cleanup().
*/
-
void kobject_put(struct kobject * kobj)
{
- if (atomic_dec_and_test(&kobj->refcount))
- kobject_cleanup(kobj);
+ if (kobj)
+ kref_put(&kobj->kref, kobject_release);
}
}
}
-
+EXPORT_SYMBOL(kobject_get_path);
EXPORT_SYMBOL(kobject_init);
EXPORT_SYMBOL(kobject_register);
EXPORT_SYMBOL(kobject_unregister);