diff mbox series

i2c: smbus: Fixed uninitialized variable msgbuf in i2c_smbus_xfer_emulated

Message ID 20231215063452.3097535-1-guoqi0226@163.com
State New
Headers show
Series i2c: smbus: Fixed uninitialized variable msgbuf in i2c_smbus_xfer_emulated | expand

Commit Message

guoqi0226 Dec. 15, 2023, 6:34 a.m. UTC
From: cuiguoqi <cuiguoqi@kylinos.cn>

When the slave device is disconnected during i2c transmission, the communication is interrupted because the ACK cannot be received.
However, if the uninitialized msgbuf1 is used by i2c_smbus_xfer_emulated, abnormal random values will be reported.
The test proves that the exception communication using SMBUS after initialization is more reliable.

Signed-off-by: cuiguoqi <cuiguoqi@kylinos.cn>
---
 drivers/i2c/i2c-core-smbus.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c
index e3b96fc..f7b0980d 100644
--- a/drivers/i2c/i2c-core-smbus.c
+++ b/drivers/i2c/i2c-core-smbus.c
@@ -351,6 +351,8 @@  static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,
 	bool wants_pec = ((flags & I2C_CLIENT_PEC) && size != I2C_SMBUS_QUICK
 			  && size != I2C_SMBUS_I2C_BLOCK_DATA);
 
+	memset(msgbuf0, 0, sizeof(msgbuf0));
+	memset(msgbuf1, 0, sizeof(msgbuf1));
 	msgbuf0[0] = command;
 	switch (size) {
 	case I2C_SMBUS_QUICK: