* [PATCH 1/1] i2c: tegra: fix error handling in tegra_i2c_xfer()
@ 2026-05-06 19:53 Saurav Sachidanand
0 siblings, 0 replies; only message in thread
From: Saurav Sachidanand @ 2026-05-06 19:53 UTC (permalink / raw)
To: wsa+renesas
Cc: Saurav Sachidanand, Laxman Dewangan, Dmitry Osipenko, Andi Shyti,
Thierry Reding, Jonathan Hunter, Kartik Rajput, Akhil R,
linux-i2c, linux-tegra, linux-kernel
Fix two bugs in the SW mutex path introduced by commit 6077cfd716fb
("i2c: tegra: Add support for SW mutex register"):
1. If tegra_i2c_mutex_lock() fails, the function returns without calling
pm_runtime_put(), leaking the runtime PM reference acquired by the
preceding pm_runtime_get_sync(). Add the missing pm_runtime_put()
before returning.
2. tegra_i2c_mutex_unlock() unconditionally overwrites ret, which may
already hold a transfer error from tegra_i2c_xfer_msg(). If the
transfer failed but the unlock succeeds, the error is silently lost
and the function incorrectly reports success. Use a separate variable
for the unlock return value and preserve error priority:
transfer error > unlock error > message count.
Fixes: 6077cfd716fb ("i2c: tegra: Add support for SW mutex register")
Signed-off-by: Saurav Sachidanand <sauravsc@amazon.com>
---
drivers/i2c/busses/i2c-tegra.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index 9fd5ade774a0b..704942d10d69d 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -1656,7 +1656,7 @@ static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],
int num)
{
struct tegra_i2c_dev *i2c_dev = i2c_get_adapdata(adap);
- int i, ret;
+ int i, ret, ret2;
ret = pm_runtime_get_sync(i2c_dev->dev);
if (ret < 0) {
@@ -1666,8 +1666,10 @@ static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],
}
ret = tegra_i2c_mutex_lock(i2c_dev);
- if (ret)
+ if (ret) {
+ pm_runtime_put(i2c_dev->dev);
return ret;
+ }
for (i = 0; i < num; i++) {
enum msg_end_type end_type = MSG_END_STOP;
@@ -1698,10 +1700,10 @@ static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],
break;
}
- ret = tegra_i2c_mutex_unlock(i2c_dev);
+ ret2 = tegra_i2c_mutex_unlock(i2c_dev);
pm_runtime_put(i2c_dev->dev);
- return ret ?: i;
+ return ret ?: ret2 ?: i;
}
static int tegra_i2c_xfer_atomic(struct i2c_adapter *adap,
--
2.47.3
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-05-06 19:54 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-06 19:53 [PATCH 1/1] i2c: tegra: fix error handling in tegra_i2c_xfer() Saurav Sachidanand
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox