From: Purva Yeshi <purvayeshi550@gmail.com>
To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
Purva Yeshi <purvayeshi550@gmail.com>
Subject: [PATCH] iio: adc: ad_sigma_delta: Fix use of uninitialized variable status_pos
Date: Thu, 10 Apr 2025 01:31:51 +0530 [thread overview]
Message-ID: <20250409200151.201327-1-purvayeshi550@gmail.com> (raw)
[-- 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
next reply other threads:[~2025-04-09 20:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-09 20:01 Purva Yeshi [this message]
2025-04-10 11:09 ` [PATCH] iio: adc: ad_sigma_delta: Fix use of uninitialized variable status_pos Nuno Sá
2025-04-10 16:58 ` Purva Yeshi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250409200151.201327-1-purvayeshi550@gmail.com \
--to=purvayeshi550@gmail.com \
--cc=Michael.Hennerich@analog.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox