mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] i2c: qcom-geni: fix double free of the DMA bounce buffer
@ 2026-10-28 15:33 Thomas Fourier
  2026-10-29  5:36 ` Mukesh Savaliya
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Fourier @ 2026-10-28 15:33 UTC (permalink / raw)
  Cc: Thomas Fourier, Mukesh Kumar Savaliya, Viken Dadhaniya,
	Andi Shyti, Sumit Semwal, Christian König, Philipp Stanner,
	Akash Asthana, Roja Rani Yarubandi, Wolfram Sang,
	open list:QUALCOMM I2C QCOM GENI DRIVER,
	open list:QUALCOMM I2C QCOM GENI DRIVER, open list,
	open list:DMA BUFFER SHARING
	FRAMEWORK:Keyword:bdma_(?:buf|fence|resv)b,
	open list:DMA BUFFER SHARING
	FRAMEWORK:Keyword:bdma_(?:buf|fence|resv)b,
	moderated list:DMA BUFFER SHARING
	FRAMEWORK:Keyword:bdma_(?:buf|fence|resv)b

geni_i2c_{rx,tx}_msg_cleanup() release gi2c->dma_buf through
i2c_put_dma_safe_msg_buf(), which kfree()s the bounce buffer when the
message buffer is not DMA safe, but leave the pointer set. gi2c->dma_buf
is only updated when the DMA setup in geni_i2c_{rx,tx}_one_msg()
succeeds. If the setup fails for a later message, the function clears
only its local copy, so the cleanup helper sees the stale pointer from
the previous transfer, unmaps it again and frees it a second time.

Clear gi2c->dma_buf once it has been released.

This bug was found statically and compile-tested only.

Fixes: 357ee8841d0b ("i2c: qcom-geni: Store DMA mapping data in geni_i2c_dev struct")
Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
---
 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 a431e98723ef..78701310936b 100644
--- a/drivers/i2c/busses/i2c-qcom-geni.c
+++ b/drivers/i2c/busses/i2c-qcom-geni.c
@@ -500,6 +500,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;
 	}
 }
 
@@ -512,6 +513,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.53.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-29  5:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-28 15:33 [PATCH] i2c: qcom-geni: fix double free of the DMA bounce buffer Thomas Fourier
2026-10-29  5:36 ` Mukesh Savaliya

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®