* [PATCH 1/2] i2c: cadence: cdns_i2c_master_xfer(): Fix runtime PM leak on error path
@ 2023-04-14 2:10 Lars-Peter Clausen
2023-04-14 2:10 ` [PATCH 2/2] i2c: xiic: xiic_xfer(): " Lars-Peter Clausen
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Lars-Peter Clausen @ 2023-04-14 2:10 UTC (permalink / raw)
To: Wolfram Sang
Cc: Michal Simek, Shubhrajyoti Datta, linux-i2c, Lars-Peter Clausen
The cdns_i2c_master_xfer() function gets a runtime PM reference when the
function is entered. This reference is released when the function is
exited. There is currently one error path where the function exits
directly, which leads to a leak of the runtime PM reference.
Make sure that this error path also releases the runtime PM reference.
Fixes: 1a351b10b967 ("i2c: cadence: Added slave support")
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
drivers/i2c/busses/i2c-cadence.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index f1a67c410ad3..3a4edf7e75f9 100644
--- a/drivers/i2c/busses/i2c-cadence.c
+++ b/drivers/i2c/busses/i2c-cadence.c
@@ -834,8 +834,10 @@ static int cdns_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
#if IS_ENABLED(CONFIG_I2C_SLAVE)
/* Check i2c operating mode and switch if possible */
if (id->dev_mode == CDNS_I2C_MODE_SLAVE) {
- if (id->slave_state != CDNS_I2C_SLAVE_STATE_IDLE)
- return -EAGAIN;
+ if (id->slave_state != CDNS_I2C_SLAVE_STATE_IDLE) {
+ ret = -EAGAIN;
+ goto out;
+ }
/* Set mode to master */
cdns_i2c_set_mode(CDNS_I2C_MODE_MASTER, id);
--
2.30.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] i2c: xiic: xiic_xfer(): Fix runtime PM leak on error path
2023-04-14 2:10 [PATCH 1/2] i2c: cadence: cdns_i2c_master_xfer(): Fix runtime PM leak on error path Lars-Peter Clausen
@ 2023-04-14 2:10 ` Lars-Peter Clausen
2023-04-14 12:57 ` Michal Simek
2023-04-18 16:44 ` Wolfram Sang
2023-04-14 12:57 ` [PATCH 1/2] i2c: cadence: cdns_i2c_master_xfer(): " Michal Simek
2023-04-18 16:44 ` Wolfram Sang
2 siblings, 2 replies; 7+ messages in thread
From: Lars-Peter Clausen @ 2023-04-14 2:10 UTC (permalink / raw)
To: Wolfram Sang
Cc: Michal Simek, Shubhrajyoti Datta, linux-i2c, Lars-Peter Clausen
The xiic_xfer() function gets a runtime PM reference when the function is
entered. This reference is released when the function is exited. There is
currently one error path where the function exits directly, which leads to
a leak of the runtime PM reference.
Make sure that this error path also releases the runtime PM reference.
Fixes: fdacc3c7405d ("i2c: xiic: Switch from waitqueue to completion")
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
drivers/i2c/busses/i2c-xiic.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c
index e7d37eb20f2b..8a3d9817cb41 100644
--- a/drivers/i2c/busses/i2c-xiic.c
+++ b/drivers/i2c/busses/i2c-xiic.c
@@ -1164,7 +1164,7 @@ static int xiic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
err = xiic_start_xfer(i2c, msgs, num);
if (err < 0) {
dev_err(adap->dev.parent, "Error xiic_start_xfer\n");
- return err;
+ goto out;
}
err = wait_for_completion_timeout(&i2c->completion, XIIC_XFER_TIMEOUT);
@@ -1178,6 +1178,8 @@ static int xiic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
err = (i2c->state == STATE_DONE) ? num : -EIO;
}
mutex_unlock(&i2c->lock);
+
+out:
pm_runtime_mark_last_busy(i2c->dev);
pm_runtime_put_autosuspend(i2c->dev);
return err;
--
2.30.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] i2c: xiic: xiic_xfer(): Fix runtime PM leak on error path
2023-04-14 2:10 ` [PATCH 2/2] i2c: xiic: xiic_xfer(): " Lars-Peter Clausen
@ 2023-04-14 12:57 ` Michal Simek
2023-04-18 16:44 ` Wolfram Sang
1 sibling, 0 replies; 7+ messages in thread
From: Michal Simek @ 2023-04-14 12:57 UTC (permalink / raw)
To: Lars-Peter Clausen, Wolfram Sang; +Cc: Shubhrajyoti Datta, linux-i2c
On 4/14/23 04:10, Lars-Peter Clausen wrote:
> The xiic_xfer() function gets a runtime PM reference when the function is
> entered. This reference is released when the function is exited. There is
> currently one error path where the function exits directly, which leads to
> a leak of the runtime PM reference.
>
> Make sure that this error path also releases the runtime PM reference.
>
> Fixes: fdacc3c7405d ("i2c: xiic: Switch from waitqueue to completion")
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> ---
> drivers/i2c/busses/i2c-xiic.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c
> index e7d37eb20f2b..8a3d9817cb41 100644
> --- a/drivers/i2c/busses/i2c-xiic.c
> +++ b/drivers/i2c/busses/i2c-xiic.c
> @@ -1164,7 +1164,7 @@ static int xiic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
> err = xiic_start_xfer(i2c, msgs, num);
> if (err < 0) {
> dev_err(adap->dev.parent, "Error xiic_start_xfer\n");
> - return err;
> + goto out;
> }
>
> err = wait_for_completion_timeout(&i2c->completion, XIIC_XFER_TIMEOUT);
> @@ -1178,6 +1178,8 @@ static int xiic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
> err = (i2c->state == STATE_DONE) ? num : -EIO;
> }
> mutex_unlock(&i2c->lock);
> +
> +out:
> pm_runtime_mark_last_busy(i2c->dev);
> pm_runtime_put_autosuspend(i2c->dev);
> return err;
Reviewed-by: Michal Simek <michal.simek@amd.com>
Thanks,
Michal
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] i2c: cadence: cdns_i2c_master_xfer(): Fix runtime PM leak on error path
2023-04-14 2:10 [PATCH 1/2] i2c: cadence: cdns_i2c_master_xfer(): Fix runtime PM leak on error path Lars-Peter Clausen
2023-04-14 2:10 ` [PATCH 2/2] i2c: xiic: xiic_xfer(): " Lars-Peter Clausen
@ 2023-04-14 12:57 ` Michal Simek
2023-04-18 16:44 ` Wolfram Sang
2 siblings, 0 replies; 7+ messages in thread
From: Michal Simek @ 2023-04-14 12:57 UTC (permalink / raw)
To: Lars-Peter Clausen, Wolfram Sang; +Cc: Shubhrajyoti Datta, linux-i2c
On 4/14/23 04:10, Lars-Peter Clausen wrote:
> The cdns_i2c_master_xfer() function gets a runtime PM reference when the
> function is entered. This reference is released when the function is
> exited. There is currently one error path where the function exits
> directly, which leads to a leak of the runtime PM reference.
>
> Make sure that this error path also releases the runtime PM reference.
>
> Fixes: 1a351b10b967 ("i2c: cadence: Added slave support")
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> ---
> drivers/i2c/busses/i2c-cadence.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
> index f1a67c410ad3..3a4edf7e75f9 100644
> --- a/drivers/i2c/busses/i2c-cadence.c
> +++ b/drivers/i2c/busses/i2c-cadence.c
> @@ -834,8 +834,10 @@ static int cdns_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
> #if IS_ENABLED(CONFIG_I2C_SLAVE)
> /* Check i2c operating mode and switch if possible */
> if (id->dev_mode == CDNS_I2C_MODE_SLAVE) {
> - if (id->slave_state != CDNS_I2C_SLAVE_STATE_IDLE)
> - return -EAGAIN;
> + if (id->slave_state != CDNS_I2C_SLAVE_STATE_IDLE) {
> + ret = -EAGAIN;
> + goto out;
> + }
>
> /* Set mode to master */
> cdns_i2c_set_mode(CDNS_I2C_MODE_MASTER, id);
Reviewed-by: Michal Simek <michal.simek@amd.com>
Thanks,
Michal
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] i2c: cadence: cdns_i2c_master_xfer(): Fix runtime PM leak on error path
2023-04-14 2:10 [PATCH 1/2] i2c: cadence: cdns_i2c_master_xfer(): Fix runtime PM leak on error path Lars-Peter Clausen
2023-04-14 2:10 ` [PATCH 2/2] i2c: xiic: xiic_xfer(): " Lars-Peter Clausen
2023-04-14 12:57 ` [PATCH 1/2] i2c: cadence: cdns_i2c_master_xfer(): " Michal Simek
@ 2023-04-18 16:44 ` Wolfram Sang
2023-04-24 9:28 ` Wolfram Sang
2 siblings, 1 reply; 7+ messages in thread
From: Wolfram Sang @ 2023-04-18 16:44 UTC (permalink / raw)
To: Lars-Peter Clausen; +Cc: Michal Simek, Shubhrajyoti Datta, linux-i2c
[-- Attachment #1: Type: text/plain, Size: 586 bytes --]
On Thu, Apr 13, 2023 at 07:10:21PM -0700, Lars-Peter Clausen wrote:
> The cdns_i2c_master_xfer() function gets a runtime PM reference when the
> function is entered. This reference is released when the function is
> exited. There is currently one error path where the function exits
> directly, which leads to a leak of the runtime PM reference.
>
> Make sure that this error path also releases the runtime PM reference.
>
> Fixes: 1a351b10b967 ("i2c: cadence: Added slave support")
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Applied to for-current, thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] i2c: xiic: xiic_xfer(): Fix runtime PM leak on error path
2023-04-14 2:10 ` [PATCH 2/2] i2c: xiic: xiic_xfer(): " Lars-Peter Clausen
2023-04-14 12:57 ` Michal Simek
@ 2023-04-18 16:44 ` Wolfram Sang
1 sibling, 0 replies; 7+ messages in thread
From: Wolfram Sang @ 2023-04-18 16:44 UTC (permalink / raw)
To: Lars-Peter Clausen; +Cc: Michal Simek, Shubhrajyoti Datta, linux-i2c
[-- Attachment #1: Type: text/plain, Size: 588 bytes --]
On Thu, Apr 13, 2023 at 07:10:22PM -0700, Lars-Peter Clausen wrote:
> The xiic_xfer() function gets a runtime PM reference when the function is
> entered. This reference is released when the function is exited. There is
> currently one error path where the function exits directly, which leads to
> a leak of the runtime PM reference.
>
> Make sure that this error path also releases the runtime PM reference.
>
> Fixes: fdacc3c7405d ("i2c: xiic: Switch from waitqueue to completion")
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Applied to for-current, thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] i2c: cadence: cdns_i2c_master_xfer(): Fix runtime PM leak on error path
2023-04-18 16:44 ` Wolfram Sang
@ 2023-04-24 9:28 ` Wolfram Sang
0 siblings, 0 replies; 7+ messages in thread
From: Wolfram Sang @ 2023-04-24 9:28 UTC (permalink / raw)
To: Lars-Peter Clausen, Michal Simek, Shubhrajyoti Datta, linux-i2c
[-- Attachment #1: Type: text/plain, Size: 737 bytes --]
On Tue, Apr 18, 2023 at 06:44:39PM +0200, Wolfram Sang wrote:
> On Thu, Apr 13, 2023 at 07:10:21PM -0700, Lars-Peter Clausen wrote:
> > The cdns_i2c_master_xfer() function gets a runtime PM reference when the
> > function is entered. This reference is released when the function is
> > exited. There is currently one error path where the function exits
> > directly, which leads to a leak of the runtime PM reference.
> >
> > Make sure that this error path also releases the runtime PM reference.
> >
> > Fixes: 1a351b10b967 ("i2c: cadence: Added slave support")
> > Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
>
> Applied to for-current, thanks!
Sorry, I missed 6.3. I'll merge this into my PR for 6.4-rc1.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-04-24 9:28 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-14 2:10 [PATCH 1/2] i2c: cadence: cdns_i2c_master_xfer(): Fix runtime PM leak on error path Lars-Peter Clausen
2023-04-14 2:10 ` [PATCH 2/2] i2c: xiic: xiic_xfer(): " Lars-Peter Clausen
2023-04-14 12:57 ` Michal Simek
2023-04-18 16:44 ` Wolfram Sang
2023-04-14 12:57 ` [PATCH 1/2] i2c: cadence: cdns_i2c_master_xfer(): " Michal Simek
2023-04-18 16:44 ` Wolfram Sang
2023-04-24 9:28 ` Wolfram Sang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox