* [PATCH v2] iio: adc: ad_sigma_delta: Fix use of uninitialized status_pos
@ 2025-04-10 17:04 Purva Yeshi
2025-04-12 17:00 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Purva Yeshi @ 2025-04-10 17:04 UTC (permalink / raw)
To: lars, Michael.Hennerich, jic23; +Cc: linux-iio, linux-kernel, Purva Yeshi
Fix Smatch-detected issue:
drivers/iio/adc/ad_sigma_delta.c:604 ad_sd_trigger_handler() error:
uninitialized symbol 'status_pos'.
The variable `status_pos` was only initialized in specific switch cases
(1, 2, 3, 4), which could leave it uninitialized if `reg_size` had an
unexpected value.
Fix by adding a default case to the switch block to catch unexpected
values of `reg_size`. Use `dev_err_ratelimited()` for error logging and
`goto irq_handled` instead of returning early.
Signed-off-by: Purva Yeshi <purvayeshi550@gmail.com>
---
V1 - https://lore.kernel.org/all/20250409200151.201327-1-purvayeshi550@gmail.com/
V2 - Moved the reg_size validation inside the switch statement using a default case,
replaced dev_err() with dev_err_ratelimited(), and replaced return IRQ_HANDLED
with goto irq_handled;
drivers/iio/adc/ad_sigma_delta.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index 6c37f8e21120..4c5f8d29a559 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -587,6 +587,10 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
* byte set to zero. */
ad_sd_read_reg_raw(sigma_delta, data_reg, transfer_size, &data[1]);
break;
+
+ default:
+ dev_err_ratelimited(&indio_dev->dev, "Unsupported reg_size: %u\n", reg_size);
+ goto irq_handled;
}
/*
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] iio: adc: ad_sigma_delta: Fix use of uninitialized status_pos
2025-04-10 17:04 [PATCH v2] iio: adc: ad_sigma_delta: Fix use of uninitialized status_pos Purva Yeshi
@ 2025-04-12 17:00 ` Jonathan Cameron
2025-04-17 5:48 ` Purva Yeshi
0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2025-04-12 17:00 UTC (permalink / raw)
To: Purva Yeshi; +Cc: lars, Michael.Hennerich, linux-iio, linux-kernel
On Thu, 10 Apr 2025 22:34:08 +0530
Purva Yeshi <purvayeshi550@gmail.com> wrote:
> Fix Smatch-detected issue:
> drivers/iio/adc/ad_sigma_delta.c:604 ad_sd_trigger_handler() error:
> uninitialized symbol 'status_pos'.
>
> The variable `status_pos` was only initialized in specific switch cases
> (1, 2, 3, 4), which could leave it uninitialized if `reg_size` had an
> unexpected value.
>
> Fix by adding a default case to the switch block to catch unexpected
> values of `reg_size`. Use `dev_err_ratelimited()` for error logging and
> `goto irq_handled` instead of returning early.
>
> Signed-off-by: Purva Yeshi <purvayeshi550@gmail.com>
Seems like reasonable hardening of the code.
Applied.
Thanks,
> ---
> V1 - https://lore.kernel.org/all/20250409200151.201327-1-purvayeshi550@gmail.com/
> V2 - Moved the reg_size validation inside the switch statement using a default case,
> replaced dev_err() with dev_err_ratelimited(), and replaced return IRQ_HANDLED
> with goto irq_handled;
>
> drivers/iio/adc/ad_sigma_delta.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
> index 6c37f8e21120..4c5f8d29a559 100644
> --- a/drivers/iio/adc/ad_sigma_delta.c
> +++ b/drivers/iio/adc/ad_sigma_delta.c
> @@ -587,6 +587,10 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
> * byte set to zero. */
> ad_sd_read_reg_raw(sigma_delta, data_reg, transfer_size, &data[1]);
> break;
> +
> + default:
> + dev_err_ratelimited(&indio_dev->dev, "Unsupported reg_size: %u\n", reg_size);
> + goto irq_handled;
> }
>
> /*
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] iio: adc: ad_sigma_delta: Fix use of uninitialized status_pos
2025-04-12 17:00 ` Jonathan Cameron
@ 2025-04-17 5:48 ` Purva Yeshi
0 siblings, 0 replies; 3+ messages in thread
From: Purva Yeshi @ 2025-04-17 5:48 UTC (permalink / raw)
To: Jonathan Cameron; +Cc: lars, Michael.Hennerich, linux-iio, linux-kernel
On 12/04/25 22:30, Jonathan Cameron wrote:
> On Thu, 10 Apr 2025 22:34:08 +0530
> Purva Yeshi <purvayeshi550@gmail.com> wrote:
>
>> Fix Smatch-detected issue:
>> drivers/iio/adc/ad_sigma_delta.c:604 ad_sd_trigger_handler() error:
>> uninitialized symbol 'status_pos'.
>>
>> The variable `status_pos` was only initialized in specific switch cases
>> (1, 2, 3, 4), which could leave it uninitialized if `reg_size` had an
>> unexpected value.
>>
>> Fix by adding a default case to the switch block to catch unexpected
>> values of `reg_size`. Use `dev_err_ratelimited()` for error logging and
>> `goto irq_handled` instead of returning early.
>>
>> Signed-off-by: Purva Yeshi <purvayeshi550@gmail.com>
> Seems like reasonable hardening of the code.
>
> Applied.
>
> Thanks,
Hi Jonathan,
Thank you for reviewing and applying the patch.
>
>> ---
>> V1 - https://lore.kernel.org/all/20250409200151.201327-1-purvayeshi550@gmail.com/
>> V2 - Moved the reg_size validation inside the switch statement using a default case,
>> replaced dev_err() with dev_err_ratelimited(), and replaced return IRQ_HANDLED
>> with goto irq_handled;
>>
>> drivers/iio/adc/ad_sigma_delta.c | 4 ++++
>> 1 file changed, 4 insertions(+)
>>
>> diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
>> index 6c37f8e21120..4c5f8d29a559 100644
>> --- a/drivers/iio/adc/ad_sigma_delta.c
>> +++ b/drivers/iio/adc/ad_sigma_delta.c
>> @@ -587,6 +587,10 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
>> * byte set to zero. */
>> ad_sd_read_reg_raw(sigma_delta, data_reg, transfer_size, &data[1]);
>> break;
>> +
>> + default:
>> + dev_err_ratelimited(&indio_dev->dev, "Unsupported reg_size: %u\n", reg_size);
>> + goto irq_handled;
>> }
>>
>> /*
>
Best regards,
Purva
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-04-17 5:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-10 17:04 [PATCH v2] iio: adc: ad_sigma_delta: Fix use of uninitialized status_pos Purva Yeshi
2025-04-12 17:00 ` Jonathan Cameron
2025-04-17 5:48 ` Purva Yeshi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox