Linux Hardware Monitor development
 help / color / mirror / Atom feed
* [PATCH] hwmon: (sht4x) do not overflow clamping operation on 32-bit platforms
@ 2022-09-24 10:11 Jason A. Donenfeld
  2022-09-24 14:31 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Jason A. Donenfeld @ 2022-09-24 10:11 UTC (permalink / raw)
  To: jdelvare, linux, linux-hwmon, davidm, navin, keescook; +Cc: 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 <Jason@zx2c4.com>
---
 drivers/hwmon/sht4x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwmon/sht4x.c b/drivers/hwmon/sht4x.c
index c19df3ade48e..13ac2d8f22c7 100644
--- a/drivers/hwmon/sht4x.c
+++ b/drivers/hwmon/sht4x.c
@@ -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;
 }
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] hwmon: (sht4x) do not overflow clamping operation on 32-bit platforms
  2022-09-24 10:11 [PATCH] hwmon: (sht4x) do not overflow clamping operation on 32-bit platforms Jason A. Donenfeld
@ 2022-09-24 14:31 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2022-09-24 14:31 UTC (permalink / raw)
  To: Jason A. Donenfeld; +Cc: jdelvare, linux-hwmon, davidm, navin, keescook

On Sat, Sep 24, 2022 at 12:11:51PM +0200, Jason A. Donenfeld wrote:
> 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>

Applied.

Thanks,
Guenter

> ---
>  drivers/hwmon/sht4x.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/sht4x.c b/drivers/hwmon/sht4x.c
> index c19df3ade48e..13ac2d8f22c7 100644
> --- a/drivers/hwmon/sht4x.c
> +++ b/drivers/hwmon/sht4x.c
> @@ -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;
>  }

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-24 14:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-24 10:11 [PATCH] hwmon: (sht4x) do not overflow clamping operation on 32-bit platforms Jason A. Donenfeld
2022-09-24 14:31 ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox