[PATCH] i2c: nomadik: handle pm_runtime errors

From: Dmitry Guzman

Date: Tue Nov 10 2026 - 08:39:12 EST


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@xxxxxxxxxxxx>
---
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@xxxxxxxxxxxx/

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@xxxxxxxxxxxx>