aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kobject.c
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@suse.de>2007-01-18 15:23:51 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2007-02-07 13:37:10 -0500
commit31b9025aa0f89b392077db3f87458fd46bcc4f58 (patch)
treed91abfcfd10f78813011c8a33d176d492c368c66 /lib/kobject.c
parent5331be090567d9335476f876b2d85427cd7c4426 (diff)
Kobject: make kobject apis more robust in handling NULL pointers
It should be ok to pass in NULL for some kobject functions, so add error checking for all exported kobject functions to be more robust. Cc: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'lib/kobject.c')
-rw-r--r--lib/kobject.c19
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 */
127void kobject_init(struct kobject * kobj) 127void 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
367void kobject_del(struct kobject * kobj) 369void 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
378void kobject_unregister(struct kobject * kobj) 382void 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
524int kset_register(struct kset * k) 530int 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
536void kset_unregister(struct kset * k) 544void 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
599void subsystem_unregister(struct subsystem * s) 612void 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)
612int subsys_create_file(struct subsystem * s, struct subsys_attribute * a) 627int 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);