i2c: k1: check for transfer error
PATCH 1/1 i2c: k1: check for transfer error
If spacemit_i2c_xfer_msg() times out waiting for a message transfer to complete, or if the hardware reports an error, it returns a negative error code (-ETIMEDOUT, -EAGAIN, -ENXIO. or -EIO).
The sole caller of spacemit_i2c_xfer_msg() is spacemit_i2c_xfer(), which is the i2c_algorithm->xfer callback function. It currently does not save the value returned by spacemit_i2c_xfer_msg().
The result is that transfer errors go unreported, and a caller has no indication anything is wrong.
When this code was out for review, the return value *was* checked in early versions. But for some reason, that assignment got dropped between versions 5 and 6 of the series, perhaps related to reworking the code to merge spacemit_i2c_xfer_core() into spacemit_i2c_xfer().
Simply assigning the value returned to "ret" fixes the problem.
--- drivers/i2c/busses/i2c-k1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-k1.c +1 -1
@@ -477,7 +477,7 @@ static int spacemit_i2c_xfer(struct i2c_adapter *adapt, struct i2c_msg *msgs, in ret =spacemit_i2c_wait_bus_idle (i2c);if (!ret) -spacemit_i2c_xfer_msg (i2c); + ret =spacemit_i2c_xfer_msg (i2c);else if (ret <0 )dev_dbg (i2c->dev,"i2c transfer error: %d\n" , ret);else
base-commit: a5806cd506af5a7c19bcd596e4708b5c464bfd21
Signature · 1 line
2.45.2
Quoted 29 lines · Alex Elder
If
spacemit_i2c_xfer_msg()times out waiting for a message transfer to complete, or if the hardware reports an error, it returns a negative error code (-ETIMEDOUT,-EAGAIN,-ENXIO. or-EIO).The sole caller of
spacemit_i2c_xfer_msg()isspacemit_i2c_xfer(), which is thei2c_algorithm->xfercallback function. It currently does not save the value returned byspacemit_i2c_xfer_msg().The result is that transfer errors go unreported, and a caller has no indication anything is wrong.
When this code was out for review, the return value *was* checked in early versions. But for some reason, that assignment got dropped between versions 5 and 6 of the series, perhaps related to reworking the code to merge
spacemit_i2c_xfer_core()intospacemit_i2c_xfer().Simply assigning the value returned to "ret" fixes the problem.
Fixes 5ea558473fa31 ("i2c: spacemit: add support for SpacemiT K1 SoC")Signed-off-by Alex Elder <[email protected]>--- drivers/i2c/busses/i2c-k1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/i2c/busses/i2c-k1.c +0
-0
drivers/i2c/busses/i2c-k1.c static int spacemit_i2c_xfer(struct i2c_adapter *adapt, struct i2c_msg *msgs, in · line 480
Quoted 5 lines
drivers/i2c/busses/i2c-k1.c +1
-1@@ -477,7 +477,7 @@ static int spacemit_i2c_xfer(struct i2c_adapter *adapt, struct i2c_msg *msgs, in ret =spacemit_i2c_wait_bus_idle (i2c);if (!ret) -spacemit_i2c_xfer_msg (i2c); + ret =spacemit_i2c_xfer_msg (i2c);
Sorry this is my mistake.
Thanks for your fixes.
Quoted 8 lines
drivers/i2c/busses/i2c-k1.c +0
-0else if (ret <0 )dev_dbg (i2c->dev,"i2c transfer error: %d\n" , ret);else base-commit:
a5806cd506af5a7c19bcd596e4708b5c464bfd21Signature · 1 line
2.45.2