diff options
author | Wolfram Sang <wsa+renesas@sang-engineering.com> | 2018-08-24 16:52:46 +0200 |
---|---|---|
committer | Simon Horman <horms+renesas@verge.net.au> | 2018-09-17 15:54:30 +0200 |
commit | 720043a4efbb3356db116d084c7b877ad41ee51a (patch) | |
tree | ab5d0be414fdddc7d4bd657c7c547ddad30e9887 | |
parent | c496b99c8a87667d08d6e0f4ad8e11ae8c316930 (diff) | |
download | renesas-backport-720043a4efbb3356db116d084c7b877ad41ee51a.tar.gz |
i2c: sh_mobile: fix leak when using DMA bounce bufferbackport/v4.14.61/snapshot-to-v4.18+fixes-v2-flattened
We only freed the bounce buffer after successful DMA, missing the cases
where DMA setup may have gone wrong. Use a better location which always
gets called after each message and use 'stop_after_dma' as a flag for a
successful transfer.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
(cherry picked from commit cebc07d84ad71bc58d6f59b770e4347da48a5a2b)
Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
-rw-r--r-- | drivers/i2c/busses/i2c-sh_mobile.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c index 626009357f33f9..f4e04cec6bceb2 100644 --- a/drivers/i2c/busses/i2c-sh_mobile.c +++ b/drivers/i2c/busses/i2c-sh_mobile.c @@ -515,8 +515,6 @@ static void sh_mobile_i2c_dma_callback(void *data) pd->pos = pd->msg->len; pd->stop_after_dma = true; - i2c_put_dma_safe_msg_buf(pd->dma_buf, pd->msg, true); - iic_set_clr(pd, ICIC, 0, ICIC_TDMAE | ICIC_RDMAE); } @@ -719,6 +717,10 @@ static int sh_mobile_i2c_xfer(struct i2c_adapter *adapter, timeout = wait_event_timeout(pd->wait, pd->sr & (ICSR_TACK | SW_DONE), adapter->timeout); + + /* 'stop_after_dma' tells if DMA transfer was complete */ + i2c_put_dma_safe_msg_buf(pd->dma_buf, pd->msg, pd->stop_after_dma); + if (!timeout) { dev_err(pd->dev, "Transfer request timed out\n"); if (pd->dma_direction != DMA_NONE) |