All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Radu Sabau" <radu.sabau@analog.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v4 5/8] iio: imu: Add driver for the ADI ADIS16607
Date: Fri, 23 Oct 2026 09:47:11 +0000	[thread overview]
Message-ID: <sashiko-outbox-182632@kernel.org> (raw)
In-Reply-To: <20261023-adis16607-v4-5-a4d541ebfd13@analog.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] iio: imu: adis16607: negative frequency wraparound in adis16607_write_raw()
--

commit 686b8ffae8bb8850532fb9fd2ba72d9f11184ab1
Author: Radu Sabau <radu.sabau@analog.com>

iio: imu: Add driver for the ADI ADIS16607

This commit adds the base IIO driver for the Analog Devices ADIS16607-2
and ADIS16607-3 precision MEMS IMUs over a custom SPI Half-Duplex
protocol. It provides support for raw channel reads, sampling frequency
control, startup/self-test via adislib, and debugfs identity entries.

> diff --git a/drivers/iio/imu/adis16607.c b/drivers/iio/imu/adis16607.c
> new file mode 100644
> index 0000000000000..2dda306d7b547
> --- /dev/null
> +++ b/drivers/iio/imu/adis16607.c
[ ... ]
> +static int adis16607_set_freq(struct adis16607 *st, u32 freq)
> +{
> +	u32 dec;
> +	int ret;
> +
> +	if (!freq)
> +		return -EINVAL;
> +
> +	adis_dev_auto_lock(&st->adis);
> +
> +	dec = DIV_ROUND_CLOSEST(st->clk_freq_mhz, freq);
> +	if (dec)
> +		dec--;
> +
> +	dec = min_t(u32, dec, st->info->max_dec);
> +
> +	ret = __adis_write_reg_16(&st->adis, ADIS16607_REG_DEC_RATE, dec);
> +	if (ret)
> +		return ret;
> +
> +	st->sample_period_ns = DIV_ROUND_CLOSEST_ULL((u64)NSEC_PER_SEC * 1000ULL * (dec + 1),
> +						     st->clk_freq_mhz);
> +
> +	return 0;
> +}
[ ... ]
> +static int adis16607_write_raw(struct iio_dev *indio_dev,
> +			       const struct iio_chan_spec *chan,
> +			       int val, int val2, long info)
> +{
> +	struct adis16607 *st = iio_priv(indio_dev);
> +	u32 tmp;
> +
> +	switch (info) {
> +	case IIO_CHAN_INFO_SAMP_FREQ:
> +		tmp = val * 1000 + val2 / 1000;
> +		return adis16607_set_freq(st, tmp);

[Severity: Medium]
What happens in adis16607_write_raw() if userspace writes a negative
sampling frequency via sysfs?

In drivers/iio/industrialio-core.c, iio_write_channel_info() parses the
input string through __iio_str_to_fixpoint(), which accepts a leading '-'
sign and passes signed negative val or val2 values into write_raw().

Without checking if (val < 0 || val2 < 0) return -EINVAL; (like
adis16480_set_freq() does in drivers/iio/imu/adis16480.c), computing
val * 1000 + val2 / 1000 and assigning a negative result to u32 tmp wraps
around to a large unsigned value.

When that wrapped value is passed to adis16607_set_freq(), it bypasses the
if (!freq) check, DIV_ROUND_CLOSEST(st->clk_freq_mhz, freq) evaluates to 0,
and __adis_write_reg_16() programs ADIS16607_REG_DEC_RATE to 0 (the maximum
8 kHz rate) instead of rejecting the invalid input. Also, if val >
INT_MAX / 1000, val * 1000 overflows signed 32-bit arithmetic.

Should adis16607_write_raw() validate that val and val2 are non-negative
and within bounds before computing tmp?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261023-adis16607-v4-0-a4d541ebfd13@analog.com?part=5

  reply	other threads:[~2026-10-23  9:47 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-23  9:30 [PATCH v4 0/8] iio: imu: Add support for the ADI ADIS16607 Radu Sabau via B4 Relay
2026-10-23  9:30 ` Radu Sabau
2026-10-23  9:30 ` [PATCH v4 1/8] iio: imu: adis: Add optional self_test callback Radu Sabau via B4 Relay
2026-10-23  9:30   ` Radu Sabau
2026-10-30 14:06   ` Nuno Sá
2026-10-23  9:30 ` [PATCH v4 2/8] iio: imu: adis: Fix custom reset dispatch in adislib Radu Sabau via B4 Relay
2026-10-23  9:30   ` Radu Sabau
2026-10-30 14:06   ` Nuno Sá
2026-10-23  9:30 ` [PATCH v4 3/8] iio: imu: adis: Add optional post_reset_setup callback Radu Sabau via B4 Relay
2026-10-23  9:30   ` Radu Sabau
2026-10-25 23:52   ` Jonathan Cameron
2026-10-26  9:52     ` Sabau, Radu bogdan
2026-10-23  9:30 ` [PATCH v4 4/8] dt-bindings: iio: imu: Add bindings for ADI ADIS16607 Radu Sabau via B4 Relay
2026-10-23  9:30   ` Radu Sabau
2026-10-25 23:54   ` Jonathan Cameron
2026-10-23  9:30 ` [PATCH v4 5/8] iio: imu: Add driver for the " Radu Sabau via B4 Relay
2026-10-23  9:30   ` Radu Sabau
2026-10-23  9:47   ` sashiko-bot [this message]
2026-10-23 10:26   ` Andy Shevchenko
2026-10-26 10:22     ` Sabau, Radu bogdan
2026-10-26 10:50       ` Andy Shevchenko
2026-10-30 14:06   ` Nuno Sá
2026-10-23  9:30 ` [PATCH v4 6/8] iio: imu: adis16607: Add FIFO-based buffered/triggered capture Radu Sabau via B4 Relay
2026-10-23  9:30   ` Radu Sabau
2026-10-23  9:53   ` sashiko-bot
2026-10-26  0:09   ` Jonathan Cameron
2026-10-27  9:36     ` Sabau, Radu bogdan
2026-10-30 14:06   ` Nuno Sá
2026-10-23  9:30 ` [PATCH v4 7/8] iio: imu: adis16607: Add external clock sync support Radu Sabau via B4 Relay
2026-10-23  9:30   ` Radu Sabau
2026-10-26  0:11   ` Jonathan Cameron
2026-10-26 10:54     ` Sabau, Radu bogdan
2026-10-30 14:06   ` Nuno Sá
2026-10-23  9:30 ` [PATCH v4 8/8] iio: imu: adis16607: Add calibration bias support for gyro/accel Radu Sabau via B4 Relay
2026-10-23  9:30   ` Radu Sabau
2026-10-26  0:15   ` 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-182632@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=radu.sabau@analog.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.