diff options
Diffstat (limited to 'drivers/hwmon/ad7414.c')
| -rw-r--r-- | drivers/hwmon/ad7414.c | 48 |
1 files changed, 18 insertions, 30 deletions
diff --git a/drivers/hwmon/ad7414.c b/drivers/hwmon/ad7414.c index df29a7fff9e..5d501adc3e5 100644 --- a/drivers/hwmon/ad7414.c +++ b/drivers/hwmon/ad7414.c @@ -50,7 +50,8 @@ struct ad7414_data { /* REG: (0.25C/bit, two's complement) << 6 */ static inline int ad7414_temp_from_reg(s16 reg) { - /* use integer division instead of equivalent right shift to + /* + * use integer division instead of equivalent right shift to * guarantee arithmetic shift and preserve the sign */ return ((int)reg / 64) * 250; @@ -130,9 +131,13 @@ static ssize_t set_max_min(struct device *dev, struct ad7414_data *data = i2c_get_clientdata(client); int index = to_sensor_dev_attr(attr)->index; u8 reg = AD7414_REG_LIMIT[index]; - long temp = simple_strtol(buf, NULL, 10); + long temp; + int ret = kstrtol(buf, 10, &temp); - temp = SENSORS_LIMIT(temp, -40000, 85000); + if (ret < 0) + return ret; + + temp = clamp_val(temp, -40000, 85000); temp = (temp + (temp < 0 ? -500 : 500)) / 1000; mutex_lock(&data->lock); @@ -180,16 +185,13 @@ static int ad7414_probe(struct i2c_client *client, int err; if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA | - I2C_FUNC_SMBUS_READ_WORD_DATA)) { - err = -EOPNOTSUPP; - goto exit; - } + I2C_FUNC_SMBUS_READ_WORD_DATA)) + return -EOPNOTSUPP; - data = kzalloc(sizeof(struct ad7414_data), GFP_KERNEL); - if (!data) { - err = -ENOMEM; - goto exit; - } + data = devm_kzalloc(&client->dev, sizeof(struct ad7414_data), + GFP_KERNEL); + if (!data) + return -ENOMEM; i2c_set_clientdata(client, data); mutex_init(&data->lock); @@ -209,7 +211,7 @@ static int ad7414_probe(struct i2c_client *client, /* Register sysfs hooks */ err = sysfs_create_group(&client->dev.kobj, &ad7414_group); if (err) - goto exit_free; + return err; data->hwmon_dev = hwmon_device_register(&client->dev); if (IS_ERR(data->hwmon_dev)) { @@ -221,19 +223,15 @@ static int ad7414_probe(struct i2c_client *client, exit_remove: sysfs_remove_group(&client->dev.kobj, &ad7414_group); -exit_free: - kfree(data); -exit: return err; } -static int __devexit ad7414_remove(struct i2c_client *client) +static int ad7414_remove(struct i2c_client *client) { struct ad7414_data *data = i2c_get_clientdata(client); hwmon_device_unregister(data->hwmon_dev); sysfs_remove_group(&client->dev.kobj, &ad7414_group); - kfree(data); return 0; } @@ -248,21 +246,11 @@ static struct i2c_driver ad7414_driver = { .name = "ad7414", }, .probe = ad7414_probe, - .remove = __devexit_p(ad7414_remove), + .remove = ad7414_remove, .id_table = ad7414_id, }; -static int __init ad7414_init(void) -{ - return i2c_add_driver(&ad7414_driver); -} -module_init(ad7414_init); - -static void __exit ad7414_exit(void) -{ - i2c_del_driver(&ad7414_driver); -} -module_exit(ad7414_exit); +module_i2c_driver(ad7414_driver); MODULE_AUTHOR("Stefan Roese <sr at denx.de>, " "Frank Edelhaeuser <frank.edelhaeuser at spansion.com>"); |
