Skip to contentSkip to conversation

hwmon: (tmp102) 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 76/95 hwmon: (tmp102) Convert to use devm_ functions

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

---
 drivers/hwmon/tmp102.c |   11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/hwmon/tmp102.c +3 -8
index 0d466b9..b6cda09 100644
@@ -159,9 +159,9 @@ static int __devinit tmp102_probe(struct i2c_client *client,
 		return -ENODEV;
 	}
 
-	tmp102 = kzalloc(sizeof(*tmp102), GFP_KERNEL);
+	tmp102 = devm_kzalloc(&client->dev, sizeof(*tmp102), GFP_KERNEL);
 	if (!tmp102) {
-		dev_dbg(&client->dev, "kzalloc failed\n");
+		dev_dbg(&client->dev, "devm_kzalloc failed\n");
 		return -ENOMEM;
 	}
 	i2c_set_clientdata(client, tmp102);
@@ -169,7 +169,7 @@ static int __devinit tmp102_probe(struct i2c_client *client,
 	status = i2c_smbus_read_word_swapped(client, TMP102_CONF_REG);
 	if (status < 0) {
 		dev_err(&client->dev, "error reading config register\n");
-		goto fail_free;
+		return status;
 	}
 	tmp102->config_orig = status;
 	status = i2c_smbus_write_word_swapped(client, TMP102_CONF_REG,
@@ -213,9 +213,6 @@ fail_remove_sysfs:
 fail_restore_config:
 	i2c_smbus_write_word_swapped(client, TMP102_CONF_REG,
 				     tmp102->config_orig);
-fail_free:
-	kfree(tmp102);
-
 	return status;
 }
 
@@ -236,8 +233,6 @@ static int __devexit tmp102_remove(struct i2c_client *client)
 						     config | TMP102_CONF_SD);
 	}
 
-	kfree(tmp102);
-
 	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 76/95
#1 lore raw
Quoted 12 lines · Guenter Roeck

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

---
 drivers/hwmon/tmp102.c |   11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/hwmon/tmp102.c +0 -0
index 0d466b9..b6cda09 100644

drivers/hwmon/tmp102.c static int __devinit tmp102_probe(struct i2c_client *client, · line 164

Quoted 8 lines
drivers/hwmon/tmp102.c +2 -2
@@ -159,9 +159,9 @@ static int __devinit tmp102_probe(struct i2c_client *client,
 		return -ENODEV;
 	}
 
-	tmp102 = kzalloc(sizeof(*tmp102), GFP_KERNEL);
+	tmp102 = devm_kzalloc(&client->dev, sizeof(*tmp102), GFP_KERNEL);
 	if (!tmp102) {
-		dev_dbg(&client->dev, "kzalloc failed\n");
+		dev_dbg(&client->dev, "devm_kzalloc failed\n");

I'd think it's not worth updating these messages, devm_kzalloc is just one flavor of kzalloc.

(These messages are useless anyway, as explained in a previous review.)

In any case:

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 25 lines · Jean Delvare
Quoted 12 lines · Guenter Roeck

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

---
 drivers/hwmon/tmp102.c |   11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/hwmon/tmp102.c +0 -0
index 0d466b9..b6cda09 100644

drivers/hwmon/tmp102.c static int __devinit tmp102_probe(struct i2c_client *client, · line 164

Quoted 8 lines
drivers/hwmon/tmp102.c +2 -2
@@ -159,9 +159,9 @@ static int __devinit tmp102_probe(struct i2c_client *client,
 		return -ENODEV;
 	}
 
-	tmp102 = kzalloc(sizeof(*tmp102), GFP_KERNEL);
+	tmp102 = devm_kzalloc(&client->dev, sizeof(*tmp102), GFP_KERNEL);
 	if (!tmp102) {
-		dev_dbg(&client->dev, "kzalloc failed\n");
+		dev_dbg(&client->dev, "devm_kzalloc failed\n");

I'd think it's not worth updating these messages, devm_kzalloc is just one flavor of kzalloc.

Quoted 2 lines

(These messages are useless anyway, as explained in a previous review.)

I dropped it.

Quoted 4 lines

In any case:

Thanks,
Guenter

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