diff options
author | Neil Horman <nhorman@tuxdriver.com> | 2006-12-06 23:37:08 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.osdl.org> | 2006-12-07 11:39:35 -0500 |
commit | 5d469ec0f40d65b2a0a704402990a43b2dafe197 (patch) | |
tree | e633e67ac9387042617f9de843f020d6116b2d84 | |
parent | dc168427e6250a5a24c59f34afed6538092dab42 (diff) |
[PATCH] Correct misc_register return code handling in several drivers
Clean up several code points in which the return code from misc_register is
not handled properly.
Several modules failed to deregister various hooks when misc_register fails,
and this patch cleans them up. Also there are a few modules that legitimately
don't care about the failure status of misc register. These drivers however
unilaterally call misc_deregister on module unload.
Since misc_register doesn't initialize the list_head in the init_routine if it
fails, the deregister operation is at risk for oopsing when list_del is
called. The initial solution was to manually init the list in the miscdev
structure in each of those modules, but the consensus in this thread was to
consolodate and do that universally inside misc_register.
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Cc: Bjorn Helgaas <bjorn.helgaas@hp.com>
Cc: Kylene Jo Hall <kjhall@us.ibm.com>
Cc: Dmitry Torokhov <dtor@mail.ru>
Cc: Olaf Hering <olh@suse.de>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r-- | drivers/char/misc.c | 2 | ||||
-rw-r--r-- | drivers/char/mmtimer.c | 23 | ||||
-rw-r--r-- | drivers/char/tpm/tpm.c | 1 | ||||
-rw-r--r-- | drivers/input/misc/hp_sdc_rtc.c | 4 | ||||
-rw-r--r-- | drivers/macintosh/apm_emu.c | 3 |
5 files changed, 26 insertions, 7 deletions
diff --git a/drivers/char/misc.c b/drivers/char/misc.c index 7a484fc7cb9e..7e975f606924 100644 --- a/drivers/char/misc.c +++ b/drivers/char/misc.c | |||
@@ -199,6 +199,8 @@ int misc_register(struct miscdevice * misc) | |||
199 | dev_t dev; | 199 | dev_t dev; |
200 | int err = 0; | 200 | int err = 0; |
201 | 201 | ||
202 | INIT_LIST_HEAD(&misc->list); | ||
203 | |||
202 | down(&misc_sem); | 204 | down(&misc_sem); |
203 | list_for_each_entry(c, &misc_list, list) { | 205 | list_for_each_entry(c, &misc_list, list) { |
204 | if (c->minor == misc->minor) { | 206 | if (c->minor == misc->minor) { |
diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c index 22b9905c1e52..c09160383a53 100644 --- a/drivers/char/mmtimer.c +++ b/drivers/char/mmtimer.c | |||
@@ -680,7 +680,7 @@ static int __init mmtimer_init(void) | |||
680 | if (sn_rtc_cycles_per_second < 100000) { | 680 | if (sn_rtc_cycles_per_second < 100000) { |
681 | printk(KERN_ERR "%s: unable to determine clock frequency\n", | 681 | printk(KERN_ERR "%s: unable to determine clock frequency\n", |
682 | MMTIMER_NAME); | 682 | MMTIMER_NAME); |
683 | return -1; | 683 | goto out1; |
684 | } | 684 | } |
685 | 685 | ||
686 | mmtimer_femtoperiod = ((unsigned long)1E15 + sn_rtc_cycles_per_second / | 686 | mmtimer_femtoperiod = ((unsigned long)1E15 + sn_rtc_cycles_per_second / |
@@ -689,13 +689,13 @@ static int __init mmtimer_init(void) | |||
689 | if (request_irq(SGI_MMTIMER_VECTOR, mmtimer_interrupt, IRQF_PERCPU, MMTIMER_NAME, NULL)) { | 689 | if (request_irq(SGI_MMTIMER_VECTOR, mmtimer_interrupt, IRQF_PERCPU, MMTIMER_NAME, NULL)) { |
690 | printk(KERN_WARNING "%s: unable to allocate interrupt.", | 690 | printk(KERN_WARNING "%s: unable to allocate interrupt.", |
691 | MMTIMER_NAME); | 691 | MMTIMER_NAME); |
692 | return -1; | 692 | goto out1; |
693 | } | 693 | } |
694 | 694 | ||
695 | if (misc_register(&mmtimer_miscdev)) { | 695 | if (misc_register(&mmtimer_miscdev)) { |
696 | printk(KERN_ERR "%s: failed to register device\n", | 696 | printk(KERN_ERR "%s: failed to register device\n", |
697 | MMTIMER_NAME); | 697 | MMTIMER_NAME); |
698 | return -1; | 698 | goto out2; |
699 | } | 699 | } |
700 | 700 | ||
701 | /* Get max numbered node, calculate slots needed */ | 701 | /* Get max numbered node, calculate slots needed */ |
@@ -709,16 +709,18 @@ static int __init mmtimer_init(void) | |||
709 | if (timers == NULL) { | 709 | if (timers == NULL) { |
710 | printk(KERN_ERR "%s: failed to allocate memory for device\n", | 710 | printk(KERN_ERR "%s: failed to allocate memory for device\n", |
711 | MMTIMER_NAME); | 711 | MMTIMER_NAME); |
712 | return -1; | 712 | goto out3; |
713 | } | 713 | } |
714 | 714 | ||
715 | memset(timers,0,(sizeof(mmtimer_t *)*maxn)); | ||
716 | |||
715 | /* Allocate mmtimer_t's for each online node */ | 717 | /* Allocate mmtimer_t's for each online node */ |
716 | for_each_online_node(node) { | 718 | for_each_online_node(node) { |
717 | timers[node] = kmalloc_node(sizeof(mmtimer_t)*NUM_COMPARATORS, GFP_KERNEL, node); | 719 | timers[node] = kmalloc_node(sizeof(mmtimer_t)*NUM_COMPARATORS, GFP_KERNEL, node); |
718 | if (timers[node] == NULL) { | 720 | if (timers[node] == NULL) { |
719 | printk(KERN_ERR "%s: failed to allocate memory for device\n", | 721 | printk(KERN_ERR "%s: failed to allocate memory for device\n", |
720 | MMTIMER_NAME); | 722 | MMTIMER_NAME); |
721 | return -1; | 723 | goto out4; |
722 | } | 724 | } |
723 | for (i=0; i< NUM_COMPARATORS; i++) { | 725 | for (i=0; i< NUM_COMPARATORS; i++) { |
724 | mmtimer_t * base = timers[node] + i; | 726 | mmtimer_t * base = timers[node] + i; |
@@ -739,6 +741,17 @@ static int __init mmtimer_init(void) | |||
739 | sn_rtc_cycles_per_second/(unsigned long)1E6); | 741 | sn_rtc_cycles_per_second/(unsigned long)1E6); |
740 | 742 | ||
741 | return 0; | 743 | return 0; |
744 | |||
745 | out4: | ||
746 | for_each_online_node(node) { | ||
747 | kfree(timers[node]); | ||
748 | } | ||
749 | out3: | ||
750 | misc_deregister(&mmtimer_miscdev); | ||
751 | out2: | ||
752 | free_irq(SGI_MMTIMER_VECTOR, NULL); | ||
753 | out1: | ||
754 | return -1; | ||
742 | } | 755 | } |
743 | 756 | ||
744 | module_init(mmtimer_init); | 757 | module_init(mmtimer_init); |
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c index 774fa861169a..33e1f66e39cb 100644 --- a/drivers/char/tpm/tpm.c +++ b/drivers/char/tpm/tpm.c | |||
@@ -1155,6 +1155,7 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend | |||
1155 | 1155 | ||
1156 | if (sysfs_create_group(&dev->kobj, chip->vendor.attr_group)) { | 1156 | if (sysfs_create_group(&dev->kobj, chip->vendor.attr_group)) { |
1157 | list_del(&chip->list); | 1157 | list_del(&chip->list); |
1158 | misc_deregister(&chip->vendor.miscdev); | ||
1158 | put_device(dev); | 1159 | put_device(dev); |
1159 | clear_bit(chip->dev_num, dev_mask); | 1160 | clear_bit(chip->dev_num, dev_mask); |
1160 | kfree(chip); | 1161 | kfree(chip); |
diff --git a/drivers/input/misc/hp_sdc_rtc.c b/drivers/input/misc/hp_sdc_rtc.c index ab4da79ee560..31d5a13bfd6b 100644 --- a/drivers/input/misc/hp_sdc_rtc.c +++ b/drivers/input/misc/hp_sdc_rtc.c | |||
@@ -695,7 +695,9 @@ static int __init hp_sdc_rtc_init(void) | |||
695 | 695 | ||
696 | if ((ret = hp_sdc_request_timer_irq(&hp_sdc_rtc_isr))) | 696 | if ((ret = hp_sdc_request_timer_irq(&hp_sdc_rtc_isr))) |
697 | return ret; | 697 | return ret; |
698 | misc_register(&hp_sdc_rtc_dev); | 698 | if (misc_register(&hp_sdc_rtc_dev) != 0) |
699 | printk(KERN_INFO "Could not register misc. dev for i8042 rtc\n"); | ||
700 | |||
699 | create_proc_read_entry ("driver/rtc", 0, NULL, | 701 | create_proc_read_entry ("driver/rtc", 0, NULL, |
700 | hp_sdc_rtc_read_proc, NULL); | 702 | hp_sdc_rtc_read_proc, NULL); |
701 | 703 | ||
diff --git a/drivers/macintosh/apm_emu.c b/drivers/macintosh/apm_emu.c index 1293876a2ebd..8862a83b8d84 100644 --- a/drivers/macintosh/apm_emu.c +++ b/drivers/macintosh/apm_emu.c | |||
@@ -529,7 +529,8 @@ static int __init apm_emu_init(void) | |||
529 | if (apm_proc) | 529 | if (apm_proc) |
530 | apm_proc->owner = THIS_MODULE; | 530 | apm_proc->owner = THIS_MODULE; |
531 | 531 | ||
532 | misc_register(&apm_device); | 532 | if (misc_register(&apm_device) != 0) |
533 | printk(KERN_INFO "Could not create misc. device for apm\n"); | ||
533 | 534 | ||
534 | pmu_register_sleep_notifier(&apm_sleep_notifier); | 535 | pmu_register_sleep_notifier(&apm_sleep_notifier); |
535 | 536 | ||