[PATCH 2/9] ARM: i.MX: guf-santaro: fix passing around of uninitialized variable

Ahmad Fatoum a.fatoum at pengutronix.de
Sat Oct 30 10:58:05 PDT 2021


i2c_device_present() does a zero byte read to probe for the i2c
device. Make i2c_write_reg handle a NULL buf to silence the compiler
warning.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/arm/boards/guf-santaro/board.c | 3 +--
 drivers/i2c/i2c.c                   | 3 ++-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/arm/boards/guf-santaro/board.c b/arch/arm/boards/guf-santaro/board.c
index 34005ff7bf17..cfc85af59ee7 100644
--- a/arch/arm/boards/guf-santaro/board.c
+++ b/arch/arm/boards/guf-santaro/board.c
@@ -22,12 +22,11 @@
 static int i2c_device_present(struct i2c_adapter *adapter, int addr)
 {
 	struct i2c_client client = {};
-	u8 reg;
 
 	client.adapter = adapter;
 	client.addr = addr;
 
-	return i2c_write_reg(&client, 0x00, &reg, 0) < 0 ? false : true;
+	return i2c_write_reg(&client, 0x00, NULL, 0) < 0 ? false : true;
 }
 
 #define TOUCH_RESET_GPIO	IMX_GPIO_NR(1, 20)
diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index c33ce81b1827..432d0e233332 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -214,7 +214,8 @@ int i2c_write_reg(struct i2c_client *client, u32 addr, const u8 *buf, u16 count)
 	msgbuf[i++] = addr;
 	msg->len += i;
 
-	memcpy(msg->buf + i, buf, count);
+	if (count)
+		memcpy(msg->buf + i, buf, count);
 
 	status = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
 	dev_dbg(&client->adapter->dev, "%s: %u@%u --> %d\n", __func__,
-- 
2.30.2




More information about the barebox mailing list