diff options
| author | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-10-12 18:49:37 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-10-12 18:49:37 -0400 |
| commit | efefc6eb38d43b8e5daef482f575d767b002004e (patch) | |
| tree | 8a3933db1f8721f9bcc9912c800dc8406f4bdf94 /lib | |
| parent | 117494a1b65183f0e3fcc817b07944bc5c465050 (diff) | |
| parent | cd59abfcc441b2abb4cf2cd62c1eb0f02a60e8dd (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: (75 commits)
PM: merge device power-management source files
sysfs: add copyrights
kobject: update the copyrights
kset: add some kerneldoc to help describe what these strange things are
Driver core: rename ktype_edd and ktype_efivar
Driver core: rename ktype_driver
Driver core: rename ktype_device
Driver core: rename ktype_class
driver core: remove subsystem_init()
sysfs: move sysfs file poll implementation to sysfs_open_dirent
sysfs: implement sysfs_open_dirent
sysfs: move sysfs_dirent->s_children into sysfs_dirent->s_dir
sysfs: make sysfs_root a regular directory dirent
sysfs: open code sysfs_attach_dentry()
sysfs: make s_elem an anonymous union
sysfs: make bin attr open get active reference of parent too
sysfs: kill unnecessary NULL pointer check in sysfs_release()
sysfs: kill unnecessary sysfs_get() in open paths
sysfs: reposition sysfs_dirent->s_mode.
sysfs: kill sysfs_update_file()
...
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Makefile | 3 | ||||
| -rw-r--r-- | lib/kobject.c | 135 | ||||
| -rw-r--r-- | lib/kobject_uevent.c | 216 |
3 files changed, 163 insertions, 191 deletions
diff --git a/lib/Makefile b/lib/Makefile index 4f3f3e256501..6c4ea33bb2cb 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
| @@ -10,7 +10,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \ | |||
| 10 | lib-$(CONFIG_MMU) += ioremap.o | 10 | lib-$(CONFIG_MMU) += ioremap.o |
| 11 | lib-$(CONFIG_SMP) += cpumask.o | 11 | lib-$(CONFIG_SMP) += cpumask.o |
| 12 | 12 | ||
| 13 | lib-y += kobject.o kref.o kobject_uevent.o klist.o | 13 | lib-y += kobject.o kref.o klist.o |
| 14 | 14 | ||
| 15 | obj-y += div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ | 15 | obj-y += div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ |
| 16 | bust_spinlocks.o hexdump.o kasprintf.o | 16 | bust_spinlocks.o hexdump.o kasprintf.o |
| @@ -20,6 +20,7 @@ CFLAGS_kobject.o += -DDEBUG | |||
| 20 | CFLAGS_kobject_uevent.o += -DDEBUG | 20 | CFLAGS_kobject_uevent.o += -DDEBUG |
| 21 | endif | 21 | endif |
| 22 | 22 | ||
| 23 | lib-$(CONFIG_HOTPLUG) += kobject_uevent.o | ||
| 23 | obj-$(CONFIG_GENERIC_IOMAP) += iomap.o | 24 | obj-$(CONFIG_GENERIC_IOMAP) += iomap.o |
| 24 | obj-$(CONFIG_HAS_IOMEM) += iomap_copy.o devres.o | 25 | obj-$(CONFIG_HAS_IOMEM) += iomap_copy.o devres.o |
| 25 | obj-$(CONFIG_CHECK_SIGNATURE) += check_signature.o | 26 | obj-$(CONFIG_CHECK_SIGNATURE) += check_signature.o |
diff --git a/lib/kobject.c b/lib/kobject.c index 4b08e0ff95c8..03d40360ff1b 100644 --- a/lib/kobject.c +++ b/lib/kobject.c | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | * kobject.c - library routines for handling generic kernel objects | 2 | * kobject.c - library routines for handling generic kernel objects |
| 3 | * | 3 | * |
| 4 | * Copyright (c) 2002-2003 Patrick Mochel <mochel@osdl.org> | 4 | * Copyright (c) 2002-2003 Patrick Mochel <mochel@osdl.org> |
| 5 | * Copyright (c) 2006-2007 Greg Kroah-Hartman <greg@kroah.com> | ||
| 6 | * Copyright (c) 2006-2007 Novell Inc. | ||
| 5 | * | 7 | * |
| 6 | * This file is released under the GPLv2. | 8 | * This file is released under the GPLv2. |
| 7 | * | 9 | * |
| @@ -44,11 +46,11 @@ static int populate_dir(struct kobject * kobj) | |||
| 44 | return error; | 46 | return error; |
| 45 | } | 47 | } |
| 46 | 48 | ||
| 47 | static int create_dir(struct kobject *kobj, struct sysfs_dirent *shadow_parent) | 49 | static int create_dir(struct kobject * kobj) |
| 48 | { | 50 | { |
| 49 | int error = 0; | 51 | int error = 0; |
| 50 | if (kobject_name(kobj)) { | 52 | if (kobject_name(kobj)) { |
| 51 | error = sysfs_create_dir(kobj, shadow_parent); | 53 | error = sysfs_create_dir(kobj); |
| 52 | if (!error) { | 54 | if (!error) { |
| 53 | if ((error = populate_dir(kobj))) | 55 | if ((error = populate_dir(kobj))) |
| 54 | sysfs_remove_dir(kobj); | 56 | sysfs_remove_dir(kobj); |
| @@ -131,7 +133,6 @@ void kobject_init(struct kobject * kobj) | |||
| 131 | return; | 133 | return; |
| 132 | kref_init(&kobj->kref); | 134 | kref_init(&kobj->kref); |
| 133 | INIT_LIST_HEAD(&kobj->entry); | 135 | INIT_LIST_HEAD(&kobj->entry); |
| 134 | init_waitqueue_head(&kobj->poll); | ||
| 135 | kobj->kset = kset_get(kobj->kset); | 136 | kobj->kset = kset_get(kobj->kset); |
| 136 | } | 137 | } |
| 137 | 138 | ||
| @@ -157,12 +158,11 @@ static void unlink(struct kobject * kobj) | |||
| 157 | } | 158 | } |
| 158 | 159 | ||
| 159 | /** | 160 | /** |
| 160 | * kobject_shadow_add - add an object to the hierarchy. | 161 | * kobject_add - add an object to the hierarchy. |
| 161 | * @kobj: object. | 162 | * @kobj: object. |
| 162 | * @shadow_parent: sysfs directory to add to. | ||
| 163 | */ | 163 | */ |
| 164 | 164 | ||
| 165 | int kobject_shadow_add(struct kobject *kobj, struct sysfs_dirent *shadow_parent) | 165 | int kobject_add(struct kobject * kobj) |
| 166 | { | 166 | { |
| 167 | int error = 0; | 167 | int error = 0; |
| 168 | struct kobject * parent; | 168 | struct kobject * parent; |
| @@ -170,7 +170,7 @@ int kobject_shadow_add(struct kobject *kobj, struct sysfs_dirent *shadow_parent) | |||
| 170 | if (!(kobj = kobject_get(kobj))) | 170 | if (!(kobj = kobject_get(kobj))) |
| 171 | return -ENOENT; | 171 | return -ENOENT; |
| 172 | if (!kobj->k_name) | 172 | if (!kobj->k_name) |
| 173 | kobj->k_name = kobj->name; | 173 | kobject_set_name(kobj, "NO_NAME"); |
| 174 | if (!*kobj->k_name) { | 174 | if (!*kobj->k_name) { |
| 175 | pr_debug("kobject attempted to be registered with no name!\n"); | 175 | pr_debug("kobject attempted to be registered with no name!\n"); |
| 176 | WARN_ON(1); | 176 | WARN_ON(1); |
| @@ -181,7 +181,7 @@ int kobject_shadow_add(struct kobject *kobj, struct sysfs_dirent *shadow_parent) | |||
| 181 | 181 | ||
| 182 | pr_debug("kobject %s: registering. parent: %s, set: %s\n", | 182 | pr_debug("kobject %s: registering. parent: %s, set: %s\n", |
| 183 | kobject_name(kobj), parent ? kobject_name(parent) : "<NULL>", | 183 | kobject_name(kobj), parent ? kobject_name(parent) : "<NULL>", |
| 184 | kobj->kset ? kobj->kset->kobj.name : "<NULL>" ); | 184 | kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>" ); |
| 185 | 185 | ||
| 186 | if (kobj->kset) { | 186 | if (kobj->kset) { |
| 187 | spin_lock(&kobj->kset->list_lock); | 187 | spin_lock(&kobj->kset->list_lock); |
| @@ -194,7 +194,7 @@ int kobject_shadow_add(struct kobject *kobj, struct sysfs_dirent *shadow_parent) | |||
| 194 | kobj->parent = parent; | 194 | kobj->parent = parent; |
| 195 | } | 195 | } |
| 196 | 196 | ||
| 197 | error = create_dir(kobj, shadow_parent); | 197 | error = create_dir(kobj); |
| 198 | if (error) { | 198 | if (error) { |
| 199 | /* unlink does the kobject_put() for us */ | 199 | /* unlink does the kobject_put() for us */ |
| 200 | unlink(kobj); | 200 | unlink(kobj); |
| @@ -216,16 +216,6 @@ int kobject_shadow_add(struct kobject *kobj, struct sysfs_dirent *shadow_parent) | |||
| 216 | } | 216 | } |
| 217 | 217 | ||
| 218 | /** | 218 | /** |
| 219 | * kobject_add - add an object to the hierarchy. | ||
| 220 | * @kobj: object. | ||
| 221 | */ | ||
| 222 | int kobject_add(struct kobject * kobj) | ||
| 223 | { | ||
| 224 | return kobject_shadow_add(kobj, NULL); | ||
| 225 | } | ||
| 226 | |||
| 227 | |||
| 228 | /** | ||
| 229 | * kobject_register - initialize and add an object. | 219 | * kobject_register - initialize and add an object. |
| 230 | * @kobj: object in question. | 220 | * @kobj: object in question. |
| 231 | */ | 221 | */ |
| @@ -255,54 +245,50 @@ int kobject_register(struct kobject * kobj) | |||
| 255 | int kobject_set_name(struct kobject * kobj, const char * fmt, ...) | 245 | int kobject_set_name(struct kobject * kobj, const char * fmt, ...) |
| 256 | { | 246 | { |
| 257 | int error = 0; | 247 | int error = 0; |
| 258 | int limit = KOBJ_NAME_LEN; | 248 | int limit; |
| 259 | int need; | 249 | int need; |
| 260 | va_list args; | 250 | va_list args; |
| 261 | char * name; | 251 | char *name; |
| 262 | 252 | ||
| 263 | /* | 253 | /* find out how big a buffer we need */ |
| 264 | * First, try the static array | 254 | name = kmalloc(1024, GFP_KERNEL); |
| 265 | */ | 255 | if (!name) { |
| 266 | va_start(args,fmt); | 256 | error = -ENOMEM; |
| 267 | need = vsnprintf(kobj->name,limit,fmt,args); | 257 | goto done; |
| 258 | } | ||
| 259 | va_start(args, fmt); | ||
| 260 | need = vsnprintf(name, 1024, fmt, args); | ||
| 268 | va_end(args); | 261 | va_end(args); |
| 269 | if (need < limit) | 262 | kfree(name); |
| 270 | name = kobj->name; | 263 | |
| 271 | else { | 264 | /* Allocate the new space and copy the string in */ |
| 272 | /* | 265 | limit = need + 1; |
| 273 | * Need more space? Allocate it and try again | 266 | name = kmalloc(limit, GFP_KERNEL); |
| 274 | */ | 267 | if (!name) { |
| 275 | limit = need + 1; | 268 | error = -ENOMEM; |
| 276 | name = kmalloc(limit,GFP_KERNEL); | 269 | goto done; |
| 277 | if (!name) { | 270 | } |
| 278 | error = -ENOMEM; | 271 | va_start(args, fmt); |
| 279 | goto Done; | 272 | need = vsnprintf(name, limit, fmt, args); |
| 280 | } | 273 | va_end(args); |
| 281 | va_start(args,fmt); | 274 | |
| 282 | need = vsnprintf(name,limit,fmt,args); | 275 | /* something wrong with the string we copied? */ |
| 283 | va_end(args); | 276 | if (need >= limit) { |
| 284 | 277 | kfree(name); | |
| 285 | /* Still? Give up. */ | 278 | error = -EFAULT; |
| 286 | if (need >= limit) { | 279 | goto done; |
| 287 | kfree(name); | ||
| 288 | error = -EFAULT; | ||
| 289 | goto Done; | ||
| 290 | } | ||
| 291 | } | 280 | } |
| 292 | 281 | ||
| 293 | /* Free the old name, if necessary. */ | 282 | /* Free the old name, if necessary. */ |
| 294 | if (kobj->k_name && | ||
