Linux IIO development
 help / color / mirror / Atom feed
* [PATCH] iio: adc: ad_sigma_delta: Fix use of uninitialized variable status_pos
@ 2025-04-09 20:01 Purva Yeshi
  2025-04-10 11:09 ` Nuno Sá
  0 siblings, 1 reply; 3+ messages in thread
From: Purva Yeshi @ 2025-04-09 20:01 UTC (permalink / raw)
  To: lars, Michael.Hennerich, jic23; +Cc: linux-iio, linux-kernel, Purva Yeshi

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 1190 bytes --]

Fix Smatch-detected error:
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 validating `reg_size` before the switch block. If it’s not
one of the expected values, return early and log an error. This ensures
`status_pos` is always initialized before use and prevents undefined
behavior.

Signed-off-by: Purva Yeshi <purvayeshi550@gmail.com>
---
 drivers/iio/adc/ad_sigma_delta.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index 6c37f8e21120..d3b59d90b728 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -568,6 +568,11 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
 	else
 		transfer_size = reg_size;
 
+	if (reg_size != 1 && reg_size != 2 && reg_size != 3 && reg_size != 4) {
+		dev_err(&indio_dev->dev, "Unsupported reg_size: %u\n", reg_size);
+		return IRQ_HANDLED;
+	}
+
 	switch (reg_size) {
 	case 4:
 	case 2:
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: adc: ad_sigma_delta: Fix use of uninitialized variable status_pos
  2025-04-09 20:01 [PATCH] iio: adc: ad_sigma_delta: Fix use of uninitialized variable status_pos Purva Yeshi
@ 2025-04-10 11:09 ` Nuno Sá
  2025-04-10 16:58   ` Purva Yeshi
  0 siblings, 1 reply; 3+ messages in thread
From: Nuno Sá @ 2025-04-10 11:09 UTC (permalink / raw)
  To: Purva Yeshi, lars, Michael.Hennerich, jic23; +Cc: linux-iio, linux-kernel

Hi Purva,

Thanks for your patch... See below
On Thu, 2025-04-10 at 01:31 +0530, Purva Yeshi wrote:
> Fix Smatch-detected error:
> 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 validating `reg_size` before the switch block. If it’s not
> one of the expected values, return early and log an error. This ensures
> `status_pos` is always initialized before use and prevents undefined
> behavior.
> 
> Signed-off-by: Purva Yeshi <purvayeshi550@gmail.com>
> ---
>  drivers/iio/adc/ad_sigma_delta.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/iio/adc/ad_sigma_delta.c
> b/drivers/iio/adc/ad_sigma_delta.c
> index 6c37f8e21120..d3b59d90b728 100644
> --- a/drivers/iio/adc/ad_sigma_delta.c
> +++ b/drivers/iio/adc/ad_sigma_delta.c
> @@ -568,6 +568,11 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void
> *p)
>  	else
>  		transfer_size = reg_size;
>  
> +	if (reg_size != 1 && reg_size != 2 && reg_size != 3 && reg_size != 4)
> {
> +		dev_err(&indio_dev->dev, "Unsupported reg_size: %u\n",
> reg_size);
> +		return IRQ_HANDLED;
> +	}
> +

Use the switch case for this. Add a default branch for the invalid case. You
should also use dev_err_ratelimited() and instead of 'return IRQ_HANDLED', do
'goto irq_handled'.

Thx!
- Nuno Sá

>  	switch (reg_size) {
>  	case 4:
>  	case 2:

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: adc: ad_sigma_delta: Fix use of uninitialized variable status_pos
  2025-04-10 11:09 ` Nuno Sá
@ 2025-04-10 16:58   ` Purva Yeshi
  0 siblings, 0 replies; 3+ messages in thread
From: Purva Yeshi @ 2025-04-10 16:58 UTC (permalink / raw)
  To: Nuno Sá, lars, Michael.Hennerich, jic23; +Cc: linux-iio, linux-kernel

On 10/04/25 16:39, Nuno Sá wrote:
> Hi Purva,
> 
> Thanks for your patch... See below
> On Thu, 2025-04-10 at 01:31 +0530, Purva Yeshi wrote:
>> Fix Smatch-detected error:
>> 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 validating `reg_size` before the switch block. If it’s not
>> one of the expected values, return early and log an error. This ensures
>> `status_pos` is always initialized before use and prevents undefined
>> behavior.
>>
>> Signed-off-by: Purva Yeshi <purvayeshi550@gmail.com>
>> ---
>>   drivers/iio/adc/ad_sigma_delta.c | 5 +++++
>>   1 file changed, 5 insertions(+)
>>
>> diff --git a/drivers/iio/adc/ad_sigma_delta.c
>> b/drivers/iio/adc/ad_sigma_delta.c
>> index 6c37f8e21120..d3b59d90b728 100644
>> --- a/drivers/iio/adc/ad_sigma_delta.c
>> +++ b/drivers/iio/adc/ad_sigma_delta.c
>> @@ -568,6 +568,11 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void
>> *p)
>>   	else
>>   		transfer_size = reg_size;
>>   
>> +	if (reg_size != 1 && reg_size != 2 && reg_size != 3 && reg_size != 4)
>> {
>> +		dev_err(&indio_dev->dev, "Unsupported reg_size: %u\n",
>> reg_size);
>> +		return IRQ_HANDLED;
>> +	}
>> +
> 
> Use the switch case for this. Add a default branch for the invalid case. You
> should also use dev_err_ratelimited() and instead of 'return IRQ_HANDLED', do
> 'goto irq_handled'.
> 
> Thx!
> - Nuno Sá

Hi Nuno,

Thank you for the review and guidance.

I’ve updated the patch to address your suggestions and will send the 
next version shortly.

Best regards,
Purva

> 
>>   	switch (reg_size) {
>>   	case 4:
>>   	case 2:


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-04-10 16:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-09 20:01 [PATCH] iio: adc: ad_sigma_delta: Fix use of uninitialized variable status_pos Purva Yeshi
2025-04-10 11:09 ` Nuno Sá
2025-04-10 16:58   ` Purva Yeshi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox