Skip to contentSkip to conversation

hwmon: (lm78) Convert to use devm_ functions

PATCH Superseded Guenter Roeck 2 participants 3 messages Jun 15, 2012 – Jun 16, 2012

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH 46/95 hwmon: (lm78) Convert to use devm_ functions

Convert to use devm_ functions to reduce code size and simplify the code.

---
 drivers/hwmon/lm78.c |   38 ++++++++++++--------------------------
 1 file changed, 12 insertions(+), 26 deletions(-)
drivers/hwmon/lm78.c +12 -26
index f6bc414..1eacac9 100644
@@ -660,7 +660,7 @@ static int lm78_i2c_probe(struct i2c_client *client,
 	struct lm78_data *data;
 	int err;
 
-	data = kzalloc(sizeof(struct lm78_data), GFP_KERNEL);
+	data = devm_kzalloc(&client->dev, sizeof(struct lm78_data), GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
 
@@ -674,20 +674,18 @@ static int lm78_i2c_probe(struct i2c_client *client,
 	/* Register sysfs hooks */
 	err = sysfs_create_group(&client->dev.kobj, &lm78_group);
 	if (err)
-		goto ERROR3;
+		return err;
 
 	data->hwmon_dev = hwmon_device_register(&client->dev);
 	if (IS_ERR(data->hwmon_dev)) {
 		err = PTR_ERR(data->hwmon_dev);
-		goto ERROR4;
+		goto error;
 	}
 
 	return 0;
 
-ERROR4:
+error:
 	sysfs_remove_group(&client->dev.kobj, &lm78_group);
-ERROR3:
-	kfree(data);
 	return err;
 }
 
@@ -697,7 +695,6 @@ static int lm78_i2c_remove(struct i2c_client *client)
 
 	hwmon_device_unregister(data->hwmon_dev);
 	sysfs_remove_group(&client->dev.kobj, &lm78_group);
-	kfree(data);
 
 	return 0;
 }
@@ -844,16 +841,14 @@ static int __devinit lm78_isa_probe(struct platform_device *pdev)
 
 	/* Reserve the ISA region */
 	res = platform_get_resource(pdev, IORESOURCE_IO, 0);
-	if (!request_region(res->start + LM78_ADDR_REG_OFFSET, 2, "lm78")) {
-		err = -EBUSY;
-		goto exit;
-	}
+	if (!devm_request_region(&pdev->dev, res->start + LM78_ADDR_REG_OFFSET,
+				 2, "lm78"))
+		return -EBUSY;
+
+	data = devm_kzalloc(&pdev->dev, sizeof(struct lm78_data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
 
-	data = kzalloc(sizeof(struct lm78_data), GFP_KERNEL);
-	if (!data) {
-		err = -ENOMEM;
-		goto exit_release_region;
-	}
 	mutex_init(&data->lock);
 	data->isa_addr = res->start;
 	platform_set_drvdata(pdev, data);
@@ -885,28 +880,19 @@ static int __devinit lm78_isa_probe(struct platform_device *pdev)
 
 	return 0;
 
- exit_remove_files:
+exit_remove_files:
 	sysfs_remove_group(&pdev->dev.kobj, &lm78_group);
 	device_remove_file(&pdev->dev, &dev_attr_name);
-	kfree(data);
- exit_release_region:
-	release_region(res->start + LM78_ADDR_REG_OFFSET, 2);
- exit:
 	return err;
 }
 
 static int __devexit lm78_isa_remove(struct platform_device *pdev)
 {
 	struct lm78_data *data = platform_get_drvdata(pdev);
-	struct resource *res;
 
 	hwmon_device_unregister(data->hwmon_dev);
 	sysfs_remove_group(&pdev->dev.kobj, &lm78_group);
 	device_remove_file(&pdev->dev, &dev_attr_name);
-	kfree(data);
-
-	res = platform_get_resource(pdev, IORESOURCE_IO, 0);
-	release_region(res->start + LM78_ADDR_REG_OFFSET, 2);
 
 	return 0;
 }
Signature · 7 lines
1.7.9.7


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

Convert to use devm_ functions to reduce code size and simplify the code.

---
 drivers/hwmon/lm78.c |   38 ++++++++++++--------------------------
 1 file changed, 12 insertions(+), 26 deletions(-)
drivers/hwmon/lm78.c +0 -0
index f6bc414..1eacac9 100644
(...)

drivers/hwmon/lm78.c static int __devinit lm78_isa_probe(struct platform_device *pdev) · line 883

Quoted 5 lines
drivers/hwmon/lm78.c +1 -1
@@ -885,28 +880,19 @@ static int __devinit lm78_isa_probe(struct platform_device *pdev)
 
 	return 0;
 
- exit_remove_files:
+exit_remove_files:

The space before the label wasn't a mistake, it's there on purpose. The goal is to let diff -p display function names rather than labels. I seemed to recall that Documentation/CodingStyle mentioned that, but I can't find it again. You'll notice though that checkpatch doesn't complain about it, not even in strict mode.

Other than this:

Signature · 6 lines
Jean Delvare

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

Convert to use devm_ functions to reduce code size and simplify the code.

---
 drivers/hwmon/lm78.c |   38 ++++++++++++--------------------------
 1 file changed, 12 insertions(+), 26 deletions(-)
drivers/hwmon/lm78.c +0 -0
index f6bc414..1eacac9 100644
(...)
@@ -885,28 +880,19 @@ static int __devinit lm78_isa_probe(struct platform_device *pdev)
 
 	return 0;
 
Quoted 9 lines

drivers/hwmon/lm78.c static int __devinit lm78_isa_probe(struct platform_device *pdev) · line 883

Quoted 2 lines
drivers/hwmon/lm78.c +1 -1
- exit_remove_files:
+exit_remove_files:

The space before the label wasn't a mistake, it's there on purpose. The goal is to let diff -p display function names rather than labels. I seemed to recall that Documentation/CodingStyle mentioned that, but I can't find it again. You'll notice though that checkpatch doesn't complain about it, not even in strict mode.

No problem, I'll change that.

Quoted 4 lines

Other than this:

Thanks,
Guenter

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