Skip to contentSkip to conversation

i2c: cadence: cdns_i2c_master_xfer(): Fix runtime PM leak on error path

PATCH Applied Lars-Peter Clausen 3 participants 7 messages Apr 14, 2023 – Apr 24, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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

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")
---
 drivers/i2c/busses/i2c-cadence.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-cadence.c +4 -2
index f1a67c410ad3..3a4edf7e75f9 100644
@@ -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);
Signature · 1 line
2.30.2
#1 lore raw

PATCH 2/2 i2c: xiic: xiic_xfer(): Fix runtime PM leak on error path

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")
---
 drivers/i2c/busses/i2c-xiic.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-xiic.c +3 -1
index e7d37eb20f2b..8a3d9817cb41 100644
@@ -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;
Signature · 1 line
2.30.2
maintainer Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] i2c: xiic: xiic_xfer(): Fix runtime PM leak on error path

Quoted 27 lines · 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")
---
  drivers/i2c/busses/i2c-xiic.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-xiic.c +1 -1
index e7d37eb20f2b..8a3d9817cb41 100644
@@ -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);

drivers/i2c/busses/i2c-xiic.c static int xiic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) · line 1185

Quoted 8 lines
drivers/i2c/busses/i2c-xiic.c +2 -0
@@ -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;

Thanks,
Michal

Applied
#3 lore raw

Re: [PATCH 2/2] i2c: xiic: xiic_xfer(): Fix runtime PM leak on error path

In reply to Lars-Peter Clausen
Quoted 9 lines · 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")

Applied to for-current, thanks!

maintainer Reviewed-by on v1 1/2
#4 lore raw
In reply to Lars-Peter Clausen
Quoted 20 lines · 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")
---
  drivers/i2c/busses/i2c-cadence.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-cadence.c +0 -0
index f1a67c410ad3..3a4edf7e75f9 100644
@@ -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 */

drivers/i2c/busses/i2c-cadence.c static int cdns_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, · line 843

Quoted 10 lines
drivers/i2c/busses/i2c-cadence.c +4 -2
  	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);

Thanks,
Michal

Applied
#5 lore raw
In reply to Lars-Peter Clausen
Quoted 9 lines · 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")

Applied to for-current, thanks!

#6 lore raw
Quoted 6 lines · Wolfram Sang
Quoted 5 lines · 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.

Quoted 6 lines
Quoted 4 lines

Make sure that this error path also releases the runtime PM reference.

Fixes 1a351b10b967 ("i2c: cadence: Added slave support")

Applied to for-current, thanks!

Sorry, I missed 6.3. I'll merge this into my PR for 6.4-rc1.