Linux IIO development
 help / color / mirror / Atom feed
* [PATCH] iio: imu: inv_icm42600: fix 64bit multiplication
@ 2025-07-16 19:22 Antonio Quartulli
  2025-07-16 19:36 ` Andy Shevchenko
  2025-07-16 19:38 ` Andy Shevchenko
  0 siblings, 2 replies; 10+ messages in thread
From: Antonio Quartulli @ 2025-07-16 19:22 UTC (permalink / raw)
  To: linux-iio
  Cc: Antonio Quartulli, Jean-Baptiste Maneyrol, Jonathan Cameron,
	David Lechner, Nuno Sá, Andy Shevchenko

In inv_icm42600_accel_convert_wom_to_roc() multiplying
`threshold` by `convert` may result in a number requiring more
than 32bit.
In this case, although `value` is 64bit wide, the result is
truncated because the multiplication is performed in the
32bit domain, due to both operands being 32bit long.

Cast the first operand to u64 to ensure the multiplication is
performed in the expected domain.

Fixes: 50cfaa9a46c8 ("iio: imu: inv_icm42600: add WoM support")
Address-Coverity-ID: 1647596 ("Integer handling issues (OVERFLOW_BEFORE_WIDEN)")
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
 drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
index 7a28051330b7..218bb3eb3dd7 100644
--- a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
+++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
@@ -347,7 +347,7 @@ static u64 inv_icm42600_accel_convert_wom_to_roc(unsigned int threshold,
 	u64 value;
 	u64 freq_uhz;
 
-	value = threshold * convert;
+	value = (u64)threshold * convert;
 	freq_uhz = (u64)accel_hz * MICRO + (u64)accel_uhz;
 
 	/* compute the differential by multiplying by the frequency */
-- 
2.49.1


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

end of thread, other threads:[~2025-07-17 12:52 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-16 19:22 [PATCH] iio: imu: inv_icm42600: fix 64bit multiplication Antonio Quartulli
2025-07-16 19:36 ` Andy Shevchenko
2025-07-16 19:44   ` Antonio Quartulli
2025-07-16 19:52     ` David Lechner
2025-07-16 20:03       ` Antonio Quartulli
2025-07-17  6:21     ` Andy Shevchenko
2025-07-17  7:50       ` Antonio Quartulli
2025-07-17 12:51         ` Andy Shevchenko
2025-07-16 19:38 ` Andy Shevchenko
2025-07-16 19:45   ` Antonio Quartulli

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