Skip to contentSkip to conversation

iio: adc: ad_sigma_delta: Fix use of uninitialized status_pos

PATCH Applied Purva Yeshi 2 participants 3 messages Apr 10, 2025 – Apr 17, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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

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.

---
V1 - https://lore.kernel.org/all/[email protected]/
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(+)
drivers/iio/adc/ad_sigma_delta.c +4 -0
index 6c37f8e21120..4c5f8d29a559 100644
@@ -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;
 	}
 
 	/*
Signature · 1 line
2.34.1
maintainer Applied
#1 lore raw
Quoted 8 lines · On Thu, 10 Apr 2025 22:34:08 +0530 Purva Yeshi <[email protected]> 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.

Quoted 5 lines

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.

Seems like reasonable hardening of the code.

Applied.

Thanks,

Quoted 24 lines

---
V1 - https://lore.kernel.org/all/[email protected]/
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(+)
drivers/iio/adc/ad_sigma_delta.c +4 -0
index 6c37f8e21120..4c5f8d29a559 100644
@@ -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 lore raw
Quoted 15 lines · Jonathan Cameron
Quoted 12 lines · On Thu, 10 Apr 2025 22:34:08 +0530 Purva Yeshi <[email protected]> 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.

Quoted 6 lines
Quoted 1 line

Seems like reasonable hardening of the code.

Applied.

Thanks,

Hi Jonathan,

Thank you for reviewing and applying the patch.

Quoted 24 lines
Quoted 24 lines

---
V1 - https://lore.kernel.org/all/[email protected]/
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(+)
drivers/iio/adc/ad_sigma_delta.c +4 -0
index 6c37f8e21120..4c5f8d29a559 100644
@@ -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;
  	}
 
Quoted 2 lines

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

Quoted 1 line
drivers/iio/adc/ad_sigma_delta.c +0 -0
  	/*

Best regards,
Purva