aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@woody.linux-foundation.org>2007-04-27 12:58:54 -0700
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-04-27 12:58:54 -0700
commitd868772fff6c4b881d66af8640251714e1aefa98 (patch)
treec95a68d358d5c875d25763ffe9a44fe9f2081f34 /lib
parenta205752d1ad2d37d6597aaae5a56fc396a770868 (diff)
parent404d5b185b4eb56d6fa2f7bd27833f8df1c38ce4 (diff)
Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-2.6
* master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-2.6: (46 commits) dev_dbg: check dev_dbg() arguments drivers/base/attribute_container.c: use mutex instead of binary semaphore mod_sysfs_setup() doesn't return errno when kobject_add_dir() failure occurs s2ram: add arch irq disable/enable hooks define platform wakeup hook, use in pci_enable_wake() security: prevent permission checking of file removal via sysfs_remove_group() device_schedule_callback() needs a module reference s390: cio: Delay uevents for subchannels sysfs: bin.c printk fix Driver core: use mutex instead of semaphore in DMA pool handler driver core: bus_add_driver should return an error if no bus debugfs: Add debugfs_create_u64() the overdue removal of the mount/umount uevents kobject: Comment and warning fixes to kobject.c Driver core: warn when userspace writes to the uevent file in a non-supported way Driver core: make uevent-environment available in uevent-file kobject core: remove rwsem from struct subsystem qeth: Remove usage of subsys.rwsem PHY: remove rwsem use from phy core IEEE1394: remove rwsem use from ieee1394 core ...
Diffstat (limited to 'lib')
-rw-r--r--lib/kobject.c62
-rw-r--r--lib/kobject_uevent.c26
-rw-r--r--lib/kref.c2
3 files changed, 67 insertions, 23 deletions
diff --git a/lib/kobject.c b/lib/kobject.c
index 057921c5945..cecf2fbede3 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -157,7 +157,7 @@ static void unlink(struct kobject * kobj)
}
/**
- * kobject_add - add an object to the hierarchy.
+ * kobject_shadow_add - add an object to the hierarchy.
* @kobj: object.
* @shadow_parent: sysfs directory to add to.
*/
@@ -174,6 +174,7 @@ int kobject_shadow_add(struct kobject * kobj, struct dentry *shadow_parent)
if (!*kobj->k_name) {
pr_debug("kobject attempted to be registered with no name!\n");
WARN_ON(1);
+ kobject_put(kobj);
return -EINVAL;
}
parent = kobject_get(kobj->parent);
@@ -190,8 +191,8 @@ int kobject_shadow_add(struct kobject * kobj, struct dentry *shadow_parent)
list_add_tail(&kobj->entry,&kobj->kset->list);
spin_unlock(&kobj->kset->list_lock);
+ kobj->parent = parent;
}
- kobj->parent = parent;
error = create_dir(kobj, shadow_parent);
if (error) {
@@ -311,13 +312,43 @@ EXPORT_SYMBOL(kobject_set_name);
int kobject_rename(struct kobject * kobj, const char *new_name)
{
int error = 0;
+ const char *devpath = NULL;
+ char *devpath_string = NULL;
+ char *envp[2];
kobj = kobject_get(kobj);
if (!kobj)
return -EINVAL;
if (!kobj->parent)
return -EINVAL;
+
+ devpath = kobject_get_path(kobj, GFP_KERNEL);
+ if (!devpath) {
+ error = -ENOMEM;
+ goto out;
+ }
+ devpath_string = kmalloc(strlen(devpath) + 15, GFP_KERNEL);
+ if (!devpath_string) {
+ error = -ENOMEM;
+ goto out;
+ }
+ sprintf(devpath_string, "DEVPATH_OLD=%s", devpath);
+ envp[0] = devpath_string;
+ envp[1] = NULL;
+ /* Note : if we want to send the new name alone, not the full path,
+ * we could probably use kobject_name(kobj); */
+
error = sysfs_rename_dir(kobj, kobj->parent->dentry, new_name);
+
+ /* This function is mostly/only used for network interface.
+ * Some hotplug package track interfaces by their name and
+ * therefore want to know when the name is changed by the user. */
+ if (!error)
+ kobject_uevent_env(kobj, KOBJ_MOVE, envp);
+
+out:
+ kfree(devpath_string);
+ kfree(devpath);
kobject_put(kobj);
return error;
@@ -488,13 +519,15 @@ static struct kobj_type dir_ktype = {
};
/**
- * kobject_add_dir - add sub directory of object.
+ * kobject_kset_add_dir - add sub directory of object.
+ * @kset: kset the directory is belongs to.
* @parent: object in which a directory is created.
* @name: directory name.
*
* Add a plain directory object as child of given object.
*/
-struct kobject *kobject_add_dir(struct kobject *parent, const char *name)
+struct kobject *kobject_kset_add_dir(struct kset *kset,
+ struct kobject *parent, const char *name)
{
struct kobject *k;
int ret;
@@ -506,13 +539,14 @@ struct kobject *kobject_add_dir(struct kobject *parent, const char *name)
if (!k)
return NULL;
+ k->kset = kset;
k->parent = parent;
k->ktype = &dir_ktype;
kobject_set_name(k, name);
ret = kobject_register(k);
if (ret < 0) {
- printk(KERN_WARNING "kobject_add_dir: "
- "kobject_register error: %d\n", ret);
+ printk(KERN_WARNING "%s: kobject_register error: %d\n",
+ __func__, ret);
kobject_del(k);
return NULL;
}
@@ -521,6 +555,18 @@ struct kobject *kobject_add_dir(struct kobject *parent, const char *name)
}
/**
+ * kobject_add_dir - add sub directory of object.
+ * @parent: object in which a directory is created.
+ * @name: directory name.
+ *
+ * Add a plain directory object as child of given object.
+ */
+struct kobject *kobject_add_dir(struct kobject *parent, const char *name)
+{
+ return kobject_kset_add_dir(NULL, parent, name);
+}
+
+/**
* kset_init - initialize a kset for use
* @k: kset
*/
@@ -613,7 +659,6 @@ struct kobject * kset_find_obj(struct kset * kset, const char * name)
void subsystem_init(struct subsystem * s)
{
- init_rwsem(&s->rwsem);
kset_init(&s->kset);
}
@@ -622,8 +667,7 @@ void subsystem_init(struct subsystem * s)
* @s: the subsystem we're registering.
*
* Once we register the subsystem, we want to make sure that
- * the kset points back to this subsystem for correct usage of
- * the rwsem.
+ * the kset points back to this subsystem.
*/
int subsystem_register(struct subsystem * s)
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index 82fc1794b69..12e311dc664 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -42,10 +42,6 @@ static char *action_to_string(enum kobject_action action)
return "remove";
case KOBJ_CHANGE:
return "change";
- case KOBJ_MOUNT:
- return "mount";
- case KOBJ_UMOUNT:
- return "umount";
case KOBJ_OFFLINE:
return "offline";
case KOBJ_ONLINE:
@@ -95,10 +91,8 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
/* search the kset we belong to */
top_kobj = kobj;
- if (!top_kobj->kset && top_kobj->parent) {
- do {
- top_kobj = top_kobj->parent;
- } while (!top_kobj->kset && top_kobj->parent);
+ while (!top_kobj->kset && top_kobj->parent) {
+ top_kobj = top_kobj->parent;
}
if (!top_kobj->kset) {
pr_debug("kobject attempted to send uevent without kset!\n");
@@ -115,6 +109,16 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
return 0;
}
+ /* originating subsystem */
+ if (uevent_ops && uevent_ops->name)
+ subsystem = uevent_ops->name(kset, kobj);
+ else
+ subsystem = kobject_name(&kset->kobj);
+ if (!subsystem) {
+ pr_debug("unset subsytem caused the event to drop!\n");
+ return 0;
+ }
+
/* environment index */
envp = kzalloc(NUM_ENVP * sizeof (char *), GFP_KERNEL);
if (!envp)
@@ -134,12 +138,6 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
goto exit;
}
- /* originating subsystem */
- if (uevent_ops && uevent_ops->name)
- subsystem = uevent_ops->name(kset, kobj);
- else
- subsystem = kobject_name(&kset->kobj);
-
/* event environemnt for helper process only */
envp[i++] = "HOME=/";
envp[i++] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
diff --git a/lib/kref.c b/lib/kref.c
index 0d07cc31c81..a6dc3ec328e 100644
--- a/lib/kref.c
+++ b/lib/kref.c
@@ -21,6 +21,7 @@
void kref_init(struct kref *kref)
{
atomic_set(&kref->refcount,1);
+ smp_mb();
}
/**
@@ -31,6 +32,7 @@ void kref_get(struct kref *kref)
{
WARN_ON(!atomic_read(&kref->refcount));
atomic_inc(&kref->refcount);
+ smp_mb__after_atomic_inc();
}
/**