diff options
Diffstat (limited to 'drivers/hwmon/lm87.c')
| -rw-r--r-- | drivers/hwmon/lm87.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c index ad501ac4a594..37bf2d1d3d09 100644 --- a/drivers/hwmon/lm87.c +++ b/drivers/hwmon/lm87.c @@ -40,7 +40,7 @@ * This driver also supports the ADM1024, a sensor chip made by Analog * Devices. That chip is fully compatible with the LM87. Complete * datasheet can be obtained from Analog's website at: - * http://www.analog.com/en/prod/0,2877,ADM1024,00.html + * https://www.analog.com/en/prod/0,2877,ADM1024,00.html */ #include <linux/module.h> @@ -116,8 +116,14 @@ static u8 LM87_REG_TEMP_LOW[3] = { 0x3A, 0x38, 0x2C }; (((val) < 0 ? (val) - 500 : \ (val) + 500) / 1000)) -#define FAN_FROM_REG(reg, div) ((reg) == 255 || (reg) == 0 ? 0 : \ - (1350000 + (reg)*(div) / 2) / ((reg) * (div))) +static int fan_from_reg(int reg, int div) +{ + if (reg == 255 || reg == 0) + return 0; + + return (1350000 + reg * div / 2) / (reg * div); +} + #define FAN_TO_REG(val, div) ((val) * (div) * 255 <= 1350000 ? 255 : \ (1350000 + (val)*(div) / 2) / ((val) * (div))) @@ -141,7 +147,7 @@ static u8 LM87_REG_TEMP_LOW[3] = { 0x3A, 0x38, 0x2C }; struct lm87_data { struct mutex update_lock; - char valid; /* zero until following fields are valid */ + bool valid; /* false until following fields are valid */ unsigned long last_updated; /* In jiffies */ u8 channel; /* register value */ @@ -251,7 +257,7 @@ static struct lm87_data *lm87_update_device(struct device *dev) data->aout = lm87_read_value(client, LM87_REG_AOUT); data->last_updated = jiffies; - data->valid = 1; + data->valid = true; } mutex_unlock(&data->update_lock); @@ -465,7 +471,7 @@ static ssize_t fan_input_show(struct device *dev, struct lm87_data *data = lm87_update_device(dev); int nr = to_sensor_dev_attr(attr)->index; - return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], + return sprintf(buf, "%d\n", fan_from_reg(data->fan[nr], FAN_DIV_FROM_REG(data->fan_div[nr]))); } @@ -475,7 +481,7 @@ static ssize_t fan_min_show(struct device *dev, struct device_attribute *attr, struct lm87_data *data = lm87_update_device(dev); int nr = to_sensor_dev_attr(attr)->index; - return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr], + return sprintf(buf, "%d\n", fan_from_reg(data->fan_min[nr], FAN_DIV_FROM_REG(data->fan_div[nr]))); } @@ -534,7 +540,7 @@ static ssize_t fan_div_store(struct device *dev, return err; mutex_lock(&data->update_lock); - min = FAN_FROM_REG(data->fan_min[nr], + min = fan_from_reg(data->fan_min[nr], FAN_DIV_FROM_REG(data->fan_div[nr])); switch (val) { @@ -833,7 +839,7 @@ static int lm87_detect(struct i2c_client *client, struct i2c_board_info *info) return -ENODEV; } - strlcpy(info->type, name, I2C_NAME_SIZE); + strscpy(info->type, name, I2C_NAME_SIZE); return 0; } @@ -912,7 +918,7 @@ static int lm87_init_client(struct i2c_client *client) return 0; } -static int lm87_probe(struct i2c_client *client, const struct i2c_device_id *id) +static int lm87_probe(struct i2c_client *client) { struct lm87_data *data; struct device *hwmon_dev; @@ -975,8 +981,8 @@ static int lm87_probe(struct i2c_client *client, const struct i2c_device_id *id) */ static const struct i2c_device_id lm87_id[] = { - { "lm87", 0 }, - { "adm1024", 0 }, + { "lm87" }, + { "adm1024" }, { } }; MODULE_DEVICE_TABLE(i2c, lm87_id); |
