mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] i2c: ocores: delete adapter before disabling controller
@ 2026-11-02  8:03 Matthias Goergens
  2026-11-04 10:20 ` Peter Korsgaard
  0 siblings, 1 reply; 2+ messages in thread
From: Matthias Goergens @ 2026-11-02  8:03 UTC (permalink / raw)
  To: Peter Korsgaard, Andrew Lunn, Andi Shyti; +Cc: linux-i2c, linux-kernel

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(-)

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)

base-commit: d89e1d186ec9271bf78e62771779e9fc03bf0fc3
-- 
2.56.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] i2c: ocores: delete adapter before disabling controller
  2026-11-02  8:03 [PATCH v2] i2c: ocores: delete adapter before disabling controller Matthias Goergens
@ 2026-11-04 10:20 ` Peter Korsgaard
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Korsgaard @ 2026-11-04 10:20 UTC (permalink / raw)
  To: Matthias Goergens; +Cc: Andrew Lunn, Andi Shyti, linux-i2c, linux-kernel

>>>>> "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>

-- 
Bye, Peter Korsgaard

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-04 10:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-02  8:03 [PATCH v2] i2c: ocores: delete adapter before disabling controller Matthias Goergens
2026-11-04 10:20 ` Peter Korsgaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®