[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20080524020321.GA3470@APFDCB5C>
Date: Sat, 24 May 2008 11:03:23 +0900
From: Akinobu Mita <akinobu.mita@...il.com>
To: linux-kernel@...r.kernel.org
Cc: Matt Domsch <Matt_Domsch@...l.com>
Subject: [PATCH] edd: fix error paths in module_init
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@...il.com>
Cc: Matt Domsch <Matt_Domsch@...l.com>
---
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@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists