mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] i2c: lpi2c: fix potential read of uninitialized variable
Date: Thu, 17 Oct 2024 11:09:47 +0200	[thread overview]
Message-ID: <20241017090947.127049-1-a.fatoum@pengutronix.de> (raw)

If the continue statement in the do {} while () loop is
reached on the first iteration, the loop condition is evaluated without
having first being set.

Fix this by initializing it to the maximum length of the I2C message.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/i2c/busses/i2c-imx-lpi2c.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c b/drivers/i2c/busses/i2c-imx-lpi2c.c
index e32bc4fd1805..763074ae63c7 100644
--- a/drivers/i2c/busses/i2c-imx-lpi2c.c
+++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
@@ -330,7 +330,7 @@ static void lpi2c_imx_set_rx_watermark(struct lpi2c_imx_struct *lpi2c_imx)
 
 static int lpi2c_imx_write_txfifo(struct lpi2c_imx_struct *lpi2c_imx)
 {
-	unsigned int data, remaining;
+	unsigned int data, remaining = lpi2c_imx->msglen;
 	unsigned int timeout = 100000;;
 
 	do {
@@ -353,7 +353,7 @@ static int lpi2c_imx_write_txfifo(struct lpi2c_imx_struct *lpi2c_imx)
 
 static int lpi2c_imx_read_rxfifo(struct lpi2c_imx_struct *lpi2c_imx)
 {
-	unsigned int remaining;
+	unsigned int remaining = lpi2c_imx->msglen;
 	unsigned int data;
 	unsigned int timeout = 100000;;
 
-- 
2.39.5




             reply	other threads:[~2024-10-17  9:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-17  9:09 Ahmad Fatoum [this message]
2024-10-18  8:54 ` Sascha Hauer

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=20241017090947.127049-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.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