diff options
Diffstat (limited to 'drivers/hwmon/thmc50.c')
| -rw-r--r-- | drivers/hwmon/thmc50.c | 115 |
1 files changed, 57 insertions, 58 deletions
diff --git a/drivers/hwmon/thmc50.c b/drivers/hwmon/thmc50.c index 7dfb4dec4c5..db288db7d3e 100644 --- a/drivers/hwmon/thmc50.c +++ b/drivers/hwmon/thmc50.c @@ -1,24 +1,24 @@ /* - thmc50.c - Part of lm_sensors, Linux kernel modules for hardware - monitoring - Copyright (C) 2007 Krzysztof Helt <krzysztof.h1@wp.pl> - Based on 2.4 driver by Frodo Looijaard <frodol@dds.nl> and - Philip Edelbrock <phil@netroedge.com> - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ + * thmc50.c - Part of lm_sensors, Linux kernel modules for hardware + * monitoring + * Copyright (C) 2007 Krzysztof Helt <krzysztof.h1@wp.pl> + * Based on 2.4 driver by Frodo Looijaard <frodol@dds.nl> and + * Philip Edelbrock <phil@netroedge.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ #include <linux/module.h> #include <linux/init.h> @@ -28,6 +28,7 @@ #include <linux/hwmon-sysfs.h> #include <linux/err.h> #include <linux/mutex.h> +#include <linux/jiffies.h> MODULE_LICENSE("GPL"); @@ -40,8 +41,8 @@ enum chips { thmc50, adm1022 }; static unsigned short adm1022_temp3[16]; static unsigned int adm1022_temp3_num; module_param_array(adm1022_temp3, ushort, &adm1022_temp3_num, 0); -MODULE_PARM_DESC(adm1022_temp3, "List of adapter,address pairs " - "to enable 3rd temperature (ADM1022 only)"); +MODULE_PARM_DESC(adm1022_temp3, + "List of adapter,address pairs to enable 3rd temperature (ADM1022 only)"); /* Many THMC50 constants specified below */ @@ -124,11 +125,16 @@ static ssize_t set_analog_out(struct device *dev, { struct i2c_client *client = to_i2c_client(dev); struct thmc50_data *data = i2c_get_clientdata(client); - int tmp = simple_strtoul(buf, NULL, 10); int config; + unsigned long tmp; + int err; + + err = kstrtoul(buf, 10, &tmp); + if (err) + return err; mutex_lock(&data->update_lock); - data->analog_out = SENSORS_LIMIT(tmp, 0, 255); + data->analog_out = clamp_val(tmp, 0, 255); i2c_smbus_write_byte_data(client, THMC50_REG_ANALOG_OUT, data->analog_out); @@ -173,10 +179,15 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, int nr = to_sensor_dev_attr(attr)->index; struct i2c_client *client = to_i2c_client(dev); struct thmc50_data *data = i2c_get_clientdata(client); - int val = simple_strtol(buf, NULL, 10); + long val; + int err; + + err = kstrtol(buf, 10, &val); + if (err) + return err; mutex_lock(&data->update_lock); - data->temp_min[nr] = SENSORS_LIMIT(val / 1000, -128, 127); + data->temp_min[nr] = clamp_val(val / 1000, -128, 127); i2c_smbus_write_byte_data(client, THMC50_REG_TEMP_MIN[nr], data->temp_min[nr]); mutex_unlock(&data->update_lock); @@ -197,10 +208,15 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, int nr = to_sensor_dev_attr(attr)->index; struct i2c_client *client = to_i2c_client(dev); struct thmc50_data *data = i2c_get_clientdata(client); - int val = simple_strtol(buf, NULL, 10); + long val; + int err; + + err = kstrtol(buf, 10, &val); + if (err) + return err; mutex_lock(&data->update_lock); - data->temp_max[nr] = SENSORS_LIMIT(val / 1000, -128, 127); + data->temp_max[nr] = clamp_val(val / 1000, -128, 127); i2c_smbus_write_byte_data(client, THMC50_REG_TEMP_MAX[nr], data->temp_max[nr]); mutex_unlock(&data->update_lock); @@ -296,8 +312,7 @@ static int thmc50_detect(struct i2c_client *client, const char *type_name; if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { - pr_debug("thmc50: detect failed, " - "smbus byte data not supported!\n"); + pr_debug("thmc50: detect failed, smbus byte data not supported!\n"); return -ENODEV; } @@ -346,12 +361,10 @@ static int thmc50_probe(struct i2c_client *client, struct thmc50_data *data; int err; - data = kzalloc(sizeof(struct thmc50_data), GFP_KERNEL); - if (!data) { - pr_debug("thmc50: detect failed, kzalloc failed!\n"); - err = -ENOMEM; - goto exit; - } + data = devm_kzalloc(&client->dev, sizeof(struct thmc50_data), + GFP_KERNEL); + if (!data) + return -ENOMEM; i2c_set_clientdata(client, data); data->type = id->driver_data; @@ -360,14 +373,16 @@ static int thmc50_probe(struct i2c_client *client, thmc50_init_client(client); /* Register sysfs hooks */ - if ((err = sysfs_create_group(&client->dev.kobj, &thmc50_group))) - goto exit_free; + err = sysfs_create_group(&client->dev.kobj, &thmc50_group); + if (err) + return err; /* Register ADM1022 sysfs hooks */ - if (data->has_temp3) - if ((err = sysfs_create_group(&client->dev.kobj, - &temp3_group))) + if (data->has_temp3) { + err = sysfs_create_group(&client->dev.kobj, &temp3_group); + if (err) goto exit_remove_sysfs_thmc50; + } /* Register a new directory entry with module sensors */ data->hwmon_dev = hwmon_device_register(&client->dev); @@ -383,9 +398,6 @@ exit_remove_sysfs: sysfs_remove_group(&client->dev.kobj, &temp3_group); exit_remove_sysfs_thmc50: sysfs_remove_group(&client->dev.kobj, &thmc50_group); -exit_free: - kfree(data); -exit: return err; } @@ -398,8 +410,6 @@ static int thmc50_remove(struct i2c_client *client) if (data->has_temp3) sysfs_remove_group(&client->dev.kobj, &temp3_group); - kfree(data); - return 0; } @@ -465,18 +475,7 @@ static struct thmc50_data *thmc50_update_device(struct device *dev) return data; } -static int __init sm_thmc50_init(void) -{ - return i2c_add_driver(&thmc50_driver); -} - -static void __exit sm_thmc50_exit(void) -{ - i2c_del_driver(&thmc50_driver); -} +module_i2c_driver(thmc50_driver); MODULE_AUTHOR("Krzysztof Helt <krzysztof.h1@wp.pl>"); MODULE_DESCRIPTION("THMC50 driver"); - -module_init(sm_thmc50_init); -module_exit(sm_thmc50_exit); |
