diff mbox series

[1/2] i2c: cadence: cdns_i2c_master_xfer(): Fix runtime PM leak on error path

Message ID 20230414021022.505291-1-lars@metafoo.de
State New
Headers show
Series [1/2] i2c: cadence: cdns_i2c_master_xfer(): Fix runtime PM leak on error path | expand

Commit Message

Lars-Peter Clausen April 14, 2023, 2:10 a.m. UTC
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(-)

Comments

Wolfram Sang April 18, 2023, 4:44 p.m. UTC | #1
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!
Wolfram Sang April 24, 2023, 9:28 a.m. UTC | #2
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.
diff mbox series

Patch

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);