diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/kobject.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/kobject.c b/lib/kobject.c index 7ce6dc138e90..9aed594bfcac 100644 --- a/lib/kobject.c +++ b/lib/kobject.c | |||
@@ -126,6 +126,8 @@ EXPORT_SYMBOL_GPL(kobject_get_path); | |||
126 | */ | 126 | */ |
127 | void kobject_init(struct kobject * kobj) | 127 | void kobject_init(struct kobject * kobj) |
128 | { | 128 | { |
129 | if (!kobj) | ||
130 | return; | ||
129 | kref_init(&kobj->kref); | 131 | kref_init(&kobj->kref); |
130 | INIT_LIST_HEAD(&kobj->entry); | 132 | INIT_LIST_HEAD(&kobj->entry); |
131 | init_waitqueue_head(&kobj->poll); | 133 | init_waitqueue_head(&kobj->poll); |
@@ -366,6 +368,8 @@ out: | |||
366 | 368 | ||
367 | void kobject_del(struct kobject * kobj) | 369 | void kobject_del(struct kobject * kobj) |
368 | { | 370 | { |
371 | if (!kobj) | ||
372 | return; | ||
369 | sysfs_remove_dir(kobj); | 373 | sysfs_remove_dir(kobj); |
370 | unlink(kobj); | 374 | unlink(kobj); |
371 | } | 375 | } |
@@ -377,6 +381,8 @@ void kobject_del(struct kobject * kobj) | |||
377 | 381 | ||
378 | void kobject_unregister(struct kobject * kobj) | 382 | void kobject_unregister(struct kobject * kobj) |
379 | { | 383 | { |
384 | if (!kobj) | ||
385 | return; | ||
380 | pr_debug("kobject %s: unregistering\n",kobject_name(kobj)); | 386 | pr_debug("kobject %s: unregistering\n",kobject_name(kobj)); |
381 | kobject_uevent(kobj, KOBJ_REMOVE); | 387 | kobject_uevent(kobj, KOBJ_REMOVE); |
382 | kobject_del(kobj); | 388 | kobject_del(kobj); |
@@ -523,6 +529,8 @@ int kset_add(struct kset * k) | |||
523 | 529 | ||
524 | int kset_register(struct kset * k) | 530 | int kset_register(struct kset * k) |
525 | { | 531 | { |
532 | if (!k) | ||
533 | return -EINVAL; | ||
526 | kset_init(k); | 534 | kset_init(k); |
527 | return kset_add(k); | 535 | return kset_add(k); |
528 | } | 536 | } |
@@ -535,6 +543,8 @@ int kset_register(struct kset * k) | |||
535 | 543 | ||
536 | void kset_unregister(struct kset * k) | 544 | void kset_unregister(struct kset * k) |
537 | { | 545 | { |
546 | if (!k) | ||
547 | return; | ||
538 | kobject_unregister(&k->kobj); | 548 | kobject_unregister(&k->kobj); |
539 | } | 549 | } |
540 | 550 | ||
@@ -586,6 +596,9 @@ int subsystem_register(struct subsystem * s) | |||
586 | { | 596 | { |
587 | int error; | 597 | int error; |
588 | 598 | ||
599 | if (!s) | ||
600 | return -EINVAL; | ||
601 | |||
589 | subsystem_init(s); | 602 | subsystem_init(s); |
590 | pr_debug("subsystem %s: registering\n",s->kset.kobj.name); | 603 | pr_debug("subsystem %s: registering\n",s->kset.kobj.name); |
591 | 604 | ||
@@ -598,6 +611,8 @@ int subsystem_register(struct subsystem * s) | |||
598 | 611 | ||
599 | void subsystem_unregister(struct subsystem * s) | 612 | void subsystem_unregister(struct subsystem * s) |
600 | { | 613 | { |
614 | if (!s) | ||
615 | return; | ||
601 | pr_debug("subsystem %s: unregistering\n",s->kset.kobj.name); | 616 | pr_debug("subsystem %s: unregistering\n",s->kset.kobj.name); |
602 | kset_unregister(&s->kset); | 617 | kset_unregister(&s->kset); |
603 | } | 618 | } |
@@ -612,6 +627,10 @@ void subsystem_unregister(struct subsystem * s) | |||
612 | int subsys_create_file(struct subsystem * s, struct subsys_attribute * a) | 627 | int subsys_create_file(struct subsystem * s, struct subsys_attribute * a) |
613 | { | 628 | { |
614 | int error = 0; | 629 | int error = 0; |
630 | |||
631 | if (!s || !a) | ||
632 | return -EINVAL; | ||
633 | |||
615 | if (subsys_get(s)) { | 634 | if (subsys_get(s)) { |
616 | error = sysfs_create_file(&s->kset.kobj,&a->attr); | 635 | error = sysfs_create_file(&s->kset.kobj,&a->attr); |
617 | subsys_put(s); | 636 | subsys_put(s); |