From: "Kurt Borja" <kuurtb@gmail.com>
To: "Chunyang Chen" <chenchunyang0908@gmail.com>, <kuurtb@gmail.com>,
<jic23@kernel.org>
Cc: <dlechner@baylibre.com>, <nuno.sa@analog.com>, <andy@kernel.org>,
<linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] iio: adc: ti-ads1018: fix type overflow for data rate
Date: Wed, 04 Mar 2026 23:36:59 -0300 [thread overview]
Message-ID: <DGUHZFW5IACK.1JUICZ99ILHKG@gmail.com> (raw)
In-Reply-To: <20260305021550.120614-1-chenchunyang0908@gmail.com>
Hi Chunyang,
On Wed Mar 4, 2026 at 11:15 PM -03, Chunyang Chen wrote:
> The variable 'drate' is currently defined as u8. However, the data rate
> values in ads1018 can reach up to 3300 Hz (e.g., in ads1018_data_rate[]),
> which exceeds the maximum value of 255 that a u8 can hold.
>
> Change the type of 'drate' to u16 to prevent integer overflow and
> ensure the data rate is handled correctly.
Good catch -- thanks!
Interestingly, my SPI controller has so much latency that I didn't catch
this while developing :/
>
> Signed-off-by: Chunyang Chen <chenchunyang0908@gmail.com>
> ---
> drivers/iio/adc/ti-ads1018.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/adc/ti-ads1018.c b/drivers/iio/adc/ti-ads1018.c
> index 6246b3cab..049b8c00f 100644
> --- a/drivers/iio/adc/ti-ads1018.c
> +++ b/drivers/iio/adc/ti-ads1018.c
> @@ -249,7 +249,7 @@ static int ads1018_single_shot(struct ads1018 *ads1018,
> struct iio_chan_spec const *chan, u16 *cnv)
> {
> u8 max_drate_mode = ads1018->chip_info->num_data_rate_mode_to_hz - 1;
> - u8 drate = ads1018->chip_info->data_rate_mode_to_hz[max_drate_mode];
> + u16 drate = ads1018->chip_info->data_rate_mode_to_hz[max_drate_mode];
data_rate_mode_to_hz[] is u32 so I prefer for this to be u32. This also
kinda matches ads1018_calc_delay() which takes unsigned int.
I'm a bit disturbed by the type inconsistency here...
> u8 pga_mode = ads1018->chan_data[chan->scan_index].pga_mode;
> struct spi_transfer xfer[2] = {
> {
--
Thanks,
~ Kurt
next prev parent reply other threads:[~2026-03-05 2:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-05 2:15 [PATCH] iio: adc: ti-ads1018: fix type overflow for data rate Chunyang Chen
2026-03-05 2:36 ` Kurt Borja [this message]
2026-03-05 7:07 ` Andy Shevchenko
2026-03-05 12:46 ` Chunyang Chen
2026-03-05 12:43 ` [PATCH v2] " Chunyang Chen
2026-03-05 13:12 ` Kurt Borja
2026-03-06 12:08 ` Andy Shevchenko
2026-03-07 12:15 ` Jonathan Cameron
2026-03-07 13:18 ` Jonathan Cameron
2026-03-09 3:20 ` Chunyang Chen
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=DGUHZFW5IACK.1JUICZ99ILHKG@gmail.com \
--to=kuurtb@gmail.com \
--cc=andy@kernel.org \
--cc=chenchunyang0908@gmail.com \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.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