From: sashiko-bot@kernel.org
To: "Srinivas Pandruvada" <srinivas.pandruvada@linux.intel.com>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v2] iio: hid-sensors: fix fractional part for unit exponents -7 and -8
Date: Wed, 04 Nov 2026 17:07:24 +0000 [thread overview]
Message-ID: <sashiko-outbox-197712@kernel.org> (raw)
In-Reply-To: <20261104165319.1890851-1-srinivas.pandruvada@linux.intel.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] iio: hid-sensors: divide by zero in convert_to_vtf_format() for exp < -6
--
commit e56afd4fc65e2d177add5e21d5704d17876c53ec
Author: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
iio: hid-sensors: fix fractional part for unit exponents -7 and -8
This commit fixes split_micro_fraction() so that HID unit exponents of -7 and
-8 divide the remainder by 10^(exp - 6) instead of passing a negative exponent
to int_pow().
> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> index 26f8554d18a57..22d33f8c25f14 100644
> --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> @@ -98,9 +98,14 @@ static void simple_div(int dividend, int divisor, int *whole, int *micro_frac)
> static void split_micro_fraction(unsigned int no, int exp, int *val1, int *val2)
> {
> int divisor = int_pow(10, exp);
> + unsigned int rem;
>
> *val1 = no / divisor;
> - *val2 = no % divisor * int_pow(10, 6 - exp);
> + rem = no % divisor;
> + if (exp > 6)
> + *val2 = rem / (unsigned int)int_pow(10, exp - 6);
> + else
> + *val2 = rem * int_pow(10, 6 - exp);
> }
[Severity: High]
As reported by Sashiko on v1 [1], the commit message notes that dividing by
10^(exp - 6) in split_micro_fraction() matches the reverse conversion in
convert_to_vtf_format(), but does convert_to_vtf_format() also need a similar
fix for unit exponents -7 and -8?
In drivers/iio/common/hid-sensors/hid-sensor-attributes.c:
static u32 convert_to_vtf_format(int size, int exp, int val1, int val2)
{
...
exp = hid_sensor_convert_exponent(exp);
if (exp < 0) {
divisor = int_pow(10, 6 + exp);
value = abs(val1) * int_pow(10, -exp);
value += abs(val2) / divisor;
}
...
}
When hid_sensor_write_raw_hyst_value() or
hid_sensor_write_raw_hyst_rel_value() calls convert_to_vtf_format() with a
unit exponent of -7 or -8, 6 + exp is -1 or -2. Because the second parameter
of int_pow() is unsigned, int_pow(10, 6 + exp) overflows to 0 modulo 2^64,
causing abs(val2) / divisor to divide by zero in the kernel.
Should convert_to_vtf_format() multiply abs(val2) by int_pow(10, -6 - exp)
when exp < -6 instead of dividing?
[1] https://lore.kernel.org/r/20261102222309.439895-1-srinivas.pandruvada@linux.intel.com
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261104165319.1890851-1-srinivas.pandruvada@linux.intel.com?part=1
next prev parent reply other threads:[~2026-11-04 17:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 16:53 [PATCH v2] iio: hid-sensors: fix fractional part for unit exponents -7 and -8 Srinivas Pandruvada
2026-11-04 17:07 ` sashiko-bot [this message]
2026-11-04 18:26 ` srinivas pandruvada
2026-11-05 19:26 ` Семён Марьясин
2026-11-05 23:56 ` Srinivas Pandruvada
2026-11-07 20:38 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-197712@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=srinivas.pandruvada@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox