Skip to contentSkip to conversation

iio: hrtimer-trigger: Fix potential integer overflow in iio_hrtimer_store_sampling_frequency

PATCH In review Gustavo A. R. Silva 3 participants 3 messages Mar 29, 2021 – Apr 6, 2021 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: hrtimer-trigger: Fix potential integer overflow in iio_hrtimer_store_sampling_frequency

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")
---
 drivers/iio/trigger/iio-trig-hrtimer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/trigger/iio-trig-hrtimer.c +1 -1
index 51e362f091c2..716c795d08fb 100644
@@ -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;
Signature · 1 line
2.27.0
maintainer
#1 lore raw
Quoted 9 lines · On Mon, 29 Mar 2021 15:58:17 -0500 "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")

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

Thanks,

Jonathan

Quoted 17 lines
---
 drivers/iio/trigger/iio-trig-hrtimer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/trigger/iio-trig-hrtimer.c +1 -1
index 51e362f091c2..716c795d08fb 100644
@@ -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 lore raw
Quoted 9 lines · Jonathan Cameron
Quoted 6 lines · On Mon, 29 Mar 2021 15:58:17 -0500 "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.

Quoted 6 lines
Quoted 3 lines

Addresses-Coverity-ID: 1503062 ("Unintentional integer overflow")

Fixes dafcf4ed8392 ("iio: hrtimer: Allow sub Hz granularity")

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