LKML Archive on
help / color / mirror / Atom feed
* [PATCH v2 2/2] i2c: core-smbus: fix a potential missing-check bug
@ 2018-05-05 13:02 Wenwen Wang
  2018-05-10 11:16 ` Wolfram Sang
  0 siblings, 1 reply; 7+ messages in thread
From: Wenwen Wang @ 2018-05-05 13:02 UTC (permalink / raw)
  To: Wenwen Wang; +Cc: Kangjie Lu, Wolfram Sang, open list:I2C SUBSYSTEM, open list

In i2c_smbus_xfer_emulated(), the function i2c_transfer() is invoked to
transfer i2c messages. The number of actual transferred messages is
returned and saved to 'status'. If 'status' is negative, that means an
error occurred during the transfer process. In that case, the value of
'status' is an error code to indicate the reason of the transfer failure.
In most cases, i2c_transfer() can transfer 'num' messages with no error.
And so 'status' == 'num'. However, due to unexpected errors, it is probable
that only partial messages are transferred by i2c_transfer(). As a result,
'status' != 'num'. This special case is not checked after the invocation of
i2c_transfer() and can potentially lead to unexpected issues in the
following execution since it is expected that 'status' == 'num'.

This patch checks the return value of i2c_transfer() and returns an error
code -EIO if the number of actual transferred messages 'status' is not
equal to 'num'.

Signed-off-by: Wenwen Wang <>
 drivers/i2c/i2c-core-smbus.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c
index 7d7700f..e7a2d2f 100644
--- a/drivers/i2c/i2c-core-smbus.c
+++ b/drivers/i2c/i2c-core-smbus.c
@@ -467,6 +467,8 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,
 	status = i2c_transfer(adapter, msg, num);
 	if (status < 0)
 		return status;
+	if (status != num)
+		return -EIO;
 	/* Check PEC if last message is a read */
 	if (i && (msg[num-1].flags & I2C_M_RD)) {

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

end of thread, other threads:[~2018-05-17 13:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-05 13:02 [PATCH v2 2/2] i2c: core-smbus: fix a potential missing-check bug Wenwen Wang
2018-05-10 11:16 ` Wolfram Sang
2018-05-10 13:36   ` Peter Rosin
2018-05-15  8:58     ` Wolfram Sang
2018-05-15 10:36       ` Peter Rosin
2018-05-17 13:06         ` Wolfram Sang
2018-05-17 13:38   ` Wolfram Sang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).