Skip to contentSkip to conversation

hwmon: (nct6683) Fix probe unwind paths to properly unregister platform devices

PATCH Superseded Axel Lin 2 participants 4 messages May 24, 2014 Hardware monitoring

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 hwmon: (nct6683) Fix probe unwind paths to properly unregister platform devices

Call platform_device_unregister() rather than platform_device_put() to unregister successfully registered platform devices.

---
 drivers/hwmon/nct6683.c | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)
drivers/hwmon/nct6683.c +16 -10
index 540c81c..1fd6098 100644
@@ -1389,13 +1389,15 @@ static int __init sensors_nct6683_init(void)
 		pdev[i] = platform_device_alloc(DRVNAME, address);
 		if (!pdev[i]) {
 			err = -ENOMEM;
-			goto exit_device_put;
+			goto exit_device_unregister;
 		}
 
 		err = platform_device_add_data(pdev[i], &sio_data,
 					       sizeof(struct nct6683_sio_data));
-		if (err)
-			goto exit_device_put;
+		if (err) {
+			platform_device_put(pdev[i]);
+			goto exit_device_unregister;
+		}
 
 		memset(&res, 0, sizeof(res));
 		res.name = DRVNAME;
@@ -1411,13 +1413,17 @@ static int __init sensors_nct6683_init(void)
 		}
 
 		err = platform_device_add_resources(pdev[i], &res, 1);
-		if (err)
-			goto exit_device_put;
+		if (err) {
+			platform_device_put(pdev[i]);
+			goto exit_device_unregister;
+		}
 
 		/* platform_device_add calls probe() */
 		err = platform_device_add(pdev[i]);
-		if (err)
-			goto exit_device_put;
+		if (err) {
+			platform_device_put(pdev[i]);
+			goto exit_device_unregister;
+		}
 	}
 	if (!found) {
 		err = -ENODEV;
@@ -1426,10 +1432,10 @@ static int __init sensors_nct6683_init(void)
 
 	return 0;
 
-exit_device_put:
-	for (i = 0; i < ARRAY_SIZE(pdev); i++) {
+exit_device_unregister:
+	while (--i >= 0) {
 		if (pdev[i])
-			platform_device_put(pdev[i]);
+			platform_device_unregister(pdev[i]);
 	}
 exit_unregister:
 	platform_driver_unregister(&nct6683_driver);
Signature · 9 lines
1.8.3.2




_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
maintainer
#1 lore raw

Re: [lm-sensors] [PATCH] hwmon: (nct6683) Fix probe unwind paths to properly unregister platform dev

Quoted 54 lines · Axel Lin

Call platform_device_unregister() rather than platform_device_put() to unregister successfully registered platform devices.

---
  drivers/hwmon/nct6683.c | 26 ++++++++++++++++----------
  1 file changed, 16 insertions(+), 10 deletions(-)
drivers/hwmon/nct6683.c +13 -7
index 540c81c..1fd6098 100644
@@ -1389,13 +1389,15 @@ static int __init sensors_nct6683_init(void)
  		pdev[i] = platform_device_alloc(DRVNAME, address);
  		if (!pdev[i]) {
  			err = -ENOMEM;
-			goto exit_device_put;
+			goto exit_device_unregister;
  		}
 
  		err = platform_device_add_data(pdev[i], &sio_data,
  					       sizeof(struct nct6683_sio_data));
-		if (err)
-			goto exit_device_put;
+		if (err) {
+			platform_device_put(pdev[i]);
+			goto exit_device_unregister;
+		}
 
  		memset(&res, 0, sizeof(res));
  		res.name = DRVNAME;
@@ -1411,13 +1413,17 @@ static int __init sensors_nct6683_init(void)
  		}
 
  		err = platform_device_add_resources(pdev[i], &res, 1);
-		if (err)
-			goto exit_device_put;
+		if (err) {
+			platform_device_put(pdev[i]);
+			goto exit_device_unregister;
+		}
 
  		/* platform_device_add calls probe() */
  		err = platform_device_add(pdev[i]);
-		if (err)
-			goto exit_device_put;
+		if (err) {
+			platform_device_put(pdev[i]);
+			goto exit_device_unregister;
+		}
  	}
  	if (!found) {
  		err = -ENODEV;

drivers/hwmon/nct6683.c static int __init sensors_nct6683_init(void) · line 1436

Quoted 7 lines
drivers/hwmon/nct6683.c +2 -2
@@ -1426,10 +1432,10 @@ static int __init sensors_nct6683_init(void)
 
  	return 0;
 
-exit_device_put:
-	for (i = 0; i < ARRAY_SIZE(pdev); i++) {
+exit_device_unregister:
+	while (--i >= 0) {

Hi Axel,

Good catch. Note that nct6775 has the same problem, if you want to tackle the problem there as well.

I think something like

exit_device_put:

	platform_device_put(pdev[i]);
exit_device_unregister:
	while (--i >= 0)
		platform_device_unregister(pdev[i]);

would be better though since it saves all the individual calls to platform_device_put(). Also, the if statement in the cleanup loop is no longer necessary.

Thanks,
Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

author
#2 lore raw

Re: [lm-sensors] [PATCH] hwmon: (nct6683) Fix probe unwind paths to properly unregister platform dev

In reply to Axel Lin
Quoted 4 lines

Hi Axel,

Good catch. Note that nct6775 has the same problem, if you want to tackle the problem there as well.

I think the nct6775 code is fine, it calls
platform_device_unregister() in probe error path.

Regards,
Axel

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

author
#3 lore raw

Re: [lm-sensors] [PATCH] hwmon: (nct6683) Fix probe unwind paths to properly unregister platform dev

In reply to Axel Lin

2014-05-24 23:08 GMT+08:00 Axel Lin <[email protected]>:

Quoted 6 lines
Quoted 4 lines

Hi Axel,

Good catch. Note that nct6775 has the same problem, if you want to tackle the problem there as well.

I think the nct6775 code is fine, it calls
platform_device_unregister() in probe error path.

Ooops, sorry.
it looks fine because I modified the code already in my local tree. will send a fix soon.

Quoted 3 lines

Regards,
Axel

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors