Skip to content

Commit

Permalink
hwmon: (sht4x) do not overflow clamping operation on 32-bit platforms
Browse files Browse the repository at this point in the history
[ Upstream commit f9c0cf8 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
zx2c4 authored and gregkh committed Oct 21, 2022
1 parent 6874b7b commit eeef147
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/hwmon/sht4x.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit eeef147

Please sign in to comment.