Skip to contentSkip to conversation

hwmon: (adt7411) Convert to use devm_ functions

PATCH Superseded Guenter Roeck 4 participants 6 messages Jun 15, 2012 – Jun 18, 2012 Hardware monitoring

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH 17/95 hwmon: (adt7411) Convert to use devm_ functions

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

---
 drivers/hwmon/adt7411.c |    9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/hwmon/adt7411.c +3 -6
index 71bacc5..fe72c69 100644
@@ -283,7 +283,7 @@ static int __devinit adt7411_probe(struct i2c_client *client,
 	struct adt7411_data *data;
 	int ret;
 
-	data = kzalloc(sizeof(*data), GFP_KERNEL);
+	data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
 
@@ -294,14 +294,14 @@ static int __devinit adt7411_probe(struct i2c_client *client,
 	ret = adt7411_modify_bit(client, ADT7411_REG_CFG1,
 				 ADT7411_CFG1_START_MONITOR, 1);
 	if (ret < 0)
-		goto exit_free;
+		return ret;
 
 	/* force update on first occasion */
 	data->next_update = jiffies;
 
 	ret = sysfs_create_group(&client->dev.kobj, &adt7411_attr_grp);
 	if (ret)
-		goto exit_free;
+		return ret;
 
 	data->hwmon_dev = hwmon_device_register(&client->dev);
 	if (IS_ERR(data->hwmon_dev)) {
@@ -315,8 +315,6 @@ static int __devinit adt7411_probe(struct i2c_client *client,
 
  exit_remove:
 	sysfs_remove_group(&client->dev.kobj, &adt7411_attr_grp);
- exit_free:
-	kfree(data);
 	return ret;
 }
 
@@ -326,7 +324,6 @@ static int __devexit adt7411_remove(struct i2c_client *client)
 
 	hwmon_device_unregister(data->hwmon_dev);
 	sysfs_remove_group(&client->dev.kobj, &adt7411_attr_grp);
-	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
#1 lore raw
Quoted 4 lines · Guenter Roeck

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

I won't NACK it, but I don't think it is worth it. It increases runtime memory usage and execution time. Marginally, yes, but the gain in code size reduction is also marginally. If there is lots of devm_* in a driver, this is usually good, but I wouldn't care about converting single kzalloc calls.

Regards,

Wolfram

Quoted 54 lines
---
 drivers/hwmon/adt7411.c |    9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/hwmon/adt7411.c +3 -6
index 71bacc5..fe72c69 100644
@@ -283,7 +283,7 @@ static int __devinit adt7411_probe(struct i2c_client *client,
 	struct adt7411_data *data;
 	int ret;
 
-	data = kzalloc(sizeof(*data), GFP_KERNEL);
+	data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
 
@@ -294,14 +294,14 @@ static int __devinit adt7411_probe(struct i2c_client *client,
 	ret = adt7411_modify_bit(client, ADT7411_REG_CFG1,
 				 ADT7411_CFG1_START_MONITOR, 1);
 	if (ret < 0)
-		goto exit_free;
+		return ret;
 
 	/* force update on first occasion */
 	data->next_update = jiffies;
 
 	ret = sysfs_create_group(&client->dev.kobj, &adt7411_attr_grp);
 	if (ret)
-		goto exit_free;
+		return ret;
 
 	data->hwmon_dev = hwmon_device_register(&client->dev);
 	if (IS_ERR(data->hwmon_dev)) {
@@ -315,8 +315,6 @@ static int __devinit adt7411_probe(struct i2c_client *client,
 
  exit_remove:
 	sysfs_remove_group(&client->dev.kobj, &adt7411_attr_grp);
- exit_free:
-	kfree(data);
 	return ret;
 }
 
@@ -326,7 +324,6 @@ static int __devexit adt7411_remove(struct i2c_client *client)
 
 	hwmon_device_unregister(data->hwmon_dev);
 	sysfs_remove_group(&client->dev.kobj, &adt7411_attr_grp);
-	kfree(data);
 	return 0;
 }
 
Signature · 1 line
1.7.9.7
Signature · 2 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

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

#2 lore raw
In reply to Guenter Roeck
Quoted 12 lines · Wolfram Sang
Quoted 4 lines · Guenter Roeck

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

I won't NACK it, but I don't think it is worth it. It increases runtime memory usage and execution time. Marginally, yes, but the gain in code size reduction is also marginally. If there is lots of devm_* in a driver, this is usually good, but I wouldn't care about converting single kzalloc calls.

Wolfram,

code size reduction on x86_64 is about 15 kBytes for all drivers. With most of the hwmon drivers built but not loaded on a typical system, that does make a difference in disk space usage, and I think it is a bit more than marginal. The runtime execution time increase only occurs once, when a module is loaded or unloaded, and the increase in memory usage only applies to loaded drivers.

In addition to that, it does help preventing memory leaks, and it does make the code a bit simpler.

So, overall I do think it is worth it. Maybe not if I only look at one driver, but very much so if I look at the overall impact.

Thanks,
Guenter

Quoted 55 lines

Regards,

Wolfram

Quoted 51 lines
---
 drivers/hwmon/adt7411.c |    9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/hwmon/adt7411.c +3 -6
index 71bacc5..fe72c69 100644
@@ -283,7 +283,7 @@ static int __devinit adt7411_probe(struct i2c_client *client,
 	struct adt7411_data *data;
 	int ret;
 
-	data = kzalloc(sizeof(*data), GFP_KERNEL);
+	data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
 
@@ -294,14 +294,14 @@ static int __devinit adt7411_probe(struct i2c_client *client,
 	ret = adt7411_modify_bit(client, ADT7411_REG_CFG1,
 				 ADT7411_CFG1_START_MONITOR, 1);
 	if (ret < 0)
-		goto exit_free;
+		return ret;
 
 	/* force update on first occasion */
 	data->next_update = jiffies;
 
 	ret = sysfs_create_group(&client->dev.kobj, &adt7411_attr_grp);
 	if (ret)
-		goto exit_free;
+		return ret;
 
 	data->hwmon_dev = hwmon_device_register(&client->dev);
 	if (IS_ERR(data->hwmon_dev)) {
@@ -315,8 +315,6 @@ static int __devinit adt7411_probe(struct i2c_client *client,
 
  exit_remove:
 	sysfs_remove_group(&client->dev.kobj, &adt7411_attr_grp);
- exit_free:
-	kfree(data);
 	return ret;
 }
 
@@ -326,7 +324,6 @@ static int __devexit adt7411_remove(struct i2c_client *client)
 
 	hwmon_device_unregister(data->hwmon_dev);
 	sysfs_remove_group(&client->dev.kobj, &adt7411_attr_grp);
-	kfree(data);
 	return 0;
 }
 
Quoted 4 lines
Quoted 3 lines
Signature · 1 line
1.7.9.7

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

#3 lore raw
In reply to Guenter Roeck
Quoted 14 lines · Guenter Roeck
Quoted 5 lines · Wolfram Sang

I won't NACK it, but I don't think it is worth it. It increases runtime memory usage and execution time. Marginally, yes, but the gain in code size reduction is also marginally. If there is lots of devm_* in a driver, this is usually good, but I wouldn't care about converting single kzalloc calls.

code size reduction on x86_64 is about 15 kBytes for all drivers. With most of the hwmon drivers built but not loaded on a typical system, that does make a difference in disk space usage, and I think it is a bit more than marginal. The runtime execution time increase only occurs once, when a module is loaded or unloaded, and the increase in memory usage only applies to loaded drivers.

Quoted 5 lines

In addition to that, it does help preventing memory leaks, and it does make the code a bit simpler.

So, overall I do think it is worth it. Maybe not if I only look at one driver, but very much so if I look at the overall impact.

I agree with Guenter here. In fact, I suspect it's only a matter of time before the use of devm_* functions becomes mandatory. Fewer lines of code and fewer bugs is definitely something we want to achieve. If it was deemed not worth the cost, the devm_* infrastructure would have been rejected in the first place. Now that it is in place, it is meant to be used as much as possible.

Gunter, I think it would make sense do document it Documentation/hwmon/submitting-patches, section 3, so that you don't have to do the same again in the future.

Great work, BTW. I don't intend to review all of it, no time, sorry, but I ack the general idea.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
author maintainer
#4 lore raw
In reply to Guenter Roeck
Quoted 28 lines · Jean Delvare
Quoted 14 lines · Guenter Roeck
Quoted 5 lines · Wolfram Sang

I won't NACK it, but I don't think it is worth it. It increases runtime memory usage and execution time. Marginally, yes, but the gain in code size reduction is also marginally. If there is lots of devm_* in a driver, this is usually good, but I wouldn't care about converting single kzalloc calls.

code size reduction on x86_64 is about 15 kBytes for all drivers. With most of the hwmon drivers built but not loaded on a typical system, that does make a difference in disk space usage, and I think it is a bit more than marginal. The runtime execution time increase only occurs once, when a module is loaded or unloaded, and the increase in memory usage only applies to loaded drivers.

Quoted 5 lines

In addition to that, it does help preventing memory leaks, and it does make the code a bit simpler.

So, overall I do think it is worth it. Maybe not if I only look at one driver, but very much so if I look at the overall impact.

I agree with Guenter here. In fact, I suspect it's only a matter of time before the use of devm_* functions becomes mandatory. Fewer lines of code and fewer bugs is definitely something we want to achieve. If it was deemed not worth the cost, the devm_* infrastructure would have been rejected in the first place. Now that it is in place, it is meant to be used as much as possible.

Quoted 4 lines

Gunter, I think it would make sense do document it Documentation/hwmon/submitting-patches, section 3, so that you don't have to do the same again in the future.

Agreed. I'll send out a patch.

Quoted 3 lines

Great work, BTW. I don't intend to review all of it, no time, sorry, but I ack the general idea.

Thanks ... one of those little things I like to do when I need distraction from my day-to-day work. And also thanks a lot for the reviews you already did - that helps a lot.

Guenter

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

#5 lore raw
In reply to Guenter Roeck

Hi,

Quoted 1 line

code size reduction on x86_64 is about 15 kBytes for all drivers. With

Ah, this is useful information. Being home in the embedded world, I only activate the drivers I need, and for that the gain is marginal if any. I can accept that saving 15kB for an all-module distro build is nice.

Quoted 2 lines

In addition to that, it does help preventing memory leaks, and it does make the code a bit simpler.

I definately agree for new drivers, but changing working code without a proper need is a risk. Especially, because converting to devm_* can cause subtle bugs when done without thought. I've been bitten by that in
[1] (last paragraph) where input_free_device is not covered by devm, so one still has to free the IRQ manually, otherwise OOPS.

[1] http://permalink.gmane.org/gmane.linux.kernel.input/24180

Quoted 2 lines

So, overall I do think it is worth it. Maybe not if I only look at one driver, but very much so if I look at the overall impact.

As said, I am not NACKing :)

Regards,

Wolfram

Signature · 2 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

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