Skip to contentSkip to conversation

i2c: scmi: fix memory leak on invalid block length

PATCH New [email protected] 1 participant 1 message Nov 20 I2C subsystem host drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: scmi: fix memory leak on invalid block length

From: Mohammad Shahid <[email protected]>

When the returned block length is invalid,the function returns -EPROTO directly without freeing the ACPI response buffer.

Use goto out instead, so the allocated buffer is freed before returning the error.

---
 drivers/i2c/busses/i2c-scmi.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-scmi.c +4 -2
index 37442c9ee222..b65771d31a28 100644
@@ -248,8 +248,10 @@ acpi_smbus_cmi_access(struct i2c_adapter *adap, u16 addr, unsigned short flags,
 			result = -EIO;
 			goto out;
 		}
-		if (len == 0 || len > I2C_SMBUS_BLOCK_MAX)
-			return -EPROTO;
+		if (len == 0 || len > I2C_SMBUS_BLOCK_MAX) {
+			result = -EPROTO;
+			goto out;
+		}
 		data->block[0] = len;
 		memcpy(data->block + 1, obj->buffer.pointer, len);
 		break;
Signature · 1 line
2.43.0