mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] i2c: nomadik: handle pm_runtime errors
@ 2026-11-10 13:06 Dmitry Guzman
  2026-11-10 19:52 ` Wolfram Sang
  0 siblings, 1 reply; 2+ messages in thread
From: Dmitry Guzman @ 2026-11-10 13:06 UTC (permalink / raw)
  To: Linus Walleij, Andi Shyti, Wolfram Sang
  Cc: linux-arm-kernel, linux-i2c, linux-kernel, Dmitry Guzman

In nmk_i2c_xfer(), pm_runtime_get_sync() is called on start and then
the controller registers are accessed without checking the return value.
If pm_runtime_get_sync() fails, access to the register of the device that
was not correctly powered on may cause a bus fault or other unpredictable
system behavior.

Replace pm_runtime_get_sync() with pm_runtime_resume_and_get() that
always return 0 on success and automatically restores PM usage counter
on failure, and return immediately if it returns any error.

Signed-off-by: Dmitry Guzman <Dmitry.Guzman@mobileye.com>
---
This is fixed version of patch #6 in a set of fixes in i2c-nomadik
driver:

https://lore.kernel.org/linux-i2c/20261103-i2c-nomadik-fixes-v1-6-655c6af2cb70@mobileye.com/

Please replace that patch with this one.

Changes in this version of the patch:

- use pm_runtime_resume_and_get() instead of pm_runtime_get_sync() in
  order to automatically restore the usage counter on failure and always
get 0 on success (pm_runtime_get_sync() may also return 1 if the device
is already active).
- use variable `status` instead of `i` for its return value.
---
 drivers/i2c/busses/i2c-nomadik.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c
index c3878670da9c..74ecf188c9eb 100644
--- a/drivers/i2c/busses/i2c-nomadik.c
+++ b/drivers/i2c/busses/i2c-nomadik.c
@@ -713,12 +713,13 @@ static int nmk_i2c_xfer_one(struct nmk_i2c_dev *priv, u16 flags)
 static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap,
 		struct i2c_msg msgs[], int num_msgs)
 {
-	int status = 0;
-	int i;
+	int status, i;
 	struct nmk_i2c_dev *priv = i2c_get_adapdata(i2c_adap);
 	int j;
 
-	pm_runtime_get_sync(&priv->adev->dev);
+	status = pm_runtime_resume_and_get(&priv->adev->dev);
+	if (status)
+		return status;
 
 	/* Attempt three times to send the message queue */
 	for (j = 0; j < 3; j++) {

---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261110-i2c-nomadik-handle-pm_errors-4925b54a5076

Best regards,
--  
Dmitry Guzman <Dmitry.Guzman@mobileye.com>


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

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

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-10 13:06 [PATCH] i2c: nomadik: handle pm_runtime errors Dmitry Guzman
2026-11-10 19:52 ` Wolfram Sang

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®