aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2016-06-19 20:06:48 -0400
committerGuenter Roeck <linux@roeck-us.net>2016-07-09 11:33:46 -0400
commit9e37d3e2298e7ca2a9d210532c77a325d07816fe (patch)
treec31f107b0e23af70ddccd1b8c6bb38b3f4261034
parenteacc48ce3accfc9092594794b009a40f91331b0e (diff)
hwmon: (lm75) Handle cleanup with devm_add_action
Use devm_add_action() to register the function to restore the original chip configuration. Use devm_hwmon_device_register_with_groups() to register the hwmon device, and drop the remove function as no longer needed. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r--drivers/hwmon/lm75.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
index 69166ab3151d..0df745501a1f 100644
--- a/drivers/hwmon/lm75.c
+++ b/drivers/hwmon/lm75.c
@@ -76,7 +76,6 @@ static const u8 LM75_REG_TEMP[3] = {
76/* Each client has this additional data */ 76/* Each client has this additional data */
77struct lm75_data { 77struct lm75_data {
78 struct i2c_client *client; 78 struct i2c_client *client;
79 struct device *hwmon_dev;
80 struct mutex update_lock; 79 struct mutex update_lock;
81 u8 orig_conf; 80 u8 orig_conf;
82 u8 resolution; /* In bits, between 9 and 12 */ 81 u8 resolution; /* In bits, between 9 and 12 */
@@ -185,10 +184,19 @@ static const struct thermal_zone_of_device_ops lm75_of_thermal_ops = {
185 184
186/* device probe and removal */ 185/* device probe and removal */
187 186
187static void lm75_remove(void *data)
188{
189 struct lm75_data *lm75 = data;
190 struct i2c_client *client = lm75->client;
191
192 i2c_smbus_write_byte_data(client, LM75_REG_CONF, lm75->orig_conf);
193}
194
188static int 195static int
189lm75_probe(struct i2c_client *client, const struct i2c_device_id *id) 196lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
190{ 197{
191 struct device *dev = &client->dev; 198 struct device *dev = &client->dev;
199 struct device *hwmon_dev;
192 struct lm75_data *data; 200 struct lm75_data *data;
193 int status; 201 int status;
194 u8 set_mask, clr_mask; 202 u8 set_mask, clr_mask;
@@ -298,29 +306,22 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
298 new |= set_mask; 306 new |= set_mask;
299 if (status != new) 307 if (status != new)
300 lm75_write_value(client, LM75_REG_CONF, new); 308 lm75_write_value(client, LM75_REG_CONF, new);
301 dev_dbg(dev, "Config %02x\n", new);
302 309
303 data->hwmon_dev = hwmon_device_register_with_groups(dev, client->name, 310 devm_add_action(dev, lm75_remove, data);
304 data, lm75_groups);
305 if (IS_ERR(data->hwmon_dev))
306 return PTR_ERR(data->hwmon_dev);
307 311
308 devm_thermal_zone_of_sensor_register(data->hwmon_dev, 0, 312 dev_dbg(dev, "Config %02x\n", new);
309 data->hwmon_dev,
310 &lm75_of_thermal_ops);
311 313
312 dev_info(dev, "%s: sensor '%s'\n", 314 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
313 dev_name(data->hwmon_dev), client->name); 315 data, lm75_groups);
316 if (IS_ERR(hwmon_dev))
317 return PTR_ERR(hwmon_dev);
314 318
315 return 0; 319 devm_thermal_zone_of_sensor_register(hwmon_dev, 0,
316} 320 hwmon_dev,
321 &lm75_of_thermal_ops);
317 322
318static int lm75_remove(struct i2c_client *client) 323 dev_info(dev, "%s: sensor '%s'\n", dev_name(hwmon_dev), client->name);
319{
320 struct lm75_data *data = i2c_get_clientdata(client);
321 324
322 hwmon_device_unregister(data->hwmon_dev);
323 lm75_write_value(client, LM75_REG_CONF, data->orig_conf);
324 return 0; 325 return 0;
325} 326}
326 327
@@ -489,7 +490,6 @@ static struct i2c_driver lm75_driver = {
489 .pm = LM75_DEV_PM_OPS, 490 .pm = LM75_DEV_PM_OPS,
490 }, 491 },
491 .probe = lm75_probe, 492 .probe = lm75_probe,
492 .remove = lm75_remove,
493 .id_table = lm75_ids, 493 .id_table = lm75_ids,
494 .detect = lm75_detect, 494 .detect = lm75_detect,
495 .address_list = normal_i2c, 495 .address_list = normal_i2c,