diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-04-30 20:05:21 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-04-30 20:05:21 -0400 |
commit | 6de3d58dcfbab516dbe9aff36ea9542f40cd1bf2 (patch) | |
tree | fc5b83ef3a34b40c71e397ee7b1e6c423628e786 | |
parent | e0066c4ea9ffa420cb79814411ff74fdc7b7d98e (diff) | |
parent | c3bb7fadaf52de3637b834002dac27f6250b4b49 (diff) |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-2.6:
klist: fix coding style errors in klist.h and klist.c
driver core: remove no longer used "struct class_device"
pcmcia: remove pccard_sysfs_interface warnings
devres: support addresses greater than an unsigned long via dev_ioremap
kobject: do not copy vargs, just pass them around
sysfs: sysfs_update_group stub for CONFIG_SYSFS=n
DEBUGFS: Correct location of debugfs API documentation.
driver core: warn about duplicate driver names on the same bus
klist: implement klist_add_{after|before}()
klist: implement KLIST_INIT() and DEFINE_KLIST()
sysfs: Disallow truncation of files in sysfs
-rw-r--r-- | drivers/base/base.h | 11 | ||||
-rw-r--r-- | drivers/base/class.c | 638 | ||||
-rw-r--r-- | drivers/base/driver.c | 10 | ||||
-rw-r--r-- | drivers/pcmcia/cs.c | 13 | ||||
-rw-r--r-- | drivers/pcmcia/cs_internal.h | 3 | ||||
-rw-r--r-- | drivers/pcmcia/socket_sysfs.c | 52 | ||||
-rw-r--r-- | fs/debugfs/file.c | 2 | ||||
-rw-r--r-- | fs/sysfs/inode.c | 2 | ||||
-rw-r--r-- | include/linux/device.h | 97 | ||||
-rw-r--r-- | include/linux/io.h | 4 | ||||
-rw-r--r-- | include/linux/klist.h | 40 | ||||
-rw-r--r-- | include/linux/sysfs.h | 6 | ||||
-rw-r--r-- | lib/devres.c | 4 | ||||
-rw-r--r-- | lib/klist.c | 235 | ||||
-rw-r--r-- | lib/kobject.c | 28 |
15 files changed, 201 insertions, 944 deletions
diff --git a/drivers/base/base.h b/drivers/base/base.h index c0444146c09a..2c9ae43e2219 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h | |||
@@ -64,17 +64,6 @@ extern void sysdev_shutdown(void); | |||
64 | extern int sysdev_suspend(pm_message_t state); | 64 | extern int sysdev_suspend(pm_message_t state); |
65 | extern int sysdev_resume(void); | 65 | extern int sysdev_resume(void); |
66 | 66 | ||
67 | static inline struct class_device *to_class_dev(struct kobject *obj) | ||
68 | { | ||
69 | return container_of(obj, struct class_device, kobj); | ||
70 | } | ||
71 | |||
72 | static inline | ||
73 | struct class_device_attribute *to_class_dev_attr(struct attribute *_attr) | ||
74 | { | ||
75 | return container_of(_attr, struct class_device_attribute, attr); | ||
76 | } | ||
77 | |||
78 | extern char *make_class_name(const char *name, struct kobject *kobj); | 67 | extern char *make_class_name(const char *name, struct kobject *kobj); |
79 | 68 | ||
80 | extern int devres_release_all(struct device *dev); | 69 | extern int devres_release_all(struct device *dev); |
diff --git a/drivers/base/class.c b/drivers/base/class.c index b4901799308b..0ef00e8d4153 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c | |||
@@ -179,27 +179,13 @@ static void class_create_release(struct class *cls) | |||
179 | kfree(cls); | 179 | kfree(cls); |
180 | } | 180 | } |
181 | 181 | ||
182 | static void class_device_create_release(struct class_device *class_dev) | ||
183 | { | ||
184 | pr_debug("%s called for %s\n", __func__, class_dev->class_id); | ||
185 | kfree(class_dev); | ||
186 | } | ||
187 | |||
188 | /* needed to allow these devices to have parent class devices */ | ||
189 | static int class_device_create_uevent(struct class_device *class_dev, | ||
190 | struct kobj_uevent_env *env) | ||
191 | { | ||
192 | pr_debug("%s called for %s\n", __func__, class_dev->class_id); | ||
193 | return 0; | ||
194 | } | ||
195 | |||
196 | /** | 182 | /** |
197 | * class_create - create a struct class structure | 183 | * class_create - create a struct class structure |
198 | * @owner: pointer to the module that is to "own" this struct class | 184 | * @owner: pointer to the module that is to "own" this struct class |
199 | * @name: pointer to a string for the name of this class. | 185 | * @name: pointer to a string for the name of this class. |
200 | * | 186 | * |
201 | * This is used to create a struct class pointer that can then be used | 187 | * This is used to create a struct class pointer that can then be used |
202 | * in calls to class_device_create(). | 188 | * in calls to device_create(). |
203 | * | 189 | * |
204 | * Note, the pointer created here is to be destroyed when finished by | 190 | * Note, the pointer created here is to be destroyed when finished by |
205 | * making a call to class_destroy(). | 191 | * making a call to class_destroy(). |
@@ -218,7 +204,6 @@ struct class *class_create(struct module *owner, const char *name) | |||
218 | cls->name = name; | 204 | cls->name = name; |
219 | cls->owner = owner; | 205 | cls->owner = owner; |
220 | cls->class_release = class_create_release; | 206 | cls->class_release = class_create_release; |
221 | cls->release = class_device_create_release; | ||
222 | 207 | ||
223 | retval = class_register(cls); | 208 | retval = class_register(cls); |
224 | if (retval) | 209 | if (retval) |
@@ -246,113 +231,6 @@ void class_destroy(struct class *cls) | |||
246 | class_unregister(cls); | 231 | class_unregister(cls); |
247 | } | 232 | } |
248 | 233 | ||
249 | /* Class Device Stuff */ | ||
250 | |||
251 | int class_device_create_file(struct class_device *class_dev, | ||
252 | const struct class_device_attribute *attr) | ||
253 | { | ||
254 | int error = -EINVAL; | ||
255 | if (class_dev) | ||
256 | error = sysfs_create_file(&class_dev->kobj, &attr->attr); | ||
257 | return error; | ||
258 | } | ||
259 | |||
260 | void class_device_remove_file(struct class_device *class_dev, | ||
261 | const struct class_device_attribute *attr) | ||
262 | { | ||
263 | if (class_dev) | ||
264 | sysfs_remove_file(&class_dev->kobj, &attr->attr); | ||
265 | } | ||
266 | |||
267 | int class_device_create_bin_file(struct class_device *class_dev, | ||
268 | struct bin_attribute *attr) | ||
269 | { | ||
270 | int error = -EINVAL; | ||
271 | if (class_dev) | ||
272 | error = sysfs_create_bin_file(&class_dev->kobj, attr); | ||
273 | return error; | ||
274 | } | ||
275 | |||
276 | void class_device_remove_bin_file(struct class_device *class_dev, | ||
277 | struct bin_attribute *attr) | ||
278 | { | ||
279 | if (class_dev) | ||
280 | sysfs_remove_bin_file(&class_dev->kobj, attr); | ||
281 | } | ||
282 | |||
283 | static ssize_t class_device_attr_show(struct kobject *kobj, | ||
284 | struct attribute *attr, char *buf) | ||
285 | { | ||
286 | struct class_device_attribute *class_dev_attr = to_class_dev_attr(attr); | ||
287 | struct class_device *cd = to_class_dev(kobj); | ||
288 | ssize_t ret = 0; | ||
289 | |||
290 | if (class_dev_attr->show) | ||
291 | ret = class_dev_attr->show(cd, buf); | ||
292 | return ret; | ||
293 | } | ||
294 | |||
295 | static ssize_t class_device_attr_store(struct kobject *kobj, | ||
296 | struct attribute *attr, | ||
297 | const char *buf, size_t count) | ||
298 | { | ||
299 | struct class_device_attribute *class_dev_attr = to_class_dev_attr(attr); | ||
300 | struct class_device *cd = to_class_dev(kobj); | ||
301 | ssize_t ret = 0; | ||
302 | |||
303 | if (class_dev_attr->store) | ||
304 | ret = class_dev_attr->store(cd, buf, count); | ||
305 | return ret; | ||
306 | } | ||
307 | |||
308 | static struct sysfs_ops class_dev_sysfs_ops = { | ||
309 | .show = class_device_attr_show, | ||
310 | .store = class_device_attr_store, | ||
311 | }; | ||
312 | |||
313 | static void class_dev_release(struct kobject *kobj) | ||
314 | { | ||
315 | struct class_device *cd = to_class_dev(kobj); | ||
316 | struct class *cls = cd->class; | ||
317 | |||
318 | pr_debug("device class '%s': release.\n", cd->class_id); | ||
319 | |||
320 | if (cd->release) | ||
321 | cd->release(cd); | ||
322 | else if (cls->release) | ||
323 | cls->release(cd); | ||
324 | else { | ||
325 | printk(KERN_ERR "Class Device '%s' does not have a release() " | ||
326 | "function, it is broken and must be fixed.\n", | ||
327 | cd->class_id); | ||
328 | WARN_ON(1); | ||
329 | } | ||
330 | } | ||
331 | |||
332 | static struct kobj_type class_device_ktype = { | ||
333 | .sysfs_ops = &class_dev_sysfs_ops, | ||
334 | .release = class_dev_release, | ||
335 | }; | ||
336 | |||
337 | static int class_uevent_filter(struct kset *kset, struct kobject *kobj) | ||
338 | { | ||
339 | struct kobj_type *ktype = get_ktype(kobj); | ||
340 | |||
341 | if (ktype == &class_device_ktype) { | ||
342 | struct class_device *class_dev = to_class_dev(kobj); | ||
343 | if (class_dev->class) | ||
344 | return 1; | ||
345 | } | ||
346 | return 0; | ||
347 | } | ||
348 | |||
349 | static const char *class_uevent_name(struct kset *kset, struct kobject *kobj) | ||
350 | { | ||
351 | struct class_device *class_dev = to_class_dev(kobj); | ||
352 | |||
353 | return class_dev->class->name; | ||
354 | } | ||
355 | |||
356 | #ifdef CONFIG_SYSFS_DEPRECATED | 234 | #ifdef CONFIG_SYSFS_DEPRECATED |
357 | char *make_class_name(const char *name, struct kobject *kobj) | 235 | char *make_class_name(const char *name, struct kobject *kobj) |
358 | { | 236 | { |
@@ -370,445 +248,8 @@ char *make_class_name(const char *name, struct kobject *kobj) | |||
370 | strcat(class_name, kobject_name(kobj)); | 248 | strcat(class_name, kobject_name(kobj)); |
371 | return class_name; | 249 | return class_name; |
372 | } | 250 | } |
373 | |||
374 | static int make_deprecated_class_device_links(struct class_device *class_dev) | ||
375 | { | ||
376 | char *class_name; | ||
377 | int error; | ||
378 | |||
379 | if (!class_dev->dev) | ||
380 | return 0; | ||
381 | |||
382 | class_name = make_class_name(class_dev->class->name, &class_dev->kobj); | ||
383 | if (class_name) | ||
384 | error = sysfs_create_link(&class_dev->dev->kobj, | ||
385 | &class_dev->kobj, class_name); | ||
386 | else | ||
387 | error = -ENOMEM; | ||
388 | kfree(class_name); | ||
389 | return error; | ||
390 | } | ||
391 | |||
392 | static void remove_deprecated_class_device_links(struct class_device *class_dev) | ||
393 | { | ||
394 | char *class_name; | ||
395 | |||
396 | if (!class_dev->dev) | ||
397 | return; | ||
398 | |||
399 | class_name = make_class_name(class_dev->class->name, &class_dev->kobj); | ||
400 | if (class_name) | ||
401 | sysfs_remove_link(&class_dev->dev->kobj, class_name); | ||
402 | kfree(class_name); | ||
403 | } | ||
404 | #else | ||
405 | static inline int make_deprecated_class_device_links(struct class_device *cd) | ||
406 | { return 0; } | ||
407 | static void remove_deprecated_class_device_links(struct class_device *cd) | ||
408 | { } | ||
409 | #endif | 251 | #endif |
410 | 252 | ||
411 | static int class_uevent(struct kset *kset, struct kobject *kobj, | ||
412 | struct kobj_uevent_env *env) | ||
413 | { | ||
414 | struct class_device *class_dev = to_class_dev(kobj); | ||
415 | struct device *dev = class_dev->dev; | ||
416 | int retval = 0; | ||
417 | |||
418 | pr_debug("%s - name = %s\n", __func__, class_dev->class_id); | ||
419 | |||
420 | if (MAJOR(class_dev->devt)) { | ||
421 | add_uevent_var(env, "MAJOR=%u", MAJOR(class_dev->devt)); | ||
422 | |||
423 | add_uevent_var(env, "MINOR=%u", MINOR(class_dev->devt)); | ||
424 | } | ||
425 | |||
426 | if (dev) { | ||
427 | const char *path = kobject_get_path(&dev->kobj, GFP_KERNEL); | ||
428 | if (path) { | ||
429 | add_uevent_var(env, "PHYSDEVPATH=%s", path); | ||
430 | kfree(path); | ||
431 | } | ||
432 | |||
433 | if (dev->bus) | ||
434 | add_uevent_var(env, "PHYSDEVBUS=%s", dev->bus->name); | ||
435 | |||
436 | if (dev->driver) | ||
437 | add_uevent_var(env, "PHYSDEVDRIVER=%s", | ||
438 | dev->driver->name); | ||
439 | } | ||
440 | |||
441 | if (class_dev->uevent) { | ||
442 | /* have the class device specific function add its stuff */ | ||
443 | retval = class_dev->uevent(class_dev, env); | ||
444 | if (retval) | ||
445 | pr_debug("class_dev->uevent() returned %d\n", retval); | ||
446 | } else if (class_dev->class->uevent) { | ||
447 | /* have the class specific function add its stuff */ | ||
448 | retval = class_dev->class->uevent(class_dev, env); | ||
449 | if (retval) | ||
450 | pr_debug("class->uevent() returned %d\n", retval); | ||
451 | } | ||
452 | |||
453 | return retval; | ||
454 | } | ||
455 | |||
456 | static struct kset_uevent_ops class_uevent_ops = { | ||
457 | .filter = class_uevent_filter, | ||
458 | .name = class_uevent_name, | ||
459 | .uevent = class_uevent, | ||
460 | }; | ||
461 | |||
462 | /* | ||
463 | * DO NOT copy how this is created, kset_create_and_add() should be | ||
464 | * called, but this is a hold-over from the old-way and will be deleted | ||
465 | * entirely soon. | ||
466 | */ | ||
467 | static struct kset class_obj_subsys = { | ||
468 | .uevent_ops = &class_uevent_ops, | ||
469 | }; | ||
470 | |||
471 | static int class_device_add_attrs(struct class_device *cd) | ||
472 | { | ||
473 | int i; | ||
474 | int error = 0; | ||
475 | struct class *cls = cd->class; | ||
476 | |||
477 | if (cls->class_dev_attrs) { | ||
478 | for (i = 0; attr_name(cls->class_dev_attrs[i]); i++) { | ||
479 | error = class_device_create_file(cd, | ||
480 | &cls->class_dev_attrs[i]); | ||
481 | if (error) | ||
482 | goto err; | ||
483 | } | ||
484 | } | ||
485 | done: | ||
486 | return error; | ||
487 | err: | ||
488 | while (--i >= 0) | ||
489 | class_device_remove_file(cd, &cls->class_dev_attrs[i]); | ||
490 | goto done; | ||
491 | } | ||
492 | |||
493 | static void class_device_remove_attrs(struct class_device *cd) | ||
494 | { | ||
495 | int i; | ||
496 | struct class *cls = cd->class; | ||
497 | |||
498 | if (cls->class_dev_attrs) { | ||
499 | for (i = 0; attr_name(cls->class_dev_attrs[i]); i++) | ||
500 | class_device_remove_file(cd, &cls->class_dev_attrs[i]); | ||
501 | } | ||
502 | } | ||
503 | |||
504 | static int class_device_add_groups(struct class_device *cd) | ||
505 | { | ||
506 | int i; | ||
507 | int error = 0; | ||
508 | |||
509 | if (cd->groups) { | ||
510 | for (i = 0; cd->groups[i]; i++) { | ||
511 | error = sysfs_create_group(&cd->kobj, cd->groups[i]); | ||
512 | if (error) { | ||
513 | while (--i >= 0) | ||
514 | sysfs_remove_group(&cd->kobj, | ||
515 | cd->groups[i]); | ||
516 | goto out; | ||
517 | } | ||
518 | } | ||
519 | } | ||
520 | out: | ||
521 | return error; | ||
522 | } | ||
523 | |||
524 | static void class_device_remove_groups(struct class_device *cd) | ||
525 | { | ||
526 | int i; | ||
527 | if (cd->groups) | ||
528 | for (i = 0; cd->groups[i]; i++) | ||
529 | sysfs_remove_group(&cd->kobj, cd->groups[i]); | ||
530 | } | ||
531 | |||
532 | static ssize_t show_dev(struct class_device *class_dev, char *buf) | ||
533 | { | ||
534 | return print_dev_t(buf, class_dev->devt); | ||
535 | } | ||
536 | |||
537 | static struct class_device_attribute class_devt_attr = | ||
538 | __ATTR(dev, S_IRUGO, show_dev, NULL); | ||
539 | |||
540 | static ssize_t store_uevent(struct class_device *class_dev, | ||
541 | const char *buf, size_t count) | ||
542 | { | ||
543 | kobject_uevent(&class_dev->kobj, KOBJ_ADD); | ||
544 | return count; | ||
545 | } | ||
546 | |||
547 | static struct class_device_attribute class_uevent_attr = | ||
548 | __ATTR(uevent, S_IWUSR, NULL, store_uevent); | ||
549 | |||
550 | void class_device_initialize(struct class_device *class_dev) | ||
551 | { | ||
552 | class_dev->kobj.kset = &class_obj_subsys; | ||
553 | kobject_init(&class_dev->kobj, &class_device_ktype); | ||
554 | INIT_LIST_HEAD(&class_dev->node); | ||
555 | } | ||
556 | |||
557 | int class_device_add(struct class_device *class_dev) | ||
558 | { | ||
559 | struct class *parent_class = NULL; | ||
560 | struct class_device *parent_class_dev = NULL; | ||
561 | struct class_interface *class_intf; | ||
562 | int error = -EINVAL; | ||
563 | |||
564 | class_dev = class_device_get(class_dev); | ||
565 | if (!class_dev) | ||
566 | return -EINVAL; | ||
567 | |||
568 | if (!strlen(class_dev->class_id)) | ||
569 | goto out1; | ||
570 | |||
571 | parent_class = class_get(class_dev->class); | ||
572 | if (!parent_class) | ||
573 | goto out1; | ||
574 | |||
575 | parent_class_dev = class_device_get(class_dev->parent); | ||
576 | |||
577 | pr_debug("CLASS: registering class device: ID = '%s'\n", | ||
578 | class_dev->class_id); | ||
579 | |||
580 | /* first, register with generic layer. */ | ||
581 | if (parent_class_dev) | ||
582 | class_dev->kobj.parent = &parent_class_dev->kobj; | ||
583 | else | ||
584 | class_dev->kobj.parent = &parent_class->subsys.kobj; | ||
585 | |||
586 | error = kobject_add(&class_dev->kobj, class_dev->kobj.parent, | ||
587 | "%s", class_dev->class_id); | ||
588 | if (error) | ||
589 | goto out2; | ||
590 | |||
591 | /* add the needed attributes to this device */ | ||
592 | error = sysfs_create_link(&class_dev->kobj, | ||
593 | &parent_class->subsys.kobj, "subsystem"); | ||
594 | if (error) | ||
595 | goto out3; | ||
596 | |||
597 | error = class_device_create_file(class_dev, &class_uevent_attr); | ||
598 | if (error) | ||
599 | goto out3; | ||
600 | |||
601 | if (MAJOR(class_dev->devt)) { | ||
602 | error = class_device_create_file(class_dev, &class_devt_attr); | ||
603 | if (error) | ||
604 | goto out4; | ||
605 | } | ||
606 | |||
607 | error = class_device_add_attrs(class_dev); | ||
608 | if (error) | ||
609 | goto out5; | ||
610 | |||
611 | if (class_dev->dev) { | ||
612 | error = sysfs_create_link(&class_dev->kobj, | ||
613 | &class_dev->dev->kobj, "device"); | ||
614 | if (error) | ||
615 | goto out6; | ||
616 | } | ||
617 | |||
618 | error = class_device_add_groups(class_dev); | ||
619 | if (error) | ||
620 | goto out7; | ||
621 | |||
622 | error = make_deprecated_class_device_links(class_dev); | ||
623 | if (error) | ||
624 | goto out8; | ||
625 | |||
626 | kobject_uevent(&class_dev->kobj, KOBJ_ADD); | ||
627 | |||
628 | /* notify any interfaces this device is now here */ | ||
629 | down(&parent_class->sem); | ||
630 | list_add_tail(&class_dev->node, &parent_class->children); | ||
631 | list_for_each_entry(class_intf, &parent_class->interfaces, node) { | ||
632 | if (class_intf->add) | ||
633 | class_intf->add(class_dev, class_intf); | ||
634 | } | ||
635 | up(&parent_class->sem); | ||
636 | |||
637 | goto out1; | ||
638 | |||
639 | out8: | ||
640 | class_device_remove_groups(class_dev); | ||
641 | out7: | ||
642 | if (class_dev->dev) | ||
643 | sysfs_remove_link(&class_dev->kobj, "device"); | ||
644 | out6: | ||
645 | class_device_remove_attrs(class_dev); | ||
646 | out5: | ||
647 | if (MAJOR(class_dev->devt)) | ||
648 | class_device_remove_file(class_dev, &class_devt_attr); | ||
649 | out4: | ||
650 | class_device_remove_file(class_dev, &class_uevent_attr); | ||
651 | out3: | ||
652 | kobject_del(&class_dev->kobj); | ||
653 | out2: | ||
654 | if (parent_class_dev) | ||
655 | class_device_put(parent_class_dev); | ||
656 | class_put(parent_class); | ||
657 | out1: | ||
658 | class_device_put(class_dev); | ||
659 | return error; | ||
660 | } | ||
661 | |||
662 | int class_device_register(struct class_device *class_dev) | ||
663 | { | ||
664 | class_device_initialize(class_dev); | ||
665 | return class_device_add(class_dev); | ||
666 | } | ||
667 | |||
668 | /** | ||
669 | * class_device_create - creates a class device and registers it with sysfs | ||
670 | * @cls: pointer to the struct class that this device should be registered to. | ||
671 | * @parent: pointer to the parent struct class_device of this new device, if | ||
672 | * any. | ||
673 | * @devt: the dev_t for the char device to be added. | ||
674 | * @device: a pointer to a struct device that is assiociated with this class | ||
675 | * device. | ||
676 | * @fmt: string for the class device's name | ||
677 | * | ||
678 | * This function can be used by char device classes. A struct | ||
679 | * class_device will be created in sysfs, registered to the specified | ||
680 | * class. | ||
681 | * A "dev" file will be created, showing the dev_t for the device, if | ||
682 | * the dev_t is not 0,0. | ||
683 | * If a pointer to a parent struct class_device is passed in, the newly | ||
684 | * created struct class_device will be a child of that device in sysfs. | ||
685 | * The pointer to the struct class_device will be returned from the | ||
686 | * call. Any further sysfs files that might be required can be created | ||
687 | * using this pointer. | ||
688 | * | ||
689 | * Note: the struct class passed to this function must have previously | ||
690 | * been created with a call to class_create(). | ||
691 | */ | ||
692 | struct class_device *class_device_create(struct class *cls, | ||
693 | struct class_device *parent, | ||
694 | dev_t devt, | ||
695 | struct device *device, | ||
696 | const char *fmt, ...) | ||
697 | { | ||
698 | va_list args; | ||
699 | struct class_device *class_dev = NULL; | ||
700 | int retval = -ENODEV; | ||
701 | |||
702 | if (cls == NULL || IS_ERR(cls)) | ||
703 | goto error; | ||
704 | |||
705 | class_dev = kzalloc(sizeof(*class_dev), GFP_KERNEL); | ||
706 | if (!class_dev) { | ||
707 | retval = -ENOMEM; | ||
708 | goto error; | ||
709 | } | ||
710 | |||
711 | class_dev->devt = devt; | ||
712 | class_dev->dev = device; | ||
713 | class_dev->class = cls; | ||
714 | class_dev->parent = parent; | ||
715 | class_dev->release = class_device_create_release; | ||
716 | class_dev->uevent = class_device_create_uevent; | ||
717 | |||
718 | va_start(args, fmt); | ||
719 | vsnprintf(class_dev->class_id, BUS_ID_SIZE, fmt, args); | ||
720 | va_end(args); | ||
721 | retval = class_device_register(class_dev); | ||
722 | if (retval) | ||
723 | goto error; | ||
724 | |||
725 | return class_dev; | ||
726 | |||
727 | error: | ||
728 | kfree(class_dev); | ||
729 | return ERR_PTR(retval); | ||
730 | } | ||
731 | |||
732 | void class_device_del(struct class_device *class_dev) | ||
733 | { | ||
734 | struct class *parent_class = class_dev->class; | ||
735 | struct class_device *parent_device = class_dev->parent; | ||
736 | struct class_interface *class_intf; | ||
737 | |||
738 | if (parent_class) { | ||
739 | down(&parent_class->sem); | ||
740 | list_del_init(&class_dev->node); | ||
741 | list_for_each_entry(class_intf, &parent_class->interfaces, node) | ||
742 | if (class_intf->remove) | ||
743 | class_intf->remove(class_dev, class_intf); | ||
744 | up(&parent_class->sem); | ||
745 | } | ||
746 | |||
747 | if (class_dev->dev) { | ||
748 | remove_deprecated_class_device_links(class_dev); | ||
749 | sysfs_remove_link(&class_dev->kobj, "device"); | ||
750 | } | ||
751 | sysfs_remove_link(&class_dev->kobj, "subsystem"); | ||
752 | class_device_remove_file(class_dev, &class_uevent_attr); | ||
753 | if (MAJOR(class_dev->devt)) | ||
754 | class_device_remove_file(class_dev, &class_devt_attr); | ||
755 | class_device_remove_attrs(class_dev); | ||
756 | class_device_remove_groups(class_dev); | ||
757 | |||
758 | kobject_uevent(&class_dev->kobj, KOBJ_REMOVE); | ||
759 | kobject_del(&class_dev->kobj); | ||
760 | |||
761 | class_device_put(parent_device); | ||
762 | class_put(parent_class); | ||
763 | } | ||
764 | |||
765 | void class_device_unregister(struct class_device *class_dev) | ||
766 | { | ||
767 | pr_debug("CLASS: Unregistering class device. ID = '%s'\n", | ||
768 | class_dev->class_id); | ||
769 | class_device_del(class_dev); | ||
770 | class_device_put(class_dev); | ||
771 | } | ||
772 | |||
773 | /** | ||
774 | * class_device_destroy - removes a class device that was created with class_device_create() | ||
775 | * @cls: the pointer to the struct class that this device was registered * with. | ||
776 | * @devt: the dev_t of the device that was previously registered. | ||
777 | * | ||
778 | * This call unregisters and cleans up a class device that was created with a | ||
779 | * call to class_device_create() | ||
780 | */ | ||
781 | void class_device_destroy(struct class *cls, dev_t devt) | ||
782 | { | ||
783 | struct class_device *class_dev = NULL; | ||
784 | struct class_device *class_dev_tmp; | ||
785 | |||
786 | down(&cls->sem); | ||
787 | list_for_each_entry(class_dev_tmp, &cls->children, node) { | ||
788 | if (class_dev_tmp->devt == devt) { | ||
789 | class_dev = class_dev_tmp; | ||
790 | break; | ||
791 | } | ||
792 | } | ||
793 | up(&cls->sem); | ||
794 | |||
795 | if (class_dev) | ||
796 | class_device_unregister(class_dev); | ||
797 | } | ||
798 | |||
799 | struct class_device *class_device_get(struct class_device *class_dev) | ||
800 | { | ||
801 | if (class_dev) | ||
802 | return to_class_dev(kobject_get(&class_dev->kobj)); | ||
803 | return NULL; | ||
804 | } | ||
805 | |||
806 | void class_device_put(struct class_device *class_dev) | ||
807 | { | ||
808 | if (class_dev) | ||
809 | kobject_put(&class_dev->kobj); | ||
810 | } | ||
811 | |||
812 | /** | 253 | /** |
813 | * class_for_each_device - device iterator | 254 | * class_for_each_device - device iterator |
814 | * @class: the class we're iterating | 255 | * @class: the class we're iterating |
@@ -897,56 +338,9 @@ struct device *class_find_device(struct class *class, void *data, | |||
897 | } | 338 | } |
898 | EXPORT_SYMBOL_GPL(class_find_device); | 339 | EXPORT_SYMBOL_GPL(class_find_device); |
899 | 340 | ||
900 | /** | ||
901 | * class_find_child - device iterator for locating a particular class_device | ||
902 | * @class: the class we're iterating | ||
903 | * @data: data for the match function | ||
904 | * @match: function to check class_device | ||
905 | * | ||
906 | * This function returns a reference to a class_device that is 'found' for | ||
907 | * later use, as determined by the @match callback. | ||
908 | * | ||
909 | * The callback should return 0 if the class_device doesn't match and non-zero | ||
910 | * if it does. If the callback returns non-zero, this function will | ||
911 | * return to the caller and not iterate over any more class_devices. | ||
912 | * | ||
913 | * Note, you will need to drop the reference with class_device_put() after use. | ||
914 | * | ||
915 | * We hold class->sem in this function, so it can not be | ||
916 | * re-acquired in @match, otherwise it will self-deadlocking. For | ||
917 | * example, calls to add or remove class members would be verboten. | ||
918 | */ | ||
919 | struct class_device *class_find_child(struct class *class, void *data, | ||
920 | int (*match)(struct class_device *, void *)) | ||
921 | { | ||
922 | struct class_device *dev; | ||
923 | int found = 0; | ||
924 | |||
925 | if (!class) | ||
926 | return NULL; | ||
927 | |||
928 | down(&class->sem); | ||
929 | list_for_each_entry(dev, &class->children, node) { | ||
930 | dev = class_device_get(dev); | ||
931 | if (dev) { | ||
932 | if (match(dev, data)) { | ||
933 | found = 1; | ||
934 | break; | ||
935 | } else | ||
936 | class_device_put(dev); | ||
937 | } else | ||
938 | break; | ||
939 | } | ||
940 | up(&class->sem); | ||
941 | |||
942 | return found ? dev : NULL; | ||
943 | } | ||
944 | EXPORT_SYMBOL_GPL(class_find_child); | ||
945 | |||
946 | int class_interface_register(struct class_interface *class_intf) | 341 | int class_interface_register(struct class_interface *class_intf) |
947 | { | 342 | { |
948 | struct class *parent; | 343 | struct class *parent; |
949 | struct class_device *class_dev; | ||
950 | struct device *dev; | 344 | struct device *dev; |
951 | 345 | ||
952 | if (!class_intf || !class_intf->class) | 346 | if (!class_intf || !class_intf->class) |
@@ -958,10 +352,6 @@ int class_interface_register(struct class_interface *class_intf) | |||
958 | 352 | ||
959 | down(&parent->sem); | 353 | down(&parent->sem); |
960 | list_add_tail(&class_intf->node, &parent->interfaces); | 354 | list_add_tail(&class_intf->node, &parent->interfaces); |
961 | if (class_intf->add) { | ||
962 | list_for_each_entry(class_dev, &parent->children, node) | ||
963 | class_intf->add(class_dev, class_intf); | ||
964 | } | ||
965 | if (class_intf->add_dev) { | 355 | if (class_intf->add_dev) { |
966 | list_for_each_entry(dev, &parent->devices, node) | 356 | list_for_each_entry(dev, &parent->devices, node) |
967 | class_intf->add_dev(dev, class_intf); | 357 | class_intf->add_dev(dev, class_intf); |
@@ -974,7 +364,6 @@ int class_interface_register(struct class_interface *class_intf) | |||
974 | void class_interface_unregister(struct class_interface *class_intf) | 364 | void class_interface_unregister(struct class_interface *class_intf) |
975 | { | 365 | { |
976 | struct class *parent = class_intf->class; | 366 | struct class *parent = class_intf->class; |
977 | struct class_device *class_dev; | ||
978 | struct device *dev; | 367 | struct device *dev; |
979 | 368 | ||
980 | if (!parent) | 369 | if (!parent) |
@@ -982,10 +371,6 @@ void class_interface_unregister(struct class_interface *class_intf) | |||
982 | 371 | ||
983 | down(&parent->sem); | 372 | down(&parent->sem); |
984 | list_del_init(&class_intf->node); | 373 | list_del_init(&class_intf->node); |
985 | if (class_intf->remove) { | ||
986 | list_for_each_entry(class_dev, &parent->children, node) | ||
987 | class_intf->remove(class_dev, class_intf); | ||
988 | } | ||
989 | if (class_intf->remove_dev) { | 374 | if (class_intf->remove_dev) { |
990 | list_for_each_entry(dev, &parent->devices, node) | 375 | list_for_each_entry(dev, &parent->devices, node) |
991 | class_intf->remove_dev(dev, class_intf); | 376 | class_intf->remove_dev(dev, class_intf); |
@@ -1000,13 +385,6 @@ int __init classes_init(void) | |||
1000 | class_kset = kset_create_and_add("class", NULL, NULL); | 385 | class_kset = kset_create_and_add("class", NULL, NULL); |
1001 | if (!class_kset) | 386 | if (!class_kset) |
1002 | return -ENOMEM; | 387 | return -ENOMEM; |
1003 | |||
1004 | /* ick, this is ugly, the things we go through to keep from showing up | ||
1005 | * in sysfs... */ | ||
1006 | kset_init(&class_obj_subsys); | ||
1007 | kobject_set_name(&class_obj_subsys.kobj, "class_obj"); | ||
1008 | if (!class_obj_subsys.kobj.parent) | ||
1009 | class_obj_subsys.kobj.parent = &class_obj_subsys.kobj; | ||
1010 | return 0; | 388 | return 0; |
1011 | } | 389 | } |
1012 | 390 | ||
@@ -1017,19 +395,5 @@ EXPORT_SYMBOL_GPL(class_unregister); | |||
1017 | EXPORT_SYMBOL_GPL(class_create); | 395 | EXPORT_SYMBOL_GPL(class_create); |
1018 | EXPORT_SYMBOL_GPL(class_destroy); | 396 | EXPORT_SYMBOL_GPL(class_destroy); |
1019 | 397 | ||
1020 | EXPORT_SYMBOL_GPL(class_device_register); | ||
1021 | EXPORT_SYMBOL_GPL(class_device_unregister); | ||
1022 | EXPORT_SYMBOL_GPL(class_device_initialize); | ||
1023 | EXPORT_SYMBOL_GPL(class_device_add); | ||
1024 | EXPORT_SYMBOL_GPL(class_device_del); | ||
1025 | EXPORT_SYMBOL_GPL(class_device_get); | ||
1026 | EXPORT_SYMBOL_GPL(class_device_put); | ||
1027 | EXPORT_SYMBOL_GPL(class_device_create); | ||
1028 | EXPORT_SYMBOL_GPL(class_device_destroy); | ||
1029 | EXPORT_SYMBOL_GPL(class_device_create_file); | ||
1030 | EXPORT_SYMBOL_GPL(class_device_remove_file); | ||
1031 | EXPORT_SYMBOL_GPL(class_device_create_bin_file); | ||
1032 | EXPORT_SYMBOL_GPL(class_device_remove_bin_file); | ||
1033 | |||
1034 | EXPORT_SYMBOL_GPL(class_interface_register); | 398 | EXPORT_SYMBOL_GPL(class_interface_register); |
1035 | EXPORT_SYMBOL_GPL(class_interface_unregister); | 399 | EXPORT_SYMBOL_GPL(class_interface_unregister); |
diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 9a6537f14401..2ef5acf4368b 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c | |||
@@ -217,12 +217,22 @@ static void driver_remove_groups(struct device_driver *drv, | |||
217 | int driver_register(struct device_driver *drv) | 217 | int driver_register(struct device_driver *drv) |
218 | { | 218 | { |
219 | int ret; | 219 | int ret; |
220 | struct device_driver *other; | ||
220 | 221 | ||
221 | if ((drv->bus->probe && drv->probe) || | 222 | if ((drv->bus->probe && drv->probe) || |
222 | (drv->bus->remove && drv->remove) || | 223 | (drv->bus->remove && drv->remove) || |
223 | (drv->bus->shutdown && drv->shutdown)) | 224 | (drv->bus->shutdown && drv->shutdown)) |
224 | printk(KERN_WARNING "Driver '%s' needs updating - please use " | 225 | printk(KERN_WARNING "Driver '%s' needs updating - please use " |
225 | "bus_type methods\n", drv->name); | 226 | "bus_type methods\n", drv->name); |
227 | |||
228 | other = driver_find(drv->name, drv->bus); | ||
229 | if (other) { | ||
230 | put_driver(other); | ||
231 | printk(KERN_ERR "Error: Driver '%s' is already registered, " | ||
232 | "aborting...\n", drv->name); | ||
233 | return -EEXIST; | ||
234 | } | ||
235 | |||
226 | ret = bus_add_driver(drv); | 236 | ret = bus_add_driver(drv); |
227 | if (ret) | 237 | if (ret) |
228 | return ret; | 238 | return ret; |
diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c index 56230dbd347a..29276bd28295 100644 --- a/drivers/pcmcia/cs.c +++ b/drivers/pcmcia/cs.c | |||
@@ -652,6 +652,9 @@ static int pccardd(void *__skt) | |||
652 | complete(&skt->thread_done); | 652 | complete(&skt->thread_done); |
653 | return 0; | 653 | return 0; |
654 | } | 654 | } |
655 | ret = pccard_sysfs_add_socket(&skt->dev); | ||
656 | if (ret) | ||
657 | dev_warn(&skt->dev, "err %d adding socket attributes\n", ret); | ||
655 | 658 | ||
656 | add_wait_queue(&skt->thread_wait, &wait); | 659 | add_wait_queue(&skt->thread_wait, &wait); |
657 | complete(&skt->thread_done); | 660 | complete(&skt->thread_done); |
@@ -694,6 +697,7 @@ static int pccardd(void *__skt) | |||
694 | remove_wait_queue(&skt->thread_wait, &wait); | 697 | remove_wait_queue(&skt->thread_wait, &wait); |
695 | 698 | ||
696 | /* remove from the device core */ | 699 | /* remove from the device core */ |
700 | pccard_sysfs_remove_socket(&skt->dev); | ||
697 | device_unregister(&skt->dev); | 701 | device_unregister(&skt->dev); |
698 | 702 | ||
699 | return 0; | 703 | return 0; |
@@ -940,20 +944,13 @@ EXPORT_SYMBOL(pcmcia_socket_class); | |||
940 | 944 | ||
941 | static int __init init_pcmcia_cs(void) | 945 | static int __init init_pcmcia_cs(void) |
942 | { | 946 | { |
943 | int ret; | ||
944 | |||
945 | init_completion(&pcmcia_unload); | 947 | init_completion(&pcmcia_unload); |
946 | ret = class_register(&pcmcia_socket_class); | 948 | return class_register(&pcmcia_socket_class); |
947 | if (ret) | ||
948 | return (ret); | ||
949 | return class_interface_register(&pccard_sysfs_interface); | ||
950 | } | 949 | } |
951 | 950 | ||
952 | static void __exit exit_pcmcia_cs(void) | 951 | static void __exit exit_pcmcia_cs(void) |
953 | { | 952 | { |
954 | class_interface_unregister(&pccard_sysfs_interface); | ||
955 | class_unregister(&pcmcia_socket_class); | 953 | class_unregister(&pcmcia_socket_class); |
956 | |||
957 | wait_for_completion(&pcmcia_unload); | 954 | wait_for_completion(&pcmcia_unload); |
958 | } | 955 | } |
959 | 956 | ||
diff --git a/drivers/pcmcia/cs_internal.h b/drivers/pcmcia/cs_internal.h index 9fa207e3c7b3..e7d5d141f24d 100644 --- a/drivers/pcmcia/cs_internal.h +++ b/drivers/pcmcia/cs_internal.h | |||
@@ -121,7 +121,8 @@ struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align, | |||
121 | void release_resource_db(struct pcmcia_socket *s); | 121 | void release_resource_db(struct pcmcia_socket *s); |
122 | 122 | ||
123 | /* In socket_sysfs.c */ | 123 | /* In socket_sysfs.c */ |
124 | extern struct class_interface pccard_sysfs_interface; | 124 | extern int pccard_sysfs_add_socket(struct device *dev); |
125 | extern void pccard_sysfs_remove_socket(struct device *dev); | ||
125 | 126 | ||
126 | /* In cs.c */ | 127 | /* In cs.c */ |
127 | extern struct rw_semaphore pcmcia_socket_list_rwsem; | 128 | extern struct rw_semaphore pcmcia_socket_list_rwsem; |
diff --git a/drivers/pcmcia/socket_sysfs.c b/drivers/pcmcia/socket_sysfs.c index b4409002b7f8..562384d6f321 100644 --- a/drivers/pcmcia/socket_sysfs.c +++ b/drivers/pcmcia/socket_sysfs.c | |||
@@ -356,19 +356,23 @@ static ssize_t pccard_store_cis(struct kobject *kobj, | |||
356 | } | 356 | } |
357 | 357 | ||
358 | 358 | ||
359 | static struct device_attribute *pccard_socket_attributes[] = { | 359 | static struct attribute *pccard_socket_attributes[] = { |
360 | &dev_attr_card_type, | 360 | &dev_attr_card_type.attr, |
361 | &dev_attr_card_voltage, | 361 | &dev_attr_card_voltage.attr, |
362 | &dev_attr_card_vpp, | 362 | &dev_attr_card_vpp.attr, |
363 | &dev_attr_card_vcc, | 363 | &dev_attr_card_vcc.attr, |
364 | &dev_attr_card_insert, | 364 | &dev_attr_card_insert.attr, |
365 | &dev_attr_card_pm_state, | 365 | &dev_attr_card_pm_state.attr, |
366 | &dev_attr_card_eject, | 366 | &dev_attr_card_eject.attr, |
367 | &dev_attr_card_irq_mask, | 367 | &dev_attr_card_irq_mask.attr, |
368 | &dev_attr_available_resources_setup_done, | 368 | &dev_attr_available_resources_setup_done.attr, |
369 | NULL, | 369 | NULL, |
370 | }; | 370 | }; |
371 | 371 | ||
372 | static const struct attribute_group socket_attrs = { | ||
373 | .attrs = pccard_socket_attributes, | ||
374 | }; | ||
375 | |||
372 | static struct bin_attribute pccard_cis_attr = { | 376 | static struct bin_attribute pccard_cis_attr = { |
373 | .attr = { .name = "cis", .mode = S_IRUGO | S_IWUSR }, | 377 | .attr = { .name = "cis", .mode = S_IRUGO | S_IWUSR }, |
374 | .size = 0x200, | 378 | .size = 0x200, |
@@ -376,35 +380,21 @@ static struct bin_attribute pccard_cis_attr = { | |||
376 | .write = pccard_store_cis, | 380 | .write = pccard_store_cis, |
377 | }; | 381 | }; |
378 | 382 | ||
379 | static int __devinit pccard_sysfs_add_socket(struct device *dev, | 383 | int pccard_sysfs_add_socket(struct device *dev) |
380 | struct class_interface *class_intf) | ||
381 | { | 384 | { |
382 | struct device_attribute **attr; | ||
383 | int ret = 0; | 385 | int ret = 0; |
384 | 386 | ||
385 | for (attr = pccard_socket_attributes; *attr; attr++) { | 387 | ret = sysfs_create_group(&dev->kobj, &socket_attrs); |
386 | ret = device_create_file(dev, *attr); | 388 | if (!ret) { |
389 | ret = sysfs_create_bin_file(&dev->kobj, &pccard_cis_attr); | ||
387 | if (ret) | 390 | if (ret) |
388 | break; | 391 | sysfs_remove_group(&dev->kobj, &socket_attrs); |
389 | } | 392 | } |
390 | if (!ret) | ||
391 | ret = sysfs_create_bin_file(&dev->kobj, &pccard_cis_attr); | ||
392 | |||
393 | return ret; | 393 | return ret; |
394 | } | 394 | } |
395 | 395 | ||
396 | static void __devexit pccard_sysfs_remove_socket(struct device *dev, | 396 | void pccard_sysfs_remove_socket(struct device *dev) |
397 | struct class_interface *class_intf) | ||
398 | { | 397 | { |
399 | struct device_attribute **attr; | ||
400 | |||
401 | sysfs_remove_bin_file(&dev->kobj, &pccard_cis_attr); | 398 | sysfs_remove_bin_file(&dev->kobj, &pccard_cis_attr); |
402 | for (attr = pccard_socket_attributes; *attr; attr++) | 399 | sysfs_remove_group(&dev->kobj, &socket_attrs); |
403 | device_remove_file(dev, *attr); | ||
404 | } | 400 | } |
405 | |||
406 | struct class_interface pccard_sysfs_interface = { | ||
407 | .class = &pcmcia_socket_class, | ||
408 | .add_dev = &pccard_sysfs_add_socket, | ||
409 | .remove_dev = __devexit_p(&pccard_sysfs_remove_socket), | ||
410 | }; | ||
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index fddffe4851f5..159a5efd6a8a 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c | |||
@@ -9,7 +9,7 @@ | |||
9 | * 2 as published by the Free Software Foundation. | 9 | * 2 as published by the Free Software Foundation. |
10 | * | 10 | * |
11 | * debugfs is for people to use instead of /proc or /sys. | 11 | * debugfs is for people to use instead of /proc or /sys. |
12 | * See Documentation/DocBook/kernel-api for more details. | 12 | * See Documentation/DocBook/filesystems for more details. |
13 | * | 13 | * |
14 | */ | 14 | */ |
15 | 15 | ||
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c index f8b82e73b3bf..eb53c632f856 100644 --- a/fs/sysfs/inode.c +++ b/fs/sysfs/inode.c | |||
@@ -59,6 +59,8 @@ int sysfs_setattr(struct dentry * dentry, struct iattr * iattr) | |||
59 | if (error) | 59 | if (error) |
60 | return error; | 60 | return error; |
61 | 61 | ||
62 | iattr->ia_valid &= ~ATTR_SIZE; /* ignore size changes */ | ||
63 | |||
62 | error = inode_setattr(inode, iattr); | 64 | error = inode_setattr(inode, iattr); |
63 | if (error) | 65 | if (error) |
64 | return error; | 66 | return error; |
diff --git a/include/linux/device.h b/include/linux/device.h index 1a060265acea..832fb0eb2933 100644 --- a/include/linux/device.h +++ b/include/linux/device.h | |||
@@ -35,7 +35,6 @@ struct device; | |||
35 | struct device_driver; | 35 | struct device_driver; |
36 | struct driver_private; | 36 | struct driver_private; |
37 | struct class; | 37 | struct class; |
38 | struct class_device; | ||
39 | struct bus_type; | 38 | struct bus_type; |
40 | struct bus_type_private; | 39 | struct bus_type_private; |
41 | 40 | ||
@@ -190,13 +189,10 @@ struct class { | |||
190 | struct kset class_dirs; | 189 | struct kset class_dirs; |
191 | struct semaphore sem; /* locks children, devices, interfaces */ | 190 | struct semaphore sem; /* locks children, devices, interfaces */ |
192 | struct class_attribute *class_attrs; | 191 | struct class_attribute *class_attrs; |
193 | struct class_device_attribute *class_dev_attrs; | ||
194 | struct device_attribute *dev_attrs; | 192 | struct device_attribute *dev_attrs; |
195 | 193 | ||
196 | int (*uevent)(struct class_device *dev, struct kobj_uevent_env *env); | ||
197 | int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env); | 194 | int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env); |
198 | 195 | ||
199 | void (*release)(struct class_device *dev); | ||
200 | void (*class_release)(struct class *class); | 196 | void (*class_release)(struct class *class); |
201 | void (*dev_release)(struct device *dev); | 197 | void (*dev_release)(struct device *dev); |
202 | 198 | ||
@@ -210,9 +206,6 @@ extern int class_for_each_device(struct class *class, void *data, | |||
210 | int (*fn)(struct device *dev, void *data)); | 206 | int (*fn)(struct device *dev, void *data)); |
211 | extern struct device *class_find_device(struct class *class, void *data, | 207 | extern struct device *class_find_device(struct class *class, void *data, |
212 | int (*match)(struct device *, void *)); | 208 | int (*match)(struct device *, void *)); |
213 | extern struct class_device *class_find_child(struct class *class, void *data, | ||
214 | int (*match)(struct class_device *, void *)); | ||
215 | |||
216 | 209 | ||
217 | struct class_attribute { | 210 | struct class_attribute { |
218 | struct attribute attr; | 211 | struct attribute attr; |
@@ -228,92 +221,10 @@ extern int __must_check class_create_file(struct class *class, | |||
228 | extern void class_remove_file(struct class *class, | 221 | extern void class_remove_file(struct class *class, |
229 | const struct class_attribute *attr); | 222 | const struct class_attribute *attr); |
230 | 223 | ||
231 | struct class_device_attribute { | ||
232 | struct attribute attr; | ||
233 | ssize_t (*show)(struct class_device *, char *buf); | ||
234 | ssize_t (*store)(struct class_device *, const char *buf, size_t count); | ||
235 | }; | ||
236 | |||
237 | #define CLASS_DEVICE_ATTR(_name, _mode, _show, _store) \ | ||
238 | struct class_device_attribute class_device_attr_##_name = \ | ||
239 | __ATTR(_name, _mode, _show, _store) | ||
240 | |||
241 | extern int __must_check class_device_create_file(struct class_device *, | ||
242 | const struct class_device_attribute *); | ||
243 | |||
244 | /** | ||
245 | * struct class_device - class devices | ||
246 | * @class: pointer to the parent class for this class device. This is required. | ||
247 | * @devt: for internal use by the driver core only. | ||
248 | * @node: for internal use by the driver core only. | ||
249 | * @kobj: for internal use by the driver core only. | ||
250 | * @groups: optional additional groups to be created | ||
251 | * @dev: if set, a symlink to the struct device is created in the sysfs | ||
252 | * directory for this struct class device. | ||
253 | * @class_data: pointer to whatever you want to store here for this struct | ||
254 | * class_device. Use class_get_devdata() and class_set_devdata() to get and | ||
255 | * set this pointer. | ||
256 | * @parent: pointer to a struct class_device that is the parent of this struct | ||
257 | * class_device. If NULL, this class_device will show up at the root of the | ||
258 | * struct class in sysfs (which is probably what you want to have happen.) | ||
259 | * @release: pointer to a release function for this struct class_device. If | ||
260 | * set, this will be called instead of the class specific release function. | ||
261 | * Only use this if you want to override the default release function, like | ||
262 | * when you are nesting class_device structures. | ||
263 | * @uevent: pointer to a uevent function for this struct class_device. If | ||
264 | * set, this will be called instead of the class specific uevent function. | ||
265 | * Only use this if you want to override the default uevent function, like | ||
266 | * when you are nesting class_device structures. | ||
267 | */ | ||
268 | struct class_device { | ||
269 | struct list_head node; | ||
270 | |||
271 | struct kobject kobj; | ||
272 | struct class *class; | ||
273 | dev_t devt; | ||
274 | struct device *dev; | ||
275 | void *class_data; | ||
276 | struct class_device *parent; | ||
277 | struct attribute_group **groups; | ||
278 | |||
279 | void (*release)(struct class_device *dev); | ||
280 | int (*uevent)(struct class_device *dev, struct kobj_uevent_env *env); | ||
281 | char class_id[BUS_ID_SIZE]; | ||
282 | }; | ||
283 | |||
284 | static inline void *class_get_devdata(struct class_device *dev) | ||
285 | { | ||
286 | return dev->class_data; | ||
287 | } | ||
288 | |||
289 | static inline void class_set_devdata(struct class_device *dev, void *data) | ||
290 | { | ||
291 | dev->class_data = data; | ||
292 | } | ||
293 | |||
294 | |||
295 | extern int __must_check class_device_register(struct class_device *); | ||
296 | extern void class_device_unregister(struct class_device *); | ||
297 | extern void class_device_initialize(struct class_device *); | ||
298 | extern int __must_check class_device_add(struct class_device *); | ||
299 | extern void class_device_del(struct class_device *); | ||
300 | |||
301 | extern struct class_device *class_device_get(struct class_device *); | ||
302 | extern void class_device_put(struct class_device *); | ||
303 | |||
304 | extern void class_device_remove_file(struct class_device *, | ||
305 | const struct class_device_attribute *); | ||
306 | extern int __must_check class_device_create_bin_file(struct class_device *, | ||
307 | struct bin_attribute *); | ||
308 | extern void class_device_remove_bin_file(struct class_device *, | ||
309 | struct bin_attribute *); | ||
310 | |||
311 | struct class_interface { | 224 | struct class_interface { |
312 | struct list_head node; | 225 | struct list_head node; |
313 | struct class *class; | 226 | struct class *class; |
314 | 227 | ||
315 | int (*add) (struct class_device *, struct class_interface *); | ||
316 | void (*remove) (struct class_device *, struct class_interface *); | ||
317 | int (*add_dev) (struct device *, struct class_interface *); | 228 | int (*add_dev) (struct device *, struct class_interface *); |
318 | void (*remove_dev) (struct device *, struct class_interface *); | 229 | void (*remove_dev) (struct device *, struct class_interface *); |
319 | }; | 230 | }; |
@@ -323,13 +234,6 @@ extern void class_interface_unregister(struct class_interface *); | |||
323 | 234 | ||
324 | extern struct class *class_create(struct module *owner, const char *name); | 235 | extern struct class *class_create(struct module *owner, const char *name); |
325 | extern void class_destroy(struct class *cls); | 236 | extern void class_destroy(struct class *cls); |
326 | extern struct class_device *class_device_create(struct class *cls, | ||
327 | struct class_device *parent, | ||
328 | dev_t devt, | ||
329 | struct device *device, | ||
330 | const char *fmt, ...) | ||
331 | __attribute__((format(printf, 5, 6))); | ||
332 | extern void class_device_destroy(struct class *cls, dev_t devt); | ||
333 | 237 | ||
334 | /* | 238 | /* |
335 | * The type of device, "struct device" is embedded in. A class | 239 | * The type of device, "struct device" is embedded in. A class |
@@ -465,7 +369,6 @@ struct device { | |||
465 | spinlock_t devres_lock; | 369 | spinlock_t devres_lock; |
466 | struct list_head devres_head; | 370 | struct list_head devres_head; |
467 | 371 | ||
468 | /* class_device migration path */ | ||
469 | struct list_head node; | 372 | struct list_head node; |
470 | struct class *class; | 373 | struct class *class; |
471 | dev_t devt; /* dev_t, creates the sysfs "dev" */ | 374 | dev_t devt; /* dev_t, creates the sysfs "dev" */ |
diff --git a/include/linux/io.h b/include/linux/io.h index e3b2dda6c8eb..3a03a3604cce 100644 --- a/include/linux/io.h +++ b/include/linux/io.h | |||
@@ -58,9 +58,9 @@ static inline void devm_ioport_unmap(struct device *dev, void __iomem *addr) | |||
58 | } | 58 | } |
59 | #endif | 59 | #endif |
60 | 60 | ||
61 | void __iomem * devm_ioremap(struct device *dev, unsigned long offset, | 61 | void __iomem *devm_ioremap(struct device *dev, resource_size_t offset, |
62 | unsigned long size); | 62 | unsigned long size); |
63 | void __iomem * devm_ioremap_nocache(struct device *dev, unsigned long offset, | 63 | void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset, |
64 | unsigned long size); | 64 | unsigned long size); |
65 | void devm_iounmap(struct device *dev, void __iomem *addr); | 65 | void devm_iounmap(struct device *dev, void __iomem *addr); |
66 | int check_signature(const volatile void __iomem *io_addr, | 66 | int check_signature(const volatile void __iomem *io_addr, |
diff --git a/include/linux/klist.h b/include/linux/klist.h index 74071254c9d3..06c338ef7f1b 100644 --- a/include/linux/klist.h +++ b/include/linux/klist.h | |||
@@ -25,37 +25,47 @@ struct klist { | |||
25 | void (*put)(struct klist_node *); | 25 | void (*put)(struct klist_node *); |
26 | }; | 26 | }; |
27 | 27 | ||
28 | #define KLIST_INIT(_name, _get, _put) \ | ||
29 | { .k_lock = __SPIN_LOCK_UNLOCKED(_name.k_lock), \ | ||
30 | .k_list = LIST_HEAD_INIT(_name.k_list), \ | ||
31 | .get = _get, \ | ||
32 | .put = _put, } | ||
28 | 33 | ||
29 | extern void klist_init(struct klist * k, void (*get)(struct klist_node *), | 34 | #define DEFINE_KLIST(_name, _get, _put) \ |
35 | struct klist _name = KLIST_INIT(_name, _get, _put) | ||
36 | |||
37 | extern void klist_init(struct klist *k, void (*get)(struct klist_node *), | ||
30 | void (*put)(struct klist_node *)); | 38 | void (*put)(struct klist_node *)); |
31 | 39 | ||
32 | struct klist_node { | 40 | struct klist_node { |
33 | struct klist * n_klist; | 41 | struct klist *n_klist; |
34 | struct list_head n_node; | 42 | struct list_head n_node; |
35 | struct kref n_ref; | 43 | struct kref n_ref; |
36 | struct completion n_removed; | 44 | struct completion n_removed; |
37 | }; | 45 | }; |
38 | 46 | ||
39 | extern void klist_add_tail(struct klist_node * n, struct klist * k); | 47 | extern void klist_add_tail(struct klist_node *n, struct klist *k); |
40 | extern void klist_add_head(struct klist_node * n, struct klist * k); | 48 | extern void klist_add_head(struct klist_node *n, struct klist *k); |
49 | extern void klist_add_after(struct klist_node *n, struct klist_node *pos); | ||
50 | extern void klist_add_before(struct klist_node *n, struct klist_node *pos); | ||
41 | 51 | ||
42 | extern void klist_del(struct klist_node * n); | 52 | extern void klist_del(struct klist_node *n); |
43 | extern void klist_remove(struct klist_node * n); | 53 | extern void klist_remove(struct klist_node *n); |
44 | 54 | ||
45 | extern int klist_node_attached(struct klist_node * n); | 55 | extern int klist_node_attached(struct klist_node *n); |
46 | 56 | ||
47 | 57 | ||
48 | struct klist_iter { | 58 | struct klist_iter { |
49 | struct klist * i_klist; | 59 | struct klist *i_klist; |
50 | struct list_head * i_head; | 60 | struct list_head *i_head; |
51 | struct klist_node * i_cur; | 61 | struct klist_node *i_cur; |
52 | }; | 62 | }; |
53 | 63 | ||
54 | 64 | ||
55 | extern void klist_iter_init(struct klist * k, struct klist_iter * i); | 65 | extern void klist_iter_init(struct klist *k, struct klist_iter *i); |
56 | extern void klist_iter_init_node(struct klist * k, struct klist_iter * i, | 66 | extern void klist_iter_init_node(struct klist *k, struct klist_iter *i, |
57 | struct klist_node * n); | 67 | struct klist_node *n); |
58 | extern void klist_iter_exit(struct klist_iter * i); | 68 | extern void klist_iter_exit(struct klist_iter *i); |
59 | extern struct klist_node * klist_next(struct klist_iter * i); | 69 | extern struct klist_node *klist_next(struct klist_iter *i); |
60 | 70 | ||
61 | #endif | 71 | #endif |
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index add3c5a40827..7858eac40aa7 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h | |||
@@ -190,6 +190,12 @@ static inline int sysfs_create_group(struct kobject *kobj, | |||
190 | return 0; | 190 | return 0; |
191 | } | 191 | } |
192 | 192 | ||
193 | static inline int sysfs_update_group(struct kobject *kobj, | ||
194 | const struct attribute_group *grp) | ||
195 | { | ||
196 | return 0; | ||
197 | } | ||
198 | |||
193 | static inline void sysfs_remove_group(struct kobject *kobj, | 199 | static inline void sysfs_remove_group(struct kobject *kobj, |
194 | const struct attribute_group *grp) | 200 | const struct attribute_group *grp) |
195 | { | 201 | { |
diff --git a/lib/devres.c b/lib/devres.c index edc27a5d1b73..26c87c49d776 100644 --- a/lib/devres.c +++ b/lib/devres.c | |||
@@ -20,7 +20,7 @@ static int devm_ioremap_match(struct device *dev, void *res, void *match_data) | |||
20 | * | 20 | * |
21 | * Managed ioremap(). Map is automatically unmapped on driver detach. | 21 | * Managed ioremap(). Map is automatically unmapped on driver detach. |
22 | */ | 22 | */ |
23 | void __iomem *devm_ioremap(struct device *dev, unsigned long offset, | 23 | void __iomem *devm_ioremap(struct device *dev, resource_size_t offset, |
24 | unsigned long size) | 24 | unsigned long size) |
25 | { | 25 | { |
26 | void __iomem **ptr, *addr; | 26 | void __iomem **ptr, *addr; |
@@ -49,7 +49,7 @@ EXPORT_SYMBOL(devm_ioremap); | |||
49 | * Managed ioremap_nocache(). Map is automatically unmapped on driver | 49 | * Managed ioremap_nocache(). Map is automatically unmapped on driver |
50 | * detach. | 50 | * detach. |
51 | */ | 51 | */ |
52 | void __iomem *devm_ioremap_nocache(struct device *dev, unsigned long offset, | 52 | void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset, |
53 | unsigned long size) | 53 | unsigned long size) |
54 | { | 54 | { |
55 | void __iomem **ptr, *addr; | 55 | void __iomem **ptr, *addr; |
diff --git a/lib/klist.c b/lib/klist.c index 120bd175aa78..cca37f96faa2 100644 --- a/lib/klist.c +++ b/lib/klist.c | |||
@@ -1,38 +1,37 @@ | |||
1 | /* | 1 | /* |
2 | * klist.c - Routines for manipulating klists. | 2 | * klist.c - Routines for manipulating klists. |
3 | * | 3 | * |
4 | * Copyright (C) 2005 Patrick Mochel | ||
4 | * | 5 | * |
5 | * This klist interface provides a couple of structures that wrap around | 6 | * This file is released under the GPL v2. |
6 | * struct list_head to provide explicit list "head" (struct klist) and | ||
7 | * list "node" (struct klist_node) objects. For struct klist, a spinlock | ||
8 | * is included that protects access to the actual list itself. struct | ||
9 | * klist_node provides a pointer to the klist that owns it and a kref | ||
10 | * reference count that indicates the number of current users of that node | ||
11 | * in the list. | ||
12 | * | 7 | * |
13 | * The entire point is to provide an interface for iterating over a list | 8 | * This klist interface provides a couple of structures that wrap around |
14 | * that is safe and allows for modification of the list during the | 9 | * struct list_head to provide explicit list "head" (struct klist) and list |
15 | * iteration (e.g. insertion and removal), including modification of the | 10 | * "node" (struct klist_node) objects. For struct klist, a spinlock is |
16 | * current node on the list. | 11 | * included that protects access to the actual list itself. struct |
12 | * klist_node provides a pointer to the klist that owns it and a kref | ||
13 | * reference count that indicates the number of current users of that node | ||
14 | * in the list. | ||
17 | * | 15 | * |
18 | * It works using a 3rd object type - struct klist_iter - that is declared | 16 | * The entire point is to provide an interface for iterating over a list |
19 | * and initialized before an iteration. klist_next() is used to acquire the | 17 | * that is safe and allows for modification of the list during the |
20 | * next element in the list. It returns NULL if there are no more items. | 18 | * iteration (e.g. insertion and removal), including modification of the |
21 | * Internally, that routine takes the klist's lock, decrements the reference | 19 | * current node on the list. |
22 | * count of the previous klist_node and increments the count of the next | ||
23 | * klist_node. It then drops the lock and returns. | ||
24 | * | 20 | * |
25 | * There are primitives for adding and removing nodes to/from a klist. | 21 | * It works using a 3rd object type - struct klist_iter - that is declared |
26 | * When deleting, klist_del() will simply decrement the reference count. | 22 | * and initialized before an iteration. klist_next() is used to acquire the |
27 | * Only when the count goes to 0 is the node removed from the list. | 23 | * next element in the list. It returns NULL if there are no more items. |
28 | * klist_remove() will try to delete the node from the list and block | 24 | * Internally, that routine takes the klist's lock, decrements the |
29 | * until it is actually removed. This is useful for objects (like devices) | 25 | * reference count of the previous klist_node and increments the count of |
30 | * that have been removed from the system and must be freed (but must wait | 26 | * the next klist_node. It then drops the lock and returns. |
31 | * until all accessors have finished). | ||
32 | * | 27 | * |
33 | * Copyright (C) 2005 Patrick Mochel | 28 | * There are primitives for adding and removing nodes to/from a klist. |
34 | * | 29 | * When deleting, klist_del() will simply decrement the reference count. |
35 | * This file is released under the GPL v2. | 30 | * Only when the count goes to 0 is the node removed from the list. |
31 | * klist_remove() will try to delete the node from the list and block until | ||
32 | * it is actually removed. This is useful for objects (like devices) that | ||
33 | * have been removed from the system and must be freed (but must wait until | ||
34 | * all accessors have finished). | ||
36 | */ | 35 | */ |
37 | 36 | ||
38 | #include <linux/klist.h> | 37 | #include <linux/klist.h> |
@@ -40,10 +39,10 @@ | |||
40 | 39 | ||
41 | 40 | ||
42 | /** | 41 | /** |
43 | * klist_init - Initialize a klist structure. | 42 | * klist_init - Initialize a klist structure. |
44 | * @k: The klist we're initializing. | 43 | * @k: The klist we're initializing. |
45 | * @get: The get function for the embedding object (NULL if none) | 44 | * @get: The get function for the embedding object (NULL if none) |
46 | * @put: The put function for the embedding object (NULL if none) | 45 | * @put: The put function for the embedding object (NULL if none) |
47 | * | 46 | * |
48 | * Initialises the klist structure. If the klist_node structures are | 47 | * Initialises the klist structure. If the klist_node structures are |
49 | * going to be embedded in refcounted objects (necessary for safe | 48 | * going to be embedded in refcounted objects (necessary for safe |
@@ -51,8 +50,7 @@ | |||
51 | * functions that take and release references on the embedding | 50 | * functions that take and release references on the embedding |
52 | * objects. | 51 | * objects. |
53 | */ | 52 | */ |
54 | 53 | void klist_init(struct klist *k, void (*get)(struct klist_node *), | |
55 | void klist_init(struct klist * k, void (*get)(struct klist_node *), | ||
56 | void (*put)(struct klist_node *)) | 54 | void (*put)(struct klist_node *)) |
57 | { | 55 | { |
58 | INIT_LIST_HEAD(&k->k_list); | 56 | INIT_LIST_HEAD(&k->k_list); |
@@ -60,26 +58,23 @@ void klist_init(struct klist * k, void (*get)(struct klist_node *), | |||
60 | k->get = get; | 58 | k->get = get; |
61 | k->put = put; | 59 | k->put = put; |
62 | } | 60 | } |
63 | |||
64 | EXPORT_SYMBOL_GPL(klist_init); | 61 | EXPORT_SYMBOL_GPL(klist_init); |
65 | 62 | ||
66 | 63 | static void add_head(struct klist *k, struct klist_node *n) | |
67 | static void add_head(struct klist * k, struct klist_node * n) | ||
68 | { | 64 | { |
69 | spin_lock(&k->k_lock); | 65 | spin_lock(&k->k_lock); |
70 | list_add(&n->n_node, &k->k_list); | 66 | list_add(&n->n_node, &k->k_list); |
71 | spin_unlock(&k->k_lock); | 67 | spin_unlock(&k->k_lock); |
72 | } | 68 | } |
73 | 69 | ||
74 | static void add_tail(struct klist * k, struct klist_node * n) | 70 | static void add_tail(struct klist *k, struct klist_node *n) |
75 | { | 71 | { |
76 | spin_lock(&k->k_lock); | 72 | spin_lock(&k->k_lock); |
77 | list_add_tail(&n->n_node, &k->k_list); | 73 | list_add_tail(&n->n_node, &k->k_list); |
78 | spin_unlock(&k->k_lock); | 74 | spin_unlock(&k->k_lock); |
79 | } | 75 | } |
80 | 76 | ||
81 | 77 | static void klist_node_init(struct klist *k, struct klist_node *n) | |
82 | static void klist_node_init(struct klist * k, struct klist_node * n) | ||
83 | { | 78 | { |
84 | INIT_LIST_HEAD(&n->n_node); | 79 | INIT_LIST_HEAD(&n->n_node); |
85 | init_completion(&n->n_removed); | 80 | init_completion(&n->n_removed); |
@@ -89,60 +84,83 @@ static void klist_node_init(struct klist * k, struct klist_node * n) | |||
89 | k->get(n); | 84 | k->get(n); |
90 | } | 85 | } |
91 | 86 | ||
92 | |||
93 | /** | 87 | /** |
94 | * klist_add_head - Initialize a klist_node and add it to front. | 88 | * klist_add_head - Initialize a klist_node and add it to front. |
95 | * @n: node we're adding. | 89 | * @n: node we're adding. |
96 | * @k: klist it's going on. | 90 | * @k: klist it's going on. |
97 | */ | 91 | */ |
98 | 92 | void klist_add_head(struct klist_node *n, struct klist *k) | |
99 | void klist_add_head(struct klist_node * n, struct klist * k) | ||
100 | { | 93 | { |
101 | klist_node_init(k, n); | 94 | klist_node_init(k, n); |
102 | add_head(k, n); | 95 | add_head(k, n); |
103 | } | 96 | } |
104 | |||
105 | EXPORT_SYMBOL_GPL(klist_add_head); | 97 | EXPORT_SYMBOL_GPL(klist_add_head); |
106 | 98 | ||
107 | |||
108 | /** | 99 | /** |
109 | * klist_add_tail - Initialize a klist_node and add it to back. | 100 | * klist_add_tail - Initialize a klist_node and add it to back. |
110 | * @n: node we're adding. | 101 | * @n: node we're adding. |
111 | * @k: klist it's going on. | 102 | * @k: klist it's going on. |
112 | */ | 103 | */ |
113 | 104 | void klist_add_tail(struct klist_node *n, struct klist *k) | |
114 | void klist_add_tail(struct klist_node * n, struct klist * k) | ||
115 | { | 105 | { |
116 | klist_node_init(k, n); | 106 | klist_node_init(k, n); |
117 | add_tail(k, n); | 107 | add_tail(k, n); |
118 | } | 108 | } |
119 | |||
120 | EXPORT_SYMBOL_GPL(klist_add_tail); | 109 | EXPORT_SYMBOL_GPL(klist_add_tail); |
121 | 110 | ||
111 | /** | ||
112 | * klist_add_after - Init a klist_node and add it after an existing node | ||
113 | * @n: node we're adding. | ||
114 | * @pos: node to put @n after | ||
115 | */ | ||
116 | void klist_add_after(struct klist_node *n, struct klist_node *pos) | ||
117 | { | ||
118 | struct klist *k = pos->n_klist; | ||
119 | |||
120 | klist_node_init(k, n); | ||
121 | spin_lock(&k->k_lock); | ||
122 | list_add(&n->n_node, &pos->n_node); | ||
123 | spin_unlock(&k->k_lock); | ||
124 | } | ||
125 | EXPORT_SYMBOL_GPL(klist_add_after); | ||
126 | |||
127 | /** | ||
128 | * klist_add_before - Init a klist_node and add it before an existing node | ||
129 | * @n: node we're adding. | ||
130 | * @pos: node to put @n after | ||
131 | */ | ||
132 | void klist_add_before(struct klist_node *n, struct klist_node *pos) | ||
133 | { | ||
134 | struct klist *k = pos->n_klist; | ||
135 | |||
136 | klist_node_init(k, n); | ||
137 | spin_lock(&k->k_lock); | ||
138 | list_add_tail(&n->n_node, &pos->n_node); | ||
139 | spin_unlock(&k->k_lock); | ||
140 | } | ||
141 | EXPORT_SYMBOL_GPL(klist_add_before); | ||
122 | 142 | ||
123 | static void klist_release(struct kref * kref) | 143 | static void klist_release(struct kref *kref) |
124 | { | 144 | { |
125 | struct klist_node * n = container_of(kref, struct klist_node, n_ref); | 145 | struct klist_node *n = container_of(kref, struct klist_node, n_ref); |
126 | 146 | ||
127 | list_del(&n->n_node); | 147 | list_del(&n->n_node); |
128 | complete(&n->n_removed); | 148 | complete(&n->n_removed); |
129 | n->n_klist = NULL; | 149 | n->n_klist = NULL; |
130 | } | 150 | } |
131 | 151 | ||
132 | static int klist_dec_and_del(struct klist_node * n) | 152 | static int klist_dec_and_del(struct klist_node *n) |
133 | { | 153 | { |
134 | return kref_put(&n->n_ref, klist_release); | 154 | return kref_put(&n->n_ref, klist_release); |
135 | } | 155 | } |
136 | 156 | ||
137 | |||
138 | /** | 157 | /** |
139 | * klist_del - Decrement the reference count of node and try to remove. | 158 | * klist_del - Decrement the reference count of node and try to remove. |
140 | * @n: node we're deleting. | 159 | * @n: node we're deleting. |
141 | */ | 160 | */ |
142 | 161 | void klist_del(struct klist_node *n) | |
143 | void klist_del(struct klist_node * n) | ||
144 | { | 162 | { |
145 | struct klist * k = n->n_klist; | 163 | struct klist *k = n->n_klist; |
146 | void (*put)(struct klist_node *) = k->put; | 164 | void (*put)(struct klist_node *) = k->put; |
147 | 165 | ||
148 | spin_lock(&k->k_lock); | 166 | spin_lock(&k->k_lock); |
@@ -152,48 +170,40 @@ void klist_del(struct klist_node * n) | |||
152 | if (put) | 170 | if (put) |
153 | put(n); | 171 | put(n); |
154 | } | 172 | } |
155 | |||
156 | EXPORT_SYMBOL_GPL(klist_del); | 173 | EXPORT_SYMBOL_GPL(klist_del); |
157 | 174 | ||
158 | |||
159 | /** | 175 | /** |
160 | * klist_remove - Decrement the refcount of node and wait for it to go away. | 176 | * klist_remove - Decrement the refcount of node and wait for it to go away. |
161 | * @n: node we're removing. | 177 | * @n: node we're removing. |
162 | */ | 178 | */ |
163 | 179 | void klist_remove(struct klist_node *n) | |
164 | void klist_remove(struct klist_node * n) | ||
165 | { | 180 | { |
166 | klist_del(n); | 181 | klist_del(n); |
167 | wait_for_completion(&n->n_removed); | 182 | wait_for_completion(&n->n_removed); |
168 | } | 183 | } |
169 | |||
170 | EXPORT_SYMBOL_GPL(klist_remove); | 184 | EXPORT_SYMBOL_GPL(klist_remove); |
171 | 185 | ||
172 | |||
173 | /** | 186 | /** |
174 | * klist_node_attached - Say whether a node is bound to a list or not. | 187 | * klist_node_attached - Say whether a node is bound to a list or not. |
175 | * @n: Node that we're testing. | 188 | * @n: Node that we're testing. |
176 | */ | 189 | */ |
177 | 190 | int klist_node_attached(struct klist_node *n) | |
178 | int klist_node_attached(struct klist_node * n) | ||
179 | { | 191 | { |
180 | return (n->n_klist != NULL); | 192 | return (n->n_klist != NULL); |
181 | } | 193 | } |
182 | |||
183 | EXPORT_SYMBOL_GPL(klist_node_attached); | 194 | EXPORT_SYMBOL_GPL(klist_node_attached); |
184 | 195 | ||
185 | |||
186 | /** | 196 | /** |
187 | * klist_iter_init_node - Initialize a klist_iter structure. | 197 | * klist_iter_init_node - Initialize a klist_iter structure. |
188 | * @k: klist we're iterating. | 198 | * @k: klist we're iterating. |
189 | * @i: klist_iter we're filling. | 199 | * @i: klist_iter we're filling. |
190 | * @n: node to start with. | 200 | * @n: node to start with. |
191 | * | 201 | * |
192 | * Similar to klist_iter_init(), but starts the action off with @n, | 202 | * Similar to klist_iter_init(), but starts the action off with @n, |
193 | * instead of with the list head. | 203 | * instead of with the list head. |
194 | */ | 204 | */ |
195 | 205 | void klist_iter_init_node(struct klist *k, struct klist_iter *i, | |
196 | void klist_iter_init_node(struct klist * k, struct klist_iter * i, struct klist_node * n) | 206 | struct klist_node *n) |
197 | { | 207 | { |
198 | i->i_klist = k; | 208 | i->i_klist = k; |
199 | i->i_head = &k->k_list; | 209 | i->i_head = &k->k_list; |
@@ -201,66 +211,56 @@ void klist_iter_init_node(struct klist * k, struct klist_iter * i, struct klist_ | |||
201 | if (n) | 211 | if (n) |
202 | kref_get(&n->n_ref); | 212 | kref_get(&n->n_ref); |
203 | } | 213 | } |
204 | |||
205 | EXPORT_SYMBOL_GPL(klist_iter_init_node); | 214 | EXPORT_SYMBOL_GPL(klist_iter_init_node); |
206 | 215 | ||
207 | |||
208 | /** | 216 | /** |
209 | * klist_iter_init - Iniitalize a klist_iter structure. | 217 | * klist_iter_init - Iniitalize a klist_iter structure. |
210 | * @k: klist we're iterating. | 218 | * @k: klist we're iterating. |
211 | * @i: klist_iter structure we're filling. | 219 | * @i: klist_iter structure we're filling. |
212 | * | 220 | * |
213 | * Similar to klist_iter_init_node(), but start with the list head. | 221 | * Similar to klist_iter_init_node(), but start with the list head. |
214 | */ | 222 | */ |
215 | 223 | void klist_iter_init(struct klist *k, struct klist_iter *i) | |
216 | void klist_iter_init(struct klist * k, struct klist_iter * i) | ||
217 | { | 224 | { |
218 | klist_iter_init_node(k, i, NULL); | 225 | klist_iter_init_node(k, i, NULL); |
219 | } | 226 | } |
220 | |||
221 | EXPORT_SYMBOL_GPL(klist_iter_init); | 227 | EXPORT_SYMBOL_GPL(klist_iter_init); |
222 | 228 | ||
223 | |||
224 | /** | 229 | /** |
225 | * klist_iter_exit - Finish a list iteration. | 230 | * klist_iter_exit - Finish a list iteration. |
226 | * @i: Iterator structure. | 231 | * @i: Iterator structure. |
227 | * | 232 | * |
228 | * Must be called when done iterating over list, as it decrements the | 233 | * Must be called when done iterating over list, as it decrements the |
229 | * refcount of the current node. Necessary in case iteration exited before | 234 | * refcount of the current node. Necessary in case iteration exited before |
230 | * the end of the list was reached, and always good form. | 235 | * the end of the list was reached, and always good form. |
231 | */ | 236 | */ |
232 | 237 | void klist_iter_exit(struct klist_iter *i) | |
233 | void klist_iter_exit(struct klist_iter * i) | ||
234 | { | 238 | { |
235 | if (i->i_cur) { | 239 | if (i->i_cur) { |
236 | klist_del(i->i_cur); | 240 | klist_del(i->i_cur); |
237 | i->i_cur = NULL; | 241 | i->i_cur = NULL; |
238 | } | 242 | } |
239 | } | 243 | } |
240 | |||
241 | EXPORT_SYMBOL_GPL(klist_iter_exit); | 244 | EXPORT_SYMBOL_GPL(klist_iter_exit); |
242 | 245 | ||
243 | 246 | static struct klist_node *to_klist_node(struct list_head *n) | |
244 | static struct klist_node * to_klist_node(struct list_head * n) | ||
245 | { | 247 | { |
246 | return container_of(n, struct klist_node, n_node); | 248 | return container_of(n, struct klist_node, n_node); |
247 | } | 249 | } |
248 | 250 | ||
249 | |||
250 | /** | 251 | /** |
251 | * klist_next - Ante up next node in list. | 252 | * klist_next - Ante up next node in list. |
252 | * @i: Iterator structure. | 253 | * @i: Iterator structure. |
253 | * | 254 | * |
254 | * First grab list lock. Decrement the reference count of the previous | 255 | * First grab list lock. Decrement the reference count of the previous |
255 | * node, if there was one. Grab the next node, increment its reference | 256 | * node, if there was one. Grab the next node, increment its reference |
256 | * count, drop the lock, and return that next node. | 257 | * count, drop the lock, and return that next node. |
257 | */ | 258 | */ |
258 | 259 | struct klist_node *klist_next(struct klist_iter *i) | |
259 | struct klist_node * klist_next(struct klist_iter * i) | ||
260 | { | 260 | { |
261 | struct list_head * next; | 261 | struct list_head *next; |
262 | struct klist_node * lnode = i->i_cur; | 262 | struct klist_node *lnode = i->i_cur; |
263 | struct klist_node * knode = NULL; | 263 | struct klist_node *knode = NULL; |
264 | void (*put)(struct klist_node *) = i->i_klist->put; | 264 | void (*put)(struct klist_node *) = i->i_klist->put; |
265 | 265 | ||
266 | spin_lock(&i->i_klist->k_lock); | 266 | spin_lock(&i->i_klist->k_lock); |
@@ -281,7 +281,4 @@ struct klist_node * klist_next(struct klist_iter * i) | |||
281 | put(lnode); | 281 | put(lnode); |
282 | return knode; | 282 | return knode; |
283 | } | 283 | } |
284 | |||
285 | EXPORT_SYMBOL_GPL(klist_next); | 284 | EXPORT_SYMBOL_GPL(klist_next); |
286 | |||
287 | |||
diff --git a/lib/kobject.c b/lib/kobject.c index fd7874032163..718e5101c263 100644 --- a/lib/kobject.c +++ b/lib/kobject.c | |||
@@ -216,21 +216,12 @@ static int kobject_add_internal(struct kobject *kobj) | |||
216 | static int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, | 216 | static int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, |
217 | va_list vargs) | 217 | va_list vargs) |
218 | { | 218 | { |
219 | va_list aq; | ||
220 | char *name; | ||
221 | |||
222 | va_copy(aq, vargs); | ||
223 | name = kvasprintf(GFP_KERNEL, fmt, vargs); | ||
224 | va_end(aq); | ||
225 | |||
226 | if (!name) | ||
227 | return -ENOMEM; | ||
228 | |||
229 | /* Free the old name, if necessary. */ | 219 | /* Free the old name, if necessary. */ |
230 | kfree(kobj->name); | 220 | kfree(kobj->name); |
231 | 221 | ||
232 | /* Now, set the new name */ | 222 | kobj->name = kvasprintf(GFP_KERNEL, fmt, vargs); |
233 | kobj->name = name; | 223 | if (!kobj->name) |
224 | return -ENOMEM; | ||
234 | 225 | ||
235 | return 0; | 226 | return 0; |
236 | } | 227 | } |
@@ -246,12 +237,12 @@ static int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, | |||
246 | */ | 237 | */ |
247 | int kobject_set_name(struct kobject *kobj, const char *fmt, ...) | 238 | int kobject_set_name(struct kobject *kobj, const char *fmt, ...) |
248 | { | 239 | { |
249 | va_list args; | 240 | va_list vargs; |
250 | int retval; | 241 | int retval; |
251 | 242 | ||
252 | va_start(args, fmt); | 243 | va_start(vargs, fmt); |
253 | retval = kobject_set_name_vargs(kobj, fmt, args); | 244 | retval = kobject_set_name_vargs(kobj, fmt, vargs); |
254 | va_end(args); | 245 | va_end(vargs); |
255 | 246 | ||
256 | return retval; | 247 | return retval; |
257 | } | 248 | } |
@@ -301,12 +292,9 @@ EXPORT_SYMBOL(kobject_init); | |||
301 | static int kobject_add_varg(struct kobject *kobj, struct kobject *parent, | 292 | static int kobject_add_varg(struct kobject *kobj, struct kobject *parent, |
302 | const char *fmt, va_list vargs) | 293 | const char *fmt, va_list vargs) |
303 | { | 294 | { |
304 | va_list aq; | ||
305 | int retval; | 295 | int retval; |
306 | 296 | ||
307 | va_copy(aq, vargs); | 297 | retval = kobject_set_name_vargs(kobj, fmt, vargs); |
308 | retval = kobject_set_name_vargs(kobj, fmt, aq); | ||
309 | va_end(aq); | ||
310 | if (retval) { | 298 | if (retval) { |
311 | printk(KERN_ERR "kobject: can not set name properly!\n"); | 299 | printk(KERN_ERR "kobject: can not set name properly!\n"); |
312 | return retval; | 300 | return retval; |