i2c: smbus: kill memory leak on emulated and failed DMA SMBus xfers
If DMA safe memory was allocated, but the subsequent I2C transfer
fails the memory is leaked. Plug this leak.
Fixes: 8a77821e74
("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
This commit is contained in:
parent
2173ed0adc
commit
9aa613674f
|
@ -465,15 +465,18 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,
|
||||||
|
|
||||||
status = i2c_transfer(adapter, msg, num);
|
status = i2c_transfer(adapter, msg, num);
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
return status;
|
goto cleanup;
|
||||||
if (status != num)
|
if (status != num) {
|
||||||
return -EIO;
|
status = -EIO;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
status = 0;
|
||||||
|
|
||||||
/* Check PEC if last message is a read */
|
/* Check PEC if last message is a read */
|
||||||
if (i && (msg[num-1].flags & I2C_M_RD)) {
|
if (i && (msg[num-1].flags & I2C_M_RD)) {
|
||||||
status = i2c_smbus_check_pec(partial_pec, &msg[num-1]);
|
status = i2c_smbus_check_pec(partial_pec, &msg[num-1]);
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
return status;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read_write == I2C_SMBUS_READ)
|
if (read_write == I2C_SMBUS_READ)
|
||||||
|
@ -499,12 +502,13 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cleanup:
|
||||||
if (msg[0].flags & I2C_M_DMA_SAFE)
|
if (msg[0].flags & I2C_M_DMA_SAFE)
|
||||||
kfree(msg[0].buf);
|
kfree(msg[0].buf);
|
||||||
if (msg[1].flags & I2C_M_DMA_SAFE)
|
if (msg[1].flags & I2C_M_DMA_SAFE)
|
||||||
kfree(msg[1].buf);
|
kfree(msg[1].buf);
|
||||||
|
|
||||||
return 0;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue