| Message ID | 20261102080327.1466598-1-matthias.goergens@gmail.com |
|---|---|
| State | New |
| Headers | show |
| Series | [v2] i2c: ocores: delete adapter before disabling controller | expand |
>>>>> "Matthias" == Matthias Goergens <matthias.goergens@gmail.com> writes: > ocores_i2c_remove() clears the core's enable bits before it calls > i2c_del_adapter(). Deleting the adapter removes its client devices, > and some client drivers talk to their device while being removed: > lm75_remove(), for example, tries to write the sensor's original > configuration back. With the core disabled, such a transfer cannot > work; in interrupt mode it times out after a second and the write is > lost. > Delete the adapter first, then disable the core. > Sashiko, the AI review bot, pointed this out while reviewing an > unrelated ocores patch. > Link: https://lore.kernel.org/all/20260813153155.3953577-1-ruoyuw560@gmail.com/ > Link: https://sashiko.dev/#/patchset/20260813153155.3953577-1-ruoyuw560@gmail.com > Fixes: 18f98b1e3147 ("[PATCH] i2c: New bus driver for the OpenCores I2C controller") > Signed-off-by: Matthias Goergens <matthias.goergens@gmail.com> Acked-by: Peter Korsgaard <peter@korsgaard.com>
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c index 2d18c1035837..ff024cf5f92d 100644 --- a/drivers/i2c/busses/i2c-ocores.c +++ b/drivers/i2c/busses/i2c-ocores.c @@ -720,14 +720,15 @@ static int ocores_i2c_probe(struct platform_device *pdev) static void ocores_i2c_remove(struct platform_device *pdev) { struct ocores_i2c *i2c = platform_get_drvdata(pdev); - u8 ctrl = oc_getreg(i2c, OCI2C_CONTROL); + u8 ctrl; + + /* remove adapter & data */ + i2c_del_adapter(&i2c->adap); /* disable i2c logic */ + ctrl = oc_getreg(i2c, OCI2C_CONTROL); ctrl &= ~(OCI2C_CTRL_EN | OCI2C_CTRL_IEN); oc_setreg(i2c, OCI2C_CONTROL, ctrl); - - /* remove adapter & data */ - i2c_del_adapter(&i2c->adap); } static int ocores_i2c_suspend(struct device *dev)
ocores_i2c_remove() clears the core's enable bits before it calls i2c_del_adapter(). Deleting the adapter removes its client devices, and some client drivers talk to their device while being removed: lm75_remove(), for example, tries to write the sensor's original configuration back. With the core disabled, such a transfer cannot work; in interrupt mode it times out after a second and the write is lost. Delete the adapter first, then disable the core. Sashiko, the AI review bot, pointed this out while reviewing an unrelated ocores patch. Link: https://lore.kernel.org/all/20260813153155.3953577-1-ruoyuw560@gmail.com/ Link: https://sashiko.dev/#/patchset/20260813153155.3953577-1-ruoyuw560@gmail.com Fixes: 18f98b1e3147 ("[PATCH] i2c: New bus driver for the OpenCores I2C controller") Signed-off-by: Matthias Goergens <matthias.goergens@gmail.com> --- v2: v1 went out before it was ready, without my Signed-off-by or a Fixes tag; sorry about that. This version adds them and says what goes wrong. The code is unchanged. The other ocores patch from v1, "i2c: ocores: synchronize startup with interrupt handling", only narrows its race: a STOP that is still in progress when the next START is written can still raise its interrupt afterwards. I am reworking it and will post it separately. v1: https://lore.kernel.org/all/20261031033240.2491016-1-matthias.goergens@gmail.com/ drivers/i2c/busses/i2c-ocores.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) base-commit: d89e1d186ec9271bf78e62771779e9fc03bf0fc3