]> git.itanic.dy.fi Git - linux-stable/commitdiff
hwmon: (sht4x) do not overflow clamping operation on 32-bit platforms
authorJason A. Donenfeld <Jason@zx2c4.com>
Sat, 24 Sep 2022 10:11:51 +0000 (12:11 +0200)
committerGuenter Roeck <linux@roeck-us.net>
Sun, 25 Sep 2022 21:22:11 +0000 (14:22 -0700)
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 <Jason@zx2c4.com>
Link: https://lore.kernel.org/r/20220924101151.4168414-1-Jason@zx2c4.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/sht4x.c

index c19df3ade48e3023d9d4052fe94af2674e6701d5..13ac2d8f22c79b77817e1faa2a3f6c1090977caf 100644 (file)
@@ -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;
 }