Skip to contentSkip to conversation

handle error path in edac_mc_sysfs_init()

PATCH In review Denis Kirjanov 4 participants 5 messages Oct 25, 2012 EDAC-core

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 handle error path in edac_mc_sysfs_init()

Handle errors on edac_mc_sysfs_init()'s error path

---
 drivers/edac/edac_mc_sysfs.c |   14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/edac/edac_mc_sysfs.c +12 -2
index ed0bc07..ea34ece 100644
@@ -1124,11 +1124,16 @@ int __init edac_mc_sysfs_init(void)
 	edac_subsys = edac_get_sysfs_subsys();
 	if (edac_subsys == NULL) {
 		edac_dbg(1, "no edac_subsys\n");
-		return -EINVAL;
+		err = -EINVAL;
+		goto out;
 	}
 
 	mci_pdev = kzalloc(sizeof(*mci_pdev), GFP_KERNEL);
-
+	if (!mci_pdev) {
+		err = -ENOMEM;
+		goto out_put_sysfs;
+	}
+		
 	mci_pdev->bus = edac_subsys;
 	mci_pdev->type = &mc_attr_type;
 	device_initialize(mci_pdev);
@@ -1141,6 +1146,11 @@ int __init edac_mc_sysfs_init(void)
 	edac_dbg(0, "device %s created\n", dev_name(mci_pdev));
 
 	return 0;
+
+out_put_sysfs:
+	edac_put_sysfs_subsys();
+out:
+	return err;
 }
 
 void __exit edac_mc_sysfs_exit(void)
Signature · 1 line
1.7.9.5
maintainer
#1 lore raw
Quoted 31 lines · Denis Kirjanov

Handle errors on edac_mc_sysfs_init()'s error path

---
 drivers/edac/edac_mc_sysfs.c |   14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/edac/edac_mc_sysfs.c +7 -2
index ed0bc07..ea34ece 100644
@@ -1124,11 +1124,16 @@ int __init edac_mc_sysfs_init(void)
 	edac_subsys = edac_get_sysfs_subsys();
 	if (edac_subsys == NULL) {
 		edac_dbg(1, "no edac_subsys\n");
-		return -EINVAL;
+		err = -EINVAL;
+		goto out;
 	}
 
 	mci_pdev = kzalloc(sizeof(*mci_pdev), GFP_KERNEL);
-
+	if (!mci_pdev) {
+		err = -ENOMEM;
+		goto out_put_sysfs;
+	}
+		
 	mci_pdev->bus = edac_subsys;
 	mci_pdev->type = &mc_attr_type;
 	device_initialize(mci_pdev);

drivers/edac/edac_mc_sysfs.c int __init edac_mc_sysfs_init(void) · line 1146

Quoted 1 line
drivers/edac/edac_mc_sysfs.c +0 -0
@@ -1141,6 +1146,11 @@ int __init edac_mc_sysfs_init(void)
 	edac_dbg(0, "device %s created\n", dev_name(mci_pdev));

Thanks for doing this.

However, from looking at this function further, it is still f*cked up - the error path after device_add needs handling too, i.e. adding another label:

out_device_add:
kfree(mci_pdev);

drivers/edac/edac_mc_sysfs.c int __init edac_mc_sysfs_init(void) · line 1153

Quoted 4 lines
drivers/edac/edac_mc_sysfs.c +4 -0
+out_put_sysfs:
+	edac_put_sysfs_subsys();
+out:
+	return err;

to which you can goto to after device_add fails.

Would you be willing to fix that too, while you're at it? Btw, I can totally understand if you say no - I'll take care of it myself instead then :-).

Thanks.

Signature · 2 lines
Regards/Gruss,
Boris.
maintainer
#2 lore raw
Quoted 3 lines · Borislav Petkov

Would you be willing to fix that too, while you're at it? Btw, I can totally understand if you say no - I'll take care of it myself instead then :-).

Ah, maybe I should look at the second patch before replying to this one. Nevermind, I'll merge the two into one and test.

Thanks.

Signature · 2 lines
Regards/Gruss,
Boris.
#3 lore raw

(remove Doug's email from CC since it bounces)

Quoted 7 lines · Borislav Petkov
Quoted 3 lines · Borislav Petkov

Would you be willing to fix that too, while you're at it? Btw, I can totally understand if you say no - I'll take care of it myself instead then :-).

Ah, maybe I should look at the second patch before replying to this one. Nevermind, I'll merge the two into one and test.

Ok, here's the final version I'm sending upstream soon:

--

Quoted 1 line

From a8373ecc0c26d8afafd0d2e88f96756e26b7f3ee Mon Sep 17 00:00:00 2001

From: Denis Kirjanov <[email protected]>
Date: Thu, 25 Oct 2012 19:42:58 +0400
Subject: [PATCH] EDAC: Handle error path in edac_mc_sysfs_init() properly

Make sure proper deregistration happens on all error paths in edac_mc_sysfs_init.

[ Boris: cleanup and concretize commit message ]
---
 drivers/edac/edac_mc_sysfs.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/edac/edac_mc_sysfs.c +15 -2
index 52813b8b0f5f..de2df92f9c77 100644
@@ -1126,10 +1126,15 @@ int __init edac_mc_sysfs_init(void)
 	edac_subsys = edac_get_sysfs_subsys();
 	if (edac_subsys == NULL) {
 		edac_dbg(1, "no edac_subsys\n");
-		return -EINVAL;
+		err = -EINVAL;
+		goto out;
 	}
 
 	mci_pdev = kzalloc(sizeof(*mci_pdev), GFP_KERNEL);
+	if (!mci_pdev) {
+		err = -ENOMEM;
+		goto out_put_sysfs;
+	}
 
 	mci_pdev->bus = edac_subsys;
 	mci_pdev->type = &mc_attr_type;
@@ -1138,11 +1143,18 @@ int __init edac_mc_sysfs_init(void)
 
 	err = device_add(mci_pdev);
 	if (err < 0)
-		return err;
+		goto out_dev_free;
 
 	edac_dbg(0, "device %s created\n", dev_name(mci_pdev));
 
 	return 0;
+
+ out_dev_free:
+	kfree(mci_pdev);
+ out_put_sysfs:
+	edac_put_sysfs_subsys();
+ out:
+	return err;
 }
 
 void __exit edac_mc_sysfs_exit(void)
@@ -1150,4 +1162,5 @@ void __exit edac_mc_sysfs_exit(void)
 	put_device(mci_pdev);
 	device_del(mci_pdev);
 	edac_put_sysfs_subsys();
+	kfree(mci_pdev);
 }
Signature · 11 lines
1.8.0

-- 
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
GM: Alberto Bozzo
Reg: Dornach, Landkreis Muenchen
HRB Nr. 43632 WEEE Registernr: 129 19551
#4 lore raw

Em Thu, 25 Oct 2012 18:36:53 +0200
Borislav Petkov <[email protected]> escreveu:

Quoted 19 lines

(remove Doug's email from CC since it bounces)

Quoted 7 lines · Borislav Petkov
Quoted 3 lines · Borislav Petkov

Would you be willing to fix that too, while you're at it? Btw, I can totally understand if you say no - I'll take care of it myself instead then :-).

Ah, maybe I should look at the second patch before replying to this one. Nevermind, I'll merge the two into one and test.

Ok, here's the final version I'm sending upstream soon:

--
From a8373ecc0c26d8afafd0d2e88f96756e26b7f3ee Mon Sep 17 00:00:00 2001
From: Denis Kirjanov <[email protected]>
Date: Thu, 25 Oct 2012 19:42:58 +0400
Subject: [PATCH] EDAC: Handle error path in edac_mc_sysfs_init() properly

Quoted 6 lines

Make sure proper deregistration happens on all error paths in edac_mc_sysfs_init.

[ Boris: cleanup and concretize commit message ]
Quoted 51 lines
---
 drivers/edac/edac_mc_sysfs.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/edac/edac_mc_sysfs.c +15 -2
index 52813b8b0f5f..de2df92f9c77 100644
@@ -1126,10 +1126,15 @@ int __init edac_mc_sysfs_init(void)
 	edac_subsys = edac_get_sysfs_subsys();
 	if (edac_subsys == NULL) {
 		edac_dbg(1, "no edac_subsys\n");
-		return -EINVAL;
+		err = -EINVAL;
+		goto out;
 	}
 
 	mci_pdev = kzalloc(sizeof(*mci_pdev), GFP_KERNEL);
+	if (!mci_pdev) {
+		err = -ENOMEM;
+		goto out_put_sysfs;
+	}
 
 	mci_pdev->bus = edac_subsys;
 	mci_pdev->type = &mc_attr_type;
@@ -1138,11 +1143,18 @@ int __init edac_mc_sysfs_init(void)
 
 	err = device_add(mci_pdev);
 	if (err < 0)
-		return err;
+		goto out_dev_free;
 
 	edac_dbg(0, "device %s created\n", dev_name(mci_pdev));
 
 	return 0;
+
+ out_dev_free:
+	kfree(mci_pdev);
+ out_put_sysfs:
+	edac_put_sysfs_subsys();
+ out:
+	return err;
 }
 
 void __exit edac_mc_sysfs_exit(void)
@@ -1150,4 +1162,5 @@ void __exit edac_mc_sysfs_exit(void)
 	put_device(mci_pdev);
 	device_del(mci_pdev);
 	edac_put_sysfs_subsys();
+	kfree(mci_pdev);
 }
Signature · 2 lines
Regards,
Mauro