diff options
author | Guenter Roeck <linux@roeck-us.net> | 2013-01-09 11:09:34 -0500 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2013-01-26 00:03:54 -0500 |
commit | 2a844c148e1f714ebf42cb96e1b172ce394c36c9 (patch) | |
tree | eb68eb8438f0470e7a81b022199abe5f6d866879 | |
parent | 142c090184ac7f9763c5d22509405da3486f9801 (diff) |
hwmon: Replace SENSORS_LIMIT with clamp_val
SENSORS_LIMIT and the generic clamp_val have the same functionality,
and clamp_val is more efficient.
This patch reduces text size by 9052 bytes and bss size by 11624 bytes
for x86_64 builds.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: George Joseph <george.joseph@fairview5.com>
Acked-by: Jean Delvare <khali@linux-fr.org>
57 files changed, 297 insertions, 319 deletions
diff --git a/drivers/hwmon/ad7414.c b/drivers/hwmon/ad7414.c index f3a5d4764eb9..5d501adc3e54 100644 --- a/drivers/hwmon/ad7414.c +++ b/drivers/hwmon/ad7414.c | |||
@@ -137,7 +137,7 @@ static ssize_t set_max_min(struct device *dev, | |||
137 | if (ret < 0) | 137 | if (ret < 0) |
138 | return ret; | 138 | return ret; |
139 | 139 | ||
140 | temp = SENSORS_LIMIT(temp, -40000, 85000); | 140 | temp = clamp_val(temp, -40000, 85000); |
141 | temp = (temp + (temp < 0 ? -500 : 500)) / 1000; | 141 | temp = (temp + (temp < 0 ? -500 : 500)) / 1000; |
142 | 142 | ||
143 | mutex_lock(&data->lock); | 143 | mutex_lock(&data->lock); |
diff --git a/drivers/hwmon/adm1021.c b/drivers/hwmon/adm1021.c index fd1d1b15854e..71bcba8abfc0 100644 --- a/drivers/hwmon/adm1021.c +++ b/drivers/hwmon/adm1021.c | |||
@@ -193,7 +193,7 @@ static ssize_t set_temp_max(struct device *dev, | |||
193 | temp /= 1000; | 193 | temp /= 1000; |
194 | 194 | ||
195 | mutex_lock(&data->update_lock); | 195 | mutex_lock(&data->update_lock); |
196 | data->temp_max[index] = SENSORS_LIMIT(temp, -128, 127); | 196 | data->temp_max[index] = clamp_val(temp, -128, 127); |
197 | if (!read_only) | 197 | if (!read_only) |
198 | i2c_smbus_write_byte_data(client, ADM1021_REG_TOS_W(index), | 198 | i2c_smbus_write_byte_data(client, ADM1021_REG_TOS_W(index), |
199 | data->temp_max[index]); | 199 | data->temp_max[index]); |
@@ -218,7 +218,7 @@ static ssize_t set_temp_min(struct device *dev, | |||
218 | temp /= 1000; | 218 | temp /= 1000; |
219 | 219 | ||
220 | mutex_lock(&data->update_lock); | 220 | mutex_lock(&data->update_lock); |
221 | data->temp_min[index] = SENSORS_LIMIT(temp, -128, 127); | 221 | data->temp_min[index] = clamp_val(temp, -128, 127); |
222 | if (!read_only) | 222 | if (!read_only) |
223 | i2c_smbus_write_byte_data(client, ADM1021_REG_THYST_W(index), | 223 | i2c_smbus_write_byte_data(client, ADM1021_REG_THYST_W(index), |
224 | data->temp_min[index]); | 224 | data->temp_min[index]); |
diff --git a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c index 0f068e7297ee..ea09046e651d 100644 --- a/drivers/hwmon/adm1026.c +++ b/drivers/hwmon/adm1026.c | |||
@@ -197,7 +197,7 @@ static int adm1026_scaling[] = { /* .001 Volts */ | |||
197 | }; | 197 | }; |
198 | #define NEG12_OFFSET 16000 | 198 | #define NEG12_OFFSET 16000 |
199 | #define SCALE(val, from, to) (((val)*(to) + ((from)/2))/(from)) | 199 | #define SCALE(val, from, to) (((val)*(to) + ((from)/2))/(from)) |
200 | #define INS_TO_REG(n, val) (SENSORS_LIMIT(SCALE(val, adm1026_scaling[n], 192),\ | 200 | #define INS_TO_REG(n, val) (clamp_val(SCALE(val, adm1026_scaling[n], 192),\ |
201 | 0, 255)) | 201 | 0, 255)) |
202 | #define INS_FROM_REG(n, val) (SCALE(val, 192, adm1026_scaling[n])) | 202 | #define INS_FROM_REG(n, val) (SCALE(val, 192, adm1026_scaling[n])) |
203 | 203 | ||
@@ -207,7 +207,7 @@ static int adm1026_scaling[] = { /* .001 Volts */ | |||
207 | * 22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) == 1350000 | 207 | * 22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) == 1350000 |
208 | */ | 208 | */ |
209 | #define FAN_TO_REG(val, div) ((val) <= 0 ? 0xff : \ | 209 | #define FAN_TO_REG(val, div) ((val) <= 0 ? 0xff : \ |
210 | SENSORS_LIMIT(1350000 / ((val) * (div)), \ | 210 | clamp_val(1350000 / ((val) * (div)), \ |
211 | 1, 254)) | 211 | 1, 254)) |
212 | #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 0xff ? 0 : \ | 212 | #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 0xff ? 0 : \ |
213 | 1350000 / ((val) * (div))) | 213 | 1350000 / ((val) * (div))) |
@@ -215,14 +215,14 @@ static int adm1026_scaling[] = { /* .001 Volts */ | |||
215 | #define DIV_TO_REG(val) ((val) >= 8 ? 3 : (val) >= 4 ? 2 : (val) >= 2 ? 1 : 0) | 215 | #define DIV_TO_REG(val) ((val) >= 8 ? 3 : (val) >= 4 ? 2 : (val) >= 2 ? 1 : 0) |
216 | 216 | ||
217 | /* Temperature is reported in 1 degC increments */ | 217 | /* Temperature is reported in 1 degC increments */ |
218 | #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) + ((val) < 0 ? -500 : 500)) \ | 218 | #define TEMP_TO_REG(val) (clamp_val(((val) + ((val) < 0 ? -500 : 500)) \ |
219 | / 1000, -127, 127)) | 219 | / 1000, -127, 127)) |
220 | #define TEMP_FROM_REG(val) ((val) * 1000) | 220 | #define TEMP_FROM_REG(val) ((val) * 1000) |
221 | #define OFFSET_TO_REG(val) (SENSORS_LIMIT(((val) + ((val) < 0 ? -500 : 500)) \ | 221 | #define OFFSET_TO_REG(val) (clamp_val(((val) + ((val) < 0 ? -500 : 500)) \ |
222 | / 1000, -127, 127)) | 222 | / 1000, -127, 127)) |
223 | #define OFFSET_FROM_REG(val) ((val) * 1000) | 223 | #define OFFSET_FROM_REG(val) ((val) * 1000) |
224 | 224 | ||
225 | #define PWM_TO_REG(val) (SENSORS_LIMIT(val, 0, 255)) | 225 | #define PWM_TO_REG(val) (clamp_val(val, 0, 255)) |
226 | #define PWM_FROM_REG(val) (val) | 226 | #define PWM_FROM_REG(val) (val) |
227 | 227 | ||
228 | #define PWM_MIN_TO_REG(val) ((val) & 0xf0) | 228 | #define PWM_MIN_TO_REG(val) ((val) & 0xf0) |
@@ -233,7 +233,7 @@ static int adm1026_scaling[] = { /* .001 Volts */ | |||
233 | * indicates that the DAC could be used to drive the fans, but in our | 233 | * indicates that the DAC could be used to drive the fans, but in our |
234 | * example board (Arima HDAMA) it isn't connected to the fans at all. | 234 | * example board (Arima HDAMA) it isn't connected to the fans at all. |
235 | */ | 235 | */ |
236 | #define DAC_TO_REG(val) (SENSORS_LIMIT(((((val) * 255) + 500) / 2500), 0, 255)) | 236 | #define DAC_TO_REG(val) (clamp_val(((((val) * 255) + 500) / 2500), 0, 255)) |
237 | #define DAC_FROM_REG(val) (((val) * 2500) / 255) | 237 | #define DAC_FROM_REG(val) (((val) * 2500) / 255) |
238 | 238 | ||
239 | /* | 239 | /* |
@@ -933,7 +933,7 @@ static void fixup_fan_min(struct device *dev, int fan, int old_div) | |||
933 | return; | 933 | return; |
934 | 934 | ||
935 | new_min = data->fan_min[fan] * old_div / new_div; | 935 | new_min = data->fan_min[fan] * old_div / new_div; |
936 | new_min = SENSORS_LIMIT(new_min, 1, 254); | 936 | new_min = clamp_val(new_min, 1, 254); |
937 | data->fan_min[fan] = new_min; | 937 | data->fan_min[fan] = new_min; |
938 | adm1026_write_value(client, ADM1026_REG_FAN_MIN(fan), new_min); | 938 | adm1026_write_value(client, ADM1026_REG_FAN_MIN(fan), new_min); |
939 | } | 939 | } |
@@ -1527,7 +1527,7 @@ static ssize_t set_auto_pwm_min(struct device *dev, | |||
1527 | return err; | 1527 | return err; |
1528 | 1528 | ||
1529 | mutex_lock(&data->update_lock); | 1529 | mutex_lock(&data->update_lock); |
1530 | data->pwm1.auto_pwm_min = SENSORS_LIMIT(val, 0, 255); | 1530 | data->pwm1.auto_pwm_min = clamp_val(val, 0, 255); |
1531 | if (data->pwm1.enable == 2) { /* apply immediately */ | 1531 | if (data->pwm1.enable == 2) { /* apply immediately */ |
1532 | data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) | | 1532 | data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) | |
1533 | PWM_MIN_TO_REG(data->pwm1.auto_pwm_min)); | 1533 | PWM_MIN_TO_REG(data->pwm1.auto_pwm_min)); |
diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c index c6a4631e833f..253ea396106d 100644 --- a/drivers/hwmon/adm1031.c +++ b/drivers/hwmon/adm1031.c | |||
@@ -162,13 +162,13 @@ adm1031_write_value(struct i2c_client *client, u8 reg, unsigned int value) | |||
162 | static int FAN_TO_REG(int reg, int div) | 162 | static int FAN_TO_REG(int reg, int div) |
163 | { | 163 | { |
164 | int tmp; | 164 | int tmp; |
165 | tmp = FAN_FROM_REG(SENSORS_LIMIT(reg, 0, 65535), div); | 165 | tmp = FAN_FROM_REG(clamp_val(reg, 0, 65535), div); |
166 | return tmp > 255 ? 255 : tmp; | 166 | return tmp > 255 ? 255 : tmp; |
167 | } | 167 | } |
168 | 168 | ||
169 | #define FAN_DIV_FROM_REG(reg) (1<<(((reg)&0xc0)>>6)) | 169 | #define FAN_DIV_FROM_REG(reg) (1<<(((reg)&0xc0)>>6)) |
170 | 170 | ||
171 | #define PWM_TO_REG(val) (SENSORS_LIMIT((val), 0, 255) >> 4) | 171 | #define PWM_TO_REG(val) (clamp_val((val), 0, 255) >> 4) |
172 | #define PWM_FROM_REG(val) ((val) << 4) | 172 | #define PWM_FROM_REG(val) ((val) << 4) |
173 | 173 | ||
174 | #define FAN_CHAN_FROM_REG(reg) (((reg) >> 5) & 7) | 174 | #define FAN_CHAN_FROM_REG(reg) (((reg) >> 5) & 7) |
@@ -675,7 +675,7 @@ static ssize_t set_temp_offset(struct device *dev, | |||
675 | if (ret) | 675 | if (ret) |
676 | return ret; | 676 | return ret; |
677 | 677 | ||
678 | val = SENSORS_LIMIT(val, -15000, 15000); | 678 | val = clamp_val(val, -15000, 15000); |
679 | mutex_lock(&data->update_lock); | 679 | mutex_lock(&data->update_lock); |
680 | data->temp_offset[nr] = TEMP_OFFSET_TO_REG(val); | 680 | data->temp_offset[nr] = TEMP_OFFSET_TO_REG(val); |
681 | adm1031_write_value(client, ADM1031_REG_TEMP_OFFSET(nr), | 681 | adm1031_write_value(client, ADM1031_REG_TEMP_OFFSET(nr), |
@@ -696,7 +696,7 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | |||
696 | if (ret) | 696 | if (ret) |
697 | return ret; | 697 | return ret; |
698 | 698 | ||
699 | val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875); | 699 | val = clamp_val(val, -55000, nr == 0 ? 127750 : 127875); |
700 | mutex_lock(&data->update_lock); | 700 | mutex_lock(&data->update_lock); |
701 | data->temp_min[nr] = TEMP_TO_REG(val); | 701 | data->temp_min[nr] = TEMP_TO_REG(val); |
702 | adm1031_write_value(client, ADM1031_REG_TEMP_MIN(nr), | 702 | adm1031_write_value(client, ADM1031_REG_TEMP_MIN(nr), |
@@ -717,7 +717,7 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | |||
717 | if (ret) | 717 | if (ret) |
718 | return ret; | 718 | return ret; |
719 | 719 | ||
720 | val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875); | 720 | val = clamp_val(val, -55000, nr == 0 ? 127750 : 127875); |
721 | mutex_lock(&data->update_lock); | 721 | mutex_lock(&data->update_lock); |
722 | data->temp_max[nr] = TEMP_TO_REG(val); | 722 | data->temp_max[nr] = TEMP_TO_REG(val); |
723 | adm1031_write_value(client, ADM1031_REG_TEMP_MAX(nr), | 723 | adm1031_write_value(client, ADM1031_REG_TEMP_MAX(nr), |
@@ -738,7 +738,7 @@ static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr, | |||
738 | if (ret) | 738 | if (ret) |
739 | return ret; | 739 | return ret; |
740 | 740 | ||
741 | val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875); | 741 | val = clamp_val(val, -55000, nr == 0 ? 127750 : 127875); |
742 | mutex_lock(&data->update_lock); | 742 | mutex_lock(&data->update_lock); |
743 | data->temp_crit[nr] = TEMP_TO_REG(val); | 743 | data->temp_crit[nr] = TEMP_TO_REG(val); |
744 | adm1031_write_value(client, ADM1031_REG_TEMP_CRIT(nr), | 744 | adm1031_write_value(client, ADM1031_REG_TEMP_CRIT(nr), |
diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c index dafa477715e3..2416628e0ab1 100644 --- a/drivers/hwmon/adm9240.c +++ b/drivers/hwmon/adm9240.c | |||
@@ -98,13 +98,13 @@ static inline unsigned int IN_FROM_REG(u8 reg, int n) | |||
98 | 98 | ||
99 | static inline u8 IN_TO_REG(unsigned long val, int n) | 99 | static inline u8 IN_TO_REG(unsigned long val, int n) |
100 | { | 100 | { |
101 | return SENSORS_LIMIT(SCALE(val, 192, nom_mv[n]), 0, 255); | 101 | return clamp_val(SCALE(val, 192, nom_mv[n]), 0, 255); |
102 | } | 102 | } |
103 | 103 | ||
104 | /* temperature range: -40..125, 127 disables temperature alarm */ | 104 | /* temperature range: -40..125, 127 disables temperature alarm */ |
105 | static inline s8 TEMP_TO_REG(long val) | 105 | static inline s8 TEMP_TO_REG(long val) |
106 | { | 106 | { |
107 | return SENSORS_LIMIT(SCALE(val, 1, 1000), -40, 127); | 107 | return clamp_val(SCALE(val, 1, 1000), -40, 127); |
108 | } | 108 | } |
109 | 109 | ||
110 | /* two fans, each with low fan speed limit */ | 110 | /* two fans, each with low fan speed limit */ |
@@ -122,7 +122,7 @@ static inline unsigned int FAN_FROM_REG(u8 reg, u8 div) | |||
122 | /* analog out 0..1250mV */ | 122 | /* analog out 0..1250mV */ |
123 | static inline u8 AOUT_TO_REG(unsigned long val) | 123 | static inline u8 AOUT_TO_REG(unsigned long val) |
124 | { | 124 | { |
125 | return SENSORS_LIMIT(SCALE(val, 255, 1250), 0, 255); | 125 | return clamp_val(SCALE(val, 255, 1250), 0, 255); |
126 | } | 126 | } |
127 | 127 | ||
128 | static inline unsigned int AOUT_FROM_REG(u8 reg) | 128 | static inline unsigned int AOUT_FROM_REG(u8 reg) |
diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c index 409b5c16defb..ba962ac4b81f 100644 --- a/drivers/hwmon/ads7828.c +++ b/drivers/hwmon/ads7828.c | |||
@@ -163,9 +163,9 @@ static int ads7828_probe(struct i2c_client *client, | |||
163 | 163 | ||
164 | /* Bound Vref with min/max values if it was provided */ | 164 | /* Bound Vref with min/max values if it was provided */ |
165 | if (data->vref_mv) | 165 | if (data->vref_mv) |
166 | data->vref_mv = SENSORS_LIMIT(data->vref_mv, | 166 | data->vref_mv = clamp_val(data->vref_mv, |
167 | ADS7828_EXT_VREF_MV_MIN, | 167 | ADS7828_EXT_VREF_MV_MIN, |
168 | ADS7828_EXT_VREF_MV_MAX); | 168 | ADS7828_EXT_VREF_MV_MAX); |
169 | else | 169 | else |
170 | data->vref_mv = ADS7828_INT_VREF_MV; | 170 | data->vref_mv = ADS7828_INT_VREF_MV; |
171 | 171 | ||
diff --git a/drivers/hwmon/adt7410.c b/drivers/hwmon/adt7410.c index 030c8d7c33a5..797c2b85c483 100644 --- a/drivers/hwmon/adt7410.c +++ b/drivers/hwmon/adt7410.c | |||
@@ -173,8 +173,8 @@ abort: | |||
173 | 173 | ||
174 | static s16 ADT7410_TEMP_TO_REG(long temp) | 174 | static s16 ADT7410_TEMP_TO_REG(long temp) |
175 | { | 175 | { |
176 | return DIV_ROUND_CLOSEST(SENSORS_LIMIT(temp, ADT7410_TEMP_MIN, | 176 | return DIV_ROUND_CLOSEST(clamp_val(temp, ADT7410_TEMP_MIN, |
177 | ADT7410_TEMP_MAX) * 128, 1000); | 177 | ADT7410_TEMP_MAX) * 128, 1000); |
178 | } | 178 | } |
179 | 179 | ||
180 | static int ADT7410_REG_TO_TEMP(struct adt7410_data *data, s16 reg) | 180 | static int ADT7410_REG_TO_TEMP(struct adt7410_data *data, s16 reg) |
@@ -269,9 +269,9 @@ static ssize_t adt7410_set_t_hyst(struct device *dev, | |||
269 | return ret; | 269 | return ret; |
270 | /* convert absolute hysteresis value to a 4 bit delta value */ | 270 | /* convert absolute hysteresis value to a 4 bit delta value */ |
271 | limit = ADT7410_REG_TO_TEMP(data, data->temp[1]); | 271 | limit = ADT7410_REG_TO_TEMP(data, data->temp[1]); |
272 | hyst = SENSORS_LIMIT(hyst, ADT7410_TEMP_MIN, ADT7410_TEMP_MAX); | 272 | hyst = clamp_val(hyst, ADT7410_TEMP_MIN, ADT7410_TEMP_MAX); |
273 | data->hyst = SENSORS_LIMIT(DIV_ROUND_CLOSEST(limit - hyst, 1000), | 273 | data->hyst = clamp_val(DIV_ROUND_CLOSEST(limit - hyst, 1000), 0, |
274 | 0, ADT7410_T_HYST_MASK); | 274 | ADT7410_T_HYST_MASK); |
275 | ret = i2c_smbus_write_byte_data(client, ADT7410_T_HYST, data->hyst); | 275 | ret = i2c_smbus_write_byte_data(client, ADT7410_T_HYST, data->hyst); |
276 | if (ret) | 276 | if (ret) |
277 | return ret; | 277 | return ret; |
diff --git a/drivers/hwmon/adt7462.c b/drivers/hwmon/adt7462.c index 98a7d81e25c5..69481d3a3d23 100644 --- a/drivers/hwmon/adt7462.c +++ b/drivers/hwmon/adt7462.c | |||
@@ -836,7 +836,7 @@ static ssize_t set_temp_min(struct device *dev, | |||
836 | return -EINVAL; | 836 | return -EINVAL; |
837 | 837 | ||
838 | temp = DIV_ROUND_CLOSEST(temp, 1000) + 64; | 838 | temp = DIV_ROUND_CLOSEST(temp, 1000) + 64; |
839 | temp = SENSORS_LIMIT(temp, 0, 255); | 839 | temp = clamp_val(temp, 0, 255); |
840 | 840 | ||
841 | mutex_lock(&data->lock); | 841 | mutex_lock(&data->lock); |
842 | data->temp_min[attr->index] = temp; | 842 | data->temp_min[attr->index] = temp; |
@@ -874,7 +874,7 @@ static ssize_t set_temp_max(struct device *dev, | |||
874 | return -EINVAL; | 874 | return -EINVAL; |
875 | 875 | ||
876 | temp = DIV_ROUND_CLOSEST(temp, 1000) + 64; | 876 | temp = DIV_ROUND_CLOSEST(temp, 1000) + 64; |
877 | temp = SENSORS_LIMIT(temp, 0, 255); | 877 | temp = clamp_val(temp, 0, 255); |
878 | 878 | ||
879 | mutex_lock(&data->lock); | 879 | mutex_lock(&data->lock); |
880 | data->temp_max[attr->index] = temp; | 880 | data->temp_max[attr->index] = temp; |
@@ -939,7 +939,7 @@ static ssize_t set_volt_max(struct device *dev, | |||
939 | 939 | ||
940 | temp *= 1000; /* convert mV to uV */ | 940 | temp *= 1000; /* convert mV to uV */ |
941 | temp = DIV_ROUND_CLOSEST(temp, x); | 941 | temp = DIV_ROUND_CLOSEST(temp, x); |
942 | temp = SENSORS_LIMIT(temp, 0, 255); | 942 | temp = clamp_val(temp, 0, 255); |
943 | 943 | ||
944 | mutex_lock(&data->lock); | 944 | mutex_lock(&data->lock); |
945 | data->volt_max[attr->index] = temp; | 945 | data->volt_max[attr->index] = temp; |
@@ -981,7 +981,7 @@ static ssize_t set_volt_min(struct device *dev, | |||
981 | 981 | ||
982 | temp *= 1000; /* convert mV to uV */ | 982 | temp *= 1000; /* convert mV to uV */ |
983 | temp = DIV_ROUND_CLOSEST(temp, x); | 983 | temp = DIV_ROUND_CLOSEST(temp, x); |
984 | temp = SENSORS_LIMIT(temp, 0, 255); | 984 | temp = clamp_val(temp, 0, 255); |
985 | 985 | ||
986 | mutex_lock(&data->lock); | 986 | mutex_lock(&data->lock); |
987 | data->volt_min[attr->index] = temp; | 987 | data->volt_min[attr->index] = temp; |
@@ -1071,7 +1071,7 @@ static ssize_t set_fan_min(struct device *dev, | |||
1071 | 1071 | ||
1072 | temp = FAN_RPM_TO_PERIOD(temp); | 1072 | temp = FAN_RPM_TO_PERIOD(temp); |
1073 | temp >>= 8; | 1073 | temp >>= 8; |
1074 | temp = SENSORS_LIMIT(temp, 1, 255); | 1074 | temp = clamp_val(temp, 1, 255); |
1075 | 1075 | ||
1076 | mutex_lock(&data->lock); | 1076 | mutex_lock(&data->lock); |
1077 | data->fan_min[attr->index] = temp; | 1077 | data->fan_min[attr->index] = temp; |
@@ -1149,7 +1149,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, | |||
1149 | if (kstrtol(buf, 10, &temp)) | 1149 | if (kstrtol(buf, 10, &temp)) |
1150 | return -EINVAL; | 1150 | return -EINVAL; |
1151 | 1151 | ||
1152 | temp = SENSORS_LIMIT(temp, 0, 255); | 1152 | temp = clamp_val(temp, 0, 255); |
1153 | 1153 | ||
1154 | mutex_lock(&data->lock); | 1154 | mutex_lock(&data->lock); |
1155 | data->pwm[attr->index] = temp; | 1155 | data->pwm[attr->index] = temp; |
@@ -1179,7 +1179,7 @@ static ssize_t set_pwm_max(struct device *dev, | |||
1179 | if (kstrtol(buf, 10, &temp)) | 1179 | if (kstrtol(buf, 10, &temp)) |
1180 | return -EINVAL; | 1180 | return -EINVAL; |
1181 | 1181 | ||
1182 | temp = SENSORS_LIMIT(temp, 0, 255); | 1182 | temp = clamp_val(temp, 0, 255); |
1183 | 1183 | ||
1184 | mutex_lock(&data->lock); | 1184 | mutex_lock(&data->lock); |
1185 | data->pwm_max = temp; | 1185 | data->pwm_max = temp; |
@@ -1211,7 +1211,7 @@ static ssize_t set_pwm_min(struct device *dev, | |||
1211 | if (kstrtol(buf, 10, &temp)) | 1211 | if (kstrtol(buf, 10, &temp)) |
1212 | return -EINVAL; | 1212 | return -EINVAL; |
1213 | 1213 | ||
1214 | temp = SENSORS_LIMIT(temp, 0, 255); | 1214 | temp = clamp_val(temp, 0, 255); |
1215 | 1215 | ||
1216 | mutex_lock(&data->lock); | 1216 | mutex_lock(&data->lock); |
1217 | data->pwm_min[attr->index] = temp; | 1217 | data->pwm_min[attr->index] = temp; |
@@ -1246,7 +1246,7 @@ static ssize_t set_pwm_hyst(struct device *dev, | |||
1246 | return -EINVAL; | 1246 | return -EINVAL; |
1247 | 1247 | ||
1248 | temp = DIV_ROUND_CLOSEST(temp, 1000); | 1248 | temp = DIV_ROUND_CLOSEST(temp, 1000); |
1249 | temp = SENSORS_LIMIT(temp, 0, 15); | 1249 | temp = clamp_val(temp, 0, 15); |
1250 | 1250 | ||
1251 | /* package things up */ | 1251 | /* package things up */ |
1252 | temp &= ADT7462_PWM_HYST_MASK; | 1252 | temp &= ADT7462_PWM_HYST_MASK; |
@@ -1333,7 +1333,7 @@ static ssize_t set_pwm_tmin(struct device *dev, | |||
1333 | return -EINVAL; | 1333 | return -EINVAL; |
1334 | 1334 | ||
1335 | temp = DIV_ROUND_CLOSEST(temp, 1000) + 64; | 1335 | temp = DIV_ROUND_CLOSEST(temp, 1000) + 64; |
1336 | temp = SENSORS_LIMIT(temp, 0, 255); | 1336 | temp = clamp_val(temp, 0, 255); |
1337 | 1337 | ||
1338 | mutex_lock(&data->lock); | 1338 | mutex_lock(&data->lock); |
1339 | data->pwm_tmin[attr->index] = temp; | 1339 | data->pwm_tmin[attr->index] = temp; |
diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c index 39ecb1a3b9ef..b83bf4bb95eb 100644 --- a/drivers/hwmon/adt7470.c +++ b/drivers/hwmon/adt7470.c | |||
@@ -452,7 +452,7 @@ static ssize_t set_auto_update_interval(struct device *dev, | |||
452 | if (kstrtol(buf, 10, &temp)) | 452 | if (kstrtol(buf, 10, &temp)) |
453 | return -EINVAL; | 453 | return -EINVAL; |
454 | 454 | ||
455 | temp = SENSORS_LIMIT(temp, 0, 60000); | 455 | temp = clamp_val(temp, 0, 60000); |
456 | 456 | ||
457 | mutex_lock(&data->lock); | 457 | mutex_lock(&data->lock); |
458 | data->auto_update_interval = temp; | 458 | data->auto_update_interval = temp; |
@@ -481,7 +481,7 @@ static ssize_t set_num_temp_sensors(struct device *dev, | |||
481 | if (kstrtol(buf, 10, &temp)) | 481 | if (kstrtol(buf, 10, &temp)) |
482 | return -EINVAL; | 482 | return -EINVAL; |
483 | 483 | ||
484 | temp = SENSORS_LIMIT(temp, -1, 10); | 484 | temp = clamp_val(temp, -1, 10); |
485 | 485 | ||
486 | mutex_lock(&data->lock); | 486 | mutex_lock(&data->lock); |
487 | data->num_temp_sensors = temp; | 487 | data->num_temp_sensors = temp; |
@@ -515,7 +515,7 @@ static ssize_t set_temp_min(struct device *dev, | |||
515 | return -EINVAL; | 515 | return -EINVAL; |
516 | 516 | ||
517 | temp = DIV_ROUND_CLOSEST(temp, 1000); | 517 | temp = DIV_ROUND_CLOSEST(temp, 1000); |
518 | temp = SENSORS_LIMIT(temp, 0, 255); | 518 | temp = clamp_val(temp, 0, 255); |
519 | 519 | ||
520 | mutex_lock(&data->lock); | 520 | mutex_lock(&data->lock); |
521 | data->temp_min[attr->index] = temp; | 521 | data->temp_min[attr->index] = temp; |
@@ -549,7 +549,7 @@ static ssize_t set_temp_max(struct device *dev, | |||
549 | return -EINVAL; | 549 | return -EINVAL; |
550 | 550 | ||
551 | temp = DIV_ROUND_CLOSEST(temp, 1000); | 551 | temp = DIV_ROUND_CLOSEST(temp, 1000); |
552 | temp = SENSORS_LIMIT(temp, 0, 255); | 552 | temp = clamp_val(temp, 0, 255); |
553 | 553 | ||
554 | mutex_lock(&data->lock); | 554 | mutex_lock(&data->lock); |
555 | data->temp_max[attr->index] = temp; | 555 | data->temp_max[attr->index] = temp; |
@@ -604,7 +604,7 @@ static ssize_t set_fan_max(struct device *dev, | |||
604 | return -EINVAL; | 604 | return -EINVAL; |
605 | 605 | ||
606 | temp = FAN_RPM_TO_PERIOD(temp); | 606 | temp = FAN_RPM_TO_PERIOD(temp); |
607 | temp = SENSORS_LIMIT(temp, 1, 65534); | 607 | temp = clamp_val(temp, 1, 65534); |
608 | 608 | ||
609 | mutex_lock(&data->lock); | 609 | mutex_lock(&data->lock); |
610 | data->fan_max[attr->index] = temp; | 610 | data->fan_max[attr->index] = temp; |
@@ -641,7 +641,7 @@ static ssize_t set_fan_min(struct device *dev, | |||
641 | return -EINVAL; | 641 | return -EINVAL; |
642 | 642 | ||
643 | temp = FAN_RPM_TO_PERIOD(temp); | 643 | temp = FAN_RPM_TO_PERIOD(temp); |
644 | temp = SENSORS_LIMIT(temp, 1, 65534); | 644 | temp = clamp_val(temp, 1, 65534); |
645 | 645 | ||
646 | mutex_lock(&data->lock); | 646 | mutex_lock(&data->lock); |
647 | data->fan_min[attr->index] = temp; | 647 | data->fan_min[attr->index] = temp; |
@@ -717,7 +717,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, | |||
717 | if (kstrtol(buf, 10, &temp)) | 717 | if (kstrtol(buf, 10, &temp)) |
718 | return -EINVAL; | 718 | return -EINVAL; |
719 | 719 | ||
720 | temp = SENSORS_LIMIT(temp, 0, 255); | 720 | temp = clamp_val(temp, 0, 255); |
721 | 721 | ||
722 | mutex_lock(&data->lock); | 722 | mutex_lock(&data->lock); |
723 | data->pwm[attr->index] = temp; | 723 | data->pwm[attr->index] = temp; |
@@ -749,7 +749,7 @@ static ssize_t set_pwm_max(struct device *dev, | |||
749 | if (kstrtol(buf, 10, &temp)) | 749 | if (kstrtol(buf, 10, &temp)) |
750 | return -EINVAL; | 750 | return -EINVAL; |
751 | 751 | ||
752 | temp = SENSORS_LIMIT(temp, 0, 255); | 752 | temp = clamp_val(temp, 0, 255); |
753 | 753 | ||
754 | mutex_lock(&data->lock); | 754 | mutex_lock(&data->lock); |
755 | data->pwm_max[attr->index] = temp; | 755 | data->pwm_max[attr->index] = temp; |
@@ -782,7 +782,7 @@ static ssize_t set_pwm_min(struct device *dev, | |||
782 | if (kstrtol(buf, 10, &temp)) | 782 | if (kstrtol(buf, 10, &temp)) |
783 | return -EINVAL; | 783 | return -EINVAL; |
784 | 784 | ||
785 | temp = SENSORS_LIMIT(temp, 0, 255); | 785 | temp = clamp_val(temp, 0, 255); |
786 | 786 | ||
787 | mutex_lock(&data->lock); | 787 | mutex_lock(&data->lock); |
788 | data->pwm_min[attr->index] = temp; | 788 | data->pwm_min[attr->index] = temp; |
@@ -826,7 +826,7 @@ static ssize_t set_pwm_tmin(struct device *dev, | |||
826 | return -EINVAL; | 826 | return -EINVAL; |
827 | 827 | ||
828 | temp = DIV_ROUND_CLOSEST(temp, 1000); | 828 | temp = DIV_ROUND_CLOSEST(temp, 1000); |
829 | temp = SENSORS_LIMIT(temp, 0, 255); | 829 | temp = clamp_val(temp, 0, 255); |
830 | 830 | ||
831 | mutex_lock(&data->lock); | 831 | mutex_lock(&data->lock); |
832 | data->pwm_tmin[attr->index] = temp; | 832 | data->pwm_tmin[attr->index] = temp; |
diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c index 989e54c39252..22d008bbdc10 100644 --- a/drivers/hwmon/adt7475.c +++ b/drivers/hwmon/adt7475.c | |||
@@ -201,10 +201,10 @@ static inline u16 temp2reg(struct adt7475_data *data, long val) | |||
201 | u16 ret; | 201 | u16 ret; |
202 | 202 | ||
203 | if (!(data->config5 & CONFIG5_TWOSCOMP)) { | 203 | if (!(data->config5 & CONFIG5_TWOSCOMP)) { |
204 | val = SENSORS_LIMIT(val, -64000, 191000); | 204 | val = clamp_val(val, -64000, 191000); |
205 | ret = (val + 64500) / 1000; | 205 | ret = (val + 64500) / 1000; |
206 | } else { | 206 | } else { |
207 | val = SENSORS_LIMIT(val, -128000, 127000); | 207 | val = clamp_val(val, -128000, 127000); |
208 | if (val < -500) | 208 | if (val < -500) |
209 | ret = (256500 + val) / 1000; | 209 | ret = (256500 + val) / 1000; |
210 | else | 210 | else |
@@ -240,7 +240,7 @@ static inline u16 rpm2tach(unsigned long rpm) | |||
240 | if (rpm == 0) | 240 | if (rpm == 0) |
241 | return 0; | 241 | return 0; |
242 | 242 | ||
243 | return SENSORS_LIMIT((90000 * 60) / rpm, 1, 0xFFFF); | 243 | return clamp_val((90000 * 60) / rpm, 1, 0xFFFF); |
244 | } | 244 | } |
245 | 245 | ||
246 | /* Scaling factors for voltage inputs, taken from the ADT7490 datasheet */ | 246 | /* Scaling factors for voltage inputs, taken from the ADT7490 datasheet */ |
@@ -271,7 +271,7 @@ static inline u16 volt2reg(int channel, long volt, u8 bypass_attn) | |||
271 | reg = (volt * 1024) / 2250; | 271 | reg = (volt * 1024) / 2250; |
272 | else | 272 | else |
273 | reg = (volt * r[1] * 1024) / ((r[0] + r[1]) * 2250); | 273 | reg = (volt * r[1] * 1024) / ((r[0] + r[1]) * 2250); |
274 | return SENSORS_LIMIT(reg, 0, 1023) & (0xff << 2); | 274 | return clamp_val(reg, 0, 1023) & (0xff << 2); |
275 | } | 275 | } |
276 | 276 | ||
277 | static u16 adt7475_read_word(struct i2c_client *client, int reg) | 277 | static u16 adt7475_read_word(struct i2c_client *client, int reg) |
@@ -451,10 +451,10 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *attr, | |||
451 | switch (sattr->nr) { | 451 | switch (sattr->nr) { |
452 | case OFFSET: | 452 | case OFFSET: |
453 | if (data->config5 & CONFIG5_TEMPOFFSET) { | 453 | if (data->config5 & CONFIG5_TEMPOFFSET) { |
454 | val = SENSORS_LIMIT(val, -63000, 127000); | 454 | val = clamp_val(val, -63000, 127000); |
455 | out = data->temp[OFFSET][sattr->index] = val / 1000; | 455 | out = data->temp[OFFSET][sattr->index] = val / 1000; |
456 | } else { | 456 | } else { |
457 | val = SENSORS_LIMIT(val, -63000, 64000); | 457 | val = clamp_val(val, -63000, 64000); |
458 | out = data->temp[OFFSET][sattr->index] = val / 500; | 458 | out = data->temp[OFFSET][sattr->index] = val / 500; |
459 | } | 459 | } |
460 | break; | 460 | break; |
@@ -471,7 +471,7 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *attr, | |||
471 | adt7475_read_hystersis(client); | 471 | adt7475_read_hystersis(client); |
472 | 472 | ||
473 | temp = reg2temp(data, data->temp[THERM][sattr->index]); | 473 | temp = reg2temp(data, data->temp[THERM][sattr->index]); |
474 | val = SENSORS_LIMIT(val, temp - 15000, temp); | 474 | val = clamp_val(val, temp - 15000, temp); |
475 | val = (temp - val) / 1000; | 475 | val = (temp - val) / 1000; |
476 | 476 | ||
477 | if (sattr->index != 1) { | 477 | if (sattr->index != 1) { |
@@ -577,7 +577,7 @@ static ssize_t set_point2(struct device *dev, struct device_attribute *attr, | |||
577 | * to figure the range | 577 | * to figure the range |
578 | */ | 578 | */ |
579 | temp = reg2temp(data, data->temp[AUTOMIN][sattr->index]); | 579 | temp = reg2temp(data, data->temp[AUTOMIN][sattr->index]); |
580 | val = SENSORS_LIMIT(val, temp + autorange_table[0], | 580 | val = clamp_val(val, temp + autorange_table[0], |
581 | temp + autorange_table[ARRAY_SIZE(autorange_table) - 1]); | 581 | temp + autorange_table[ARRAY_SIZE(autorange_table) - 1]); |
582 | val -= temp; | 582 | val -= temp; |
583 | 583 | ||
@@ -701,7 +701,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | |||
701 | break; | 701 | break; |
702 | } | 702 | } |
703 | 703 | ||
704 | data->pwm[sattr->nr][sattr->index] = SENSORS_LIMIT(val, 0, 0xFF); | 704 | data->pwm[sattr->nr][sattr->index] = clamp_val(val, 0, 0xFF); |
705 | i2c_smbus_write_byte_data(client, reg, | 705 | i2c_smbus_write_byte_data(client, reg, |
706 | data->pwm[sattr->nr][sattr->index]); | 706 | data->pwm[sattr->nr][sattr->index]); |
707 | 707 | ||
diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c index ae482e3afdac..4fe49d2bfe1d 100644 --- a/drivers/hwmon/amc6821.c +++ b/drivers/hwmon/amc6821.c | |||
@@ -241,7 +241,7 @@ static ssize_t set_temp( | |||
241 | int ret = kstrtol(buf, 10, &val); | 241 | int ret = kstrtol(buf, 10, &val); |
242 | if (ret) | 242 | if (ret) |
243 | return ret; | 243 | return ret; |
244 | val = SENSORS_LIMIT(val / 1000, -128, 127); | 244 | val = clamp_val(val / 1000, -128, 127); |
245 | 245 | ||
246 | mutex_lock(&data->update_lock); | 246 | mutex_lock(&data->update_lock); |
247 | data->temp[ix] = val; | 247 | data->temp[ix] = val; |
@@ -332,7 +332,7 @@ static ssize_t set_pwm1( | |||
332 | return ret; | 332 | return ret; |
333 | 333 | ||
334 | mutex_lock(&data->update_lock); | 334 | mutex_lock(&data->update_lock); |
335 | data->pwm1 = SENSORS_LIMIT(val , 0, 255); | 335 | data->pwm1 = clamp_val(val , 0, 255); |
336 | i2c_smbus_write_byte_data(client, AMC6821_REG_DCY, data->pwm1); | 336 | i2c_smbus_write_byte_data(client, AMC6821_REG_DCY, data->pwm1); |
337 | mutex_unlock(&data->update_lock); | 337 | mutex_unlock(&data->update_lock); |
338 | return count; | 338 | return count; |
@@ -499,11 +499,11 @@ static ssize_t set_temp_auto_point_temp( | |||
499 | mutex_lock(&data->update_lock); | 499 | mutex_lock(&data->update_lock); |
500 | switch (ix) { | 500 | switch (ix) { |
501 | case 0: | 501 | case 0: |
502 | ptemp[0] = SENSORS_LIMIT(val / 1000, 0, | 502 | ptemp[0] = clamp_val(val / 1000, 0, |
503 | data->temp1_auto_point_temp[1]); | 503 | data->temp1_auto_point_temp[1]); |
504 | ptemp[0] = SENSORS_LIMIT(ptemp[0], 0, | 504 | ptemp[0] = clamp_val(ptemp[0], 0, |
505 | data->temp2_auto_point_temp[1]); | 505 | data->temp2_auto_point_temp[1]); |
506 | ptemp[0] = SENSORS_LIMIT(ptemp[0], 0, 63); | 506 | ptemp[0] = clamp_val(ptemp[0], 0, 63); |
507 | if (i2c_smbus_write_byte_data( | 507 | if (i2c_smbus_write_byte_data( |
508 | client, | 508 | client, |
509 | AMC6821_REG_PSV_TEMP, | 509 | AMC6821_REG_PSV_TEMP, |
@@ -515,20 +515,12 @@ static ssize_t set_temp_auto_point_temp( | |||
515 | goto EXIT; | 515 | goto EXIT; |
516 | break; | 516 | break; |
517 | case 1: | 517 | case 1: |
518 | ptemp[1] = SENSORS_LIMIT( | 518 | ptemp[1] = clamp_val(val / 1000, (ptemp[0] & 0x7C) + 4, 124); |
519 | val / 1000, | ||
520 | (ptemp[0] & 0x7C) + 4, | ||
521 | 124); | ||
522 | ptemp[1] &= 0x7C; | 519 | ptemp[1] &= 0x7C; |
523 | ptemp[2] = SENSORS_LIMIT( | 520 | ptemp[2] = clamp_val(ptemp[2], ptemp[1] + 1, 255); |
524 | ptemp[2], ptemp[1] + 1, | ||
525 | 255); | ||
526 | break; | 521 | break; |
527 | case 2: | 522 | case 2: |
528 | ptemp[2] = SENSORS_LIMIT( | 523 | ptemp[2] = clamp_val(val / 1000, ptemp[1]+1, 255); |
529 | val / 1000, | ||
530 | ptemp[1]+1, | ||
531 | 255); | ||
532 | break; | 524 | break; |
533 | default: | 525 | default: |
534 | dev_dbg(dev, "Unknown attr->index (%d).\n", ix); | 526 | dev_dbg(dev, "Unknown attr->index (%d).\n", ix); |
@@ -561,7 +553,7 @@ static ssize_t set_pwm1_auto_point_pwm( | |||
561 | return ret; | 553 | return ret; |
562 | 554 | ||
563 | mutex_lock(&data->update_lock); | 555 | mutex_lock(&data->update_lock); |
564 | data->pwm1_auto_point_pwm[1] = SENSORS_LIMIT(val, 0, 254); | 556 | data->pwm1_auto_point_pwm[1] = clamp_val(val, 0, 254); |
565 | if (i2c_smbus_write_byte_data(client, AMC6821_REG_DCY_LOW_TEMP, | 557 | if (i2c_smbus_write_byte_data(client, AMC6821_REG_DCY_LOW_TEMP, |
566 | data->pwm1_auto_point_pwm[1])) { | 558 | data->pwm1_auto_point_pwm[1])) { |
567 | dev_err(&client->dev, "Register write error, aborting.\n"); | 559 | dev_err(&client->dev, "Register write error, aborting.\n"); |
@@ -629,7 +621,7 @@ static ssize_t set_fan( | |||
629 | val = 1 > val ? 0xFFFF : 6000000/val; | 621 | val = 1 > val ? 0xFFFF : 6000000/val; |
630 | 622 | ||
631 | mutex_lock(&data->update_lock); | 623 | mutex_lock(&data->update_lock); |
632 | data->fan[ix] = (u16) SENSORS_LIMIT(val, 1, 0xFFFF); | 624 | data->fan[ix] = (u16) clamp_val(val, 1, 0xFFFF); |
633 | if (i2c_smbus_write_byte_data(client, fan_reg_low[ix], | 625 | if (i2c_smbus_write_byte_data(client, fan_reg_low[ix], |
634 | data->fan[ix] & 0xFF)) { | 626 | data->fan[ix] & 0xFF)) { |
635 | dev_err(&client->dev, "Register write error, aborting.\n"); | 627 | dev_err(&client->dev, "Register write error, aborting.\n"); |
diff --git a/drivers/hwmon/asb100.c b/drivers/hwmon/asb100.c index 520e5bf4f76d..6ac612cabda1 100644 --- a/drivers/hwmon/asb100.c +++ b/drivers/hwmon/asb100.c | |||
@@ -114,7 +114,7 @@ static const u16 asb100_reg_temp_hyst[] = {0, 0x3a, 0x153, 0x253, 0x19}; | |||
114 | */ | 114 | */ |
115 | static u8 IN_TO_REG(unsigned val) | 115 | static u8 IN_TO_REG(unsigned val) |
116 | { | 116 | { |
117 | unsigned nval = SENSORS_LIMIT(val, ASB100_IN_MIN, ASB100_IN_MAX); | 117 | unsigned nval = clamp_val(val, ASB100_IN_MIN, ASB100_IN_MAX); |
118 | return (nval + 8) / 16; | 118 | return (nval + 8) / 16; |
119 | } | 119 | } |
120 | 120 | ||
@@ -129,8 +129,8 @@ static u8 FAN_TO_REG(long rpm, int div) | |||
129 | return 0; | 129 | return 0; |
130 | if (rpm == 0) | 130 | if (rpm == 0) |
131 | return 255; | 131 | return 255; |
132 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); | 132 | rpm = clamp_val(rpm, 1, 1000000); |
133 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254); | 133 | return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254); |
134 | } | 134 | } |
135 | 135 | ||
136 | static int FAN_FROM_REG(u8 val, int div) | 136 | static int FAN_FROM_REG(u8 val, int div) |
@@ -148,7 +148,7 @@ static int FAN_FROM_REG(u8 val, int div) | |||
148 | */ | 148 | */ |
149 | static u8 TEMP_TO_REG(long temp) | 149 | static u8 TEMP_TO_REG(long temp) |
150 | { | 150 | { |
151 | int ntemp = SENSORS_LIMIT(temp, ASB100_TEMP_MIN, ASB100_TEMP_MAX); | 151 | int ntemp = clamp_val(temp, ASB100_TEMP_MIN, ASB100_TEMP_MAX); |
152 | ntemp += (ntemp < 0 ? -500 : 500); | 152 | ntemp += (ntemp < 0 ? -500 : 500); |
153 | return (u8)(ntemp / 1000); | 153 | return (u8)(ntemp / 1000); |
154 | } | 154 | } |
@@ -164,7 +164,7 @@ static int TEMP_FROM_REG(u8 reg) | |||
164 | */ | 164 | */ |
165 | static u8 ASB100_PWM_TO_REG(int pwm) | 165 | static u8 ASB100_PWM_TO_REG(int pwm) |
166 | { | 166 | { |
167 | pwm = SENSORS_LIMIT(pwm, 0, 255); | 167 | pwm = clamp_val(pwm, 0, 255); |
168 | return (u8)(pwm / 16); | 168 | return (u8)(pwm / 16); |
169 | } | 169 | } |
170 | 170 | ||
diff --git a/drivers/hwmon/asc7621.c b/drivers/hwmon/asc7621.c index b867aab78049..da7f5b5d5db5 100644 --- a/drivers/hwmon/asc7621.c +++ b/drivers/hwmon/asc7621.c | |||
@@ -191,7 +191,7 @@ static ssize_t store_u8(struct device *dev, struct device_attribute *attr, | |||
191 | if (kstrtol(buf, 10, &reqval)) | 191 | if (kstrtol(buf, 10, &reqval)) |
192 | return -EINVAL; | 192 | return -EINVAL; |
193 | 193 | ||
194 | reqval = SENSORS_LIMIT(reqval, 0, 255); | 194 | reqval = clamp_val(reqval, 0, 255); |
195 | 195 | ||
196 | mutex_lock(&data->update_lock); | 196 | mutex_lock(&data->update_lock); |
197 | data->reg[param->msb[0]] = reqval; | 197 | data->reg[param->msb[0]] = reqval; |
@@ -224,7 +224,7 @@ static ssize_t store_bitmask(struct device *dev, | |||
224 | if (kstrtol(buf, 10, &reqval)) | 224 | if (kstrtol(buf, 10, &reqval)) |
225 | return -EINVAL; | 225 | return -EINVAL; |
226 | 226 | ||
227 | reqval = SENSORS_LIMIT(reqval, 0, param->mask[0]); | 227 | reqval = clamp_val(reqval, 0, param->mask[0]); |
228 | 228 | ||
229 | reqval = (reqval & param->mask[0]) << param->shift[0]; | 229 | reqval = (reqval & param->mask[0]) << param->shift[0]; |
230 | 230 | ||
@@ -274,7 +274,7 @@ static ssize_t store_fan16(struct device *dev, | |||
274 | * generating an alarm. | 274 | * generating an alarm. |
275 | */ | 275 | */ |
276 | reqval = | 276 | reqval = |
277 | (reqval <= 0 ? 0xffff : SENSORS_LIMIT(5400000 / reqval, 0, 0xfffe)); | 277 | (reqval <= 0 ? 0xffff : clamp_val(5400000 / reqval, 0, 0xfffe)); |
278 | 278 | ||
279 | mutex_lock(&data->update_lock); | 279 | mutex_lock(&data->update_lock); |
280 | data->reg[param->msb[0]] = (reqval >> 8) & 0xff; | 280 | data->reg[param->msb[0]] = (reqval >> 8) & 0xff; |
@@ -343,11 +343,11 @@ static ssize_t store_in8(struct device *dev, struct device_attribute *attr, | |||
343 | if (kstrtol(buf, 10, &reqval)) | 343 | if (kstrtol(buf, 10, &reqval)) |
344 | return -EINVAL; | 344 | return -EINVAL; |
345 | 345 | ||
346 | reqval = SENSORS_LIMIT(reqval, 0, 0xffff); | 346 | reqval = clamp_val(reqval, 0, 0xffff); |
347 | 347 | ||
348 | reqval = reqval * 0xc0 / asc7621_in_scaling[nr]; | 348 | reqval = reqval * 0xc0 / asc7621_in_scaling[nr]; |
349 | 349 | ||
350 | reqval = SENSORS_LIMIT(reqval, 0, 0xff); | 350 | reqval = clamp_val(reqval, 0, 0xff); |
351 | 351 | ||
352 | mutex_lock(&data->update_lock); | 352 | mutex_lock(&data->update_lock); |
353 | data->reg[param->msb[0]] = reqval; | 353 | data->reg[param->msb[0]] = reqval; |
@@ -376,7 +376,7 @@ static ssize_t store_temp8(struct device *dev, | |||
376 | if (kstrtol(buf, 10, &reqval)) | 376 | if (kstrtol(buf, 10, &reqval)) |
377 | return -EINVAL; | 377 | return -EINVAL; |
378 | 378 | ||
379 | reqval = SENSORS_LIMIT(reqval, -127000, 127000); | 379 | reqval = clamp_val(reqval, -127000, 127000); |
380 | 380 | ||
381 | temp = reqval / 1000; | 381 | temp = reqval / 1000; |
382 | 382 | ||
@@ -432,7 +432,7 @@ static ssize_t store_temp62(struct device *dev, | |||
432 | if (kstrtol(buf, 10, &reqval)) | 432 | if (kstrtol(buf, 10, &reqval)) |
433 | return -EINVAL; | 433 | return -EINVAL; |
434 | 434 | ||
435 | reqval = SENSORS_LIMIT(reqval, -32000, 31750); | 435 | reqval = clamp_val(reqval, -32000, 31750); |
436 | i = reqval / 1000; | 436 | i = reqval / 1000; |
437 | f = reqval - (i * 1000); | 437 | f = reqval - (i * 1000); |
438 | temp = i << 2; | 438 | temp = i << 2; |
@@ -468,7 +468,7 @@ static ssize_t show_ap2_temp(struct device *dev, | |||
468 | auto_point1 = ((s8) data->reg[param->msb[1]]) * 1000; | 468 | auto_point1 = ((s8) data->reg[param->msb[1]]) * 1000; |
469 | regval = | 469 | regval = |
470 | ((data->reg[param->msb[0]] >> param->shift[0]) & param->mask[0]); | 470 | ((data->reg[param->msb[0]] >> param->shift[0]) & param->mask[0]); |
471 | temp = auto_point1 + asc7621_range_map[SENSORS_LIMIT(regval, 0, 15)]; | 471 | temp = auto_point1 + asc7621_range_map[clamp_val(regval, 0, 15)]; |
472 | mutex_unlock(&data->update_lock); | 472 | mutex_unlock(&data->update_lock); |
473 | 473 | ||
474 | return sprintf(buf, "%d\n", temp); | 474 | return sprintf(buf, "%d\n", temp); |
@@ -489,7 +489,7 @@ static ssize_t store_ap2_temp(struct device *dev, | |||
489 | 489 | ||
490 | mutex_lock(&data->update_lock); | 490 | mutex_lock(&data->update_lock); |
491 | auto_point1 = data->reg[param->msb[1]] * 1000; | 491 | auto_point1 = data->reg[param->msb[1]] * 1000; |
492 | reqval = SENSORS_LIMIT(reqval, auto_point1 + 2000, auto_point1 + 80000); | 492 | reqval = clamp_val(reqval, auto_point1 + 2000, auto_point1 + 80000); |
493 | 493 | ||
494 | for (i = ARRAY_SIZE(asc7621_range_map) - 1; i >= 0; i--) { | 494 | for (i = ARRAY_SIZE(asc7621_range_map) - 1; i >= 0; i--) { |
495 | if (reqval >= auto_point1 + asc7621_range_map[i]) { | 495 | if (reqval >= auto_point1 + asc7621_range_map[i]) { |
@@ -523,7 +523,7 @@ static ssize_t show_pwm_ac(struct device *dev, | |||
523 | regval = config | (altbit << 3); | 523 | regval = config | (altbit << 3); |
524 | mutex_unlock(&data->update_lock); | 524 | mutex_unlock(&data->update_lock); |
525 | 525 | ||
526 | return sprintf(buf, "%u\n", map[SENSORS_LIMIT(regval, 0, 15)]); | 526 | return sprintf(buf, "%u\n", map[clamp_val(regval, 0, 15)]); |
527 | } | 527 | } |
528 | 528 | ||
529 | static ssize_t store_pwm_ac(struct device *dev, | 529 | static ssize_t store_pwm_ac(struct device *dev, |
@@ -663,7 +663,7 @@ static ssize_t show_pwm_freq(struct device *dev, | |||
663 | u8 regval = | 663 | u8 regval = |
664 | (data->reg[param->msb[0]] >> param->shift[0]) & param->mask[0]; | 664 | (data->reg[param->msb[0]] >> param->shift[0]) & param->mask[0]; |
665 | 665 | ||
666 | regval = SENSORS_LIMIT(regval, 0, 15); | 666 | regval = clamp_val(regval, 0, 15); |
667 | 667 | ||
668 | return sprintf(buf, "%u\n", asc7621_pwm_freq_map[regval]); | 668 | return sprintf(buf, "%u\n", asc7621_pwm_freq_map[regval]); |
669 | } | 669 | } |
@@ -711,7 +711,7 @@ static ssize_t show_pwm_ast(struct device *dev, | |||
711 | u8 regval = | 711 | u8 regval = |
712 | (data->reg[param->msb[0]] >> param->shift[0]) & param->mask[0]; | 712 | (data->reg[param->msb[0]] >> param->shift[0]) & param->mask[0]; |
713 | 713 | ||
714 | regval = SENSORS_LIMIT(regval, 0, 7); | 714 | regval = clamp_val(regval, 0, 7); |
715 | 715 | ||
716 | return sprintf(buf, "%u\n", asc7621_pwm_auto_spinup_map[regval]); | 716 | return sprintf(buf, "%u\n", asc7621_pwm_auto_spinup_map[regval]); |
717 | 717 | ||
@@ -759,7 +759,7 @@ static ssize_t show_temp_st(struct device *dev, | |||
759 | SETUP_SHOW_data_param(dev, attr); | 759 | SETUP_SHOW_data_param(dev, attr); |
760 | u8 regval = | 760 | u8 regval = |
761 | (data->reg[param->msb[0]] >> param->shift[0]) & param->mask[0]; | 761 | (data->reg[param->msb[0]] >> param->shift[0]) & param->mask[0]; |
762 | regval = SENSORS_LIMIT(regval, 0, 7); | 762 | regval = clamp_val(regval, 0, 7); |
763 | 763 | ||
764 | return sprintf(buf, "%u\n", asc7621_temp_smoothing_time_map[regval]); | 764 | return sprintf(buf, "%u\n", asc7621_temp_smoothing_time_map[regval]); |
765 | } | 765 | } |
diff --git a/drivers/hwmon/dme1737.c b/drivers/hwmon/dme1737.c index 7430f70ae452..c347c94f2f73 100644 --- a/drivers/hwmon/dme1737.c +++ b/drivers/hwmon/dme1737.c | |||
@@ -277,7 +277,7 @@ static inline int IN_FROM_REG(int reg, int nominal, int res) | |||
277 | 277 | ||
278 | static inline int IN_TO_REG(int val, int nominal) | 278 | static inline int IN_TO_REG(int val, int nominal) |
279 | { | 279 | { |
280 | return SENSORS_LIMIT((val * 192 + nominal / 2) / nominal, 0, 255); | 280 | return clamp_val((val * 192 + nominal / 2) / nominal, 0, 255); |
281 | } | 281 | } |
282 | 282 | ||
283 | /* | 283 | /* |
@@ -293,8 +293,7 @@ static inline int TEMP_FROM_REG(int reg, int res) | |||
293 | 293 | ||
294 | static inline int TEMP_TO_REG(int val) | 294 | static inline int TEMP_TO_REG(int val) |
295 | { | 295 | { |
296 | return SENSORS_LIMIT((val < 0 ? val - 500 : val + 500) / 1000, | 296 | return clamp_val((val < 0 ? val - 500 : val + 500) / 1000, -128, 127); |
297 | -128, 127); | ||
298 | } | 297 | } |
299 | 298 | ||
300 | /* Temperature range */ | 299 | /* Temperature range */ |
@@ -332,7 +331,7 @@ static inline int TEMP_HYST_FROM_REG(int reg, int ix) | |||
332 | 331 | ||
333 | static inline int TEMP_HYST_TO_REG(int val, int ix, int reg) | 332 | static inline int TEMP_HYST_TO_REG(int val, int ix, int reg) |
334 | { | 333 | { |
335 | int hyst = SENSORS_LIMIT((val + 500) / 1000, 0, 15); | 334 | int hyst = clamp_val((val + 500) / 1000, 0, 15); |
336 | 335 | ||
337 | return (ix == 1) ? (reg & 0xf0) | hyst : (reg & 0x0f) | (hyst << 4); | 336 | return (ix == 1) ? (reg & 0xf0) | hyst : (reg & 0x0f) | (hyst << 4); |
338 | } | 337 | } |
@@ -349,10 +348,10 @@ static inline int FAN_FROM_REG(int reg, int tpc) | |||
349 | static inline int FAN_TO_REG(int val, int tpc) | 348 | static inline int FAN_TO_REG(int val, int tpc) |
350 | { | 349 | { |
351 | if (tpc) { | 350 | if (tpc) { |
352 | return SENSORS_LIMIT(val / tpc, 0, 0xffff); | 351 | return clamp_val(val / tpc, 0, 0xffff); |
353 | } else { | 352 | } else { |
354 | return (val <= 0) ? 0xffff : | 353 | return (val <= 0) ? 0xffff : |
355 | SENSORS_LIMIT(90000 * 60 / val, 0, 0xfffe); | 354 | clamp_val(90000 * 60 / val, 0, 0xfffe); |
356 | } | 355 | } |
357 | } | 356 | } |
358 | 357 | ||
@@ -1282,7 +1281,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | |||
1282 | mutex_lock(&data->update_lock); | 1281 | mutex_lock(&data->update_lock); |
1283 | switch (fn) { | 1282 | switch (fn) { |
1284 | case SYS_PWM: | 1283 | case SYS_PWM: |
1285 | data->pwm[ix] = SENSORS_LIMIT(val, 0, 255); | 1284 | data->pwm[ix] = clamp_val(val, 0, 255); |
1286 | dme1737_write(data, DME1737_REG_PWM(ix), data->pwm[ix]); | 1285 | dme1737_write(data, DME1737_REG_PWM(ix), data->pwm[ix]); |
1287 | break; | 1286 | break; |
1288 | case SYS_PWM_FREQ: | 1287 | case SYS_PWM_FREQ: |
@@ -1450,7 +1449,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | |||
1450 | break; | 1449 | break; |
1451 | case SYS_PWM_AUTO_POINT1_PWM: | 1450 | case SYS_PWM_AUTO_POINT1_PWM: |
1452 | /* Only valid for pwm[1-3] */ | 1451 | /* Only valid for pwm[1-3] */ |
1453 | data->pwm_min[ix] = SENSORS_LIMIT(val, 0, 255); | 1452 | data->pwm_min[ix] = clamp_val(val, 0, 255); |
1454 | dme1737_write(data, DME1737_REG_PWM_MIN(ix), | 1453 | dme1737_write(data, DME1737_REG_PWM_MIN(ix), |
1455 | data->pwm_min[ix]); | 1454 | data->pwm_min[ix]); |
1456 | break; | 1455 | break; |
diff --git a/drivers/hwmon/emc2103.c b/drivers/hwmon/emc2103.c index 77f434c58236..b07305622087 100644 --- a/drivers/hwmon/emc2103.c +++ b/drivers/hwmon/emc2103.c | |||
@@ -405,7 +405,7 @@ static ssize_t set_fan_target(struct device *dev, struct device_attribute *da, | |||
405 | if (rpm_target == 0) | 405 | if (rpm_target == 0) |
406 | data->fan_target = 0x1fff; | 406 | data->fan_target = 0x1fff; |
407 | else | 407 | else |
408 | data->fan_target = SENSORS_LIMIT( | 408 | data->fan_target = clamp_val( |
409 | (FAN_RPM_FACTOR * data->fan_multiplier) / rpm_target, | 409 | (FAN_RPM_FACTOR * data->fan_multiplier) / rpm_target, |
410 | 0, 0x1fff); | 410 | 0, 0x1fff); |
411 | 411 | ||
diff --git a/drivers/hwmon/emc6w201.c b/drivers/hwmon/emc6w201.c index 789bd4fb329b..936898f82f94 100644 --- a/drivers/hwmon/emc6w201.c +++ b/drivers/hwmon/emc6w201.c | |||
@@ -220,7 +220,7 @@ static ssize_t set_in(struct device *dev, struct device_attribute *devattr, | |||
220 | : EMC6W201_REG_IN_HIGH(nr); | 220 | : EMC6W201_REG_IN_HIGH(nr); |
221 | 221 | ||
222 | mutex_lock(&data->update_lock); | 222 | mutex_lock(&data->update_lock); |
223 | data->in[sf][nr] = SENSORS_LIMIT(val, 0, 255); | 223 | data->in[sf][nr] = clamp_val(val, 0, 255); |
224 | err = emc6w201_write8(client, reg, data->in[sf][nr]); | 224 | err = emc6w201_write8(client, reg, data->in[sf][nr]); |
225 | mutex_unlock(&data->update_lock); | 225 | mutex_unlock(&data->update_lock); |
226 | 226 | ||
@@ -257,7 +257,7 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *devattr, | |||
257 | : EMC6W201_REG_TEMP_HIGH(nr); | 257 | : EMC6W201_REG_TEMP_HIGH(nr); |
258 | 258 | ||
259 | mutex_lock(&data->update_lock); | 259 | mutex_lock(&data->update_lock); |
260 | data->temp[sf][nr] = SENSORS_LIMIT(val, -127, 128); | 260 | data->temp[sf][nr] = clamp_val(val, -127, 128); |
261 | err = emc6w201_write8(client, reg, data->temp[sf][nr]); | 261 | err = emc6w201_write8(client, reg, data->temp[sf][nr]); |
262 | mutex_unlock(&data->update_lock); | 262 | mutex_unlock(&data->update_lock); |
263 | 263 | ||
@@ -298,7 +298,7 @@ static ssize_t set_fan(struct device *dev, struct device_attribute *devattr, | |||
298 | val = 0xFFFF; | 298 | val = 0xFFFF; |
299 | } else { | 299 | } else { |
300 | val = DIV_ROUND_CLOSEST(5400000U, val); | 300 | val = DIV_ROUND_CLOSEST(5400000U, val); |
301 | val = SENSORS_LIMIT(val, 0, 0xFFFE); | 301 | val = clamp_val(val, 0, 0xFFFE); |
302 | } | 302 | } |
303 | 303 | ||
304 | mutex_lock(&data->update_lock); | 304 | mutex_lock(&data->update_lock); |
diff --git a/drivers/hwmon/f71882fg.c b/drivers/hwmon/f71882fg.c index bb7275cc47f3..cfb02dd91aad 100644 --- a/drivers/hwmon/f71882fg.c +++ b/drivers/hwmon/f71882fg.c | |||
@@ -1350,7 +1350,7 @@ static ssize_t store_fan_full_speed(struct device *dev, | |||
1350 | if (err) | 1350 | if (err) |
1351 | return err; | 1351 | return err; |
1352 | 1352 | ||
1353 | val = SENSORS_LIMIT(val, 23, 1500000); | 1353 | val = clamp_val(val, 23, 1500000); |
1354 | val = fan_to_reg(val); | 1354 | val = fan_to_reg(val); |
1355 | 1355 | ||
1356 | mutex_lock(&data->update_lock); | 1356 | mutex_lock(&data->update_lock); |
@@ -1438,7 +1438,7 @@ static ssize_t store_in_max(struct device *dev, struct device_attribute | |||
1438 | return err; | 1438 | return err; |
1439 | 1439 | ||
1440 | val /= 8; | 1440 | val /= 8; |
1441 | val = SENSORS_LIMIT(val, 0, 255); | 1441 | val = clamp_val(val, 0, 255); |
1442 | 1442 | ||
1443 | mutex_lock(&data->update_lock); | 1443 | mutex_lock(&data->update_lock); |
1444 | f71882fg_write8(data, F71882FG_REG_IN1_HIGH, val); | 1444 | f71882fg_write8(data, F71882FG_REG_IN1_HIGH, val); |
@@ -1542,7 +1542,7 @@ static ssize_t store_temp_max(struct device *dev, struct device_attribute | |||
1542 | return err; | 1542 | return err; |
1543 | 1543 | ||
1544 | val /= 1000; | 1544 | val /= 1000; |
1545 | val = SENSORS_LIMIT(val, 0, 255); | 1545 | val = clamp_val(val, 0, 255); |
1546 | 1546 | ||
1547 | mutex_lock(&data->update_lock); | 1547 | mutex_lock(&data->update_lock); |
1548 | f71882fg_write8(data, F71882FG_REG_TEMP_HIGH(nr), val); | 1548 | f71882fg_write8(data, F71882FG_REG_TEMP_HIGH(nr), val); |
@@ -1589,8 +1589,7 @@ static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute | |||
1589 | 1589 | ||
1590 | /* convert abs to relative and check */ | 1590 | /* convert abs to relative and check */ |
1591 | data->temp_high[nr] = f71882fg_read8(data, F71882FG_REG_TEMP_HIGH(nr)); | 1591 | data->temp_high[nr] = f71882fg_read8(data, F71882FG_REG_TEMP_HIGH(nr)); |
1592 | val = SENSORS_LIMIT(val, data->temp_high[nr] - 15, | 1592 | val = clamp_val(val, data->temp_high[nr] - 15, data->temp_high[nr]); |
1593 | data->temp_high[nr]); | ||
1594 | val = data->temp_high[nr] - val; | 1593 | val = data->temp_high[nr] - val; |
1595 | 1594 | ||
1596 | /* convert value to register contents */ | 1595 | /* convert value to register contents */ |
@@ -1627,7 +1626,7 @@ static ssize_t store_temp_crit(struct device *dev, struct device_attribute | |||
1627 | return err; | 1626 | return err; |
1628 | 1627 | ||
1629 | val /= 1000; | 1628 | val /= 1000; |
1630 | val = SENSORS_LIMIT(val, 0, 255); | 1629 | val = clamp_val(val, 0, 255); |
1631 | 1630 | ||
1632 | mutex_lock(&data->update_lock); | 1631 | mutex_lock(&data->update_lock); |
1633 | f71882fg_write8(data, F71882FG_REG_TEMP_OVT(nr), val); | 1632 | f71882fg_write8(data, F71882FG_REG_TEMP_OVT(nr), val); |
@@ -1754,7 +1753,7 @@ static ssize_t store_pwm(struct device *dev, | |||
1754 | if (err) | 1753 | if (err) |
1755 | return err; | 1754 | return err; |
1756 | 1755 | ||
1757 | val = SENSORS_LIMIT(val, 0, 255); | 1756 | val = clamp_val(val, 0, 255); |
1758 | 1757 | ||
1759 | mutex_lock(&data->update_lock); | 1758 | mutex_lock(&data->update_lock); |
1760 | data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE); | 1759 | data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE); |
@@ -1805,7 +1804,7 @@ static ssize_t store_simple_pwm(struct device *dev, | |||
1805 | if (err) | 1804 | if (err) |
1806 | return err; | 1805 | return err; |
1807 | 1806 | ||
1808 | val = SENSORS_LIMIT(val, 0, 255); | 1807 | val = clamp_val(val, 0, 255); |
1809 | 1808 | ||
1810 | mutex_lock(&data->update_lock); | 1809 | mutex_lock(&data->update_lock); |
1811 | f71882fg_write8(data, F71882FG_REG_PWM(nr), val); | 1810 | f71882fg_write8(data, F71882FG_REG_PWM(nr), val); |
@@ -1932,7 +1931,7 @@ static ssize_t store_pwm_auto_point_pwm(struct device *dev, | |||
1932 | if (err) | 1931 | if (err) |
1933 | return err; | 1932 | return err; |
1934 | 1933 | ||
1935 | val = SENSORS_LIMIT(val, 0, 255); | 1934 | val = clamp_val(val, 0, 255); |
1936 | 1935 | ||
1937 | mutex_lock(&data->update_lock); | 1936 | mutex_lock(&data->update_lock); |
1938 | data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE); | 1937 | data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE); |
@@ -1991,8 +1990,8 @@ static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev, | |||
1991 | mutex_lock(&data->update_lock); | 1990 | mutex_lock(&data->update_lock); |
1992 | data->pwm_auto_point_temp[nr][point] = | 1991 | data->pwm_auto_point_temp[nr][point] = |
1993 | f71882fg_read8(data, F71882FG_REG_POINT_TEMP(nr, point)); | 1992 | f71882fg_read8(data, F71882FG_REG_POINT_TEMP(nr, point)); |
1994 | val = SENSORS_LIMIT(val, data->pwm_auto_point_temp[nr][point] - 15, | 1993 | val = clamp_val(val, data->pwm_auto_point_temp[nr][point] - 15, |
1995 | data->pwm_auto_point_temp[nr][point]); | 1994 | data->pwm_auto_point_temp[nr][point]); |
1996 | val = data->pwm_auto_point_temp[nr][point] - val; | 1995 | val = data->pwm_auto_point_temp[nr][point] - val; |
1997 | 1996 | ||
1998 | reg = f71882fg_read8(data, F71882FG_REG_FAN_HYST(nr / 2)); | 1997 | reg = f71882fg_read8(data, F71882FG_REG_FAN_HYST(nr / 2)); |
@@ -2126,9 +2125,9 @@ static ssize_t store_pwm_auto_point_temp(struct device *dev, | |||
2126 | val /= 1000; | 2125 | val /= 1000; |
2127 | 2126 | ||
2128 | if (data->auto_point_temp_signed) | 2127 | if (data->auto_point_temp_signed) |
2129 | val = SENSORS_LIMIT(val, -128, 127); | 2128 | val = clamp_val(val, -128, 127); |
2130 | else | 2129 | else |
2131 | val = SENSORS_LIMIT(val, 0, 127); | 2130 | val = clamp_val(val, 0, 127); |
2132 | 2131 | ||
2133 | mutex_lock(&data->update_lock); | 2132 | mutex_lock(&data->update_lock); |
2134 | f71882fg_write8(data, F71882FG_REG_POINT_TEMP(pwm, point), val); | 2133 | f71882fg_write8(data, F71882FG_REG_POINT_TEMP(pwm, point), val); |
diff --git a/drivers/hwmon/f75375s.c b/drivers/hwmon/f75375s.c index f7dba229395f..9e300e567f15 100644 --- a/drivers/hwmon/f75375s.c +++ b/drivers/hwmon/f75375s.c | |||
@@ -359,7 +359,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | |||
359 | return -EINVAL; | 359 | return -EINVAL; |
360 | 360 | ||
361 | mutex_lock(&data->update_lock); | 361 | mutex_lock(&data->update_lock); |
362 | data->pwm[nr] = SENSORS_LIMIT(val, 0, 255); | 362 | data->pwm[nr] = clamp_val(val, 0, 255); |
363 | f75375_write_pwm(client, nr); | 363 | f75375_write_pwm(client, nr); |
364 | mutex_unlock(&data->update_lock); | 364 | mutex_unlock(&data->update_lock); |
365 | return count; | 365 | return count; |
@@ -556,7 +556,7 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, | |||
556 | if (err < 0) | 556 | if (err < 0) |
557 | return err; | 557 | return err; |
558 | 558 | ||
559 | val = SENSORS_LIMIT(VOLT_TO_REG(val), 0, 0xff); | 559 | val = clamp_val(VOLT_TO_REG(val), 0, 0xff); |
560 | mutex_lock(&data->update_lock); | 560 | mutex_lock(&data->update_lock); |
561 | data->in_max[nr] = val; | 561 | data->in_max[nr] = val; |
562 | f75375_write8(client, F75375_REG_VOLT_HIGH(nr), data->in_max[nr]); | 562 | f75375_write8(client, F75375_REG_VOLT_HIGH(nr), data->in_max[nr]); |
@@ -577,7 +577,7 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, | |||
577 | if (err < 0) | 577 | if (err < 0) |
578 | return err; | 578 | return err; |
579 | 579 | ||
580 | val = SENSORS_LIMIT(VOLT_TO_REG(val), 0, 0xff); | 580 | val = clamp_val(VOLT_TO_REG(val), 0, 0xff); |
581 | mutex_lock(&data->update_lock); | 581 | mutex_lock(&data->update_lock); |
582 | data->in_min[nr] = val; | 582 | data->in_min[nr] = val; |
583 | f75375_write8(client, F75375_REG_VOLT_LOW(nr), data->in_min[nr]); | 583 | f75375_write8(client, F75375_REG_VOLT_LOW(nr), data->in_min[nr]); |
@@ -625,7 +625,7 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | |||
625 | if (err < 0) | 625 | if (err < 0) |
626 | return err; | 626 | return err; |
627 | 627 | ||
628 | val = SENSORS_LIMIT(TEMP_TO_REG(val), 0, 127); | 628 | val = clamp_val(TEMP_TO_REG(val), 0, 127); |
629 | mutex_lock(&data->update_lock); | 629 | mutex_lock(&data->update_lock); |
630 | data->temp_high[nr] = val; | 630 | data->temp_high[nr] = val; |
631 | f75375_write8(client, F75375_REG_TEMP_HIGH(nr), data->temp_high[nr]); | 631 | f75375_write8(client, F75375_REG_TEMP_HIGH(nr), data->temp_high[nr]); |
@@ -646,7 +646,7 @@ static ssize_t set_temp_max_hyst(struct device *dev, | |||
646 | if (err < 0) | 646 | if (err < 0) |
647 | return err; | 647 | return err; |
648 | 648 | ||
649 | val = SENSORS_LIMIT(TEMP_TO_REG(val), 0, 127); | 649 | val = clamp_val(TEMP_TO_REG(val), 0, 127); |
650 | mutex_lock(&data->update_lock); | 650 | mutex_lock(&data->update_lock); |
651 | data->temp_max_hyst[nr] = val; | 651 | data->temp_max_hyst[nr] = val; |
652 | f75375_write8(client, F75375_REG_TEMP_HYST(nr), | 652 | f75375_write8(client, F75375_REG_TEMP_HYST(nr), |
@@ -822,7 +822,7 @@ static void f75375_init(struct i2c_client *client, struct f75375_data *data, | |||
822 | if (auto_mode_enabled(f75375s_pdata->pwm_enable[nr]) || | 822 | if (auto_mode_enabled(f75375s_pdata->pwm_enable[nr]) || |
823 | !duty_mode_enabled(f75375s_pdata->pwm_enable[nr])) | 823 | !duty_mode_enabled(f75375s_pdata->pwm_enable[nr])) |
824 | continue; | 824 | continue; |
825 | data->pwm[nr] = SENSORS_LIMIT(f75375s_pdata->pwm[nr], 0, 255); | 825 | data->pwm[nr] = clamp_val(f75375s_pdata->pwm[nr], 0, 255); |
826 | f75375_write_pwm(client, nr); | 826 | f75375_write_pwm(client, nr); |
827 | } | 827 | } |
828 | 828 | ||
diff --git a/drivers/hwmon/fschmd.c b/drivers/hwmon/fschmd.c index 519ce8b9c142..8af2755cdb87 100644 --- a/drivers/hwmon/fschmd.c +++ b/drivers/hwmon/fschmd.c | |||
@@ -379,7 +379,7 @@ static ssize_t store_temp_max(struct device *dev, struct device_attribute | |||
379 | if (err) | 379 | if (err) |
380 | return err; | 380 | return err; |
381 | 381 | ||
382 | v = SENSORS_LIMIT(v / 1000, -128, 127) + 128; | 382 | v = clamp_val(v / 1000, -128, 127) + 128; |
383 | 383 | ||
384 | mutex_lock(&data->update_lock); | 384 | mutex_lock(&data->update_lock); |
385 | i2c_smbus_write_byte_data(to_i2c_client(dev), | 385 | i2c_smbus_write_byte_data(to_i2c_client(dev), |
@@ -540,7 +540,7 @@ static ssize_t store_pwm_auto_point1_pwm(struct device *dev, | |||
540 | 540 | ||
541 | /* reg: 0 = allow turning off (except on the syl), 1-255 = 50-100% */ | 541 | /* reg: 0 = allow turning off (except on the syl), 1-255 = 50-100% */ |
542 | if (v || data->kind == fscsyl) { | 542 | if (v || data->kind == fscsyl) { |
543 | v = SENSORS_LIMIT(v, 128, 255); | 543 | v = clamp_val(v, 128, 255); |
544 | v = (v - 128) * 2 + 1; | 544 | v = (v - 128) * 2 + 1; |
545 | } | 545 | } |
546 | 546 | ||
diff --git a/drivers/hwmon/g760a.c b/drivers/hwmon/g760a.c index 8b2106f60eda..ea6480b80e7f 100644 --- a/drivers/hwmon/g760a.c +++ b/drivers/hwmon/g760a.c | |||
@@ -171,7 +171,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *da, | |||
171 | return -EINVAL; | 171 | return -EINVAL; |
172 | 172 | ||
173 | mutex_lock(&data->update_lock); | 173 | mutex_lock(&data->update_lock); |
174 | data->set_cnt = PWM_TO_CNT(SENSORS_LIMIT(val, 0, 255)); | 174 | data->set_cnt = PWM_TO_CNT(clamp_val(val, 0, 255)); |
175 | g760a_write_value(client, G760A_REG_SET_CNT, data->set_cnt); | 175 | g760a_write_value(client, G760A_REG_SET_CNT, data->set_cnt); |
176 | mutex_unlock(&data->update_lock); | 176 | mutex_unlock(&data->update_lock); |
177 | 177 | ||
diff --git a/drivers/hwmon/gl518sm.c b/drivers/hwmon/gl518sm.c index 2c74673f48e5..e2e5909a34df 100644 --- a/drivers/hwmon/gl518sm.c +++ b/drivers/hwmon/gl518sm.c | |||
@@ -86,7 +86,7 @@ enum chips { gl518sm_r00, gl518sm_r80 }; | |||
86 | #define BOOL_FROM_REG(val) ((val) ? 0 : 1) | 86 | #define BOOL_FROM_REG(val) ((val) ? 0 : 1) |
87 | #define BOOL_TO_REG(val) ((val) ? 0 : 1) | 87 | #define BOOL_TO_REG(val) ((val) ? 0 : 1) |
88 | 88 | ||
89 | #define TEMP_TO_REG(val) SENSORS_LIMIT(((((val) < 0 ? \ | 89 | #define TEMP_TO_REG(val) clamp_val(((((val) < 0 ? \ |
90 | (val) - 500 : \ | 90 | (val) - 500 : \ |
91 | (val) + 500) / 1000) + 119), 0, 255) | 91 | (val) + 500) / 1000) + 119), 0, 255) |
92 | #define TEMP_FROM_REG(val) (((val) - 119) * 1000) | 92 | #define TEMP_FROM_REG(val) (((val) - 119) * 1000) |
@@ -96,15 +96,15 @@ static inline u8 FAN_TO_REG(long rpm, int div) | |||
96 | long rpmdiv; | 96 | long rpmdiv; |
97 | if (rpm == 0) | 97 | if (rpm == 0) |
98 | return 0; | 98 | return 0; |
99 | rpmdiv = SENSORS_LIMIT(rpm, 1, 960000) * div; | 99 | rpmdiv = clamp_val(rpm, 1, 960000) * div; |
100 | return SENSORS_LIMIT((480000 + rpmdiv / 2) / rpmdiv, 1, 255); | 100 | return clamp_val((480000 + rpmdiv / 2) / rpmdiv, 1, 255); |
101 | } | 101 | } |
102 | #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : (480000 / ((val) * (div)))) | 102 | #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : (480000 / ((val) * (div)))) |
103 | 103 | ||
104 | #define IN_TO_REG(val) SENSORS_LIMIT((((val) + 9) / 19), 0, 255) | 104 | #define IN_TO_REG(val) clamp_val((((val) + 9) / 19), 0, 255) |
105 | #define IN_FROM_REG(val) ((val) * 19) | 105 | #define IN_FROM_REG(val) ((val) * 19) |
106 | 106 | ||
107 | #define VDD_TO_REG(val) SENSORS_LIMIT((((val) * 4 + 47) / 95), 0, 255) | 107 | #define VDD_TO_REG(val) clamp_val((((val) * 4 + 47) / 95), 0, 255) |
108 | #define VDD_FROM_REG(val) (((val) * 95 + 2) / 4) | 108 | #define VDD_FROM_REG(val) (((val) * 95 + 2) / 4) |
109 | 109 | ||
110 | #define DIV_FROM_REG(val) (1 << (val)) | 110 | #define DIV_FROM_REG(val) (1 << (val)) |
diff --git a/drivers/hwmon/gl520sm.c b/drivers/hwmon/gl520sm.c index a21ff252f2f1..ed56e09c3dd7 100644 --- a/drivers/hwmon/gl520sm.c +++ b/drivers/hwmon/gl520sm.c | |||
@@ -144,10 +144,10 @@ static ssize_t get_cpu_vid(struct device *dev, struct device_attribute *attr, | |||
144 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, get_cpu_vid, NULL); | 144 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, get_cpu_vid, NULL); |
145 | 145 | ||
146 | #define VDD_FROM_REG(val) (((val) * 95 + 2) / 4) | 146 | #define VDD_FROM_REG(val) (((val) * 95 + 2) / 4) |
147 | #define VDD_TO_REG(val) SENSORS_LIMIT((((val) * 4 + 47) / 95), 0, 255) | 147 | #define VDD_TO_REG(val) clamp_val((((val) * 4 + 47) / 95), 0, 255) |
148 | 148 | ||
149 | #define IN_FROM_REG(val) ((val) * 19) | 149 | #define IN_FROM_REG(val) ((val) * 19) |
150 | #define IN_TO_REG(val) SENSORS_LIMIT((((val) + 9) / 19), 0, 255) | 150 | #define IN_TO_REG(val) clamp_val((((val) + 9) / 19), 0, 255) |
151 | 151 | ||
152 | static ssize_t get_in_input(struct device *dev, struct device_attribute *attr, | 152 | static ssize_t get_in_input(struct device *dev, struct device_attribute *attr, |
153 | char *buf) | 153 | char *buf) |
@@ -285,8 +285,7 @@ static SENSOR_DEVICE_ATTR(in4_max, S_IRUGO | S_IWUSR, | |||
285 | #define DIV_FROM_REG(val) (1 << (val)) | 285 | #define DIV_FROM_REG(val) (1 << (val)) |
286 | #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : (480000 / ((val) << (div)))) | 286 | #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : (480000 / ((val) << (div)))) |
287 | #define FAN_TO_REG(val, div) ((val) <= 0 ? 0 : \ | 287 | #define FAN_TO_REG(val, div) ((val) <= 0 ? 0 : \ |
288 | SENSORS_LIMIT((480000 + ((val) << ((div)-1))) / ((val) << (div)), 1, \ | 288 | clamp_val((480000 + ((val) << ((div)-1))) / ((val) << (div)), 1, 255)) |
289 | 255)) | ||
290 | 289 | ||
291 | static ssize_t get_fan_input(struct device *dev, struct device_attribute *attr, | 290 | static ssize_t get_fan_input(struct device *dev, struct device_attribute *attr, |
292 | char *buf) | 291 | char *buf) |
@@ -450,7 +449,7 @@ static DEVICE_ATTR(fan1_off, S_IRUGO | S_IWUSR, | |||
450 | get_fan_off, set_fan_off); | 449 | get_fan_off, set_fan_off); |
451 | 450 | ||
452 | #define TEMP_FROM_REG(val) (((val) - 130) * 1000) | 451 | #define TEMP_FROM_REG(val) (((val) - 130) * 1000) |
453 | #define TEMP_TO_REG(val) SENSORS_LIMIT(((((val) < 0 ? \ | 452 | #define TEMP_TO_REG(val) clamp_val(((((val) < 0 ? \ |
454 | (val) - 500 : (val) + 500) / 1000) + 130), 0, 255) | 453 | (val) - 500 : (val) + 500) / 1000) + 130), 0, 255) |
455 | 454 | ||
456 | static ssize_t get_temp_input(struct device *dev, struct device_attribute *attr, | 455 | static ssize_t get_temp_input(struct device *dev, struct device_attribute *attr, |
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c index 117d66fcded6..29632e849285 100644 --- a/drivers/hwmon/it87.c +++ b/drivers/hwmon/it87.c | |||
@@ -384,7 +384,7 @@ static int adc_lsb(const struct it87_data *data, int nr) | |||
384 | static u8 in_to_reg(const struct it87_data *data, int nr, long val) | 384 | static u8 in_to_reg(const struct it87_data *data, int nr, long val) |
385 | { | 385 | { |
386 | val = DIV_ROUND_CLOSEST(val, adc_lsb(data, nr)); | 386 | val = DIV_ROUND_CLOSEST(val, adc_lsb(data, nr)); |
387 | return SENSORS_LIMIT(val, 0, 255); | 387 | return clamp_val(val, 0, 255); |
388 | } | 388 | } |
389 | 389 | ||
390 | static int in_from_reg(const struct it87_data *data, int nr, int val) | 390 | static int in_from_reg(const struct it87_data *data, int nr, int val) |
@@ -396,16 +396,15 @@ static inline u8 FAN_TO_REG(long rpm, int div) | |||
396 | { | 396 | { |
397 | if (rpm == 0) | 397 | if (rpm == 0) |
398 | return 255; | 398 | return 255; |
399 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); | 399 | rpm = clamp_val(rpm, 1, 1000000); |
400 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, | 400 | return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254); |
401 | 254); | ||
402 | } | 401 | } |
403 | 402 | ||
404 | static inline u16 FAN16_TO_REG(long rpm) | 403 | static inline u16 FAN16_TO_REG(long rpm) |
405 | { | 404 | { |
406 | if (rpm == 0) | 405 | if (rpm == 0) |
407 | return 0xffff; | 406 | return 0xffff; |
408 | return SENSORS_LIMIT((1350000 + rpm) / (rpm * 2), 1, 0xfffe); | 407 | return clamp_val((1350000 + rpm) / (rpm * 2), 1, 0xfffe); |
409 | } | 408 | } |
410 | 409 | ||
411 | #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 255 ? 0 : \ | 410 | #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 255 ? 0 : \ |
@@ -414,8 +413,8 @@ static inline u16 FAN16_TO_REG(long rpm) | |||
414 | #define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \ | 413 | #define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \ |
415 | 1350000 / ((val) * 2)) | 414 | 1350000 / ((val) * 2)) |
416 | 415 | ||
417 | #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) < 0 ? (((val) - 500) / 1000) : \ | 416 | #define TEMP_TO_REG(val) (clamp_val(((val) < 0 ? (((val) - 500) / 1000) : \ |
418 | ((val) + 500) / 1000), -128, 127)) | 417 | ((val) + 500) / 1000), -128, 127)) |
419 | #define TEMP_FROM_REG(val) ((val) * 1000) | 418 | #define TEMP_FROM_REG(val) ((val) * 1000) |
420 | 419 | ||
421 | static u8 pwm_to_reg(const struct it87_data *data, long val) | 420 | static u8 pwm_to_reg(const struct it87_data *data, long val) |
diff --git a/drivers/hwmon/jc42.c b/drivers/hwmon/jc42.c index e21e43c13156..82d962488f55 100644 --- a/drivers/hwmon/jc42.c +++ b/drivers/hwmon/jc42.c | |||
@@ -237,9 +237,9 @@ static struct i2c_driver jc42_driver = { | |||
237 | 237 | ||
238 | static u16 jc42_temp_to_reg(int temp, bool extended) | 238 | static u16 jc42_temp_to_reg(int temp, bool extended) |
239 | { | 239 | { |
240 | int ntemp = SENSORS_LIMIT(temp, | 240 | int ntemp = clamp_val(temp, |
241 | extended ? JC42_TEMP_MIN_EXTENDED : | 241 | extended ? JC42_TEMP_MIN_EXTENDED : |
242 | JC42_TEMP_MIN, JC42_TEMP_MAX); | 242 | JC42_TEMP_MIN, JC42_TEMP_MAX); |
243 | 243 | ||
244 | /* convert from 0.001 to 0.0625 resolution */ | 244 | /* convert from 0.001 to 0.0625 resolution */ |
245 | return (ntemp * 2 / 125) & 0x1fff; | 245 | return (ntemp * 2 / 125) & 0x1fff; |
diff --git a/drivers/hwmon/lm63.c b/drivers/hwmon/lm63.c index eed4d9401788..f644a2e57599 100644 --- a/drivers/hwmon/lm63.c +++ b/drivers/hwmon/lm63.c | |||
@@ -209,9 +209,9 @@ static inline int lut_temp_to_reg(struct lm63_data *data, long val) | |||
209 | { | 209 | { |
210 | val -= data->temp2_offset; | 210 | val -= data->temp2_offset; |
211 | if (data->lut_temp_highres) | 211 | if (data->lut_temp_highres) |
212 | return DIV_ROUND_CLOSEST(SENSORS_LIMIT(val, 0, 127500), 500); | 212 | return DIV_ROUND_CLOSEST(clamp_val(val, 0, 127500), 500); |
213 | else | 213 | else |
214 | return DIV_ROUND_CLOSEST(SENSORS_LIMIT(val, 0, 127000), 1000); | 214 | return DIV_ROUND_CLOSEST(clamp_val(val, 0, 127000), 1000); |
215 | } | 215 | } |
216 | 216 | ||
217 | /* | 217 | /* |
@@ -415,7 +415,7 @@ static ssize_t set_pwm1(struct device *dev, struct device_attribute *devattr, | |||
415 | return err; | 415 | return err; |
416 | 416 | ||
417 | reg = nr ? LM63_REG_LUT_PWM(nr - 1) : LM63_REG_PWM_VALUE; | 417 | reg = nr ? LM63_REG_LUT_PWM(nr - 1) : LM63_REG_PWM_VALUE; |
418 | val = SENSORS_LIMIT(val, 0, 255); | 418 | val = clamp_val(val, 0, 255); |
419 | 419 | ||
420 | mutex_lock(&data->update_lock); | 420 | mutex_lock(&data->update_lock); |
421 | data->pwm1[nr] = data->pwm_highres ? val : | 421 | data->pwm1[nr] = data->pwm_highres ? val : |
@@ -700,7 +700,7 @@ static ssize_t set_update_interval(struct device *dev, | |||
700 | return err; | 700 | return err; |
701 | 701 | ||
702 | mutex_lock(&data->update_lock); | 702 | mutex_lock(&data->update_lock); |
703 | lm63_set_convrate(client, data, SENSORS_LIMIT(val, 0, 100000)); | 703 | lm63_set_convrate(client, data, clamp_val(val, 0, 100000)); |
704 | mutex_unlock(&data->update_lock); | 704 | mutex_unlock(&data->update_lock); |
705 | 705 | ||
706 | return count; | 706 | return count; |
diff --git a/drivers/hwmon/lm73.c b/drivers/hwmon/lm73.c index 7272176a9ec7..5166a8e3a061 100644 --- a/drivers/hwmon/lm73.c +++ b/drivers/hwmon/lm73.c | |||
@@ -56,8 +56,8 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da, | |||
56 | return status; | 56 | return status; |
57 | 57 | ||
58 | /* Write value */ | 58 | /* Write value */ |
59 | value = (short) SENSORS_LIMIT(temp/250, (LM73_TEMP_MIN*4), | 59 | value = (short) clamp_val(temp / 250, LM73_TEMP_MIN * 4, |
60 | (LM73_TEMP_MAX*4)) << 5; | 60 | LM73_TEMP_MAX * 4) << 5; |
61 | err = i2c_smbus_write_word_swapped(client, attr->index, value); | 61 | err = i2c_smbus_write_word_swapped(client, attr->index, value); |
62 | return (err < 0) ? err : count; | 62 | return (err < 0) ? err : count; |
63 | } | 63 | } |
diff --git a/drivers/hwmon/lm75.h b/drivers/hwmon/lm75.h index 89aa9098ba5b..668ff4721323 100644 --- a/drivers/hwmon/lm75.h +++ b/drivers/hwmon/lm75.h | |||
@@ -36,7 +36,7 @@ | |||
36 | REG: (0.5C/bit, two's complement) << 7 */ | 36 | REG: (0.5C/bit, two's complement) << 7 */ |
37 | static inline u16 LM75_TEMP_TO_REG(long temp) | 37 | static inline u16 LM75_TEMP_TO_REG(long temp) |
38 | { | 38 | { |
39 | int ntemp = SENSORS_LIMIT(temp, LM75_TEMP_MIN, LM75_TEMP_MAX); | 39 | int ntemp = clamp_val(temp, LM75_TEMP_MIN, LM75_TEMP_MAX); |
40 | ntemp += (ntemp < 0 ? -250 : 250); | 40 | ntemp += (ntemp < 0 ? -250 : 250); |
41 | return (u16)((ntemp / 500) << 7); | 41 | return (u16)((ntemp / 500) << 7); |
42 | } | 42 | } |
diff --git a/drivers/hwmon/lm77.c b/drivers/hwmon/lm77.c index f82acf67acf5..f17beb5e6dd6 100644 --- a/drivers/hwmon/lm77.c +++ b/drivers/hwmon/lm77.c | |||
@@ -101,7 +101,7 @@ static struct i2c_driver lm77_driver = { | |||
101 | */ | 101 | */ |
102 | static inline s16 LM77_TEMP_TO_REG(int temp) | 102 | static inline s16 LM77_TEMP_TO_REG(int temp) |
103 | { | 103 | { |
104 | int ntemp = SENSORS_LIMIT(temp, LM77_TEMP_MIN, LM77_TEMP_MAX); | 104 | int ntemp = clamp_val(temp, LM77_TEMP_MIN, LM77_TEMP_MAX); |
105 | return (ntemp / 500) * 8; | 105 | return (ntemp / 500) * 8; |
106 | } | 106 | } |
107 | 107 | ||
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c index 53d6ee8ffa33..483538fa1bd5 100644 --- a/drivers/hwmon/lm78.c +++ b/drivers/hwmon/lm78.c | |||
@@ -85,7 +85,7 @@ enum chips { lm78, lm79 }; | |||
85 | */ | 85 | */ |
86 | static inline u8 IN_TO_REG(unsigned long val) | 86 | static inline u8 IN_TO_REG(unsigned long val) |
87 | { | 87 | { |
88 | unsigned long nval = SENSORS_LIMIT(val, 0, 4080); | 88 | unsigned long nval = clamp_val(val, 0, 4080); |
89 | return (nval + 8) / 16; | 89 | return (nval + 8) / 16; |
90 | } | 90 | } |
91 | #define IN_FROM_REG(val) ((val) * 16) | 91 | #define IN_FROM_REG(val) ((val) * 16) |
@@ -94,7 +94,7 @@ static inline u8 FAN_TO_REG(long rpm, int div) | |||
94 | { | 94 | { |
95 | if (rpm <= 0) | 95 | if (rpm <= 0) |
96 | return 255; | 96 | return 255; |
97 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254); | 97 | return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254); |
98 | } | 98 | } |
99 | 99 | ||
100 | static inline int FAN_FROM_REG(u8 val, int div) | 100 | static inline int FAN_FROM_REG(u8 val, int div) |
@@ -108,7 +108,7 @@ static inline int FAN_FROM_REG(u8 val, int div) | |||
108 | */ | 108 | */ |
109 | static inline s8 TEMP_TO_REG(int val) | 109 | static inline s8 TEMP_TO_REG(int val) |
110 | { | 110 | { |
111 | int nval = SENSORS_LIMIT(val, -128000, 127000) ; | 111 | int nval = clamp_val(val, -128000, 127000) ; |
112 | return nval < 0 ? (nval - 500) / 1000 : (nval + 500) / 1000; | 112 | return nval < 0 ? (nval - 500) / 1000 : (nval + 500) / 1000; |
113 | } | 113 | } |
114 | 114 | ||
diff --git a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c index 28a8b71f4571..357fbb998728 100644 --- a/drivers/hwmon/lm80.c +++ b/drivers/hwmon/lm80.c | |||
@@ -72,15 +72,15 @@ static const unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, | |||
72 | * Fixing this is just not worth it. | 72 | * Fixing this is just not worth it. |
73 | */ | 73 | */ |
74 | 74 | ||
75 | #define IN_TO_REG(val) (SENSORS_LIMIT(((val) + 5) / 10, 0, 255)) | 75 | #define IN_TO_REG(val) (clamp_val(((val) + 5) / 10, 0, 255)) |
76 | #define IN_FROM_REG(val) ((val) * 10) | 76 | #define IN_FROM_REG(val) ((val) * 10) |
77 | 77 | ||
78 | static inline unsigned char FAN_TO_REG(unsigned rpm, unsigned div) | 78 | static inline unsigned char FAN_TO_REG(unsigned rpm, unsigned div) |
79 | { | 79 | { |
80 | if (rpm == 0) | 80 | if (rpm == 0) |
81 | return 255; | 81 | return 255; |
82 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); | 82 | rpm = clamp_val(rpm, 1, 1000000); |
83 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254); | 83 | return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254); |
84 | } | 84 | } |
85 | 85 | ||
86 | #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \ | 86 | #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \ |
@@ -102,7 +102,7 @@ static inline long TEMP_FROM_REG(u16 temp) | |||
102 | #define TEMP_LIMIT_FROM_REG(val) (((val) > 0x80 ? \ | 102 | #define TEMP_LIMIT_FROM_REG(val) (((val) > 0x80 ? \ |
103 | (val) - 0x100 : (val)) * 1000) | 103 | (val) - 0x100 : (val)) * 1000) |
104 | 104 | ||
105 | #define TEMP_LIMIT_TO_REG(val) SENSORS_LIMIT((val) < 0 ? \ | 105 | #define TEMP_LIMIT_TO_REG(val) clamp_val((val) < 0 ? \ |
106 | ((val) - 500) / 1000 : ((val) + 500) / 1000, 0, 255) | 106 | ((val) - 500) / 1000 : ((val) + 500) / 1000, 0, 255) |
107 | 107 | ||
108 | #define DIV_FROM_REG(val) (1 << (val)) | 108 | #define DIV_FROM_REG(val) (1 << (val)) |
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c index 9f2dd77e1e0e..47ade8ba152d 100644 --- a/drivers/hwmon/lm85.c +++ b/drivers/hwmon/lm85.c | |||
@@ -139,7 +139,7 @@ static const int lm85_scaling[] = { /* .001 Volts */ | |||
139 | #define SCALE(val, from, to) (((val) * (to) + ((from) / 2)) / (from)) | 139 | #define SCALE(val, from, to) (((val) * (to) + ((from) / 2)) / (from)) |
140 | 140 | ||
141 | #define INS_TO_REG(n, val) \ | 141 | #define INS_TO_REG(n, val) \ |
142 | SENSORS_LIMIT(SCALE(val, lm85_scaling[n], 192), 0, 255) | 142 | clamp_val(SCALE(val, lm85_scaling[n], 192), 0, 255) |
143 | 143 | ||
144 | #define INSEXT_FROM_REG(n, val, ext) \ | 144 | #define INSEXT_FROM_REG(n, val, ext) \ |
145 | SCALE(((val) << 4) + (ext), 192 << 4, lm85_scaling[n]) | 145 | SCALE(((val) << 4) + (ext), 192 << 4, lm85_scaling[n]) |
@@ -151,19 +151,19 @@ static inline u16 FAN_TO_REG(unsigned long val) | |||
151 | { | 151 | { |
152 | if (!val) | 152 | if (!val) |
153 | return 0xffff; | 153 | return 0xffff; |
154 | return SENSORS_LIMIT(5400000 / val, 1, 0xfffe); | 154 | return clamp_val(5400000 / val, 1, 0xfffe); |
155 | } | 155 | } |
156 | #define FAN_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \ | 156 | #define FAN_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \ |
157 | 5400000 / (val)) | 157 | 5400000 / (val)) |
158 | 158 | ||
159 | /* Temperature is reported in .001 degC increments */ | 159 | /* Temperature is reported in .001 degC increments */ |
160 | #define TEMP_TO_REG(val) \ | 160 | #define TEMP_TO_REG(val) \ |
161 | SENSORS_LIMIT(SCALE(val, 1000, 1), -127, 127) | 161 | clamp_val(SCALE(val, 1000, 1), -127, 127) |
162 | #define TEMPEXT_FROM_REG(val, ext) \ | 162 | #define TEMPEXT_FROM_REG(val, ext) \ |
163 | SCALE(((val) << 4) + (ext), 16, 1000) | 163 | SCALE(((val) << 4) + (ext), 16, 1000) |
164 | #define TEMP_FROM_REG(val) ((val) * 1000) | 164 | #define TEMP_FROM_REG(val) ((val) * 1000) |
165 | 165 | ||
166 | #define PWM_TO_REG(val) SENSORS_LIMIT(val, 0, 255) | 166 | #define PWM_TO_REG(val) clamp_val(val, 0, 255) |
167 | #define PWM_FROM_REG(val) (val) | 167 | #define PWM_FROM_REG(val) (val) |
168 | 168 | ||
169 | 169 | ||
@@ -258,7 +258,7 @@ static int ZONE_TO_REG(int zone) | |||
258 | return i << 5; | 258 | return i << 5; |
259 | } | 259 | } |
260 | 260 | ||
261 | #define HYST_TO_REG(val) SENSORS_LIMIT(((val) + 500) / 1000, 0, 15) | 261 | #define HYST_TO_REG(val) clamp_val(((val) + 500) / 1000, 0, 15) |
262 | #define HYST_FROM_REG(val) ((val) * 1000) | 262 | #define HYST_FROM_REG(val) ((val) * 1000) |
263 | 263 | ||
264 | /* | 264 | /* |
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index 863412a02bdd..8eeb141c85ac 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c | |||
@@ -931,7 +931,7 @@ static ssize_t set_update_interval(struct device *dev, | |||
931 | return err; | 931 | return err; |
932 | 932 | ||
933 | mutex_lock(&data->update_lock); | 933 | mutex_lock(&data->update_lock); |
934 | lm90_set_convrate(client, data, SENSORS_LIMIT(val, 0, 100000)); | 934 | lm90_set_convrate(client, data, clamp_val(val, 0, 100000)); |
935 | mutex_unlock(&data->update_lock); | 935 | mutex_unlock(&data->update_lock); |
936 | 936 | ||
937 | return count; | 937 | return count; |
diff --git a/drivers/hwmon/lm93.c b/drivers/hwmon/lm93.c index 1a003f73e4e4..b40f34cdb3ca 100644 --- a/drivers/hwmon/lm93.c +++ b/drivers/hwmon/lm93.c | |||
@@ -371,8 +371,8 @@ static unsigned LM93_IN_FROM_REG(int nr, u8 reg) | |||
371 | static u8 LM93_IN_TO_REG(int nr, unsigned val) | 371 | static u8 LM93_IN_TO_REG(int nr, unsigned val) |
372 | { | 372 | { |
373 | /* range limit */ | 373 | /* range limit */ |
374 | const long mV = SENSORS_LIMIT(val, | 374 | const long mV = clamp_val(val, |
375 | lm93_vin_val_min[nr], lm93_vin_val_max[nr]); | 375 | lm93_vin_val_min[nr], lm93_vin_val_max[nr]); |
376 | 376 | ||
377 | /* try not to lose too much precision here */ | 377 | /* try not to lose too much precision here */ |
378 | const long uV = mV * 1000; | 378 | const long uV = mV * 1000; |
@@ -385,8 +385,8 @@ static u8 LM93_IN_TO_REG(int nr, unsigned val) | |||
385 | const long intercept = uV_min - slope * lm93_vin_reg_min[nr]; | 385 | const long intercept = uV_min - slope * lm93_vin_reg_min[nr]; |
386 | 386 | ||
387 | u8 result = ((uV - intercept + (slope/2)) / slope); | 387 | u8 result = ((uV - intercept + (slope/2)) / slope); |
388 | result = SENSORS_LIMIT(result, | 388 | result = clamp_val(result, |
389 | lm93_vin_reg_min[nr], lm93_vin_reg_max[nr]); | 389 | lm93_vin_reg_min[nr], lm93_vin_reg_max[nr]); |
390 | return result; | 390 | return result; |
391 | } | 391 | } |
392 | 392 | ||
@@ -411,10 +411,10 @@ static u8 LM93_IN_REL_TO_REG(unsigned val, int upper, int vid) | |||
411 | { | 411 | { |
412 | long uV_offset = vid * 1000 - val * 10000; | 412 | long uV_offset = vid * 1000 - val * 10000; |
413 | if (upper) { | 413 | if (upper) { |
414 | uV_offset = SENSORS_LIMIT(uV_offset, 12500, 200000); | 414 | uV_offset = clamp_val(uV_offset, 12500, 200000); |
415 | return (u8)((uV_offset / 12500 - 1) << 4); | 415 | return (u8)((uV_offset / 12500 - 1) << 4); |
416 | } else { | 416 | } else { |
417 | uV_offset = SENSORS_LIMIT(uV_offset, -400000, -25000); | 417 | uV_offset = clamp_val(uV_offset, -400000, -25000); |
418 | return (u8)((uV_offset / -25000 - 1) << 0); | 418 | return (u8)((uV_offset / -25000 - 1) << 0); |
419 | } | 419 | } |
420 | } | 420 | } |
@@ -437,7 +437,7 @@ static int LM93_TEMP_FROM_REG(u8 reg) | |||
437 | */ | 437 | */ |
438 | static u8 LM93_TEMP_TO_REG(long temp) | 438 | static u8 LM93_TEMP_TO_REG(long temp) |
439 | { | 439 | { |
440 | int ntemp = SENSORS_LIMIT(temp, LM93_TEMP_MIN, LM93_TEMP_MAX); | 440 | int ntemp = clamp_val(temp, LM93_TEMP_MIN, LM93_TEMP_MAX); |
441 | ntemp += (ntemp < 0 ? -500 : 500); | 441 | ntemp += (ntemp < 0 ? -500 : 500); |
442 | return (u8)(ntemp / 1000); | 442 | return (u8)(ntemp / 1000); |
443 | } | 443 | } |
@@ -472,7 +472,7 @@ static u8 LM93_TEMP_OFFSET_TO_REG(int off, int mode) | |||
472 | { | 472 | { |
473 | int factor = mode ? 5 : 10; | 473 | int factor = mode ? 5 : 10; |
474 | 474 | ||
475 | off = SENSORS_LIMIT(off, LM93_TEMP_OFFSET_MIN, | 475 | off = clamp_val(off, LM93_TEMP_OFFSET_MIN, |
476 | mode ? LM93_TEMP_OFFSET_MAX1 : LM93_TEMP_OFFSET_MAX0); | 476 | mode ? LM93_TEMP_OFFSET_MAX1 : LM93_TEMP_OFFSET_MAX0); |
477 | return (u8)((off + factor/2) / factor); | 477 | return (u8)((off + factor/2) / factor); |
478 | } | 478 | } |
@@ -620,8 +620,8 @@ static u16 LM93_FAN_TO_REG(long rpm) | |||
620 | if (rpm == 0) { | 620 | if (rpm == 0) { |
621 | count = 0x3fff; | 621 | count = 0x3fff; |
622 | } else { | 622 | } else { |
623 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); | 623 | rpm = clamp_val(rpm, 1, 1000000); |
624 | count = SENSORS_LIMIT((1350000 + rpm) / rpm, 1, 0x3ffe); | 624 | count = clamp_val((1350000 + rpm) / rpm, 1, 0x3ffe); |
625 | } | 625 | } |
626 | 626 | ||
627 | regs = count << 2; | 627 | regs = count << 2; |
@@ -692,7 +692,7 @@ static int LM93_RAMP_FROM_REG(u8 reg) | |||
692 | */ | 692 | */ |
693 | static u8 LM93_RAMP_TO_REG(int ramp) | 693 | static u8 LM93_RAMP_TO_REG(int ramp) |
694 | { | 694 | { |
695 | ramp = SENSORS_LIMIT(ramp, LM93_RAMP_MIN, LM93_RAMP_MAX); | 695 | ramp = clamp_val(ramp, LM93_RAMP_MIN, LM93_RAMP_MAX); |
696 | return (u8)((ramp + 2) / 5); | 696 | return (u8)((ramp + 2) / 5); |
697 | } | 697 | } |
698 | 698 | ||
@@ -702,7 +702,7 @@ static u8 LM93_RAMP_TO_REG(int ramp) | |||
702 | */ | 702 | */ |
703 | static u8 LM93_PROCHOT_TO_REG(long prochot) | 703 | static u8 LM93_PROCHOT_TO_REG(long prochot) |
704 | { | 704 | { |
705 | prochot = SENSORS_LIMIT(prochot, 0, 255); | 705 | prochot = clamp_val(prochot, 0, 255); |
706 | return (u8)prochot; | 706 | return (u8)prochot; |
707 | } | 707 | } |
708 | 708 | ||
@@ -2052,7 +2052,7 @@ static ssize_t store_pwm_auto_channels(struct device *dev, | |||
2052 | return err; | 2052 | return err; |
2053 | 2053 | ||
2054 | mutex_lock(&data->update_lock); | 2054 | mutex_lock(&data->update_lock); |
2055 | data->block9[nr][LM93_PWM_CTL1] = SENSORS_LIMIT(val, 0, 255); | 2055 | data->block9[nr][LM93_PWM_CTL1] = clamp_val(val, 0, 255); |
2056 | lm93_write_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL1), | 2056 | lm93_write_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL1), |
2057 | data->block9[nr][LM93_PWM_CTL1]); | 2057 | data->block9[nr][LM93_PWM_CTL1]); |
2058 | mutex_unlock(&data->update_lock); | 2058 | mutex_unlock(&data->update_lock); |
@@ -2397,7 +2397,7 @@ static ssize_t store_prochot_override_duty_cycle(struct device *dev, | |||
2397 | 2397 | ||
2398 | mutex_lock(&data->update_lock); | 2398 | mutex_lock(&data->update_lock); |
2399 | data->prochot_override = (data->prochot_override & 0xf0) | | 2399 | data->prochot_override = (data->prochot_override & 0xf0) | |
2400 | SENSORS_LIMIT(val, 0, 15); | 2400 | clamp_val(val, 0, 15); |
2401 | lm93_write_byte(client, LM93_REG_PROCHOT_OVERRIDE, | 2401 | lm93_write_byte(client, LM93_REG_PROCHOT_OVERRIDE, |
2402 | data->prochot_override); | 2402 | data->prochot_override); |
2403 | mutex_unlock(&data->update_lock); | 2403 | mutex_unlock(&data->update_lock); |
diff --git a/drivers/hwmon/lm95245.c b/drivers/hwmon/lm95245.c index 2915fd908364..a6c85f0ff8f3 100644 --- a/drivers/hwmon/lm95245.c +++ b/drivers/hwmon/lm95245.c | |||
@@ -259,7 +259,7 @@ static ssize_t set_limit(struct device *dev, struct device_attribute *attr, | |||
259 | 259 | ||
260 | val /= 1000; | 260 | val /= 1000; |
261 | 261 | ||
262 | val = SENSORS_LIMIT(val, 0, (index == 6 ? 127 : 255)); | 262 | val = clamp_val(val, 0, (index == 6 ? 127 : 255)); |
263 | 263 | ||
264 | mutex_lock(&data->update_lock); | 264 | mutex_lock(&data->update_lock); |
265 | 265 | ||
@@ -284,7 +284,7 @@ static ssize_t set_crit_hyst(struct device *dev, struct device_attribute *attr, | |||
284 | 284 | ||
285 | val /= 1000; | 285 | val /= 1000; |
286 | 286 | ||
287 | val = SENSORS_LIMIT(val, 0, 31); | 287 | val = clamp_val(val, 0, 31); |
288 | 288 | ||
289 | mutex_lock(&data->update_lock); | 289 | mutex_lock(&data->update_lock); |
290 | 290 | ||
diff --git a/drivers/hwmon/max16065.c b/drivers/hwmon/max16065.c index e0019c69d1bb..2fa2c02f5569 100644 --- a/drivers/hwmon/max16065.c +++ b/drivers/hwmon/max16065.c | |||
@@ -118,7 +118,7 @@ static inline int LIMIT_TO_MV(int limit, int range) | |||
118 | 118 | ||
119 | static inline int MV_TO_LIMIT(int mv, int range) | 119 | static inline int MV_TO_LIMIT(int mv, int range) |
120 | { | 120 | { |
121 | return SENSORS_LIMIT(DIV_ROUND_CLOSEST(mv * 256, range), 0, 255); | 121 | return clamp_val(DIV_ROUND_CLOSEST(mv * 256, range), 0, 255); |
122 | } | 122 | } |
123 | 123 | ||
124 | static inline int ADC_TO_CURR(int adc, int gain) | 124 | static inline int ADC_TO_CURR(int adc, int gain) |
diff --git a/drivers/hwmon/max1668.c b/drivers/hwmon/max1668.c index 666d9f6263eb..a7626358c95d 100644 --- a/drivers/hwmon/max1668.c +++ b/drivers/hwmon/max1668.c | |||
@@ -215,7 +215,7 @@ static ssize_t set_temp_max(struct device *dev, | |||
215 | return ret; | 215 | return ret; |
216 | 216 | ||
217 | mutex_lock(&data->update_lock); | 217 | mutex_lock(&data->update_lock); |
218 | data->temp_max[index] = SENSORS_LIMIT(temp/1000, -128, 127); | 218 | data->temp_max[index] = clamp_val(temp/1000, -128, 127); |
219 | if (i2c_smbus_write_byte_data(client, | 219 | if (i2c_smbus_write_byte_data(client, |
220 | MAX1668_REG_LIMH_WR(index), | 220 | MAX1668_REG_LIMH_WR(index), |
221 | data->temp_max[index])) | 221 | data->temp_max[index])) |
@@ -240,7 +240,7 @@ static ssize_t set_temp_min(struct device *dev, | |||
240 | return ret; | 240 | return ret; |
241 | 241 | ||
242 | mutex_lock(&data->update_lock); | 242 | mutex_lock(&data->update_lock); |
243 | data->temp_min[index] = SENSORS_LIMIT(temp/1000, -128, 127); | 243 | data->temp_min[index] = clamp_val(temp/1000, -128, 127); |
244 | if (i2c_smbus_write_byte_data(client, | 244 | if (i2c_smbus_write_byte_data(client, |
245 | MAX1668_REG_LIML_WR(index), | 245 | MAX1668_REG_LIML_WR(index), |
246 | data->temp_max[index])) | 246 | data->temp_max[index])) |
diff --git a/drivers/hwmon/max6639.c b/drivers/hwmon/max6639.c index 6e60036abfa7..3e7b4269f5b9 100644 --- a/drivers/hwmon/max6639.c +++ b/drivers/hwmon/max6639.c | |||
@@ -74,7 +74,7 @@ static const int rpm_ranges[] = { 2000, 4000, 8000, 16000 }; | |||
74 | 74 | ||
75 | #define FAN_FROM_REG(val, rpm_range) ((val) == 0 || (val) == 255 ? \ | 75 | #define FAN_FROM_REG(val, rpm_range) ((val) == 0 || (val) == 255 ? \ |
76 | 0 : (rpm_ranges[rpm_range] * 30) / (val)) | 76 | 0 : (rpm_ranges[rpm_range] * 30) / (val)) |
77 | #define TEMP_LIMIT_TO_REG(val) SENSORS_LIMIT((val) / 1000, 0, 255) | 77 | #define TEMP_LIMIT_TO_REG(val) clamp_val((val) / 1000, 0, 255) |
78 | 78 | ||
79 | /* | 79 | /* |
80 | * Client data (each client gets its own) | 80 | * Client data (each client gets its own) |
@@ -312,7 +312,7 @@ static ssize_t set_pwm(struct device *dev, | |||
312 | if (res) | 312 | if (res) |
313 | return res; | 313 | return res; |
314 | 314 | ||
315 | val = SENSORS_LIMIT(val, 0, 255); | 315 | val = clamp_val(val, 0, 255); |
316 | 316 | ||
317 | mutex_lock(&data->update_lock); | 317 | mutex_lock(&data->update_lock); |
318 | data->pwm[attr->index] = (u8)(val * 120 / 255); | 318 | data->pwm[attr->index] = (u8)(val * 120 / 255); |
diff --git a/drivers/hwmon/max6642.c b/drivers/hwmon/max6642.c index 223461a6d70f..57d58cd32206 100644 --- a/drivers/hwmon/max6642.c +++ b/drivers/hwmon/max6642.c | |||
@@ -239,7 +239,7 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | |||
239 | return err; | 239 | return err; |
240 | 240 | ||
241 | mutex_lock(&data->update_lock); | 241 | mutex_lock(&data->update_lock); |
242 | data->temp_high[attr2->nr] = SENSORS_LIMIT(temp_to_reg(val), 0, 255); | 242 | data->temp_high[attr2->nr] = clamp_val(temp_to_reg(val), 0, 255); |
243 | i2c_smbus_write_byte_data(client, attr2->index, | 243 | i2c_smbus_write_byte_data(client, attr2->index, |
244 | data->temp_high[attr2->nr]); | 244 | data->temp_high[attr2->nr]); |
245 | mutex_unlock(&data->update_lock); | 245 | mutex_unlock(&data->update_lock); |
diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c index f739f83bafb9..3c16cbd4c002 100644 --- a/drivers/hwmon/max6650.c +++ b/drivers/hwmon/max6650.c | |||
@@ -245,7 +245,7 @@ static ssize_t set_target(struct device *dev, struct device_attribute *devattr, | |||
245 | if (err) | 245 | if (err) |
246 | return err; | 246 | return err; |
247 | 247 | ||
248 | rpm = SENSORS_LIMIT(rpm, FAN_RPM_MIN, FAN_RPM_MAX); | 248 | rpm = clamp_val(rpm, FAN_RPM_MIN, FAN_RPM_MAX); |
249 | 249 | ||
250 | /* | 250 | /* |
251 | * Divide the required speed by 60 to get from rpm to rps, then | 251 | * Divide the required speed by 60 to get from rpm to rps, then |
@@ -313,7 +313,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, | |||
313 | if (err) | 313 | if (err) |
314 | return err; | 314 | return err; |
315 | 315 | ||
316 | pwm = SENSORS_LIMIT(pwm, 0, 255); | 316 | pwm = clamp_val(pwm, 0, 255); |
317 | 317 | ||
318 | mutex_lock(&data->update_lock); | 318 | mutex_lock(&data->update_lock); |
319 | 319 | ||
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index 7d19b1bb9ce6..dbacde6abaa8 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c | |||
@@ -657,7 +657,7 @@ static u16 pmbus_data2reg_direct(struct pmbus_data *data, | |||
657 | static u16 pmbus_data2reg_vid(struct pmbus_data *data, | 657 | static u16 pmbus_data2reg_vid(struct pmbus_data *data, |
658 | enum pmbus_sensor_classes class, long val) | 658 | enum pmbus_sensor_classes class, long val) |
659 | { | 659 | { |
660 | val = SENSORS_LIMIT(val, 500, 1600); | 660 | val = clamp_val(val, 500, 1600); |
661 | 661 | ||
662 | return 2 + DIV_ROUND_CLOSEST((1600 - val) * 100, 625); | 662 | return 2 + DIV_ROUND_CLOSEST((1600 - val) * 100, 625); |
663 | } | 663 | } |
diff --git a/drivers/hwmon/sis5595.c b/drivers/hwmon/sis5595.c index 06ce3c911db9..c35847a1a0a3 100644 --- a/drivers/hwmon/sis5595.c +++ b/drivers/hwmon/sis5595.c | |||
@@ -132,7 +132,7 @@ static struct platform_device *pdev; | |||
132 | */ | 132 | */ |
133 | static inline u8 IN_TO_REG(unsigned long val) | 133 | static inline u8 IN_TO_REG(unsigned long val) |
134 | { | 134 | { |
135 | unsigned long nval = SENSORS_LIMIT(val, 0, 4080); | 135 | unsigned long nval = clamp_val(val, 0, 4080); |
136 | return (nval + 8) / 16; | 136 | return (nval + 8) / 16; |
137 | } | 137 | } |
138 | #define IN_FROM_REG(val) ((val) * 16) | 138 | #define IN_FROM_REG(val) ((val) * 16) |
@@ -141,7 +141,7 @@ static inline u8 FAN_TO_REG(long rpm, int div) | |||
141 | { | 141 | { |
142 | if (rpm <= 0) | 142 | if (rpm <= 0) |
143 | return 255; | 143 | return 255; |
144 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254); | 144 | return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254); |
145 | } | 145 | } |
146 | 146 | ||
147 | static inline int FAN_FROM_REG(u8 val, int div) | 147 | static inline int FAN_FROM_REG(u8 val, int div) |
@@ -159,7 +159,7 @@ static inline int TEMP_FROM_REG(s8 val) | |||
159 | } | 159 | } |
160 | static inline s8 TEMP_TO_REG(int val) | 160 | static inline s8 TEMP_TO_REG(int val) |
161 | { | 161 | { |
162 | int nval = SENSORS_LIMIT(val, -54120, 157530) ; | 162 | int nval = clamp_val(val, -54120, 157530) ; |
163 | return nval < 0 ? (nval - 5212 - 415) / 830 : (nval - 5212 + 415) / 830; | 163 | return nval < 0 ? (nval - 5212 - 415) / 830 : (nval - 5212 + 415) / 830; |
164 | } | 164 | } |
165 | 165 | ||
diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c index dba0c567e7a1..6d8255ccf07a 100644 --- a/drivers/hwmon/smsc47m1.c +++ b/drivers/hwmon/smsc47m1.c | |||
@@ -326,7 +326,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute | |||
326 | /* Preserve fan min */ | 326 | /* Preserve fan min */ |
327 | tmp = 192 - (old_div * (192 - data->fan_preload[nr]) | 327 | tmp = 192 - (old_div * (192 - data->fan_preload[nr]) |
328 | + new_div / 2) / new_div; | 328 | + new_div / 2) / new_div; |
329 | data->fan_preload[nr] = SENSORS_LIMIT(tmp, 0, 191); | 329 | data->fan_preload[nr] = clamp_val(tmp, 0, 191); |
330 | smsc47m1_write_value(data, SMSC47M1_REG_FAN_PRELOAD[nr], | 330 | smsc47m1_write_value(data, SMSC47M1_REG_FAN_PRELOAD[nr], |
331 | data->fan_preload[nr]); | 331 | data->fan_preload[nr]); |
332 | mutex_unlock(&data->update_lock); | 332 | mutex_unlock(&data->update_lock); |
diff --git a/drivers/hwmon/smsc47m192.c b/drivers/hwmon/smsc47m192.c index 36a3478d0799..efee4c59239f 100644 --- a/drivers/hwmon/smsc47m192.c +++ b/drivers/hwmon/smsc47m192.c | |||
@@ -77,7 +77,7 @@ static inline unsigned int IN_FROM_REG(u8 reg, int n) | |||
77 | 77 | ||
78 | static inline u8 IN_TO_REG(unsigned long val, int n) | 78 | static inline u8 IN_TO_REG(unsigned long val, int n) |
79 | { | 79 | { |
80 | return SENSORS_LIMIT(SCALE(val, 192, nom_mv[n]), 0, 255); | 80 | return clamp_val(SCALE(val, 192, nom_mv[n]), 0, 255); |
81 | } | 81 | } |
82 | 82 | ||
83 | /* | 83 | /* |
@@ -86,7 +86,7 @@ static inline u8 IN_TO_REG(unsigned long val, int n) | |||
86 | */ | 86 | */ |
87 | static inline s8 TEMP_TO_REG(int val) | 87 | static inline s8 TEMP_TO_REG(int val) |
88 | { | 88 | { |
89 | return SENSORS_LIMIT(SCALE(val, 1, 1000), -128000, 127000); | 89 | return clamp_val(SCALE(val, 1, 1000), -128000, 127000); |
90 | } | 90 | } |
91 | 91 | ||
92 | static inline int TEMP_FROM_REG(s8 val) | 92 | static inline int TEMP_FROM_REG(s8 val) |
diff --git a/drivers/hwmon/thmc50.c b/drivers/hwmon/thmc50.c index 3c2c48d904e6..4b59eb53b18a 100644 --- a/drivers/hwmon/thmc50.c +++ b/drivers/hwmon/thmc50.c | |||
@@ -134,7 +134,7 @@ static ssize_t set_analog_out(struct device *dev, | |||
134 | return err; | 134 | return err; |
135 | 135 | ||
136 | mutex_lock(&data->update_lock); | 136 | mutex_lock(&data->update_lock); |
137 | data->analog_out = SENSORS_LIMIT(tmp, 0, 255); | 137 | data->analog_out = clamp_val(tmp, 0, 255); |
138 | i2c_smbus_write_byte_data(client, THMC50_REG_ANALOG_OUT, | 138 | i2c_smbus_write_byte_data(client, THMC50_REG_ANALOG_OUT, |
139 | data->analog_out); | 139 | data->analog_out); |
140 | 140 | ||
@@ -187,7 +187,7 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | |||
187 | return err; | 187 | return err; |
188 | 188 | ||
189 | mutex_lock(&data->update_lock); | 189 | mutex_lock(&data->update_lock); |
190 | data->temp_min[nr] = SENSORS_LIMIT(val / 1000, -128, 127); | 190 | data->temp_min[nr] = clamp_val(val / 1000, -128, 127); |
191 | i2c_smbus_write_byte_data(client, THMC50_REG_TEMP_MIN[nr], | 191 | i2c_smbus_write_byte_data(client, THMC50_REG_TEMP_MIN[nr], |
192 | data->temp_min[nr]); | 192 | data->temp_min[nr]); |
193 | mutex_unlock(&data->update_lock); | 193 | mutex_unlock(&data->update_lock); |
@@ -216,7 +216,7 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | |||
216 | return err; | 216 | return err; |
217 | 217 | ||
218 | mutex_lock(&data->update_lock); | 218 | mutex_lock(&data->update_lock); |
219 | data->temp_max[nr] = SENSORS_LIMIT(val / 1000, -128, 127); | 219 | data->temp_max[nr] = clamp_val(val / 1000, -128, 127); |
220 | i2c_smbus_write_byte_data(client, THMC50_REG_TEMP_MAX[nr], | 220 | i2c_smbus_write_byte_data(client, THMC50_REG_TEMP_MAX[nr], |
221 | data->temp_max[nr]); | 221 | data->temp_max[nr]); |
222 | mutex_unlock(&data->update_lock); | 222 | mutex_unlock(&data->update_lock); |
diff --git a/drivers/hwmon/tmp102.c b/drivers/hwmon/tmp102.c index b10c3d36ccbc..523dd89ba498 100644 --- a/drivers/hwmon/tmp102.c +++ b/drivers/hwmon/tmp102.c | |||
@@ -115,7 +115,7 @@ static ssize_t tmp102_set_temp(struct device *dev, | |||
115 | 115 | ||
116 | if (kstrtol(buf, 10, &val) < 0) | 116 | if (kstrtol(buf, 10, &val) < 0) |
117 | return -EINVAL; | 117 | return -EINVAL; |
118 | val = SENSORS_LIMIT(val, -256000, 255000); | 118 | val = clamp_val(val, -256000, 255000); |
119 | 119 | ||
120 | mutex_lock(&tmp102->lock); | 120 | mutex_lock(&tmp102->lock); |
121 | tmp102->temp[sda->index] = val; | 121 | tmp102->temp[sda->index] = val; |
diff --git a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c index e62054875164..c85f6967ccc3 100644 --- a/drivers/hwmon/tmp401.c +++ b/drivers/hwmon/tmp401.c | |||
@@ -142,10 +142,10 @@ static int tmp401_register_to_temp(u16 reg, u8 config) | |||
142 | static u16 tmp401_temp_to_register(long temp, u8 config) | 142 | static u16 tmp401_temp_to_register(long temp, u8 config) |
143 | { | 143 | { |
144 | if (config & TMP401_CONFIG_RANGE) { | 144 | if (config & TMP401_CONFIG_RANGE) { |
145 | temp = SENSORS_LIMIT(temp, -64000, 191000); | 145 | temp = clamp_val(temp, -64000, 191000); |
146 | temp += 64000; | 146 | temp += 64000; |
147 | } else | 147 | } else |
148 | temp = SENSORS_LIMIT(temp, 0, 127000); | 148 | temp = clamp_val(temp, 0, 127000); |
149 | 149 | ||
150 | return (temp * 160 + 312) / 625; | 150 | return (temp * 160 + 312) / 625; |
151 | } | 151 | } |
@@ -163,10 +163,10 @@ static int tmp401_crit_register_to_temp(u8 reg, u8 config) | |||
163 | static u8 tmp401_crit_temp_to_register(long temp, u8 config) | 163 | static u8 tmp401_crit_temp_to_register(long temp, u8 config) |
164 | { | 164 | { |
165 | if (config & TMP401_CONFIG_RANGE) { | 165 | if (config & TMP401_CONFIG_RANGE) { |
166 | temp = SENSORS_LIMIT(temp, -64000, 191000); | 166 | temp = clamp_val(temp, -64000, 191000); |
167 | temp += 64000; | 167 | temp += 64000; |
168 | } else | 168 | } else |
169 | temp = SENSORS_LIMIT(temp, 0, 127000); | 169 | temp = clamp_val(temp, 0, 127000); |
170 | 170 | ||
171 | return (temp + 500) / 1000; | 171 | return (temp + 500) / 1000; |
172 | } | 172 | } |
@@ -417,14 +417,14 @@ static ssize_t store_temp_crit_hyst(struct device *dev, struct device_attribute | |||
417 | return -EINVAL; | 417 | return -EINVAL; |
418 | 418 | ||
419 | if (data->config & TMP401_CONFIG_RANGE) | 419 | if (data->config & TMP401_CONFIG_RANGE) |
420 | val = SENSORS_LIMIT(val, -64000, 191000); | 420 | val = clamp_val(val, -64000, 191000); |
421 | else | 421 | else |
422 | val = SENSORS_LIMIT(val, 0, 127000); | 422 | val = clamp_val(val, 0, 127000); |
423 | 423 | ||
424 | mutex_lock(&data->update_lock); | 424 | mutex_lock(&data->update_lock); |
425 | temp = tmp401_crit_register_to_temp(data->temp_crit[index], | 425 | temp = tmp401_crit_register_to_temp(data->temp_crit[index], |
426 | data->config); | 426 | data->config); |
427 | val = SENSORS_LIMIT(val, temp - 255000, temp); | 427 | val = clamp_val(val, temp - 255000, temp); |
428 | reg = ((temp - val) + 500) / 1000; | 428 | reg = ((temp - val) + 500) / 1000; |
429 | 429 | ||
430 | i2c_smbus_write_byte_data(to_i2c_client(dev), | 430 | i2c_smbus_write_byte_data(to_i2c_client(dev), |
diff --git a/drivers/hwmon/via686a.c b/drivers/hwmon/via686a.c index e0e14a9f1658..3123b30208c5 100644 --- a/drivers/hwmon/via686a.c +++ b/drivers/hwmon/via686a.c | |||
@@ -135,17 +135,14 @@ static inline u8 IN_TO_REG(long val, int inNum) | |||
135 | * for the constants. | 135 | * for the constants. |
136 | */ | 136 | */ |
137 | if (inNum <= 1) | 137 | if (inNum <= 1) |
138 | return (u8) | 138 | return (u8) clamp_val((val * 21024 - 1205000) / 250000, 0, 255); |
139 | SENSORS_LIMIT((val * 21024 - 1205000) / 250000, 0, 255); | ||
140 | else if (inNum == 2) | 139 | else if (inNum == 2) |
141 | return (u8) | 140 | return (u8) clamp_val((val * 15737 - 1205000) / 250000, 0, 255); |
142 | SENSORS_LIMIT((val * 15737 - 1205000) / 250000, 0, 255); | ||
143 | else if (inNum == 3) | 141 | else if (inNum == 3) |
144 | return (u8) | 142 | return (u8) clamp_val((val * 10108 - 1205000) / 250000, 0, 255); |
145 | SENSORS_LIMIT((val * 10108 - 1205000) / 250000, 0, 255); | ||
146 | else | 143 | else |
147 | return (u8) | 144 | return (u8) clamp_val((val * 41714 - 12050000) / 2500000, 0, |
148 | SENSORS_LIMIT((val * 41714 - 12050000) / 2500000, 0, 255); | 145 | 255); |
149 | } | 146 | } |
150 | 147 | ||
151 | static inline long IN_FROM_REG(u8 val, int inNum) | 148 | static inline long IN_FROM_REG(u8 val, int inNum) |
@@ -175,8 +172,8 @@ static inline u8 FAN_TO_REG(long rpm, int div) | |||
175 | { | 172 | { |
176 | if (rpm == 0) | 173 | if (rpm == 0) |
177 | return 0; | 174 | return 0; |
178 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); | 175 | rpm = clamp_val(rpm, 1, 1000000); |
179 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 255); | 176 | return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 255); |
180 | } | 177 | } |
181 | 178 | ||
182 | #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : (val) == 255 ? 0 : 1350000 / \ | 179 | #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : (val) == 255 ? 0 : 1350000 / \ |
diff --git a/drivers/hwmon/vt1211.c b/drivers/hwmon/vt1211.c index 751703059fae..dcc62f80f67b 100644 --- a/drivers/hwmon/vt1211.c +++ b/drivers/hwmon/vt1211.c | |||
@@ -158,7 +158,7 @@ struct vt1211_data { | |||
158 | #define IN_FROM_REG(ix, reg) ((reg) < 3 ? 0 : (ix) == 5 ? \ | 158 | #define IN_FROM_REG(ix, reg) ((reg) < 3 ? 0 : (ix) == 5 ? \ |
159 | (((reg) - 3) * 15882 + 479) / 958 : \ | 159 | (((reg) - 3) * 15882 + 479) / 958 : \ |
160 | (((reg) - 3) * 10000 + 479) / 958) | 160 | (((reg) - 3) * 10000 + 479) / 958) |
161 | #define IN_TO_REG(ix, val) (SENSORS_LIMIT((ix) == 5 ? \ | 161 | #define IN_TO_REG(ix, val) (clamp_val((ix) == 5 ? \ |
162 | ((val) * 958 + 7941) / 15882 + 3 : \ | 162 | ((val) * 958 + 7941) / 15882 + 3 : \ |
163 | ((val) * 958 + 5000) / 10000 + 3, 0, 255)) | 163 | ((val) * 958 + 5000) / 10000 + 3, 0, 255)) |
164 | 164 | ||
@@ -173,7 +173,7 @@ struct vt1211_data { | |||
173 | (ix) == 1 ? (reg) < 51 ? 0 : \ | 173 | (ix) == 1 ? (reg) < 51 ? 0 : \ |
174 | ((reg) - 51) * 1000 : \ | 174 | ((reg) - 51) * 1000 : \ |
175 | ((253 - (reg)) * 2200 + 105) / 210) | 175 | ((253 - (reg)) * 2200 + 105) / 210) |
176 | #define TEMP_TO_REG(ix, val) SENSORS_LIMIT( \ | 176 | #define TEMP_TO_REG(ix, val) clamp_val( \ |
177 | ((ix) == 0 ? ((val) + 500) / 1000 : \ | 177 | ((ix) == 0 ? ((val) + 500) / 1000 : \ |
178 | (ix) == 1 ? ((val) + 500) / 1000 + 51 : \ | 178 | (ix) == 1 ? ((val) + 500) / 1000 + 51 : \ |
179 | 253 - ((val) * 210 + 1100) / 2200), 0, 255) | 179 | 253 - ((val) * 210 + 1100) / 2200), 0, 255) |
@@ -183,7 +183,7 @@ struct vt1211_data { | |||
183 | #define RPM_FROM_REG(reg, div) (((reg) == 0) || ((reg) == 255) ? 0 : \ | 183 | #define RPM_FROM_REG(reg, div) (((reg) == 0) || ((reg) == 255) ? 0 : \ |
184 | 1310720 / (reg) / DIV_FROM_REG(div)) | 184 | 1310720 / (reg) / DIV_FROM_REG(div)) |
185 | #define RPM_TO_REG(val, div) ((val) == 0 ? 255 : \ | 185 | #define RPM_TO_REG(val, div) ((val) == 0 ? 255 : \ |
186 | SENSORS_LIMIT((1310720 / (val) / \ | 186 | clamp_val((1310720 / (val) / \ |
187 | DIV_FROM_REG(div)), 1, 254)) | 187 | DIV_FROM_REG(div)), 1, 254)) |
188 | 188 | ||
189 | /* --------------------------------------------------------------------- | 189 | /* --------------------------------------------------------------------- |
@@ -687,7 +687,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | |||
687 | data->fan_ctl)); | 687 | data->fan_ctl)); |
688 | break; | 688 | break; |
689 | case SHOW_SET_PWM_FREQ: | 689 | case SHOW_SET_PWM_FREQ: |
690 | val = 135000 / SENSORS_LIMIT(val, 135000 >> 7, 135000); | 690 | val = 135000 / clamp_val(val, 135000 >> 7, 135000); |
691 | /* calculate tmp = log2(val) */ | 691 | /* calculate tmp = log2(val) */ |
692 | tmp = 0; | 692 | tmp = 0; |
693 | for (val >>= 1; val > 0; val >>= 1) | 693 | for (val >>= 1; val > 0; val >>= 1) |
@@ -845,7 +845,7 @@ static ssize_t set_pwm_auto_point_pwm(struct device *dev, | |||
845 | return err; | 845 | return err; |
846 | 846 | ||
847 | mutex_lock(&data->update_lock); | 847 | mutex_lock(&data->update_lock); |
848 | data->pwm_auto_pwm[ix][ap] = SENSORS_LIMIT(val, 0, 255); | 848 | data->pwm_auto_pwm[ix][ap] = clamp_val(val, 0, 255); |
849 | vt1211_write8(data, VT1211_REG_PWM_AUTO_PWM(ix, ap), | 849 | vt1211_write8(data, VT1211_REG_PWM_AUTO_PWM(ix, ap), |
850 | data->pwm_auto_pwm[ix][ap]); | 850 | data->pwm_auto_pwm[ix][ap]); |
851 | mutex_unlock(&data->update_lock); | 851 | mutex_unlock(&data->update_lock); |
diff --git a/drivers/hwmon/vt8231.c b/drivers/hwmon/vt8231.c index a56355cef184..988a2a796764 100644 --- a/drivers/hwmon/vt8231.c +++ b/drivers/hwmon/vt8231.c | |||
@@ -147,7 +147,7 @@ static inline u8 FAN_TO_REG(long rpm, int div) | |||
147 | { | 147 | { |
148 | if (rpm == 0) | 148 | if (rpm == 0) |
149 | return 0; | 149 | return 0; |
150 | return SENSORS_LIMIT(1310720 / (rpm * div), 1, 255); | 150 | return clamp_val(1310720 / (rpm * div), 1, 255); |
151 | } | 151 | } |
152 | 152 | ||
153 | #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : 1310720 / ((val) * (div))) | 153 | #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : 1310720 / ((val) * (div))) |
@@ -236,7 +236,7 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, | |||
236 | return err; | 236 | return err; |
237 | 237 | ||
238 | mutex_lock(&data->update_lock); | 238 | mutex_lock(&data->update_lock); |
239 | data->in_min[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255); | 239 | data->in_min[nr] = clamp_val(((val * 958) / 10000) + 3, 0, 255); |
240 | vt8231_write_value(data, regvoltmin[nr], data->in_min[nr]); | 240 | vt8231_write_value(data, regvoltmin[nr], data->in_min[nr]); |
241 | mutex_unlock(&data->update_lock); | 241 | mutex_unlock(&data->update_lock); |
242 | return count; | 242 | return count; |
@@ -256,7 +256,7 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, | |||
256 | return err; | 256 | return err; |
257 | 257 | ||
258 | mutex_lock(&data->update_lock); | 258 | mutex_lock(&data->update_lock); |
259 | data->in_max[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255); | 259 | data->in_max[nr] = clamp_val(((val * 958) / 10000) + 3, 0, 255); |
260 | vt8231_write_value(data, regvoltmax[nr], data->in_max[nr]); | 260 | vt8231_write_value(data, regvoltmax[nr], data->in_max[nr]); |
261 | mutex_unlock(&data->update_lock); | 261 | mutex_unlock(&data->update_lock); |
262 | return count; | 262 | return count; |
@@ -302,8 +302,8 @@ static ssize_t set_in5_min(struct device *dev, struct device_attribute *attr, | |||
302 | return err; | 302 | return err; |
303 | 303 | ||
304 | mutex_lock(&data->update_lock); | 304 | mutex_lock(&data->update_lock); |
305 | data->in_min[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3, | 305 | data->in_min[5] = clamp_val(((val * 958 * 34) / (10000 * 54)) + 3, |
306 | 0, 255); | 306 | 0, 255); |
307 | vt8231_write_value(data, regvoltmin[5], data->in_min[5]); | 307 | vt8231_write_value(data, regvoltmin[5], data->in_min[5]); |
308 | mutex_unlock(&data->update_lock); | 308 | mutex_unlock(&data->update_lock); |
309 | return count; | 309 | return count; |
@@ -321,8 +321,8 @@ static ssize_t set_in5_max(struct device *dev, struct device_attribute *attr, | |||
321 | return err; | 321 | return err; |
322 | 322 | ||
323 | mutex_lock(&data->update_lock); | 323 | mutex_lock(&data->update_lock); |
324 | data->in_max[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3, | 324 | data->in_max[5] = clamp_val(((val * 958 * 34) / (10000 * 54)) + 3, |
325 | 0, 255); | 325 | 0, 255); |
326 | vt8231_write_value(data, regvoltmax[5], data->in_max[5]); | 326 | vt8231_write_value(data, regvoltmax[5], data->in_max[5]); |
327 | mutex_unlock(&data->update_lock); | 327 | mutex_unlock(&data->update_lock); |
328 | return count; | 328 | return count; |
@@ -380,7 +380,7 @@ static ssize_t set_temp0_max(struct device *dev, struct device_attribute *attr, | |||
380 | return err; | 380 | return err; |
381 | 381 | ||
382 | mutex_lock(&data->update_lock); | 382 | mutex_lock(&data->update_lock); |
383 | data->temp_max[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255); | 383 | data->temp_max[0] = clamp_val((val + 500) / 1000, 0, 255); |
384 | vt8231_write_value(data, regtempmax[0], data->temp_max[0]); | 384 | vt8231_write_value(data, regtempmax[0], data->temp_max[0]); |
385 | mutex_unlock(&data->update_lock); | 385 | mutex_unlock(&data->update_lock); |
386 | return count; | 386 | return count; |
@@ -397,7 +397,7 @@ static ssize_t set_temp0_min(struct device *dev, struct device_attribute *attr, | |||
397 | return err; | 397 | return err; |
398 | 398 | ||
399 | mutex_lock(&data->update_lock); | 399 | mutex_lock(&data->update_lock); |
400 | data->temp_min[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255); | 400 | data->temp_min[0] = clamp_val((val + 500) / 1000, 0, 255); |
401 | vt8231_write_value(data, regtempmin[0], data->temp_min[0]); | 401 | vt8231_write_value(data, regtempmin[0], data->temp_min[0]); |
402 | mutex_unlock(&data->update_lock); | 402 | mutex_unlock(&data->update_lock); |
403 | return count; | 403 | return count; |
@@ -444,7 +444,7 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | |||
444 | return err; | 444 | return err; |
445 | 445 | ||
446 | mutex_lock(&data->update_lock); | 446 | mutex_lock(&data->update_lock); |
447 | data->temp_max[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255); | 447 | data->temp_max[nr] = clamp_val(TEMP_MAXMIN_TO_REG(val), 0, 255); |
448 | vt8231_write_value(data, regtempmax[nr], data->temp_max[nr]); | 448 | vt8231_write_value(data, regtempmax[nr], data->temp_max[nr]); |
449 | mutex_unlock(&data->update_lock); | 449 | mutex_unlock(&data->update_lock); |
450 | return count; | 450 | return count; |
@@ -463,7 +463,7 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | |||
463 | return err; | 463 | return err; |
464 | 464 | ||
465 | mutex_lock(&data->update_lock); | 465 | mutex_lock(&data->update_lock); |
466 | data->temp_min[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255); | 466 | data->temp_min[nr] = clamp_val(TEMP_MAXMIN_TO_REG(val), 0, 255); |
467 | vt8231_write_value(data, regtempmin[nr], data->temp_min[nr]); | 467 | vt8231_write_value(data, regtempmin[nr], data->temp_min[nr]); |
468 | mutex_unlock(&data->update_lock); | 468 | mutex_unlock(&data->update_lock); |
469 | return count; | 469 | return count; |
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c index 0e8ffd6059a0..0a89211c25f6 100644 --- a/drivers/hwmon/w83627ehf.c +++ b/drivers/hwmon/w83627ehf.c | |||
@@ -354,8 +354,8 @@ static inline unsigned int step_time_from_reg(u8 reg, u8 mode) | |||
354 | 354 | ||
355 | static inline u8 step_time_to_reg(unsigned int msec, u8 mode) | 355 | static inline u8 step_time_to_reg(unsigned int msec, u8 mode) |
356 | { | 356 | { |
357 | return SENSORS_LIMIT((mode ? (msec + 50) / 100 : | 357 | return clamp_val((mode ? (msec + 50) / 100 : (msec + 200) / 400), |
358 | (msec + 200) / 400), 1, 255); | 358 | 1, 255); |
359 | } | 359 | } |
360 | 360 | ||
361 | static unsigned int fan_from_reg8(u16 reg, unsigned int divreg) | 361 | static unsigned int fan_from_reg8(u16 reg, unsigned int divreg) |
@@ -414,8 +414,7 @@ static inline long in_from_reg(u8 reg, u8 nr, const u16 *scale_in) | |||
414 | 414 | ||
415 | static inline u8 in_to_reg(u32 val, u8 nr, const u16 *scale_in) | 415 | static inline u8 in_to_reg(u32 val, u8 nr, const u16 *scale_in) |
416 | { | 416 | { |
417 | return SENSORS_LIMIT(DIV_ROUND_CLOSEST(val * 100, scale_in[nr]), 0, | 417 | return clamp_val(DIV_ROUND_CLOSEST(val * 100, scale_in[nr]), 0, 255); |
418 | 255); | ||
419 | } | 418 | } |
420 | 419 | ||
421 | /* | 420 | /* |
@@ -1267,7 +1266,7 @@ store_temp_offset(struct device *dev, struct device_attribute *attr, | |||
1267 | if (err < 0) | 1266 | if (err < 0) |
1268 | return err; | 1267 | return err; |
1269 | 1268 | ||
1270 | val = SENSORS_LIMIT(DIV_ROUND_CLOSEST(val, 1000), -128, 127); | 1269 | val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), -128, 127); |
1271 | 1270 | ||
1272 | mutex_lock(&data->update_lock); | 1271 | mutex_lock(&data->update_lock); |
1273 | data->temp_offset[nr] = val; | 1272 | data->temp_offset[nr] = val; |
@@ -1435,7 +1434,7 @@ store_pwm(struct device *dev, struct device_attribute *attr, | |||
1435 | if (err < 0) | 1434 | if (err < 0) |
1436 | return err; | 1435 | return err; |
1437 | 1436 | ||
1438 | val = SENSORS_LIMIT(val, 0, 255); | 1437 | val = clamp_val(val, 0, 255); |
1439 | 1438 | ||
1440 | mutex_lock(&data->update_lock); | 1439 | mutex_lock(&data->update_lock); |
1441 | data->pwm[nr] = val; | 1440 | data->pwm[nr] = val; |
@@ -1514,7 +1513,7 @@ store_target_temp(struct device *dev, struct device_attribute *attr, | |||
1514 | if (err < 0) | 1513 | if (err < 0) |
1515 | return err; | 1514 | return err; |
1516 | 1515 | ||
1517 | val = SENSORS_LIMIT(DIV_ROUND_CLOSEST(val, 1000), 0, 127); | 1516 | val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 0, 127); |
1518 | 1517 | ||
1519 | mutex_lock(&data->update_lock); | 1518 | mutex_lock(&data->update_lock); |
1520 | data->target_temp[nr] = val; | 1519 | data->target_temp[nr] = val; |
@@ -1540,7 +1539,7 @@ store_tolerance(struct device *dev, struct device_attribute *attr, | |||
1540 | return err; | 1539 | return err; |
1541 | 1540 | ||
1542 | /* Limit the temp to 0C - 15C */ | 1541 | /* Limit the temp to 0C - 15C */ |
1543 | val = SENSORS_LIMIT(DIV_ROUND_CLOSEST(val, 1000), 0, 15); | 1542 | val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 0, 15); |
1544 | 1543 | ||
1545 | mutex_lock(&data->update_lock); | 1544 | mutex_lock(&data->update_lock); |
1546 | if (sio_data->kind == nct6775 || sio_data->kind == nct6776) { | 1545 | if (sio_data->kind == nct6775 || sio_data->kind == nct6776) { |
@@ -1639,7 +1638,7 @@ store_##reg(struct device *dev, struct device_attribute *attr, \ | |||
1639 | err = kstrtoul(buf, 10, &val); \ | 1638 | err = kstrtoul(buf, 10, &val); \ |
1640 | if (err < 0) \ | 1639 | if (err < 0) \ |
1641 | return err; \ | 1640 | return err; \ |
1642 | val = SENSORS_LIMIT(val, 1, 255); \ | 1641 | val = clamp_val(val, 1, 255); \ |
1643 | mutex_lock(&data->update_lock); \ | 1642 | mutex_lock(&data->update_lock); \ |
1644 | data->reg[nr] = val; \ | 1643 | data->reg[nr] = val; \ |
1645 | w83627ehf_write_value(data, data->REG_##REG[nr], val); \ | 1644 | w83627ehf_write_value(data, data->REG_##REG[nr], val); \ |
diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c index 81f486520cea..3b9ef2d23452 100644 --- a/drivers/hwmon/w83627hf.c +++ b/drivers/hwmon/w83627hf.c | |||
@@ -254,16 +254,15 @@ static const u8 BIT_SCFG2[] = { 0x10, 0x20, 0x40 }; | |||
254 | * these macros are called: arguments may be evaluated more than once. | 254 | * these macros are called: arguments may be evaluated more than once. |
255 | * Fixing this is just not worth it. | 255 | * Fixing this is just not worth it. |
256 | */ | 256 | */ |
257 | #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255)) | 257 | #define IN_TO_REG(val) (clamp_val((((val) + 8) / 16), 0, 255)) |
258 | #define IN_FROM_REG(val) ((val) * 16) | 258 | #define IN_FROM_REG(val) ((val) * 16) |
259 | 259 | ||
260 | static inline u8 FAN_TO_REG(long rpm, int div) | 260 | static inline u8 FAN_TO_REG(long rpm, int div) |
261 | { | 261 | { |
262 | if (rpm == 0) | 262 | if (rpm == 0) |
263 | return 255; | 263 | return 255; |
264 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); | 264 | rpm = clamp_val(rpm, 1, 1000000); |
265 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, | 265 | return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254); |
266 | 254); | ||
267 | } | 266 | } |
268 | 267 | ||
269 | #define TEMP_MIN (-128000) | 268 | #define TEMP_MIN (-128000) |
@@ -275,9 +274,9 @@ static inline u8 FAN_TO_REG(long rpm, int div) | |||
275 | */ | 274 | */ |
276 | static u8 TEMP_TO_REG(long temp) | 275 | static u8 TEMP_TO_REG(long temp) |
277 | { | 276 | { |
278 | int ntemp = SENSORS_LIMIT(temp, TEMP_MIN, TEMP_MAX); | 277 | int ntemp = clamp_val(temp, TEMP_MIN, TEMP_MAX); |
279 | ntemp += (ntemp<0 ? -500 : 500); | 278 | ntemp += (ntemp < 0 ? -500 : 500); |
280 | return (u8)(ntemp / 1000); | 279 | return (u8)(ntemp / 1000); |
281 | } | 280 | } |
282 | 281 | ||
283 | static int TEMP_FROM_REG(u8 reg) | 282 | static int TEMP_FROM_REG(u8 reg) |
@@ -287,7 +286,7 @@ static int TEMP_FROM_REG(u8 reg) | |||
287 | 286 | ||
288 | #define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div))) | 287 | #define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div))) |
289 | 288 | ||
290 | #define PWM_TO_REG(val) (SENSORS_LIMIT((val),0,255)) | 289 | #define PWM_TO_REG(val) (clamp_val((val), 0, 255)) |
291 | 290 | ||
292 | static inline unsigned long pwm_freq_from_reg_627hf(u8 reg) | 291 | static inline unsigned long pwm_freq_from_reg_627hf(u8 reg) |
293 | { | 292 | { |
@@ -342,7 +341,7 @@ static inline u8 pwm_freq_to_reg(unsigned long val) | |||
342 | static inline u8 DIV_TO_REG(long val) | 341 | static inline u8 DIV_TO_REG(long val) |
343 | { | 342 | { |
344 | int i; | 343 | int i; |
345 | val = SENSORS_LIMIT(val, 1, 128) >> 1; | 344 | val = clamp_val(val, 1, 128) >> 1; |
346 | for (i = 0; i < 7; i++) { | 345 | for (i = 0; i < 7; i++) { |
347 | if (val == 0) | 346 | if (val == 0) |
348 | break; | 347 | break; |
@@ -614,8 +613,7 @@ static ssize_t store_regs_in_min0(struct device *dev, struct device_attribute *a | |||
614 | 613 | ||
615 | /* use VRM9 calculation */ | 614 | /* use VRM9 calculation */ |
616 | data->in_min[0] = | 615 | data->in_min[0] = |
617 | SENSORS_LIMIT(((val * 100) - 70000 + 244) / 488, 0, | 616 | clamp_val(((val * 100) - 70000 + 244) / 488, 0, 255); |
618 | 255); | ||
619 | else | 617 | else |
620 | /* use VRM8 (standard) calculation */ | 618 | /* use VRM8 (standard) calculation */ |
621 | data->in_min[0] = IN_TO_REG(val); | 619 | data->in_min[0] = IN_TO_REG(val); |
@@ -644,8 +642,7 @@ static ssize_t store_regs_in_max0(struct device *dev, struct device_attribute *a | |||
644 | 642 | ||
645 | /* use VRM9 calculation */ | 643 | /* use VRM9 calculation */ |
646 | data->in_max[0] = | 644 | data->in_max[0] = |
647 | SENSORS_LIMIT(((val * 100) - 70000 + 244) / 488, 0, | 645 | clamp_val(((val * 100) - 70000 + 244) / 488, 0, 255); |
648 | 255); | ||
649 | else | 646 | else |
650 | /* use VRM8 (standard) calculation */ | 647 | /* use VRM8 (standard) calculation */ |
651 | data->in_max[0] = IN_TO_REG(val); | 648 | data->in_max[0] = IN_TO_REG(val); |
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c index 93bd28639595..aeec5b1d81c9 100644 --- a/drivers/hwmon/w83781d.c +++ b/drivers/hwmon/w83781d.c | |||
@@ -159,7 +159,7 @@ static const u8 BIT_SCFG2[] = { 0x10, 0x20, 0x40 }; | |||
159 | #define W83781D_DEFAULT_BETA 3435 | 159 | #define W83781D_DEFAULT_BETA 3435 |
160 | 160 | ||
161 | /* Conversions */ | 161 | /* Conversions */ |
162 | #define IN_TO_REG(val) SENSORS_LIMIT(((val) + 8) / 16, 0, 255) | 162 | #define IN_TO_REG(val) clamp_val(((val) + 8) / 16, 0, 255) |
163 | #define IN_FROM_REG(val) ((val) * 16) | 163 | #define IN_FROM_REG(val) ((val) * 16) |
164 | 164 | ||
165 | static inline u8 | 165 | static inline u8 |
@@ -167,8 +167,8 @@ FAN_TO_REG(long rpm, int div) | |||
167 | { | 167 | { |
168 | if (rpm == 0) | 168 | if (rpm == 0) |
169 | return 255; | 169 | return 255; |
170 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); | 170 | rpm = clamp_val(rpm, 1, 1000000); |
171 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254); | 171 | return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254); |
172 | } | 172 | } |
173 | 173 | ||
174 | static inline long | 174 | static inline long |
@@ -181,7 +181,7 @@ FAN_FROM_REG(u8 val, int div) | |||
181 | return 1350000 / (val * div); | 181 | return 1350000 / (val * div); |
182 | } | 182 | } |
183 | 183 | ||
184 | #define TEMP_TO_REG(val) SENSORS_LIMIT((val) / 1000, -127, 128) | 184 | #define TEMP_TO_REG(val) clamp_val((val) / 1000, -127, 128) |
185 | #define TEMP_FROM_REG(val) ((val) * 1000) | 185 | #define TEMP_FROM_REG(val) ((val) * 1000) |
186 | 186 | ||
187 | #define BEEP_MASK_FROM_REG(val, type) ((type) == as99127f ? \ | 187 | #define BEEP_MASK_FROM_REG(val, type) ((type) == as99127f ? \ |
@@ -195,9 +195,8 @@ static inline u8 | |||
195 | DIV_TO_REG(long val, enum chips type) | 195 | DIV_TO_REG(long val, enum chips type) |
196 | { | 196 | { |
197 | int i; | 197 | int i; |
198 | val = SENSORS_LIMIT(val, 1, | 198 | val = clamp_val(val, 1, |
199 | ((type == w83781d | 199 | ((type == w83781d || type == as99127f) ? 8 : 128)) >> 1; |
200 | || type == as99127f) ? 8 : 128)) >> 1; | ||
201 | for (i = 0; i < 7; i++) { | 200 | for (i = 0; i < 7; i++) { |
202 | if (val == 0) | 201 | if (val == 0) |
203 | break; | 202 | break; |
@@ -443,7 +442,7 @@ store_vrm_reg(struct device *dev, struct device_attribute *attr, | |||
443 | err = kstrtoul(buf, 10, &val); | 442 | err = kstrtoul(buf, 10, &val); |
444 | if (err) | 443 | if (err) |
445 | return err; | 444 | return err; |
446 | data->vrm = SENSORS_LIMIT(val, 0, 255); | 445 | data->vrm = clamp_val(val, 0, 255); |
447 | 446 | ||
448 | return count; | 447 | return count; |
449 | } | 448 | } |
@@ -730,7 +729,7 @@ store_pwm(struct device *dev, struct device_attribute *da, const char *buf, | |||
730 | return err; | 729 | return err; |
731 | 730 | ||
732 | mutex_lock(&data->update_lock); | 731 | mutex_lock(&data->update_lock); |
733 | data->pwm[nr] = SENSORS_LIMIT(val, 0, 255); | 732 | data->pwm[nr] = clamp_val(val, 0, 255); |
734 | w83781d_write_value(data, W83781D_REG_PWM[nr], data->pwm[nr]); | 733 | w83781d_write_value(data, W83781D_REG_PWM[nr], data->pwm[nr]); |
735 | mutex_unlock(&data->update_lock); | 734 | mutex_unlock(&data->update_lock); |
736 | return count; | 735 | return count; |
diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c index ed397c645198..38dddddf8875 100644 --- a/drivers/hwmon/w83791d.c +++ b/drivers/hwmon/w83791d.c | |||
@@ -220,15 +220,15 @@ static inline int w83791d_write(struct i2c_client *client, u8 reg, u8 value) | |||
220 | * in mV as would be measured on the chip input pin, need to just | 220 | * in mV as would be measured on the chip input pin, need to just |
221 | * multiply/divide by 16 to translate from/to register values. | 221 | * multiply/divide by 16 to translate from/to register values. |
222 | */ | 222 | */ |
223 | #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8) / 16), 0, 255)) | 223 | #define IN_TO_REG(val) (clamp_val((((val) + 8) / 16), 0, 255)) |
224 | #define IN_FROM_REG(val) ((val) * 16) | 224 | #define IN_FROM_REG(val) ((val) * 16) |
225 | 225 | ||
226 | static u8 fan_to_reg(long rpm, int div) | 226 | static u8 fan_to_reg(long rpm, int div) |
227 | { | 227 | { |
228 | if (rpm == 0) | 228 | if (rpm == 0) |
229 | return 255; | 229 | return 255; |
230 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); | 230 | rpm = clamp_val(rpm, 1, 1000000); |
231 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254); | 231 | return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254); |
232 | } | 232 | } |
233 | 233 | ||
234 | #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \ | 234 | #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \ |
@@ -273,7 +273,7 @@ static u8 div_to_reg(int nr, long val) | |||
273 | int i; | 273 | int i; |
274 | 274 | ||
275 | /* fan divisors max out at 128 */ | 275 | /* fan divisors max out at 128 */ |
276 | val = SENSORS_LIMIT(val, 1, 128) >> 1; | 276 | val = clamp_val(val, 1, 128) >> 1; |
277 | for (i = 0; i < 7; i++) { | 277 | for (i = 0; i < 7; i++) { |
278 | if (val == 0) | 278 | if (val == 0) |
279 | break; | 279 | break; |
@@ -747,7 +747,7 @@ static ssize_t store_pwm(struct device *dev, struct device_attribute *attr, | |||
747 | return -EINVAL; | 747 | return -EINVAL; |
748 | 748 | ||
749 | mutex_lock(&data->update_lock); | 749 | mutex_lock(&data->update_lock); |
750 | data->pwm[nr] = SENSORS_LIMIT(val, 0, 255); | 750 | data->pwm[nr] = clamp_val(val, 0, 255); |
751 | w83791d_write(client, W83791D_REG_PWM[nr], data->pwm[nr]); | 751 | w83791d_write(client, W83791D_REG_PWM[nr], data->pwm[nr]); |
752 | mutex_unlock(&data->update_lock); | 752 | mutex_unlock(&data->update_lock); |
753 | return count; | 753 | return count; |
diff --git a/drivers/hwmon/w83792d.c b/drivers/hwmon/w83792d.c index 301942d08453..5cb83ddf2cc6 100644 --- a/drivers/hwmon/w83792d.c +++ b/drivers/hwmon/w83792d.c | |||
@@ -235,8 +235,8 @@ FAN_TO_REG(long rpm, int div) | |||
235 | { | 235 | { |
236 | if (rpm == 0) | 236 | if (rpm == 0) |
237 | return 255; | 237 | return 255; |
238 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); | 238 | rpm = clamp_val(rpm, 1, 1000000); |
239 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254); | 239 | return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254); |
240 | } | 240 | } |
241 | 241 | ||
242 | #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \ | 242 | #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \ |
@@ -244,16 +244,15 @@ FAN_TO_REG(long rpm, int div) | |||
244 | 1350000 / ((val) * (div)))) | 244 | 1350000 / ((val) * (div)))) |
245 | 245 | ||
246 | /* for temp1 */ | 246 | /* for temp1 */ |
247 | #define TEMP1_TO_REG(val) (SENSORS_LIMIT(((val) < 0 ? (val)+0x100*1000 \ | 247 | #define TEMP1_TO_REG(val) (clamp_val(((val) < 0 ? (val) + 0x100 * 1000 \ |
248 | : (val)) / 1000, 0, 0xff)) | 248 | : (val)) / 1000, 0, 0xff)) |
249 | #define TEMP1_FROM_REG(val) (((val) & 0x80 ? (val)-0x100 : (val)) * 1000) | 249 | #define TEMP1_FROM_REG(val) (((val) & 0x80 ? (val)-0x100 : (val)) * 1000) |
250 | /* for temp2 and temp3, because they need additional resolution */ | 250 | /* for temp2 and temp3, because they need additional resolution */ |
251 | #define TEMP_ADD_FROM_REG(val1, val2) \ | 251 | #define TEMP_ADD_FROM_REG(val1, val2) \ |
252 | ((((val1) & 0x80 ? (val1)-0x100 \ | 252 | ((((val1) & 0x80 ? (val1)-0x100 \ |
253 | : (val1)) * 1000) + ((val2 & 0x80) ? 500 : 0)) | 253 | : (val1)) * 1000) + ((val2 & 0x80) ? 500 : 0)) |
254 | #define TEMP_ADD_TO_REG_HIGH(val) \ | 254 | #define TEMP_ADD_TO_REG_HIGH(val) \ |
255 | (SENSORS_LIMIT(((val) < 0 ? (val)+0x100*1000 \ | 255 | (clamp_val(((val) < 0 ? (val) + 0x100 * 1000 : (val)) / 1000, 0, 0xff)) |
256 | : (val)) / 1000, 0, 0xff)) | ||
257 | #define TEMP_ADD_TO_REG_LOW(val) ((val%1000) ? 0x80 : 0x00) | 256 | #define TEMP_ADD_TO_REG_LOW(val) ((val%1000) ? 0x80 : 0x00) |
258 | 257 | ||
259 | #define DIV_FROM_REG(val) (1 << (val)) | 258 | #define DIV_FROM_REG(val) (1 << (val)) |
@@ -262,7 +261,7 @@ static inline u8 | |||
262 | DIV_TO_REG(long val) | 261 | DIV_TO_REG(long val) |
263 | { | 262 | { |
264 | int i; | 263 | int i; |
265 | val = SENSORS_LIMIT(val, 1, 128) >> 1; | 264 | val = clamp_val(val, 1, 128) >> 1; |
266 | for (i = 0; i < 7; i++) { | 265 | for (i = 0; i < 7; i++) { |
267 | if (val == 0) | 266 | if (val == 0) |
268 | break; | 267 | break; |
@@ -397,7 +396,7 @@ static ssize_t store_in_##reg(struct device *dev, \ | |||
397 | if (err) \ | 396 | if (err) \ |
398 | return err; \ | 397 | return err; \ |
399 | mutex_lock(&data->update_lock); \ | 398 | mutex_lock(&data->update_lock); \ |
400 | data->in_##reg[nr] = SENSORS_LIMIT(IN_TO_REG(nr, val) / 4, 0, 255); \ | 399 | data->in_##reg[nr] = clamp_val(IN_TO_REG(nr, val) / 4, 0, 255); \ |
401 | w83792d_write_value(client, W83792D_REG_IN_##REG[nr], \ | 400 | w83792d_write_value(client, W83792D_REG_IN_##REG[nr], \ |
402 | data->in_##reg[nr]); \ | 401 | data->in_##reg[nr]); \ |
403 | mutex_unlock(&data->update_lock); \ | 402 | mutex_unlock(&data->update_lock); \ |
@@ -645,7 +644,7 @@ store_pwm(struct device *dev, struct device_attribute *attr, | |||
645 | err = kstrtoul(buf, 10, &val); | 644 | err = kstrtoul(buf, 10, &val); |
646 | if (err) | 645 | if (err) |
647 | return err; | 646 | return err; |
648 | val = SENSORS_LIMIT(val, 0, 255) >> 4; | 647 | val = clamp_val(val, 0, 255) >> 4; |
649 | 648 | ||
650 | mutex_lock(&data->update_lock); | 649 | mutex_lock(&data->update_lock); |
651 | val |= w83792d_read_value(client, W83792D_REG_PWM[nr]) & 0xf0; | 650 | val |= w83792d_read_value(client, W83792D_REG_PWM[nr]) & 0xf0; |
@@ -799,7 +798,7 @@ store_thermal_cruise(struct device *dev, struct device_attribute *attr, | |||
799 | mutex_lock(&data->update_lock); | 798 | mutex_lock(&data->update_lock); |
800 | target_mask = w83792d_read_value(client, | 799 | target_mask = w83792d_read_value(client, |
801 | W83792D_REG_THERMAL[nr]) & 0x80; | 800 | W83792D_REG_THERMAL[nr]) & 0x80; |
802 | data->thermal_cruise[nr] = SENSORS_LIMIT(target_tmp, 0, 255); | 801 | data->thermal_cruise[nr] = clamp_val(target_tmp, 0, 255); |
803 | w83792d_write_value(client, W83792D_REG_THERMAL[nr], | 802 | w83792d_write_value(client, W83792D_REG_THERMAL[nr], |
804 | (data->thermal_cruise[nr]) | target_mask); | 803 | (data->thermal_cruise[nr]) | target_mask); |
805 | mutex_unlock(&data->update_lock); | 804 | mutex_unlock(&data->update_lock); |
@@ -837,7 +836,7 @@ store_tolerance(struct device *dev, struct device_attribute *attr, | |||
837 | mutex_lock(&data->update_lock); | 836 | mutex_lock(&data->update_lock); |
838 | tol_mask = w83792d_read_value(client, | 837 | tol_mask = w83792d_read_value(client, |
839 | W83792D_REG_TOLERANCE[nr]) & ((nr == 1) ? 0x0f : 0xf0); | 838 | W83792D_REG_TOLERANCE[nr]) & ((nr == 1) ? 0x0f : 0xf0); |
840 | tol_tmp = SENSORS_LIMIT(val, 0, 15); | 839 | tol_tmp = clamp_val(val, 0, 15); |
841 | tol_tmp &= 0x0f; | 840 | tol_tmp &= 0x0f; |
842 | data->tolerance[nr] = tol_tmp; | 841 | data->tolerance[nr] = tol_tmp; |
843 | if (nr == 1) | 842 | if (nr == 1) |
@@ -881,7 +880,7 @@ store_sf2_point(struct device *dev, struct device_attribute *attr, | |||
881 | return err; | 880 | return err; |
882 | 881 | ||
883 | mutex_lock(&data->update_lock); | 882 | mutex_lock(&data->update_lock); |
884 | data->sf2_points[index][nr] = SENSORS_LIMIT(val, 0, 127); | 883 | data->sf2_points[index][nr] = clamp_val(val, 0, 127); |
885 | mask_tmp = w83792d_read_value(client, | 884 | mask_tmp = w83792d_read_value(client, |
886 | W83792D_REG_POINTS[index][nr]) & 0x80; | 885 | W83792D_REG_POINTS[index][nr]) & 0x80; |
887 | w83792d_write_value(client, W83792D_REG_POINTS[index][nr], | 886 | w83792d_write_value(client, W83792D_REG_POINTS[index][nr], |
@@ -923,7 +922,7 @@ store_sf2_level(struct device *dev, struct device_attribute *attr, | |||
923 | return err; | 922 | return err; |
924 | 923 | ||
925 | mutex_lock(&data->update_lock); | 924 | mutex_lock(&data->update_lock); |
926 | data->sf2_levels[index][nr] = SENSORS_LIMIT((val * 15) / 100, 0, 15); | 925 | data->sf2_levels[index][nr] = clamp_val((val * 15) / 100, 0, 15); |
927 | mask_tmp = w83792d_read_value(client, W83792D_REG_LEVELS[index][nr]) | 926 | mask_tmp = w83792d_read_value(client, W83792D_REG_LEVELS[index][nr]) |
928 | & ((nr == 3) ? 0xf0 : 0x0f); | 927 | & ((nr == 3) ? 0xf0 : 0x0f); |
929 | if (nr == 3) | 928 | if (nr == 3) |
diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c index 99799fd1d917..660427520c53 100644 --- a/drivers/hwmon/w83793.c +++ b/drivers/hwmon/w83793.c | |||
@@ -191,7 +191,7 @@ static inline u16 FAN_TO_REG(long rpm) | |||
191 | { | 191 | { |
192 | if (rpm <= 0) | 192 | if (rpm <= 0) |
193 | return 0x0fff; | 193 | return 0x0fff; |
194 | return SENSORS_LIMIT((1350000 + (rpm >> 1)) / rpm, 1, 0xffe); | 194 | return clamp_val((1350000 + (rpm >> 1)) / rpm, 1, 0xffe); |
195 | } | 195 | } |
196 | 196 | ||
197 | static inline unsigned long TIME_FROM_REG(u8 reg) | 197 | static inline unsigned long TIME_FROM_REG(u8 reg) |
@@ -201,7 +201,7 @@ static inline unsigned long TIME_FROM_REG(u8 reg) | |||
201 | 201 | ||
202 | static inline u8 TIME_TO_REG(unsigned long val) | 202 | static inline u8 TIME_TO_REG(unsigned long val) |
203 | { | 203 | { |
204 | return SENSORS_LIMIT((val + 50) / 100, 0, 0xff); | 204 | return clamp_val((val + 50) / 100, 0, 0xff); |
205 | } | 205 | } |
206 | 206 | ||
207 | static inline long TEMP_FROM_REG(s8 reg) | 207 | static inline long TEMP_FROM_REG(s8 reg) |
@@ -211,7 +211,7 @@ static inline long TEMP_FROM_REG(s8 reg) | |||
211 | 211 | ||
212 | static inline s8 TEMP_TO_REG(long val, s8 min, s8 max) | 212 | static inline s8 TEMP_TO_REG(long val, s8 min, s8 max) |
213 | { | 213 | { |
214 | return SENSORS_LIMIT((val + (val < 0 ? -500 : 500)) / 1000, min, max); | 214 | return clamp_val((val + (val < 0 ? -500 : 500)) / 1000, min, max); |
215 | } | 215 | } |
216 | 216 | ||
217 | struct w83793_data { | 217 | struct w83793_data { |
@@ -558,7 +558,7 @@ store_pwm(struct device *dev, struct device_attribute *attr, | |||
558 | w83793_write_value(client, W83793_REG_PWM_STOP_TIME(index), | 558 | w83793_write_value(client, W83793_REG_PWM_STOP_TIME(index), |
559 | val); | 559 | val); |
560 | } else { | 560 | } else { |
561 | val = SENSORS_LIMIT(val, 0, 0xff) >> 2; | 561 | val = clamp_val(val, 0, 0xff) >> 2; |
562 | data->pwm[index][nr] = | 562 | data->pwm[index][nr] = |
563 | w83793_read_value(client, W83793_REG_PWM(index, nr)) & 0xc0; | 563 | w83793_read_value(client, W83793_REG_PWM(index, nr)) & 0xc0; |
564 | data->pwm[index][nr] |= val; | 564 | data->pwm[index][nr] |= val; |
@@ -739,7 +739,7 @@ store_sf_setup(struct device *dev, struct device_attribute *attr, | |||
739 | if (nr == SETUP_PWM_DEFAULT) { | 739 | if (nr == SETUP_PWM_DEFAULT) { |
740 | data->pwm_default = | 740 | data->pwm_default = |
741 | w83793_read_value(client, W83793_REG_PWM_DEFAULT) & 0xc0; | 741 | w83793_read_value(client, W83793_REG_PWM_DEFAULT) & 0xc0; |
742 | data->pwm_default |= SENSORS_LIMIT(val, 0, 0xff) >> 2; | 742 | data->pwm_default |= clamp_val(val, 0, 0xff) >> 2; |
743 | w83793_write_value(client, W83793_REG_PWM_DEFAULT, | 743 | w83793_write_value(client, W83793_REG_PWM_DEFAULT, |
744 | data->pwm_default); | 744 | data->pwm_default); |
745 | } else if (nr == SETUP_PWM_UPTIME) { | 745 | } else if (nr == SETUP_PWM_UPTIME) { |
@@ -838,7 +838,7 @@ store_sf_ctrl(struct device *dev, struct device_attribute *attr, | |||
838 | 838 | ||
839 | mutex_lock(&data->update_lock); | 839 | mutex_lock(&data->update_lock); |
840 | if (nr == TEMP_FAN_MAP) { | 840 | if (nr == TEMP_FAN_MAP) { |
841 | val = SENSORS_LIMIT(val, 0, 255); | 841 | val = clamp_val(val, 0, 255); |
842 | w83793_write_value(client, W83793_REG_TEMP_FAN_MAP(index), val); | 842 | w83793_write_value(client, W83793_REG_TEMP_FAN_MAP(index), val); |
843 | data->temp_fan_map[index] = val; | 843 | data->temp_fan_map[index] = val; |
844 | } else if (nr == TEMP_PWM_ENABLE) { | 844 | } else if (nr == TEMP_PWM_ENABLE) { |
@@ -907,7 +907,7 @@ store_sf2_pwm(struct device *dev, struct device_attribute *attr, | |||
907 | err = kstrtoul(buf, 10, &val); | 907 | err = kstrtoul(buf, 10, &val); |
908 | if (err) | 908 | if (err) |
909 | return err; | 909 | return err; |
910 | val = SENSORS_LIMIT(val, 0, 0xff) >> 2; | 910 | val = clamp_val(val, 0, 0xff) >> 2; |
911 | 911 | ||
912 | mutex_lock(&data->update_lock); | 912 | mutex_lock(&data->update_lock); |
913 | data->sf2_pwm[index][nr] = | 913 | data->sf2_pwm[index][nr] = |
@@ -1003,9 +1003,9 @@ store_in(struct device *dev, struct device_attribute *attr, | |||
1003 | /* fix the limit values of 5VDD and 5VSB to ALARM mechanism */ | 1003 | /* fix the limit values of 5VDD and 5VSB to ALARM mechanism */ |
1004 | if (nr == 1 || nr == 2) | 1004 | if (nr == 1 || nr == 2) |
1005 | val -= scale_in_add[index] / scale_in[index]; | 1005 | val -= scale_in_add[index] / scale_in[index]; |
1006 | val = SENSORS_LIMIT(val, 0, 255); | 1006 | val = clamp_val(val, 0, 255); |
1007 | } else { | 1007 | } else { |
1008 | val = SENSORS_LIMIT(val, 0, 0x3FF); | 1008 | val = clamp_val(val, 0, 0x3FF); |
1009 | data->in_low_bits[nr] = | 1009 | data->in_low_bits[nr] = |
1010 | w83793_read_value(client, W83793_REG_IN_LOW_BITS[nr]); | 1010 | w83793_read_value(client, W83793_REG_IN_LOW_BITS[nr]); |
1011 | data->in_low_bits[nr] &= ~(0x03 << (2 * index)); | 1011 | data->in_low_bits[nr] &= ~(0x03 << (2 * index)); |
diff --git a/drivers/hwmon/w83795.c b/drivers/hwmon/w83795.c index 55a4f4894531..e226096148eb 100644 --- a/drivers/hwmon/w83795.c +++ b/drivers/hwmon/w83795.c | |||
@@ -262,7 +262,7 @@ static inline u16 fan_to_reg(long rpm) | |||
262 | { | 262 | { |
263 | if (rpm <= 0) | 263 | if (rpm <= 0) |
264 | return 0x0fff; | 264 | return 0x0fff; |
265 | return SENSORS_LIMIT((1350000 + (rpm >> 1)) / rpm, 1, 0xffe); | 265 | return clamp_val((1350000 + (rpm >> 1)) / rpm, 1, 0xffe); |
266 | } | 266 | } |
267 | 267 | ||
268 | static inline unsigned long time_from_reg(u8 reg) | 268 | static inline unsigned long time_from_reg(u8 reg) |
@@ -272,7 +272,7 @@ static inline unsigned long time_from_reg(u8 reg) | |||
272 | 272 | ||
273 | static inline u8 time_to_reg(unsigned long val) | 273 | static inline u8 time_to_reg(unsigned long val) |
274 | { | 274 | { |
275 | return SENSORS_LIMIT((val + 50) / 100, 0, 0xff); | 275 | return clamp_val((val + 50) / 100, 0, 0xff); |
276 | } | 276 | } |
277 | 277 | ||
278 | static inline long temp_from_reg(s8 reg) | 278 | static inline long temp_from_reg(s8 reg) |
@@ -282,7 +282,7 @@ static inline long temp_from_reg(s8 reg) | |||
282 | 282 | ||
283 | static inline s8 temp_to_reg(long val, s8 min, s8 max) | 283 | static inline s8 temp_to_reg(long val, s8 min, s8 max) |
284 | { | 284 | { |
285 | return SENSORS_LIMIT(val / 1000, min, max); | 285 | return clamp_val(val / 1000, min, max); |
286 | } | 286 | } |
287 | 287 | ||
288 | static const u16 pwm_freq_cksel0[16] = { | 288 | static const u16 pwm_freq_cksel0[16] = { |
@@ -319,7 +319,7 @@ static u8 pwm_freq_to_reg(unsigned long val, u16 clkin) | |||
319 | 319 | ||
320 | /* Best fit for cksel = 1 */ | 320 | /* Best fit for cksel = 1 */ |
321 | base_clock = clkin * 1000 / ((clkin == 48000) ? 384 : 256); | 321 | base_clock = clkin * 1000 / ((clkin == 48000) ? 384 : 256); |
322 | reg1 = SENSORS_LIMIT(DIV_ROUND_CLOSEST(base_clock, val), 1, 128); | 322 | reg1 = clamp_val(DIV_ROUND_CLOSEST(base_clock, val), 1, 128); |
323 | best1 = base_clock / reg1; | 323 | best1 = base_clock / reg1; |
324 | reg1 = 0x80 | (reg1 - 1); | 324 | reg1 = 0x80 | (reg1 - 1); |
325 | 325 | ||
@@ -889,7 +889,7 @@ store_pwm(struct device *dev, struct device_attribute *attr, | |||
889 | val = pwm_freq_to_reg(val, data->clkin); | 889 | val = pwm_freq_to_reg(val, data->clkin); |
890 | break; | 890 | break; |
891 | default: | 891 | default: |
892 | val = SENSORS_LIMIT(val, 0, 0xff); | 892 | val = clamp_val(val, 0, 0xff); |
893 | break; | 893 | break; |
894 | } | 894 | } |
895 | w83795_write(client, W83795_REG_PWM(index, nr), val); | 895 | w83795_write(client, W83795_REG_PWM(index, nr), val); |
@@ -1126,7 +1126,7 @@ store_temp_pwm_enable(struct device *dev, struct device_attribute *attr, | |||
1126 | break; | 1126 | break; |
1127 | case TEMP_PWM_FAN_MAP: | 1127 | case TEMP_PWM_FAN_MAP: |
1128 | mutex_lock(&data->update_lock); | 1128 | mutex_lock(&data->update_lock); |
1129 | tmp = SENSORS_LIMIT(tmp, 0, 0xff); | 1129 | tmp = clamp_val(tmp, 0, 0xff); |
1130 | w83795_write(client, W83795_REG_TFMR(index), tmp); | 1130 | w83795_write(client, W83795_REG_TFMR(index), tmp); |
1131 | data->pwm_tfmr[index] = tmp; | 1131 | data->pwm_tfmr[index] = tmp; |
1132 | mutex_unlock(&data->update_lock); | 1132 | mutex_unlock(&data->update_lock); |
@@ -1177,13 +1177,13 @@ store_fanin(struct device *dev, struct device_attribute *attr, | |||
1177 | mutex_lock(&data->update_lock); | 1177 | mutex_lock(&data->update_lock); |
1178 | switch (nr) { | 1178 | switch (nr) { |
1179 | case FANIN_TARGET: | 1179 | case FANIN_TARGET: |
1180 | val = fan_to_reg(SENSORS_LIMIT(val, 0, 0xfff)); | 1180 | val = fan_to_reg(clamp_val(val, 0, 0xfff)); |
1181 | w83795_write(client, W83795_REG_FTSH(index), val >> 4); | 1181 | w83795_write(client, W83795_REG_FTSH(index), val >> 4); |
1182 | w83795_write(client, W83795_REG_FTSL(index), (val << 4) & 0xf0); | 1182 | w83795_write(client, W83795_REG_FTSL(index), (val << 4) & 0xf0); |
1183 | data->target_speed[index] = val; | 1183 | data->target_speed[index] = val; |
1184 | break; | 1184 | break; |
1185 | case FANIN_TOL: | 1185 | case FANIN_TOL: |
1186 | val = SENSORS_LIMIT(val, 0, 0x3f); | 1186 | val = clamp_val(val, 0, 0x3f); |
1187 | w83795_write(client, W83795_REG_TFTS, val); | 1187 | w83795_write(client, W83795_REG_TFTS, val); |
1188 | data->tol_speed = val; | 1188 | data->tol_speed = val; |
1189 | break; | 1189 | break; |
@@ -1227,22 +1227,22 @@ store_temp_pwm(struct device *dev, struct device_attribute *attr, | |||
1227 | mutex_lock(&data->update_lock); | 1227 | mutex_lock(&data->update_lock); |
1228 | switch (nr) { | 1228 | switch (nr) { |
1229 | case TEMP_PWM_TTTI: | 1229 | case TEMP_PWM_TTTI: |
1230 | val = SENSORS_LIMIT(val, 0, 0x7f); | 1230 | val = clamp_val(val, 0, 0x7f); |
1231 | w83795_write(client, W83795_REG_TTTI(index), val); | 1231 | w83795_write(client, W83795_REG_TTTI(index), val); |
1232 | break; | 1232 | break; |
1233 | case TEMP_PWM_CTFS: | 1233 | case TEMP_PWM_CTFS: |
1234 | val = SENSORS_LIMIT(val, 0, 0x7f); | 1234 | val = clamp_val(val, 0, 0x7f); |
1235 | w83795_write(client, W83795_REG_CTFS(index), val); | 1235 | w83795_write(client, W83795_REG_CTFS(index), val); |
1236 | break; | 1236 | break; |
1237 | case TEMP_PWM_HCT: | 1237 | case TEMP_PWM_HCT: |
1238 | val = SENSORS_LIMIT(val, 0, 0x0f); | 1238 | val = clamp_val(val, 0, 0x0f); |
1239 | tmp = w83795_read(client, W83795_REG_HT(index)); | 1239 | tmp = w83795_read(client, W83795_REG_HT(index)); |
1240 | tmp &= 0x0f; | 1240 | tmp &= 0x0f; |
1241 | tmp |= (val << 4) & 0xf0; | 1241 | tmp |= (val << 4) & 0xf0; |
1242 | w83795_write(client, W83795_REG_HT(index), tmp); | 1242 | w83795_write(client, W83795_REG_HT(index), tmp); |
1243 | break; | 1243 | break; |
1244 | case TEMP_PWM_HOT: | 1244 | case TEMP_PWM_HOT: |
1245 | val = SENSORS_LIMIT(val, 0, 0x0f); | 1245 | val = clamp_val(val, 0, 0x0f); |
1246 | tmp = w83795_read(client, W83795_REG_HT(index)); | 1246 | tmp = w83795_read(client, W83795_REG_HT(index)); |
1247 | tmp &= 0xf0; | 1247 | tmp &= 0xf0; |
1248 | tmp |= val & 0x0f; | 1248 | tmp |= val & 0x0f; |
@@ -1541,7 +1541,7 @@ store_in(struct device *dev, struct device_attribute *attr, | |||
1541 | if ((index >= 17) && | 1541 | if ((index >= 17) && |
1542 | !((data->has_gain >> (index - 17)) & 1)) | 1542 | !((data->has_gain >> (index - 17)) & 1)) |
1543 | val /= 8; | 1543 | val /= 8; |
1544 | val = SENSORS_LIMIT(val, 0, 0x3FF); | 1544 | val = clamp_val(val, 0, 0x3FF); |
1545 | mutex_lock(&data->update_lock); | 1545 | mutex_lock(&data->update_lock); |
1546 | 1546 | ||
1547 | lsb_idx = IN_LSB_SHIFT_IDX[index][IN_LSB_IDX]; | 1547 | lsb_idx = IN_LSB_SHIFT_IDX[index][IN_LSB_IDX]; |
@@ -1596,7 +1596,7 @@ store_sf_setup(struct device *dev, struct device_attribute *attr, | |||
1596 | 1596 | ||
1597 | switch (nr) { | 1597 | switch (nr) { |
1598 | case SETUP_PWM_DEFAULT: | 1598 | case SETUP_PWM_DEFAULT: |
1599 | val = SENSORS_LIMIT(val, 0, 0xff); | 1599 | val = clamp_val(val, 0, 0xff); |
1600 | break; | 1600 | break; |
1601 | case SETUP_PWM_UPTIME: | 1601 | case SETUP_PWM_UPTIME: |
1602 | case SETUP_PWM_DOWNTIME: | 1602 | case SETUP_PWM_DOWNTIME: |
diff --git a/drivers/hwmon/w83l786ng.c b/drivers/hwmon/w83l786ng.c index 79710bcac2f7..edb06cda5a68 100644 --- a/drivers/hwmon/w83l786ng.c +++ b/drivers/hwmon/w83l786ng.c | |||
@@ -86,8 +86,8 @@ FAN_TO_REG(long rpm, int div) | |||
86 | { | 86 | { |
87 | if (rpm == 0) | 87 | if (rpm == 0) |
88 | return 255; | 88 | return 255; |
89 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); | 89 | rpm = clamp_val(rpm, 1, 1000000); |
90 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254); | 90 | return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254); |
91 | } | 91 | } |
92 | 92 | ||
93 | #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \ | 93 | #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \ |
@@ -95,9 +95,8 @@ FAN_TO_REG(long rpm, int div) | |||
95 | 1350000 / ((val) * (div)))) | 95 | 1350000 / ((val) * (div)))) |
96 | 96 | ||
97 | /* for temp */ | 97 | /* for temp */ |
98 | #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) < 0 ? \ | 98 | #define TEMP_TO_REG(val) (clamp_val(((val) < 0 ? (val) + 0x100 * 1000 \ |
99 | (val) + 0x100 * 1000 \ | 99 | : (val)) / 1000, 0, 0xff)) |
100 | : (val)) / 1000, 0, 0xff)) | ||
101 | #define TEMP_FROM_REG(val) (((val) & 0x80 ? \ | 100 | #define TEMP_FROM_REG(val) (((val) & 0x80 ? \ |
102 | (val) - 0x100 : (val)) * 1000) | 101 | (val) - 0x100 : (val)) * 1000) |
103 | 102 | ||
@@ -106,7 +105,7 @@ FAN_TO_REG(long rpm, int div) | |||
106 | * in mV as would be measured on the chip input pin, need to just | 105 | * in mV as would be measured on the chip input pin, need to just |
107 | * multiply/divide by 8 to translate from/to register values. | 106 | * multiply/divide by 8 to translate from/to register values. |
108 | */ | 107 | */ |
109 | #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 4) / 8), 0, 255)) | 108 | #define IN_TO_REG(val) (clamp_val((((val) + 4) / 8), 0, 255)) |
110 | #define IN_FROM_REG(val) ((val) * 8) | 109 | #define IN_FROM_REG(val) ((val) * 8) |
111 | 110 | ||
112 | #define DIV_FROM_REG(val) (1 << (val)) | 111 | #define DIV_FROM_REG(val) (1 << (val)) |
@@ -115,7 +114,7 @@ static inline u8 | |||
115 | DIV_TO_REG(long val) | 114 | DIV_TO_REG(long val) |
116 | { | 115 | { |
117 | int i; | 116 | int i; |
118 | val = SENSORS_LIMIT(val, 1, 128) >> 1; | 117 | val = clamp_val(val, 1, 128) >> 1; |
119 | for (i = 0; i < 7; i++) { | 118 | for (i = 0; i < 7; i++) { |
120 | if (val == 0) | 119 | if (val == 0) |
121 | break; | 120 | break; |
@@ -481,7 +480,7 @@ store_pwm(struct device *dev, struct device_attribute *attr, | |||
481 | err = kstrtoul(buf, 10, &val); | 480 | err = kstrtoul(buf, 10, &val); |
482 | if (err) | 481 | if (err) |
483 | return err; | 482 | return err; |
484 | val = SENSORS_LIMIT(val, 0, 255); | 483 | val = clamp_val(val, 0, 255); |
485 | 484 | ||
486 | mutex_lock(&data->update_lock); | 485 | mutex_lock(&data->update_lock); |
487 | data->pwm[nr] = val; | 486 | data->pwm[nr] = val; |
@@ -564,7 +563,7 @@ store_tolerance(struct device *dev, struct device_attribute *attr, | |||
564 | mutex_lock(&data->update_lock); | 563 | mutex_lock(&data->update_lock); |
565 | tol_mask = w83l786ng_read_value(client, | 564 | tol_mask = w83l786ng_read_value(client, |
566 | W83L786NG_REG_TOLERANCE) & ((nr == 1) ? 0x0f : 0xf0); | 565 | W83L786NG_REG_TOLERANCE) & ((nr == 1) ? 0x0f : 0xf0); |
567 | tol_tmp = SENSORS_LIMIT(val, 0, 15); | 566 | tol_tmp = clamp_val(val, 0, 15); |
568 | tol_tmp &= 0x0f; | 567 | tol_tmp &= 0x0f; |
569 | data->tolerance[nr] = tol_tmp; | 568 | data->tolerance[nr] = tol_tmp; |
570 | if (nr == 1) | 569 | if (nr == 1) |