mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] iio: hid-sensors: fix fractional part for unit exponents -7 and -8
@ 2026-11-02 22:23 Srinivas Pandruvada
  0 siblings, 0 replies; only message in thread
From: Srinivas Pandruvada @ 2026-11-02 22:23 UTC (permalink / raw)
  To: jic23, andy; +Cc: linux-iio, linux-kernel, Srinivas Pandruvada, stable

split_micro_fraction() scales the remainder to micro units by
multiplying it by 10^(6 - exp). The unit exponent of a HID field goes
down to -8, so exp can be 7 or 8 here. Then the argument of int_pow()
is negative, which the unsigned parameter turns into a huge power of
ten: 0 modulo 2^64. As a result, the fractional part of a value read
from the hysteresis attributes is always reported as 0.

Divide by 10^(exp - 6) in these two cases. This matches the reverse
conversion in convert_to_vtf_format().

Fixes: 73c6768b710a ("iio: hid-sensors: Common attribute and trigger")
Cc: stable@vger.kernel.org
Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/common/hid-sensors/hid-sensor-attributes.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index 9e7c26e37880..0e6ea5373434 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
@@ -98,7 +98,10 @@ static void split_micro_fraction(unsigned int no, int exp, int *val1, int *val2)
 	int divisor = int_pow(10, exp);
 
 	*val1 = no / divisor;
-	*val2 = no % divisor * int_pow(10, 6 - exp);
+	if (exp > 6)
+		*val2 = no % divisor / int_pow(10, exp - 6);
+	else
+		*val2 = no % divisor * int_pow(10, 6 - exp);
 }
 
 /*
-- 
2.56.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-02 22:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-02 22:23 [PATCH] iio: hid-sensors: fix fractional part for unit exponents -7 and -8 Srinivas Pandruvada

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

all inboxes | Powered by JetHome®