Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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")
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Link: https://lore.kernel.org/r/20210329205817.GA188755@embeddedor
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Gustavo A. R. Silva and committed by
Jonathan Cameron
c10f8109 4d84487d

+1 -1
+1 -1
drivers/iio/trigger/iio-trig-hrtimer.c
··· 63 63 if (integer < 0 || fract < 0) 64 64 return -ERANGE; 65 65 66 - val = fract + 1000 * integer; /* mHz */ 66 + val = fract + 1000ULL * integer; /* mHz */ 67 67 68 68 if (!val || val > UINT_MAX) 69 69 return -EINVAL;