[PATCH] edd: fix error paths in module_init
From: Akinobu Mita
Date: Fri May 23 2008 - 22:15:34 EST
This patch fixes error handlings when kzalloc() or edd_device_register()
failed in module_init. It needs to clean registered edd_devices before
return error.
Also this patch fixes return value of module_init. module_init should not
return positive value.
Signed-off-by: Akinobu Mita <akinobu.mita@xxxxxxxxx>
Cc: Matt Domsch <Matt_Domsch@xxxxxxxx>
---
drivers/firmware/edd.c | 30 ++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)
Index: 2.6-git/drivers/firmware/edd.c
===================================================================
--- 2.6-git.orig/drivers/firmware/edd.c
+++ 2.6-git/drivers/firmware/edd.c
@@ -718,8 +718,7 @@ edd_device_register(struct edd_device *e
{
int error;
- if (!edev)
- return 1;
+ BUG_ON(!edev);
edd_dev_set_info(edev, i);
edev->kobj.kset = edd_kset;
error = kobject_init_and_add(&edev->kobj, &edd_ktype, NULL,
@@ -744,8 +743,8 @@ static inline int edd_num_devices(void)
static int __init
edd_init(void)
{
- unsigned int i;
- int rc=0;
+ int i;
+ int rc;
struct edd_device *edev;
printk(KERN_INFO "BIOS EDD facility v%s %s, %d devices found\n",
@@ -753,29 +752,36 @@ edd_init(void)
if (!edd_num_devices()) {
printk(KERN_INFO "EDD information not available.\n");
- return 1;
+ return -ENODEV;
}
edd_kset = kset_create_and_add("edd", NULL, firmware_kobj);
if (!edd_kset)
return -ENOMEM;
- for (i = 0; i < edd_num_devices() && !rc; i++) {
+ for (i = 0; i < edd_num_devices(); i++) {
edev = kzalloc(sizeof (*edev), GFP_KERNEL);
- if (!edev)
- return -ENOMEM;
+ if (!edev) {
+ rc = -ENOMEM;
+ goto out;
+ }
rc = edd_device_register(edev, i);
if (rc) {
kfree(edev);
- break;
+ goto out;
}
edd_devices[i] = edev;
}
- if (rc)
- kset_unregister(edd_kset);
- return rc;
+ return 0;
+out:
+ while (--i >= 0)
+ edd_device_unregister(edd_devices[i]);
+
+ kset_unregister(edd_kset);
+
+ return rc;
}
static void __exit
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/