Skip to contentSkip to conversation

hwmon: (thmc50) Convert to use devm_ functions

PATCH Superseded Guenter Roeck 2 participants 3 messages Jun 15, 2012 – Jun 17, 2012 Hardware monitoring

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH 75/95 hwmon: (thmc50) Convert to use devm_ functions

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

---
 drivers/hwmon/thmc50.c |   15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/hwmon/thmc50.c +5 -10
index add9f01..2f78e3f 100644
@@ -361,11 +361,11 @@ static int thmc50_probe(struct i2c_client *client,
 	struct thmc50_data *data;
 	int err;
 
-	data = kzalloc(sizeof(struct thmc50_data), GFP_KERNEL);
+	data = devm_kzalloc(&client->dev, sizeof(struct thmc50_data),
+			    GFP_KERNEL);
 	if (!data) {
-		pr_debug("thmc50: detect failed, kzalloc failed!\n");
-		err = -ENOMEM;
-		goto exit;
+		pr_debug("thmc50: detect failed, devm_kzalloc failed!\n");
+		return -ENOMEM;
 	}
 
 	i2c_set_clientdata(client, data);
@@ -377,7 +377,7 @@ static int thmc50_probe(struct i2c_client *client,
 	/* Register sysfs hooks */
 	err = sysfs_create_group(&client->dev.kobj, &thmc50_group);
 	if (err)
-		goto exit_free;
+		return err;
 
 	/* Register ADM1022 sysfs hooks */
 	if (data->has_temp3) {
@@ -400,9 +400,6 @@ exit_remove_sysfs:
 		sysfs_remove_group(&client->dev.kobj, &temp3_group);
 exit_remove_sysfs_thmc50:
 	sysfs_remove_group(&client->dev.kobj, &thmc50_group);
-exit_free:
-	kfree(data);
-exit:
 	return err;
 }
 
@@ -415,8 +412,6 @@ static int thmc50_remove(struct i2c_client *client)
 	if (data->has_temp3)
 		sysfs_remove_group(&client->dev.kobj, &temp3_group);
 
-	kfree(data);
-
 	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 75/95
#1 lore raw
Quoted 13 lines · Guenter Roeck

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

---
 drivers/hwmon/thmc50.c |   15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/hwmon/thmc50.c +0 -0
index add9f01..2f78e3f 100644
@@ -361,11 +361,11 @@ static int thmc50_probe(struct i2c_client *client,
 	struct thmc50_data *data;

drivers/hwmon/thmc50.c static int thmc50_probe(struct i2c_client *client, · line 367

Quoted 10 lines
drivers/hwmon/thmc50.c +3 -4
 	int err;
 
-	data = kzalloc(sizeof(struct thmc50_data), GFP_KERNEL);
+	data = devm_kzalloc(&client->dev, sizeof(struct thmc50_data),
+			    GFP_KERNEL);
 	if (!data) {
-		pr_debug("thmc50: detect failed, kzalloc failed!\n");
-		err = -ENOMEM;
-		goto exit;
+		pr_debug("thmc50: detect failed, devm_kzalloc failed!\n");

This message is confusing, as we are in the probe function and not the detect function. Plus, dev_dbg() should be used instead or pr_debug.

But actually I don't think we need any message here, the driver core will display a warning message whenever a probe fails (other than with -ENXIO or -ENODEV) so this one is redundant. Please drop it.

drivers/hwmon/thmc50.c static int thmc50_probe(struct i2c_client *client, · line 369

Quoted 3 lines
drivers/hwmon/thmc50.c +1 -0
+		return -ENOMEM;
 	}
(...)

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 28 lines · Jean Delvare
Quoted 13 lines · Guenter Roeck

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

---
 drivers/hwmon/thmc50.c |   15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/hwmon/thmc50.c +0 -0
index add9f01..2f78e3f 100644
@@ -361,11 +361,11 @@ static int thmc50_probe(struct i2c_client *client,
 	struct thmc50_data *data;

drivers/hwmon/thmc50.c static int thmc50_probe(struct i2c_client *client, · line 367

Quoted 10 lines
drivers/hwmon/thmc50.c +3 -4
 	int err;
 
-	data = kzalloc(sizeof(struct thmc50_data), GFP_KERNEL);
+	data = devm_kzalloc(&client->dev, sizeof(struct thmc50_data),
+			    GFP_KERNEL);
 	if (!data) {
-		pr_debug("thmc50: detect failed, kzalloc failed!\n");
-		err = -ENOMEM;
-		goto exit;
+		pr_debug("thmc50: detect failed, devm_kzalloc failed!\n");

This message is confusing, as we are in the probe function and not the detect function. Plus, dev_dbg() should be used instead or pr_debug.

Quoted 4 lines

But actually I don't think we need any message here, the driver core will display a warning message whenever a probe fails (other than with -ENXIO or -ENODEV) so this one is redundant. Please drop it.

Done.

Thanks,
Guenter

Quoted 11 lines

drivers/hwmon/thmc50.c static int thmc50_probe(struct i2c_client *client, · line 369

Quoted 3 lines
drivers/hwmon/thmc50.c +1 -0
+		return -ENOMEM;
 	}
(...)

Other than this:

Signature · 1 line
Jean Delvare

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