diff options
author | Peter Rosin <peda@axentia.se> | 2018-06-20 11:43:23 +0200 |
---|---|---|
committer | Simon Horman <horms+renesas@verge.net.au> | 2018-09-11 11:36:48 +0200 |
commit | a87465b56cbf03424640f54e48d38436e1f7e80b (patch) | |
tree | 1b4fab546abb84e30c2ddfda5ba7eccd09d90eec | |
parent | 5c77ee9b13a285eed79448e59f9d9e4a0c68a198 (diff) | |
download | renesas-backport-backport/v4.14.40/i2c.tar.gz |
i2c: smbus: kill memory leak on emulated and failed DMA SMBus xfersbackport/v4.14.40/i2c-selected-to-v4.19-rc3backport/v4.14.40/i2c
If DMA safe memory was allocated, but the subsequent I2C transfer
fails the memory is leaked. Plug this leak.
Fixes: 8a77821e74d6 ("i2c: smbus: use DMA safe buffers for emulated SMBus transactions")
Signed-off-by: Peter Rosin <peda@axentia.se>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Cc: stable@kernel.org
(cherry picked from commit 9aa613674f89d01248ae2e4afe691b515ff8fbb6)
Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
-rw-r--r-- | drivers/i2c/i2c-core-smbus.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c index 60b1ee21709c6..663173d347cbe 100644 --- a/drivers/i2c/i2c-core-smbus.c +++ b/drivers/i2c/i2c-core-smbus.c @@ -460,15 +460,18 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, status = i2c_transfer(adapter, msg, num); if (status < 0) - return status; - if (status != num) - return -EIO; + goto cleanup; + if (status != num) { + status = -EIO; + goto cleanup; + } + status = 0; /* Check PEC if last message is a read */ if (i && (msg[num-1].flags & I2C_M_RD)) { status = i2c_smbus_check_pec(partial_pec, &msg[num-1]); if (status < 0) - return status; + goto cleanup; } if (read_write == I2C_SMBUS_READ) @@ -494,12 +497,13 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, break; } +cleanup: if (msg[0].flags & I2C_M_DMA_SAFE) kfree(msg[0].buf); if (msg[1].flags & I2C_M_DMA_SAFE) kfree(msg[1].buf); - return 0; + return status; } /** |