mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] i2c: lpi2c: fix potential read of uninitialized variable
@ 2024-10-17  9:09 Ahmad Fatoum
  2024-10-18  8:54 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2024-10-17  9:09 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-10-18  9:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-17  9:09 [PATCH] i2c: lpi2c: fix potential read of uninitialized variable Ahmad Fatoum
2024-10-18  8:54 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox