* [PATCH] iio: adc: ti-ads1018: fix type overflow for data rate
@ 2026-03-05 2:15 Chunyang Chen
2026-03-05 2:36 ` Kurt Borja
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Chunyang Chen @ 2026-03-05 2:15 UTC (permalink / raw)
To: kuurtb, jic23
Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel, Chunyang Chen
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.
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];
u8 pga_mode = ads1018->chan_data[chan->scan_index].pga_mode;
struct spi_transfer xfer[2] = {
{
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] iio: adc: ti-ads1018: fix type overflow for data rate
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
2026-03-05 7:07 ` Andy Shevchenko
2026-03-05 12:43 ` [PATCH v2] " Chunyang Chen
2 siblings, 0 replies; 10+ messages in thread
From: Kurt Borja @ 2026-03-05 2:36 UTC (permalink / raw)
To: Chunyang Chen, kuurtb, jic23
Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] iio: adc: ti-ads1018: fix type overflow for data rate
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
@ 2026-03-05 7:07 ` Andy Shevchenko
2026-03-05 12:46 ` Chunyang Chen
2026-03-05 12:43 ` [PATCH v2] " Chunyang Chen
2 siblings, 1 reply; 10+ messages in thread
From: Andy Shevchenko @ 2026-03-05 7:07 UTC (permalink / raw)
To: Chunyang Chen
Cc: kuurtb, jic23, dlechner, nuno.sa, andy, linux-iio, linux-kernel
On Thu, Mar 05, 2026 at 10:15:50AM +0800, 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.
Needs Fixes tag.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2] iio: adc: ti-ads1018: fix type overflow for data rate
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
2026-03-05 7:07 ` Andy Shevchenko
@ 2026-03-05 12:43 ` Chunyang Chen
2026-03-05 13:12 ` Kurt Borja
` (2 more replies)
2 siblings, 3 replies; 10+ messages in thread
From: Chunyang Chen @ 2026-03-05 12:43 UTC (permalink / raw)
To: kuurtb, jic23
Cc: andriy.shevchenko, dlechner, nuno.sa, andy, linux-iio,
linux-kernel, Chunyang Chen
The variable 'drate' is currently defined as u8. However, the data rate
values in ads1018 can reach up to 3300 Hz, which exceeds the maximum
value of 255 that a u8 can hold.
Change the type of 'drate' to u32 to match the data_rate_mode_to_hz
array definition and ensure the data rate is handled correctly.
Fixes: bf0bba486b5b ("iio: adc: ti-ads1018: add ti-ads1018 driver")
Signed-off-by: Chunyang Chen <chenchunyang0908@gmail.com>
---
v2:
- Change drate type to u32 as suggested by Kurt.
- Add Fixes tag as requested by Andy.
---
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..0780abd0d 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];
+ u32 drate = ads1018->chip_info->data_rate_mode_to_hz[max_drate_mode];
u8 pga_mode = ads1018->chan_data[chan->scan_index].pga_mode;
struct spi_transfer xfer[2] = {
{
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] iio: adc: ti-ads1018: fix type overflow for data rate
2026-03-05 7:07 ` Andy Shevchenko
@ 2026-03-05 12:46 ` Chunyang Chen
0 siblings, 0 replies; 10+ messages in thread
From: Chunyang Chen @ 2026-03-05 12:46 UTC (permalink / raw)
To: Andy Shevchenko
Cc: kuurtb, jic23, dlechner, nuno.sa, andy, linux-iio, linux-kernel
Hi Kurt, Andy,
Thanks for your review and suggestions!
I have sent out the v2 patch, which addresses the following:
On Thu, Mar 5, 2026, Kurt Borja wrote:
> 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.
Changed 'drate' type to u32 to match the array definition and maintain
consistency, as suggested by Kurt.
On Thu, Mar 5, 2026, Andy Shevchenko wrote:
> Needs Fixes tag.
Added the Fixes tag as requested by Andy.
Best regards,
Chunyang Chen
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] iio: adc: ti-ads1018: fix type overflow for data rate
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 13:18 ` Jonathan Cameron
2 siblings, 0 replies; 10+ messages in thread
From: Kurt Borja @ 2026-03-05 13:12 UTC (permalink / raw)
To: Chunyang Chen, kuurtb, jic23
Cc: andriy.shevchenko, dlechner, nuno.sa, andy, linux-iio,
linux-kernel
On Thu Mar 5, 2026 at 9:43 AM -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, which exceeds the maximum
> value of 255 that a u8 can hold.
>
> Change the type of 'drate' to u32 to match the data_rate_mode_to_hz
> array definition and ensure the data rate is handled correctly.
>
> Fixes: bf0bba486b5b ("iio: adc: ti-ads1018: add ti-ads1018 driver")
> Signed-off-by: Chunyang Chen <chenchunyang0908@gmail.com>
Reviewed-by: Kurt Borja <kuurtb@gmail.com>
>
> ---
> v2:
> - Change drate type to u32 as suggested by Kurt.
> - Add Fixes tag as requested by Andy.
> ---
> 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..0780abd0d 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];
> + u32 drate = ads1018->chip_info->data_rate_mode_to_hz[max_drate_mode];
> u8 pga_mode = ads1018->chan_data[chan->scan_index].pga_mode;
> struct spi_transfer xfer[2] = {
> {
--
Thanks,
~ Kurt
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] iio: adc: ti-ads1018: fix type overflow for data rate
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
2 siblings, 1 reply; 10+ messages in thread
From: Andy Shevchenko @ 2026-03-06 12:08 UTC (permalink / raw)
To: Chunyang Chen
Cc: kuurtb, jic23, dlechner, nuno.sa, andy, linux-iio, linux-kernel
On Thu, Mar 05, 2026 at 08:43:02PM +0800, Chunyang Chen wrote:
> The variable 'drate' is currently defined as u8. However, the data rate
> values in ads1018 can reach up to 3300 Hz, which exceeds the maximum
> value of 255 that a u8 can hold.
>
> Change the type of 'drate' to u32 to match the data_rate_mode_to_hz
> array definition and ensure the data rate is handled correctly.
>
> Fixes: bf0bba486b5b ("iio: adc: ti-ads1018: add ti-ads1018 driver")
> Signed-off-by: Chunyang Chen <chenchunyang0908@gmail.com>
New version — new email thread.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] iio: adc: ti-ads1018: fix type overflow for data rate
2026-03-06 12:08 ` Andy Shevchenko
@ 2026-03-07 12:15 ` Jonathan Cameron
0 siblings, 0 replies; 10+ messages in thread
From: Jonathan Cameron @ 2026-03-07 12:15 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Chunyang Chen, kuurtb, dlechner, nuno.sa, andy, linux-iio,
linux-kernel
On Fri, 6 Mar 2026 14:08:15 +0200
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> On Thu, Mar 05, 2026 at 08:43:02PM +0800, Chunyang Chen wrote:
> > The variable 'drate' is currently defined as u8. However, the data rate
> > values in ads1018 can reach up to 3300 Hz, which exceeds the maximum
> > value of 255 that a u8 can hold.
> >
> > Change the type of 'drate' to u32 to match the data_rate_mode_to_hz
> > array definition and ensure the data rate is handled correctly.
> >
> > Fixes: bf0bba486b5b ("iio: adc: ti-ads1018: add ti-ads1018 driver")
> > Signed-off-by: Chunyang Chen <chenchunyang0908@gmail.com>
>
> New version — new email thread.
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
>
Applied to the fixes-togreg branch of iio.git
Thanks,
Jonathan
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] iio: adc: ti-ads1018: fix type overflow for data rate
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 13:18 ` Jonathan Cameron
2026-03-09 3:20 ` Chunyang Chen
2 siblings, 1 reply; 10+ messages in thread
From: Jonathan Cameron @ 2026-03-07 13:18 UTC (permalink / raw)
To: Chunyang Chen
Cc: kuurtb, andriy.shevchenko, dlechner, nuno.sa, andy, linux-iio,
linux-kernel
On Thu, 5 Mar 2026 20:43:02 +0800
Chunyang Chen <chenchunyang0908@gmail.com> wrote:
> The variable 'drate' is currently defined as u8. However, the data rate
> values in ads1018 can reach up to 3300 Hz, which exceeds the maximum
> value of 255 that a u8 can hold.
>
> Change the type of 'drate' to u32 to match the data_rate_mode_to_hz
> array definition and ensure the data rate is handled correctly.
>
> Fixes: bf0bba486b5b ("iio: adc: ti-ads1018: add ti-ads1018 driver")
The patch name in this fixes tag is wrong. I fixed up.
J
> Signed-off-by: Chunyang Chen <chenchunyang0908@gmail.com>
>
> ---
> v2:
> - Change drate type to u32 as suggested by Kurt.
> - Add Fixes tag as requested by Andy.
> ---
> 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..0780abd0d 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];
> + u32 drate = ads1018->chip_info->data_rate_mode_to_hz[max_drate_mode];
> u8 pga_mode = ads1018->chan_data[chan->scan_index].pga_mode;
> struct spi_transfer xfer[2] = {
> {
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] iio: adc: ti-ads1018: fix type overflow for data rate
2026-03-07 13:18 ` Jonathan Cameron
@ 2026-03-09 3:20 ` Chunyang Chen
0 siblings, 0 replies; 10+ messages in thread
From: Chunyang Chen @ 2026-03-09 3:20 UTC (permalink / raw)
To: Jonathan Cameron
Cc: kuurtb, andriy.shevchenko, dlechner, nuno.sa, andy, linux-iio,
linux-kernel
Hi Jonathan, Andy, Kurt,
Thanks for the review and for applying this patch to iio/fixes-togreg!
Also, thanks Jonathan for fixing up the patch name in the Fixes tag.
Best regards,
Chunyang Chen
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-03-09 3:20 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox