Skip to contentSkip to conversation

iio: adc: ad_sigma_delta: Fix use of uninitialized variable status_pos

PATCH Superseded Purva Yeshi 2 participants 3 messages Apr 9, 2025 – Apr 10, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: adc: ad_sigma_delta: Fix use of uninitialized variable status_pos

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.

---
 drivers/iio/adc/ad_sigma_delta.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/iio/adc/ad_sigma_delta.c +5 -0
index 6c37f8e21120..d3b59d90b728 100644
@@ -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:
Signature · 1 line
2.34.1
#1 lore raw

Hi Purva,

Thanks for your patch... See below

Quoted 32 lines · Purva Yeshi

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.

---
 drivers/iio/adc/ad_sigma_delta.c | 5 +++++

 1 file changed, 5 insertions(+)
drivers/iio/adc/ad_sigma_delta.c +0 -0
index 6c37f8e21120..d3b59d90b728 100644
@@ -568,6 +568,11 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void
 *p)

  else
  transfer_size = reg_size;

drivers/iio/adc/ad_sigma_delta.c +1 -0
+	if (reg_size != 1 && reg_size != 2 && reg_size != 3 && reg_size != 4)

{

drivers/iio/adc/ad_sigma_delta.c +1 -0
+		dev_err(&indio_dev->dev, "Unsupported reg_size: %u\n",

reg_size);

drivers/iio/adc/ad_sigma_delta.c static irqreturn_t ad_sd_trigger_handler(int irq, void *p) · line 575

Quoted 3 lines
drivers/iio/adc/ad_sigma_delta.c +3 -0
+		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á

Quoted 3 lines

  switch (reg_size) {
  case 4:
  case 2:

#2 lore raw
Quoted 44 lines · Nuno Sá

Hi Purva,

Thanks for your patch... See below

Quoted 25 lines · Purva Yeshi

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.

---
  drivers/iio/adc/ad_sigma_delta.c | 5 +++++
  1 file changed, 5 insertions(+)
drivers/iio/adc/ad_sigma_delta.c +0 -0
index 6c37f8e21120..d3b59d90b728 100644
@@ -568,6 +568,11 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void
 *p)

drivers/iio/adc/ad_sigma_delta.c static irqreturn_t ad_sd_trigger_handler(int irq, void · line 578

Quoted 10 lines
drivers/iio/adc/ad_sigma_delta.c +5 -0
  	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'.

Quoted 2 lines

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

Quoted 4 lines
Quoted 4 lines

  switch (reg_size) {
  case 4:
  case 2: