public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
From: Suraj Sonawane <surajsonawane0215@gmail.com>
To: tharunkumar.pasumarthi@microchip.com,
	kumaravel.thiagarajan@microchip.com
Cc: UNGLinuxDriver@microchip.com, andi.shyti@kernel.org,
	linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
	Suraj Sonawane <surajsonawane0215@gmail.com>
Subject: [PATCH] i2c: busses: fix uninit-value in pci1xxxx_i2c_xfer
Date: Wed, 23 Oct 2024 00:38:45 +0530	[thread overview]
Message-ID: <20241022190845.23536-1-surajsonawane0215@gmail.com> (raw)

Fix an issue reported by the smatch static analysis tool:
drivers/i2c/busses/i2c-mchp-pci1xxxx.c:1030 pci1xxxx_i2c_xfer() error:
uninitialized symbol 'retval'.

The error occurs because retval may be used without being set if the
transfer loop does not execute (e.g., when num is 0). This could cause
the function to return an undefined value, leading to unpredictable
behavior.

Initialize retval to 0 before the transfer loop to ensure that the
function returns a valid value even if no transfers are processed. This
change also preserves proper error handling within the loop.

Signed-off-by: Suraj Sonawane <surajsonawane0215@gmail.com>
---
 drivers/i2c/busses/i2c-mchp-pci1xxxx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-mchp-pci1xxxx.c b/drivers/i2c/busses/i2c-mchp-pci1xxxx.c
index 5ef136c3e..4dfa11650 100644
--- a/drivers/i2c/busses/i2c-mchp-pci1xxxx.c
+++ b/drivers/i2c/busses/i2c-mchp-pci1xxxx.c
@@ -994,7 +994,7 @@ static int pci1xxxx_i2c_xfer(struct i2c_adapter *adap,
 {
 	struct pci1xxxx_i2c *i2c = i2c_get_adapdata(adap);
 	u8 slaveaddr;
-	int retval;
+	int retval = 0;
 	u32 i;
 
 	i2c->i2c_xfer_in_progress = true;
-- 
2.34.1


             reply	other threads:[~2024-10-22 19:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-22 19:08 Suraj Sonawane [this message]
2024-10-23 23:02 ` [PATCH] i2c: busses: fix uninit-value in pci1xxxx_i2c_xfer Andi Shyti
2024-10-26  7:39   ` Suraj Sonawane

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=20241022190845.23536-1-surajsonawane0215@gmail.com \
    --to=surajsonawane0215@gmail.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=andi.shyti@kernel.org \
    --cc=kumaravel.thiagarajan@microchip.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tharunkumar.pasumarthi@microchip.com \
    /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