Skip to content

Commit

Permalink
i2c: npcm7xx: Fix callback completion ordering
Browse files Browse the repository at this point in the history
[ Upstream commit 92e73d807b68b2214fcafca4e130b5300a9d4b3c ]

Sometimes, our completions race with new master transfers and override
the bus->operation and bus->master_or_slave variables. This causes
transactions to timeout and kernel crashes less frequently.

To remedy this, we re-order all completions to the very end of the
function.

Fixes: 56a1485 ("i2c: npcm7xx: Add Nuvoton NPCM I2C controller driver")
Signed-off-by: William A. Kennington III <[email protected]>
Reviewed-by: Tali Perry <[email protected]>
Signed-off-by: Wolfram Sang <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
wkennington authored and gregkh committed Oct 10, 2023
1 parent dd81e91 commit 061f402
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions drivers/i2c/busses/i2c-npcm7xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ static void npcm_i2c_callback(struct npcm_i2c *bus,
{
struct i2c_msg *msgs;
int msgs_num;
bool do_complete = false;

msgs = bus->msgs;
msgs_num = bus->msgs_num;
Expand All @@ -701,23 +702,17 @@ static void npcm_i2c_callback(struct npcm_i2c *bus,
msgs[1].flags & I2C_M_RD)
msgs[1].len = info;
}
if (completion_done(&bus->cmd_complete) == false)
complete(&bus->cmd_complete);
break;

do_complete = true;
break;
case I2C_NACK_IND:
/* MASTER transmit got a NACK before tx all bytes */
bus->cmd_err = -ENXIO;
if (bus->master_or_slave == I2C_MASTER)
complete(&bus->cmd_complete);

do_complete = true;
break;
case I2C_BUS_ERR_IND:
/* Bus error */
bus->cmd_err = -EAGAIN;
if (bus->master_or_slave == I2C_MASTER)
complete(&bus->cmd_complete);

do_complete = true;
break;
case I2C_WAKE_UP_IND:
/* I2C wake up */
Expand All @@ -731,6 +726,8 @@ static void npcm_i2c_callback(struct npcm_i2c *bus,
if (bus->slave)
bus->master_or_slave = I2C_SLAVE;
#endif
if (do_complete)
complete(&bus->cmd_complete);
}

static u8 npcm_i2c_fifo_usage(struct npcm_i2c *bus)
Expand Down

0 comments on commit 061f402

Please sign in to comment.