diff options
author | Guenter Roeck <linux@roeck-us.net> | 2016-06-13 09:19:11 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2016-07-09 11:35:39 -0400 |
commit | 1f17a444b42bd7522016417a871f0485abeffda4 (patch) | |
tree | 72a21aaee7173b33ba65293e5187282688b4fcfa /drivers/hwmon/lm90.c | |
parent | e65365fed87f5385c04124b6e7ab8967ca600b26 (diff) |
hwmon: (lm90) Use devm_add_action for cleanup
Use devm_add_action where possible to simplify error handling and
cleanup on remove.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/lm90.c')
-rw-r--r-- | drivers/hwmon/lm90.c | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index e30a5939dc0d..4b530ef731aa 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c | |||
@@ -369,7 +369,6 @@ struct lm90_data { | |||
369 | struct device *hwmon_dev; | 369 | struct device *hwmon_dev; |
370 | const struct attribute_group *groups[6]; | 370 | const struct attribute_group *groups[6]; |
371 | struct mutex update_lock; | 371 | struct mutex update_lock; |
372 | struct regulator *regulator; | ||
373 | char valid; /* zero until following fields are valid */ | 372 | char valid; /* zero until following fields are valid */ |
374 | unsigned long last_updated; /* in jiffies */ | 373 | unsigned long last_updated; /* in jiffies */ |
375 | int kind; | 374 | int kind; |
@@ -1404,8 +1403,11 @@ static int lm90_detect(struct i2c_client *client, | |||
1404 | return 0; | 1403 | return 0; |
1405 | } | 1404 | } |
1406 | 1405 | ||
1407 | static void lm90_restore_conf(struct i2c_client *client, struct lm90_data *data) | 1406 | static void lm90_restore_conf(void *_data) |
1408 | { | 1407 | { |
1408 | struct lm90_data *data = _data; | ||
1409 | struct i2c_client *client = data->client; | ||
1410 | |||
1409 | /* Restore initial configuration */ | 1411 | /* Restore initial configuration */ |
1410 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE, | 1412 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE, |
1411 | data->convrate_orig); | 1413 | data->convrate_orig); |
@@ -1456,6 +1458,8 @@ static void lm90_init_client(struct i2c_client *client, struct lm90_data *data) | |||
1456 | config &= 0xBF; /* run */ | 1458 | config &= 0xBF; /* run */ |
1457 | if (config != data->config_orig) /* Only write if changed */ | 1459 | if (config != data->config_orig) /* Only write if changed */ |
1458 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config); | 1460 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config); |
1461 | |||
1462 | devm_add_action(&client->dev, lm90_restore_conf, data); | ||
1459 | } | 1463 | } |
1460 | 1464 | ||
1461 | static bool lm90_is_tripped(struct i2c_client *client, u16 *status) | 1465 | static bool lm90_is_tripped(struct i2c_client *client, u16 *status) |
@@ -1506,6 +1510,16 @@ static irqreturn_t lm90_irq_thread(int irq, void *dev_id) | |||
1506 | return IRQ_NONE; | 1510 | return IRQ_NONE; |
1507 | } | 1511 | } |
1508 | 1512 | ||
1513 | static void lm90_remove_pec(void *dev) | ||
1514 | { | ||
1515 | device_remove_file(dev, &dev_attr_pec); | ||
1516 | } | ||
1517 | |||
1518 | static void lm90_regulator_disable(void *regulator) | ||
1519 | { | ||
1520 | regulator_disable(regulator); | ||
1521 | } | ||
1522 | |||
1509 | static int lm90_probe(struct i2c_client *client, | 1523 | static int lm90_probe(struct i2c_client *client, |
1510 | const struct i2c_device_id *id) | 1524 | const struct i2c_device_id *id) |
1511 | { | 1525 | { |
@@ -1526,6 +1540,8 @@ static int lm90_probe(struct i2c_client *client, | |||
1526 | return err; | 1540 | return err; |
1527 | } | 1541 | } |
1528 | 1542 | ||
1543 | devm_add_action(dev, lm90_regulator_disable, regulator); | ||
1544 | |||
1529 | data = devm_kzalloc(dev, sizeof(struct lm90_data), GFP_KERNEL); | 1545 | data = devm_kzalloc(dev, sizeof(struct lm90_data), GFP_KERNEL); |
1530 | if (!data) | 1546 | if (!data) |
1531 | return -ENOMEM; | 1547 | return -ENOMEM; |
@@ -1534,8 +1550,6 @@ static int lm90_probe(struct i2c_client *client, | |||
1534 | i2c_set_clientdata(client, data); | 1550 | i2c_set_clientdata(client, data); |
1535 | mutex_init(&data->update_lock); | 1551 | mutex_init(&data->update_lock); |
1536 | 1552 | ||
1537 | data->regulator = regulator; | ||
1538 | |||
1539 | /* Set the device type */ | 1553 | /* Set the device type */ |
1540 | data->kind = id->driver_data; | 1554 | data->kind = id->driver_data; |
1541 | if (data->kind == adm1032) { | 1555 | if (data->kind == adm1032) { |
@@ -1577,15 +1591,14 @@ static int lm90_probe(struct i2c_client *client, | |||
1577 | if (client->flags & I2C_CLIENT_PEC) { | 1591 | if (client->flags & I2C_CLIENT_PEC) { |
1578 | err = device_create_file(dev, &dev_attr_pec); | 1592 | err = device_create_file(dev, &dev_attr_pec); |
1579 | if (err) | 1593 | if (err) |
1580 | goto exit_restore; | 1594 | return err; |
1595 | devm_add_action(dev, lm90_remove_pec, dev); | ||
1581 | } | 1596 | } |
1582 | 1597 | ||
1583 | data->hwmon_dev = hwmon_device_register_with_groups(dev, client->name, | 1598 | data->hwmon_dev = hwmon_device_register_with_groups(dev, client->name, |
1584 | data, data->groups); | 1599 | data, data->groups); |
1585 | if (IS_ERR(data->hwmon_dev)) { | 1600 | if (IS_ERR(data->hwmon_dev)) |
1586 | err = PTR_ERR(data->hwmon_dev); | 1601 | return PTR_ERR(data->hwmon_dev); |
1587 | goto exit_remove_pec; | ||
1588 | } | ||
1589 | 1602 | ||
1590 | if (client->irq) { | 1603 | if (client->irq) { |
1591 | dev_dbg(dev, "IRQ: %d\n", client->irq); | 1604 | dev_dbg(dev, "IRQ: %d\n", client->irq); |
@@ -1603,12 +1616,6 @@ static int lm90_probe(struct i2c_client *client, | |||
1603 | 1616 | ||
1604 | exit_unregister: | 1617 | exit_unregister: |
1605 | hwmon_device_unregister(data->hwmon_dev); | 1618 | hwmon_device_unregister(data->hwmon_dev); |
1606 | exit_remove_pec: | ||
1607 | device_remove_file(dev, &dev_attr_pec); | ||
1608 | exit_restore: | ||
1609 | lm90_restore_conf(client, data); | ||
1610 | regulator_disable(data->regulator); | ||
1611 | |||
1612 | return err; | 1619 | return err; |
1613 | } | 1620 | } |
1614 | 1621 | ||
@@ -1617,9 +1624,6 @@ static int lm90_remove(struct i2c_client *client) | |||
1617 | struct lm90_data *data = i2c_get_clientdata(client); | 1624 | struct lm90_data *data = i2c_get_clientdata(client); |
1618 | 1625 | ||
1619 | hwmon_device_unregister(data->hwmon_dev); | 1626 | hwmon_device_unregister(data->hwmon_dev); |
1620 | device_remove_file(&client->dev, &dev_attr_pec); | ||
1621 | lm90_restore_conf(client, data); | ||
1622 | regulator_disable(data->regulator); | ||
1623 | 1627 | ||
1624 | return 0; | 1628 | return 0; |
1625 | } | 1629 | } |