* [PATCH] i2c: npcm7xx: Fix callback completion ordering
@ 2023-09-24 1:02 William A. Kennington III
2023-09-26 5:41 ` Tali Perry
2023-09-27 19:31 ` Wolfram Sang
0 siblings, 2 replies; 3+ messages in thread
From: William A. Kennington III @ 2023-09-24 1:02 UTC (permalink / raw)
To: tmaimon77, tali.perry1, avifishman70, wsa, joel
Cc: linux-i2c, linux-kernel, William A. Kennington III
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: 56a1485b102e ("i2c: npcm7xx: Add Nuvoton NPCM I2C controller driver")
Signed-off-by: William A. Kennington III <william@wkennington.com>
---
drivers/i2c/busses/i2c-npcm7xx.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c
index 495a8b5f6a2b..ae4bae63ad4f 100644
--- a/drivers/i2c/busses/i2c-npcm7xx.c
+++ b/drivers/i2c/busses/i2c-npcm7xx.c
@@ -694,6 +694,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;
@@ -722,23 +723,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 */
@@ -752,6 +747,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)
--
2.42.0.515.g380fc7ccd1-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] i2c: npcm7xx: Fix callback completion ordering
2023-09-24 1:02 [PATCH] i2c: npcm7xx: Fix callback completion ordering William A. Kennington III
@ 2023-09-26 5:41 ` Tali Perry
2023-09-27 19:31 ` Wolfram Sang
1 sibling, 0 replies; 3+ messages in thread
From: Tali Perry @ 2023-09-26 5:41 UTC (permalink / raw)
To: William A. Kennington III
Cc: tmaimon77, avifishman70, wsa, joel, linux-i2c, linux-kernel
On Sun, Sep 24, 2023 at 4:02 AM William A. Kennington III
<william@wkennington.com> wrote:
>
> 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: 56a1485b102e ("i2c: npcm7xx: Add Nuvoton NPCM I2C controller driver")
> Signed-off-by: William A. Kennington III <william@wkennington.com>
> ---
> drivers/i2c/busses/i2c-npcm7xx.c | 17 +++++++----------
> 1 file changed, 7 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c
> index 495a8b5f6a2b..ae4bae63ad4f 100644
> --- a/drivers/i2c/busses/i2c-npcm7xx.c
> +++ b/drivers/i2c/busses/i2c-npcm7xx.c
> @@ -694,6 +694,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;
> @@ -722,23 +723,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 */
> @@ -752,6 +747,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)
> --
> 2.42.0.515.g380fc7ccd1-goog
>
Thanks William for the fix!
Reviewed-by: Tali Perry <tali.perry1@gmail.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] i2c: npcm7xx: Fix callback completion ordering
2023-09-24 1:02 [PATCH] i2c: npcm7xx: Fix callback completion ordering William A. Kennington III
2023-09-26 5:41 ` Tali Perry
@ 2023-09-27 19:31 ` Wolfram Sang
1 sibling, 0 replies; 3+ messages in thread
From: Wolfram Sang @ 2023-09-27 19:31 UTC (permalink / raw)
To: William A. Kennington III
Cc: tmaimon77, tali.perry1, avifishman70, joel, linux-i2c,
linux-kernel
[-- Attachment #1: Type: text/plain, Size: 561 bytes --]
On Sat, Sep 23, 2023 at 06:02:14PM -0700, William A. Kennington III wrote:
> 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: 56a1485b102e ("i2c: npcm7xx: Add Nuvoton NPCM I2C controller driver")
> Signed-off-by: William A. Kennington III <william@wkennington.com>
Applied to for-current, thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-09-27 19:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-24 1:02 [PATCH] i2c: npcm7xx: Fix callback completion ordering William A. Kennington III
2023-09-26 5:41 ` Tali Perry
2023-09-27 19:31 ` Wolfram Sang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox