Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: jdelvare@suse.com, linux-hwmon@vger.kernel.org,
	davidm@egauge.net, navin@linumiz.com, keescook@chromium.org
Subject: Re: [PATCH] hwmon: (sht4x) do not overflow clamping operation on 32-bit platforms
Date: Sat, 24 Sep 2022 07:31:44 -0700	[thread overview]
Message-ID: <20220924143144.GA2299435@roeck-us.net> (raw)
In-Reply-To: <20220924101151.4168414-1-Jason@zx2c4.com>

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;
>  }

      reply	other threads:[~2022-09-24 14:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220924143144.GA2299435@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=Jason@zx2c4.com \
    --cc=davidm@egauge.net \
    --cc=jdelvare@suse.com \
    --cc=keescook@chromium.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=navin@linumiz.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox