linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] iio: hrtimer-trigger: Fix potential integer overflow in iio_hrtimer_store_sampling_frequency
@ 2021-03-29 20:58 Gustavo A. R. Silva
  2021-04-05 16:26 ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Gustavo A. R. Silva @ 2021-03-29 20:58 UTC (permalink / raw)
  To: Jonathan Cameron, Lars-Peter Clausen
  Cc: linux-iio, linux-kernel, Gustavo A. R. Silva

Add suffix ULL to constant 1000 in order to avoid a potential integer
overflow and give the compiler complete information about the proper
arithmetic to use. Notice that this constant is being used in a context
that expects an expression of type unsigned long long, but it's
currently evaluated using 32-bit arithmetic.

Addresses-Coverity-ID: 1503062 ("Unintentional integer overflow")
Fixes: dafcf4ed8392 ("iio: hrtimer: Allow sub Hz granularity")
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 drivers/iio/trigger/iio-trig-hrtimer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/trigger/iio-trig-hrtimer.c b/drivers/iio/trigger/iio-trig-hrtimer.c
index 51e362f091c2..716c795d08fb 100644
--- a/drivers/iio/trigger/iio-trig-hrtimer.c
+++ b/drivers/iio/trigger/iio-trig-hrtimer.c
@@ -63,7 +63,7 @@ ssize_t iio_hrtimer_store_sampling_frequency(struct device *dev,
 	if (integer < 0 || fract < 0)
 		return -ERANGE;
 
-	val = fract + 1000 * integer;  /* mHz */
+	val = fract + 1000ULL * integer;  /* mHz */
 
 	if (!val || val > UINT_MAX)
 		return -EINVAL;
-- 
2.27.0


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

* Re: [PATCH][next] iio: hrtimer-trigger: Fix potential integer overflow in iio_hrtimer_store_sampling_frequency
  2021-03-29 20:58 [PATCH][next] iio: hrtimer-trigger: Fix potential integer overflow in iio_hrtimer_store_sampling_frequency Gustavo A. R. Silva
@ 2021-04-05 16:26 ` Jonathan Cameron
  2021-04-06 10:13   ` Gustavo A. R. Silva
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2021-04-05 16:26 UTC (permalink / raw)
  To: Gustavo A. R. Silva; +Cc: Lars-Peter Clausen, linux-iio, linux-kernel

On Mon, 29 Mar 2021 15:58:17 -0500
"Gustavo A. R. Silva" <gustavoars@kernel.org> wrote:

> Add suffix ULL to constant 1000 in order to avoid a potential integer
> overflow and give the compiler complete information about the proper
> arithmetic to use. Notice that this constant is being used in a context
> that expects an expression of type unsigned long long, but it's
> currently evaluated using 32-bit arithmetic.
> 
> Addresses-Coverity-ID: 1503062 ("Unintentional integer overflow")
> Fixes: dafcf4ed8392 ("iio: hrtimer: Allow sub Hz granularity")
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks, Applied to the togreg branch of iio.git and pushed out as testing
for 0-day to poke at it.

Thanks,

Jonathan

> ---
>  drivers/iio/trigger/iio-trig-hrtimer.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/trigger/iio-trig-hrtimer.c b/drivers/iio/trigger/iio-trig-hrtimer.c
> index 51e362f091c2..716c795d08fb 100644
> --- a/drivers/iio/trigger/iio-trig-hrtimer.c
> +++ b/drivers/iio/trigger/iio-trig-hrtimer.c
> @@ -63,7 +63,7 @@ ssize_t iio_hrtimer_store_sampling_frequency(struct device *dev,
>  	if (integer < 0 || fract < 0)
>  		return -ERANGE;
>  
> -	val = fract + 1000 * integer;  /* mHz */
> +	val = fract + 1000ULL * integer;  /* mHz */
>  
>  	if (!val || val > UINT_MAX)
>  		return -EINVAL;


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

* Re: [PATCH][next] iio: hrtimer-trigger: Fix potential integer overflow in iio_hrtimer_store_sampling_frequency
  2021-04-05 16:26 ` Jonathan Cameron
@ 2021-04-06 10:13   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2021-04-06 10:13 UTC (permalink / raw)
  To: Jonathan Cameron, Gustavo A. R. Silva
  Cc: Lars-Peter Clausen, linux-iio, linux-kernel



On 4/5/21 11:26, Jonathan Cameron wrote:
> On Mon, 29 Mar 2021 15:58:17 -0500
> "Gustavo A. R. Silva" <gustavoars@kernel.org> wrote:
> 
>> Add suffix ULL to constant 1000 in order to avoid a potential integer
>> overflow and give the compiler complete information about the proper
>> arithmetic to use. Notice that this constant is being used in a context
>> that expects an expression of type unsigned long long, but it's
>> currently evaluated using 32-bit arithmetic.
>>
>> Addresses-Coverity-ID: 1503062 ("Unintentional integer overflow")
>> Fixes: dafcf4ed8392 ("iio: hrtimer: Allow sub Hz granularity")
>> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> 
> Thanks, Applied to the togreg branch of iio.git and pushed out as testing
> for 0-day to poke at it.

Awesome. :)

Thanks, Jonathan.

--
Gustavo

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

end of thread, other threads:[~2021-04-06 10:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-29 20:58 [PATCH][next] iio: hrtimer-trigger: Fix potential integer overflow in iio_hrtimer_store_sampling_frequency Gustavo A. R. Silva
2021-04-05 16:26 ` Jonathan Cameron
2021-04-06 10:13   ` Gustavo A. R. Silva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).