Skip to contentSkip to conversation

hwmon: (ltc4245) Use device managed function to register hwmon device

PATCH In review Guenter Roeck 2 participants 3 messages Feb 16, 2014 – Feb 23, 2014 Hardware monitoring

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH 1/3 hwmon: (ltc4245) Use device managed function to register hwmon device

This simplifies the code and reduces code size.

---
 drivers/hwmon/ltc4245.c |   23 ++++-------------------
 1 file changed, 4 insertions(+), 19 deletions(-)
drivers/hwmon/ltc4245.c +4 -19
index d4172933..2c6da5d 100644
@@ -512,24 +512,10 @@ static int ltc4245_probe(struct i2c_client *client,
 	/* Add sysfs hooks */
 	ltc4245_sysfs_add_groups(data);
 
-	hwmon_dev = hwmon_device_register_with_groups(&client->dev,
-						      client->name, data,
-						      data->groups);
-	if (IS_ERR(hwmon_dev))
-		return PTR_ERR(hwmon_dev);
-
-	i2c_set_clientdata(client, hwmon_dev);
-
-	return 0;
-}
-
-static int ltc4245_remove(struct i2c_client *client)
-{
-	struct device *hwmon_dev = i2c_get_clientdata(client);
-
-	hwmon_device_unregister(hwmon_dev);
-
-	return 0;
+	hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev,
+							   client->name, data,
+							   data->groups);
+	return PTR_ERR_OR_ZERO(hwmon_dev);
 }
 
 static const struct i2c_device_id ltc4245_id[] = {
@@ -544,7 +530,6 @@ static struct i2c_driver ltc4245_driver = {
 		.name	= "ltc4245",
 	},
 	.probe		= ltc4245_probe,
-	.remove		= ltc4245_remove,
 	.id_table	= ltc4245_id,
 };
 
Signature · 7 lines
1.7.9.7


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

This simplifies the code and reduces code size.

---
 drivers/hwmon/ltc4245.c |   23 ++++-------------------
 1 file changed, 4 insertions(+), 19 deletions(-)
drivers/hwmon/ltc4245.c +4 -18
index d4172933..2c6da5d 100644
@@ -512,24 +512,10 @@ static int ltc4245_probe(struct i2c_client *client,
 	/* Add sysfs hooks */
 	ltc4245_sysfs_add_groups(data);
 
-	hwmon_dev = hwmon_device_register_with_groups(&client->dev,
-						      client->name, data,
-						      data->groups);
-	if (IS_ERR(hwmon_dev))
-		return PTR_ERR(hwmon_dev);
-
-	i2c_set_clientdata(client, hwmon_dev);
-
-	return 0;
-}
-
-static int ltc4245_remove(struct i2c_client *client)
-{
-	struct device *hwmon_dev = i2c_get_clientdata(client);
-
-	hwmon_device_unregister(hwmon_dev);
-
-	return 0;
+	hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev,
+							   client->name, data,
+							   data->groups);
+	return PTR_ERR_OR_ZERO(hwmon_dev);
 }
 
 static const struct i2c_device_id ltc4245_id[] = {

drivers/hwmon/ltc4245.c static struct i2c_driver ltc4245_driver = { · line 535

Quoted 7 lines
drivers/hwmon/ltc4245.c +0 -1
@@ -544,7 +530,6 @@ static struct i2c_driver ltc4245_driver = {
 		.name	= "ltc4245",
 	},
 	.probe		= ltc4245_probe,
-	.remove		= ltc4245_remove,
 	.id_table	= ltc4245_id,
 };
 

Nice.

Signature · 7 lines
Jean Delvare
Suse L3 Support

_______________________________________________
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 52 lines · Jean Delvare
Quoted 41 lines · Guenter Roeck

This simplifies the code and reduces code size.

---
  drivers/hwmon/ltc4245.c |   23 ++++-------------------
  1 file changed, 4 insertions(+), 19 deletions(-)
drivers/hwmon/ltc4245.c +4 -18
index d4172933..2c6da5d 100644
@@ -512,24 +512,10 @@ static int ltc4245_probe(struct i2c_client *client,
  	/* Add sysfs hooks */
  	ltc4245_sysfs_add_groups(data);
 
-	hwmon_dev = hwmon_device_register_with_groups(&client->dev,
-						      client->name, data,
-						      data->groups);
-	if (IS_ERR(hwmon_dev))
-		return PTR_ERR(hwmon_dev);
-
-	i2c_set_clientdata(client, hwmon_dev);
-
-	return 0;
-}
-
-static int ltc4245_remove(struct i2c_client *client)
-{
-	struct device *hwmon_dev = i2c_get_clientdata(client);
-
-	hwmon_device_unregister(hwmon_dev);
-
-	return 0;
+	hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev,
+							   client->name, data,
+							   data->groups);
+	return PTR_ERR_OR_ZERO(hwmon_dev);
  }
 
  static const struct i2c_device_id ltc4245_id[] = {

drivers/hwmon/ltc4245.c static struct i2c_driver ltc4245_driver = { · line 535

Quoted 7 lines
drivers/hwmon/ltc4245.c +0 -1
@@ -544,7 +530,6 @@ static struct i2c_driver ltc4245_driver = {
  		.name	= "ltc4245",
  	},
  	.probe		= ltc4245_probe,
-	.remove		= ltc4245_remove,
  	.id_table	= ltc4245_id,
  };
 

Nice.

Quoted 2 lines

Thanks!

Guenter

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