Skip to content

Commit 40cadb3

Browse files
MulinChaonashif
authored andcommitted
driver: i2c: npcx: Prevent transaction result overwritten by recovery.
This CL prevents the transaction result overwritten by the recovery function. Even if the recovery mechanism succeeds, the upper layer still needs to know why the transaction failed. Signed-off-by: Mulin Chao <[email protected]>
1 parent c3beabd commit 40cadb3

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

drivers/i2c/i2c_npcx_controller.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,7 @@ int npcx_i2c_ctrl_transfer(const struct device *i2c_dev, struct i2c_msg *msgs,
779779
if (i2c_ctrl_bus_busy(i2c_dev) ||
780780
data->oper_state == NPCX_I2C_ERROR_RECOVERY) {
781781
ret = i2c_ctrl_recovery(i2c_dev);
782+
/* Recovery failed, return it immediately */
782783
if (ret) {
783784
return ret;
784785
}
@@ -825,7 +826,14 @@ int npcx_i2c_ctrl_transfer(const struct device *i2c_dev, struct i2c_msg *msgs,
825826
}
826827

827828
if (data->oper_state == NPCX_I2C_ERROR_RECOVERY) {
828-
ret = i2c_ctrl_recovery(i2c_dev);
829+
int recovery_error = i2c_ctrl_recovery(i2c_dev);
830+
/*
831+
* Recovery failed, return it immediately. Otherwise, the upper
832+
* layer still needs to know why the transaction failed.
833+
*/
834+
if (recovery_error != 0) {
835+
return recovery_error;
836+
}
829837
}
830838

831839
return ret;

0 commit comments

Comments
 (0)