geni_i2c_rx_msg_cleanup() and geni_i2c_tx_msg_cleanup() release
gi2c->dma_buf without setting it back to NULL.  If a subsequent
transfer fails geni_se_{rx,tx}_dma_prep() and falls back to FIFO mode,
gi2c->dma_buf retains the stale pointer from the previous transfer,
causing the cleanup helper to unprepare and free the buffer a second
time.

Set gi2c->dma_buf to NULL after releasing it in both cleanup functions.

Fixes: 357ee8841d0b ("i2c: qcom-geni: Store DMA mapping data in geni_i2c_dev 
struct")
Closes: https://sashiko.dev/#/bug/linux-d60db3da-ca85-40ac-8a6c-62b1d80be7ac
Cc: [email protected]
Signed-off-by: Lee Jones <[email protected]>
---
 drivers/i2c/busses/i2c-qcom-geni.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/i2c/busses/i2c-qcom-geni.c 
b/drivers/i2c/busses/i2c-qcom-geni.c
index 926bc484ead2..6779719bbefa 100644
--- a/drivers/i2c/busses/i2c-qcom-geni.c
+++ b/drivers/i2c/busses/i2c-qcom-geni.c
@@ -505,6 +505,7 @@ static void geni_i2c_rx_msg_cleanup(struct geni_i2c_dev 
*gi2c,
                        geni_i2c_rx_fsm_rst(gi2c);
                geni_se_rx_dma_unprep(&gi2c->se, gi2c->dma_addr, 
gi2c->xfer_len);
                i2c_put_dma_safe_msg_buf(gi2c->dma_buf, cur, !gi2c->err);
+               gi2c->dma_buf = NULL;
        }
 }
 
@@ -517,6 +518,7 @@ static void geni_i2c_tx_msg_cleanup(struct geni_i2c_dev 
*gi2c,
                        geni_i2c_tx_fsm_rst(gi2c);
                geni_se_tx_dma_unprep(&gi2c->se, gi2c->dma_addr, 
gi2c->xfer_len);
                i2c_put_dma_safe_msg_buf(gi2c->dma_buf, cur, !gi2c->err);
+               gi2c->dma_buf = NULL;
        }
 }
 
-- 
2.56.1.911.g883d8bcb20-goog

Reply via email to