From: Jonathan Cameron <jic23@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Josef Bacik" <josef@toxicpanda.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
stable <stable@kernel.org>, "Jyoti Bhayana" <jbhayana@google.com>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>
Subject: Re: [PATCH 14/15] iio: scmi: use 64-bit divisions for rates and intervals
Date: Wed, 28 Oct 2026 01:46:26 +0000 [thread overview]
Message-ID: <20261028014626.4187905f@jic23-hlaptop> (raw)
In-Reply-To: <20261027-llm-char-misc-iio-v1-14-0d818334f6c7@linuxfoundation.org>
On Tue, 27 Oct 2026 17:19:18 +0100
Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote:
> From: Josef Bacik <josef@toxicpanda.com>
>
> do_div() only uses the low 32 bits of its divisor. Two divisors in this
> driver need more:
>
> - scmi_iio_set_odr_val() divides by the requested sampling frequency in
> micro-Hertz, which exceeds 32 bits from 4295 Hz on. The update interval
> sent to the firmware is then computed from the wrong frequency.
> - convert_ns_to_freq() divides by the update interval in nanoseconds, which
> exceeds 32 bits from 4.3 seconds on. The sampling frequency and the list
> of available frequencies of a slow sensor are reported wrong.
>
> Use div64_u64(). A requested frequency of 0, which was a division by zero,
> is refused with -EINVAL like other values that cannot be represented.
>
> Fixes: f774117c96f9 ("iio/scmi: Adding support for IIO SCMI Based Sensors")
> Cc: stable <stable@kernel.org>
> Cc: Jyoti Bhayana <jbhayana@google.com>
> Cc: David Lechner <dlechner@baylibre.com>
> Cc: "Nuno Sá" <nuno.sa@analog.com>
> Cc: Andy Shevchenko <andy@kernel.org>
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
We have some other fixes in this area. They don't completely overlap
though much of the content does match.
https://lore.kernel.org/all/20261006045244.13993-1-kapoorarnav43@gmail.com/
> ---
> drivers/iio/common/scmi_sensors/scmi_iio.c | 12 ++++--------
> 1 file changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/iio/common/scmi_sensors/scmi_iio.c b/drivers/iio/common/scmi_sensors/scmi_iio.c
> index 442b40ef27cf..0e51e9c16b90 100644
> --- a/drivers/iio/common/scmi_sensors/scmi_iio.c
> +++ b/drivers/iio/common/scmi_sensors/scmi_iio.c
> @@ -161,8 +161,7 @@ static int scmi_iio_set_odr_val(struct iio_dev *iio_dev, int val, int val2)
> do_div(sf, MICROHZ_PER_HZ);
> mult = scnprintf(buf, sizeof(buf), "%llu", sf) - 1;
>
> - sec = int_pow(10, mult) * MICROHZ_PER_HZ;
> - do_div(sec, uHz);
> + sec = uHz ? div64_u64(int_pow(10, mult) * MICROHZ_PER_HZ, uHz) : 0;
> if (sec == 0) {
> dev_err(&iio_dev->dev,
> "Trying to set invalid sensor update value for sensor %s",
> @@ -237,13 +236,10 @@ static int scmi_iio_read_avail(struct iio_dev *iio_dev,
>
> static void convert_ns_to_freq(u64 interval_ns, u64 *hz, u64 *uhz)
> {
> - u64 rem, freq;
> + u64 rem;
>
> - freq = NSEC_PER_SEC;
> - rem = do_div(freq, interval_ns);
> - *hz = freq;
> - *uhz = rem * 1000000UL;
> - do_div(*uhz, interval_ns);
> + *hz = div64_u64_rem(NSEC_PER_SEC, interval_ns, &rem);
> + *uhz = div64_u64(rem * 1000000UL, interval_ns);
> }
>
> static int scmi_iio_get_odr_val(struct iio_dev *iio_dev, int *val, int *val2)
>
next prev parent reply other threads:[~2026-10-28 1:46 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-27 16:19 [PATCH 00/15] IIO: a bunch of llm-found fixes Greg Kroah-Hartman
2026-10-27 16:19 ` [PATCH 01/15] iio: buffer: let the block keep its DMA fence Greg Kroah-Hartman
2026-10-28 9:30 ` Nuno Sá
2026-10-27 16:19 ` [PATCH 02/15] iio: trigger: fail the attach if no sub-IRQ is left Greg Kroah-Hartman
2026-10-28 9:38 ` Nuno Sá
2026-10-27 16:19 ` [PATCH 03/15] iio: accel: adxl367: don't stay in standby on -EINVAL Greg Kroah-Hartman
2026-10-28 10:01 ` Nuno Sá
2026-10-27 16:19 ` [PATCH 04/15] iio: accel: adxl380: " Greg Kroah-Hartman
2026-10-28 10:02 ` Nuno Sá
2026-10-27 16:19 ` [PATCH 05/15] iio: adc: check the result of ad_sd_init() Greg Kroah-Hartman
2026-10-28 9:40 ` Nuno Sá
2026-10-27 16:19 ` [PATCH 06/15] iio: adc: ad7923: add the AD7927 to the SPI ID table Greg Kroah-Hartman
2026-10-28 9:35 ` Nuno Sá
2026-10-27 16:19 ` [PATCH 07/15] iio: addac: ad74413r: fix the values of set_multiple Greg Kroah-Hartman
2026-10-28 9:38 ` Nuno Sá
2026-10-27 16:19 ` [PATCH 08/15] iio: light: apds9306: push events to the IIO device Greg Kroah-Hartman
2026-10-27 16:19 ` [PATCH 09/15] iio: light: tsl2591: don't divide by zero in the dark Greg Kroah-Hartman
2026-10-27 16:19 ` [PATCH 10/15] iio: light: tsl2591: don't divide by zero with low gain Greg Kroah-Hartman
2026-10-28 2:13 ` Jonathan Cameron
2026-10-28 4:16 ` Greg Kroah-Hartman
2026-10-27 16:19 ` [PATCH 11/15] iio: hid-sensors: fix a division by zero Greg Kroah-Hartman
2026-10-27 16:19 ` [PATCH 12/15] iio: imu: inv_mpu6050: don't disable the IRQ under lock Greg Kroah-Hartman
2026-10-27 16:19 ` [PATCH 13/15] iio: proximity: sx9500: hand on probe deferral of GPIOs Greg Kroah-Hartman
2026-10-28 2:09 ` Jonathan Cameron
2026-10-27 16:19 ` [PATCH 14/15] iio: scmi: use 64-bit divisions for rates and intervals Greg Kroah-Hartman
2026-10-28 1:46 ` Jonathan Cameron [this message]
2026-10-27 16:19 ` [PATCH 15/15] iio: sx9310: use the data of the I2C table Greg Kroah-Hartman
2026-10-27 16:25 ` Biju Das
2026-10-27 16:38 ` Andy Shevchenko
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=20261028014626.4187905f@jic23-hlaptop \
--to=jic23@kernel.org \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=gregkh@linuxfoundation.org \
--cc=jbhayana@google.com \
--cc=josef@toxicpanda.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=stable@kernel.org \
/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
all inboxes | Powered by JetHome®