diff options
author | Kay Sievers <kay.sievers@vrfy.org> | 2008-03-12 15:47:35 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2008-04-30 19:52:49 -0400 |
commit | c3b19ff06e0808555403491d61e8f0cbbb53e933 (patch) | |
tree | 04fbb1a3a6944aa32d306f72cc8ca16d2446ba9a /drivers | |
parent | 4356d73d028ad0726cfaf31ad30c5d28fcd98795 (diff) |
driver core: remove no longer used "struct class_device"
Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/base/base.h | 11 | ||||
-rw-r--r-- | drivers/base/class.c | 638 |
2 files changed, 1 insertions, 648 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); |