hwmon: (sht4x) do not overflow clamping operation on 32-bit platforms
PATCH 1/1 hwmon: (sht4x) do not overflow clamping operation on 32-bit platforms
On 32-bit platforms, long is 32 bits, so (long)UINT_MAX is less than (long)SHT4X_MIN_POLL_INTERVAL, which means the clamping operation is bogus. Fix this by clamping at INT_MAX, so that the upperbound is the same on all platforms.
Signed-off-by Jason A. Donenfeld <[email protected]>
--- drivers/hwmon/sht4x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/sht4x.c +1 -1
@@ -129,7 +129,7 @@ static int sht4x_read_values(struct sht4x_data *data)static ssize_t sht4x_interval_write (struct sht4x_data *data,long val) { - data->update_interval =clamp_val (val,SHT4X_MIN_POLL_INTERVAL ,UINT_MAX ); + data->update_interval =clamp_val (val,SHT4X_MIN_POLL_INTERVAL ,INT_MAX );return 0 ; }
Signature · 1 line
2.37.3
Quoted 6 lines · Jason A. Donenfeld
On 32-bit platforms, long is 32 bits, so (long)UINT_MAX is less than (long)SHT4X_MIN_POLL_INTERVAL, which means the clamping operation is bogus. Fix this by clamping at
INT_MAX, so that the upperbound is the same on all platforms.Signed-off-by Jason A. Donenfeld <[email protected]>
Applied.
Thanks,
Guenter
Quoted 17 lines
--- drivers/hwmon/sht4x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/hwmon/sht4x.c +1
-1@@ -129,7 +129,7 @@ static int sht4x_read_values(struct sht4x_data *data)static ssize_t sht4x_interval_write (struct sht4x_data *data,long val) { - data->update_interval =clamp_val (val,SHT4X_MIN_POLL_INTERVAL ,UINT_MAX ); + data->update_interval =clamp_val (val,SHT4X_MIN_POLL_INTERVAL ,INT_MAX );return 0 ; }