mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Matthias Goergens <matthias.goergens@gmail.com>
To: Peter Korsgaard <peter@korsgaard.com>,
	Andrew Lunn <andrew@lunn.ch>, Andi Shyti <andi.shyti@kernel.org>
Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2] i2c: ocores: delete adapter before disabling controller
Date: Mon,  2 Nov 2026 16:03:27 +0800	[thread overview]
Message-ID: <20261102080327.1466598-1-matthias.goergens@gmail.com> (raw)

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


             reply	other threads:[~2026-11-02  8:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02  8:03 Matthias Goergens [this message]
2026-11-04 10:20 ` Peter Korsgaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261102080327.1466598-1-matthias.goergens@gmail.com \
    --to=matthias.goergens@gmail.com \
    --cc=andi.shyti@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peter@korsgaard.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®