Skip to contentSkip to conversation

hwmon: (it87) Convert to use devm_kzalloc

PATCH In review Guenter Roeck 3 participants 4 messages May 9, 2012 – May 11, 2012

Subsystems (2)
lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH 2/3 hwmon: (it87) Convert to use devm_kzalloc

This makes the code a bit simpler and smaller.

---
 drivers/hwmon/it87.c |   10 ++--------
 1 files changed, 2 insertions(+), 8 deletions(-)
drivers/hwmon/it87.c +2 -8
index baf4173..47dbb2c 100644
@@ -1967,7 +1967,7 @@ static int __devinit it87_probe(struct platform_device *pdev)
 		goto ERROR0;
 	}
 
-	data = kzalloc(sizeof(struct it87_data), GFP_KERNEL);
+	data = devm_kzalloc(&pdev->dev, sizeof(struct it87_data), GFP_KERNEL);
 	if (!data) {
 		err = -ENOMEM;
 		goto ERROR1;
@@ -1982,7 +1982,7 @@ static int __devinit it87_probe(struct platform_device *pdev)
 	if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80)
 	 || it87_read_value(data, IT87_REG_CHIPID) != 0x90) {
 		err = -ENODEV;
-		goto ERROR2;
+		goto ERROR1;
 	}
 
 	platform_set_drvdata(pdev, data);
@@ -2114,9 +2114,6 @@ static int __devinit it87_probe(struct platform_device *pdev)
 
 ERROR4:
 	it87_remove_files(dev);
-ERROR2:
-	platform_set_drvdata(pdev, NULL);
-	kfree(data);
 ERROR1:
 	release_region(res->start, IT87_EC_EXTENT);
 ERROR0:
@@ -2131,9 +2128,6 @@ static int __devexit it87_remove(struct platform_device *pdev)
 	it87_remove_files(&pdev->dev);
 
 	release_region(data->addr, IT87_EC_EXTENT);
-	platform_set_drvdata(pdev, NULL);
-	kfree(data);
-
 	return 0;
 }
 
Signature · 7 lines
1.7.5.4


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Acked-by on v1 2/3
#1 lore raw
Quoted 40 lines · Guenter Roeck

This makes the code a bit simpler and smaller.

---
 drivers/hwmon/it87.c |   10 ++--------
 1 files changed, 2 insertions(+), 8 deletions(-)
drivers/hwmon/it87.c +2 -5
index baf4173..47dbb2c 100644
@@ -1967,7 +1967,7 @@ static int __devinit it87_probe(struct platform_device *pdev)
 		goto ERROR0;
 	}
 
-	data = kzalloc(sizeof(struct it87_data), GFP_KERNEL);
+	data = devm_kzalloc(&pdev->dev, sizeof(struct it87_data), GFP_KERNEL);
 	if (!data) {
 		err = -ENOMEM;
 		goto ERROR1;
@@ -1982,7 +1982,7 @@ static int __devinit it87_probe(struct platform_device *pdev)
 	if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80)
 	 || it87_read_value(data, IT87_REG_CHIPID) != 0x90) {
 		err = -ENODEV;
-		goto ERROR2;
+		goto ERROR1;
 	}
 
 	platform_set_drvdata(pdev, data);
@@ -2114,9 +2114,6 @@ static int __devinit it87_probe(struct platform_device *pdev)
 
 ERROR4:
 	it87_remove_files(dev);
-ERROR2:
-	platform_set_drvdata(pdev, NULL);
-	kfree(data);
 ERROR1:
 	release_region(res->start, IT87_EC_EXTENT);
 ERROR0:

drivers/hwmon/it87.c static int __devexit it87_remove(struct platform_device *pdev) · line 2133

Quoted 9 lines
drivers/hwmon/it87.c +0 -3
@@ -2131,9 +2128,6 @@ static int __devexit it87_remove(struct platform_device *pdev)
 	it87_remove_files(&pdev->dev);
 
 	release_region(data->addr, IT87_EC_EXTENT);
-	platform_set_drvdata(pdev, NULL);
-	kfree(data);
-
 	return 0;
 }
 

Looks good.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#2 lore raw
In reply to Guenter Roeck
Quoted 6 lines · Guenter Roeck

This makes the code a bit simpler and smaller.

---
 drivers/hwmon/it87.c |   10 ++--------
 1 files changed, 2 insertions(+), 8 deletions(-)

You'll have to adjust this patch as it is killing label ERROR2 which is still in use now that patch "hwmon: (it87) Create voltage attributes only if voltage is enabled" was updated.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#3 lore raw
In reply to Guenter Roeck
Quoted 12 lines · Jean Delvare
Quoted 6 lines · Guenter Roeck

This makes the code a bit simpler and smaller.

---
 drivers/hwmon/it87.c |   10 ++--------
 1 files changed, 2 insertions(+), 8 deletions(-)

You'll have to adjust this patch as it is killing label ERROR2 which is still in use now that patch "hwmon: (it87) Create voltage attributes only if voltage is enabled" was updated.

Actually, since I am touching it, I'll also convert the request_region call to devm_request_region. That will remove most of the labels. I'll send out a revised patch in a minute.

Thanks,
Guenter

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