Commit 8f8c1fb0 authored by Darrick J. Wong's avatar Darrick J. Wong Committed by Linus Torvalds

adt74{62, 70, 73}: Use DIV_ROUND_CLOSEST for rounded division

Modify some hwmon drivers to use DIV_ROUND_CLOSEST instead of bloating
source with (naughty) macros.
Signed-off-by: default avatarDarrick J. Wong <djwong@us.ibm.com>
Cc: Jean Delvare <khali@linux-fr.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 57b9c6d9
...@@ -204,8 +204,6 @@ I2C_CLIENT_INSMOD_1(adt7462); ...@@ -204,8 +204,6 @@ I2C_CLIENT_INSMOD_1(adt7462);
#define MASK_AND_SHIFT(value, prefix) \ #define MASK_AND_SHIFT(value, prefix) \
(((value) & prefix##_MASK) >> prefix##_SHIFT) (((value) & prefix##_MASK) >> prefix##_SHIFT)
#define ROUND_DIV(x, divisor) (((x) + ((divisor) / 2)) / (divisor))
struct adt7462_data { struct adt7462_data {
struct device *hwmon_dev; struct device *hwmon_dev;
struct attribute_group attrs; struct attribute_group attrs;
...@@ -840,7 +838,7 @@ static ssize_t set_temp_min(struct device *dev, ...@@ -840,7 +838,7 @@ static ssize_t set_temp_min(struct device *dev,
if (strict_strtol(buf, 10, &temp) || !temp_enabled(data, attr->index)) if (strict_strtol(buf, 10, &temp) || !temp_enabled(data, attr->index))
return -EINVAL; return -EINVAL;
temp = ROUND_DIV(temp, 1000) + 64; temp = DIV_ROUND_CLOSEST(temp, 1000) + 64;
temp = SENSORS_LIMIT(temp, 0, 255); temp = SENSORS_LIMIT(temp, 0, 255);
mutex_lock(&data->lock); mutex_lock(&data->lock);
...@@ -878,7 +876,7 @@ static ssize_t set_temp_max(struct device *dev, ...@@ -878,7 +876,7 @@ static ssize_t set_temp_max(struct device *dev,
if (strict_strtol(buf, 10, &temp) || !temp_enabled(data, attr->index)) if (strict_strtol(buf, 10, &temp) || !temp_enabled(data, attr->index))
return -EINVAL; return -EINVAL;
temp = ROUND_DIV(temp, 1000) + 64; temp = DIV_ROUND_CLOSEST(temp, 1000) + 64;
temp = SENSORS_LIMIT(temp, 0, 255); temp = SENSORS_LIMIT(temp, 0, 255);
mutex_lock(&data->lock); mutex_lock(&data->lock);
...@@ -943,7 +941,7 @@ static ssize_t set_volt_max(struct device *dev, ...@@ -943,7 +941,7 @@ static ssize_t set_volt_max(struct device *dev,
return -EINVAL; return -EINVAL;
temp *= 1000; /* convert mV to uV */ temp *= 1000; /* convert mV to uV */
temp = ROUND_DIV(temp, x); temp = DIV_ROUND_CLOSEST(temp, x);
temp = SENSORS_LIMIT(temp, 0, 255); temp = SENSORS_LIMIT(temp, 0, 255);
mutex_lock(&data->lock); mutex_lock(&data->lock);
...@@ -985,7 +983,7 @@ static ssize_t set_volt_min(struct device *dev, ...@@ -985,7 +983,7 @@ static ssize_t set_volt_min(struct device *dev,
return -EINVAL; return -EINVAL;
temp *= 1000; /* convert mV to uV */ temp *= 1000; /* convert mV to uV */
temp = ROUND_DIV(temp, x); temp = DIV_ROUND_CLOSEST(temp, x);
temp = SENSORS_LIMIT(temp, 0, 255); temp = SENSORS_LIMIT(temp, 0, 255);
mutex_lock(&data->lock); mutex_lock(&data->lock);
...@@ -1250,7 +1248,7 @@ static ssize_t set_pwm_hyst(struct device *dev, ...@@ -1250,7 +1248,7 @@ static ssize_t set_pwm_hyst(struct device *dev,
if (strict_strtol(buf, 10, &temp)) if (strict_strtol(buf, 10, &temp))
return -EINVAL; return -EINVAL;
temp = ROUND_DIV(temp, 1000); temp = DIV_ROUND_CLOSEST(temp, 1000);
temp = SENSORS_LIMIT(temp, 0, 15); temp = SENSORS_LIMIT(temp, 0, 15);
/* package things up */ /* package things up */
...@@ -1337,7 +1335,7 @@ static ssize_t set_pwm_tmin(struct device *dev, ...@@ -1337,7 +1335,7 @@ static ssize_t set_pwm_tmin(struct device *dev,
if (strict_strtol(buf, 10, &temp)) if (strict_strtol(buf, 10, &temp))
return -EINVAL; return -EINVAL;
temp = ROUND_DIV(temp, 1000) + 64; temp = DIV_ROUND_CLOSEST(temp, 1000) + 64;
temp = SENSORS_LIMIT(temp, 0, 255); temp = SENSORS_LIMIT(temp, 0, 255);
mutex_lock(&data->lock); mutex_lock(&data->lock);
......
...@@ -137,8 +137,6 @@ I2C_CLIENT_INSMOD_1(adt7470); ...@@ -137,8 +137,6 @@ I2C_CLIENT_INSMOD_1(adt7470);
#define FAN_PERIOD_INVALID 65535 #define FAN_PERIOD_INVALID 65535
#define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID)
#define ROUND_DIV(x, divisor) (((x) + ((divisor) / 2)) / (divisor))
struct adt7470_data { struct adt7470_data {
struct device *hwmon_dev; struct device *hwmon_dev;
struct attribute_group attrs; struct attribute_group attrs;
...@@ -360,7 +358,7 @@ static ssize_t set_temp_min(struct device *dev, ...@@ -360,7 +358,7 @@ static ssize_t set_temp_min(struct device *dev,
if (strict_strtol(buf, 10, &temp)) if (strict_strtol(buf, 10, &temp))
return -EINVAL; return -EINVAL;
temp = ROUND_DIV(temp, 1000); temp = DIV_ROUND_CLOSEST(temp, 1000);
temp = SENSORS_LIMIT(temp, 0, 255); temp = SENSORS_LIMIT(temp, 0, 255);
mutex_lock(&data->lock); mutex_lock(&data->lock);
...@@ -394,7 +392,7 @@ static ssize_t set_temp_max(struct device *dev, ...@@ -394,7 +392,7 @@ static ssize_t set_temp_max(struct device *dev,
if (strict_strtol(buf, 10, &temp)) if (strict_strtol(buf, 10, &temp))
return -EINVAL; return -EINVAL;
temp = ROUND_DIV(temp, 1000); temp = DIV_ROUND_CLOSEST(temp, 1000);
temp = SENSORS_LIMIT(temp, 0, 255); temp = SENSORS_LIMIT(temp, 0, 255);
mutex_lock(&data->lock); mutex_lock(&data->lock);
...@@ -671,7 +669,7 @@ static ssize_t set_pwm_tmin(struct device *dev, ...@@ -671,7 +669,7 @@ static ssize_t set_pwm_tmin(struct device *dev,
if (strict_strtol(buf, 10, &temp)) if (strict_strtol(buf, 10, &temp))
return -EINVAL; return -EINVAL;
temp = ROUND_DIV(temp, 1000); temp = DIV_ROUND_CLOSEST(temp, 1000);
temp = SENSORS_LIMIT(temp, 0, 255); temp = SENSORS_LIMIT(temp, 0, 255);
mutex_lock(&data->lock); mutex_lock(&data->lock);
......
...@@ -129,8 +129,6 @@ I2C_CLIENT_INSMOD_1(adt7473); ...@@ -129,8 +129,6 @@ I2C_CLIENT_INSMOD_1(adt7473);
#define FAN_PERIOD_INVALID 65535 #define FAN_PERIOD_INVALID 65535
#define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID)
#define ROUND_DIV(x, divisor) (((x) + ((divisor) / 2)) / (divisor))
struct adt7473_data { struct adt7473_data {
struct device *hwmon_dev; struct device *hwmon_dev;
struct attribute_group attrs; struct attribute_group attrs;
...@@ -459,7 +457,7 @@ static ssize_t set_temp_min(struct device *dev, ...@@ -459,7 +457,7 @@ static ssize_t set_temp_min(struct device *dev,
if (strict_strtol(buf, 10, &temp)) if (strict_strtol(buf, 10, &temp))
return -EINVAL; return -EINVAL;
temp = ROUND_DIV(temp, 1000); temp = DIV_ROUND_CLOSEST(temp, 1000);
temp = encode_temp(data->temp_twos_complement, temp); temp = encode_temp(data->temp_twos_complement, temp);
mutex_lock(&data->lock); mutex_lock(&data->lock);
...@@ -495,7 +493,7 @@ static ssize_t set_temp_max(struct device *dev, ...@@ -495,7 +493,7 @@ static ssize_t set_temp_max(struct device *dev,
if (strict_strtol(buf, 10, &temp)) if (strict_strtol(buf, 10, &temp))
return -EINVAL; return -EINVAL;
temp = ROUND_DIV(temp, 1000); temp = DIV_ROUND_CLOSEST(temp, 1000);
temp = encode_temp(data->temp_twos_complement, temp); temp = encode_temp(data->temp_twos_complement, temp);
mutex_lock(&data->lock); mutex_lock(&data->lock);
...@@ -720,7 +718,7 @@ static ssize_t set_temp_tmax(struct device *dev, ...@@ -720,7 +718,7 @@ static ssize_t set_temp_tmax(struct device *dev,
if (strict_strtol(buf, 10, &temp)) if (strict_strtol(buf, 10, &temp))
return -EINVAL; return -EINVAL;
temp = ROUND_DIV(temp, 1000); temp = DIV_ROUND_CLOSEST(temp, 1000);
temp = encode_temp(data->temp_twos_complement, temp); temp = encode_temp(data->temp_twos_complement, temp);
mutex_lock(&data->lock); mutex_lock(&data->lock);
...@@ -756,7 +754,7 @@ static ssize_t set_temp_tmin(struct device *dev, ...@@ -756,7 +754,7 @@ static ssize_t set_temp_tmin(struct device *dev,
if (strict_strtol(buf, 10, &temp)) if (strict_strtol(buf, 10, &temp))
return -EINVAL; return -EINVAL;
temp = ROUND_DIV(temp, 1000); temp = DIV_ROUND_CLOSEST(temp, 1000);
temp = encode_temp(data->temp_twos_complement, temp); temp = encode_temp(data->temp_twos_complement, temp);
mutex_lock(&data->lock); mutex_lock(&data->lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment