Skip to content

Commit 92e73d8

Browse files
wkenningtonwsakernel
authored andcommitted
i2c: npcm7xx: Fix callback completion ordering
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 <william@wkennington.com> Reviewed-by: Tali Perry <tali.perry1@gmail.com> Signed-off-by: Wolfram Sang <wsa@kernel.org>
1 parent b13e59e commit 92e73d8

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

drivers/i2c/busses/i2c-npcm7xx.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ static void npcm_i2c_callback(struct npcm_i2c *bus,
694694
{
695695
struct i2c_msg *msgs;
696696
int msgs_num;
697+
bool do_complete = false;
697698

698699
msgs = bus->msgs;
699700
msgs_num = bus->msgs_num;
@@ -722,23 +723,17 @@ static void npcm_i2c_callback(struct npcm_i2c *bus,
722723
msgs[1].flags & I2C_M_RD)
723724
msgs[1].len = info;
724725
}
725-
if (completion_done(&bus->cmd_complete) == false)
726-
complete(&bus->cmd_complete);
727-
break;
728-
726+
do_complete = true;
727+
break;
729728
case I2C_NACK_IND:
730729
/* MASTER transmit got a NACK before tx all bytes */
731730
bus->cmd_err = -ENXIO;
732-
if (bus->master_or_slave == I2C_MASTER)
733-
complete(&bus->cmd_complete);
734-
731+
do_complete = true;
735732
break;
736733
case I2C_BUS_ERR_IND:
737734
/* Bus error */
738735
bus->cmd_err = -EAGAIN;
739-
if (bus->master_or_slave == I2C_MASTER)
740-
complete(&bus->cmd_complete);
741-
736+
do_complete = true;
742737
break;
743738
case I2C_WAKE_UP_IND:
744739
/* I2C wake up */
@@ -752,6 +747,8 @@ static void npcm_i2c_callback(struct npcm_i2c *bus,
752747
if (bus->slave)
753748
bus->master_or_slave = I2C_SLAVE;
754749
#endif
750+
if (do_complete)
751+
complete(&bus->cmd_complete);
755752
}
756753

757754
static u8 npcm_i2c_fifo_usage(struct npcm_i2c *bus)

0 commit comments

Comments
 (0)