Linux Media Controller development
 help / color / mirror / Atom feed
* [PATCH 00/10] i2c: Fix Critical and High issues reported by Sashiko
@ 2026-12-03 18:31 Lee Jones
  2026-12-03 18:31 ` [PATCH 02/10] i2c: qcom-geni: Clear dma_buf pointer after releasing DMA buffer Lee Jones
  2026-12-03 18:31 ` [PATCH 03/10] i2c: sh_mobile: Terminate DMA before freeing bounce buffer in sh_mobile_xfer() Lee Jones
  0 siblings, 2 replies; 3+ messages in thread
From: Lee Jones @ 2026-12-03 18:31 UTC (permalink / raw)
  To: lee, Sumit Semwal, Christian König, Philipp Stanner,
	linux-media, dri-devel, linaro-mm-sig
  Cc: linux-kernel, Clément Le Goffic, Niklas Söderlund,
	Aaro Koskinen, Akash Asthana, Alain Volmat, Alexandre Torgue,
	Andi Shyti, Andreas Kemnade, Asmaa Mnebhi, Bakulchandra Shah,
	Carlos Munoz, Carlos Song, Cedric Madianga, Dong Aisheng,
	Elie Morisse, Fabio Estevam, Felipe Balbi, Frank Li, Gao Pan,
	Greg Kroah-Hartman, Hans de Goede, Imre Deak, imx, Israel Cepeda,
	Janusz Krzysztofik, Juha Yrjola, Kevin Hilman, Khalil Blaiech,
	linux-arm-kernel, linux-arm-msm, linux-i2c, linux-omap,
	linux-renesas-soc, linux-stm32, Maxime Coquelin,
	Mukesh Kumar Savaliya, Nishant Menon, Pengutronix Kernel Team,
	Pierre-Yves MORDRET, Piyush Malgujar, Robert Richter,
	Roger Quadros, Roja Rani Yarubandi, Sakari Ailus, Sascha Hauer,
	Shubhrajyoti D, Shyam Sundar S K, Siemens Networks,
	Suneel Garapati, Syed Khasim, Tony Lindgren, Vadim Pasternak,
	Vignesh R, Viken Dadhaniya, Wolfram Sang

These issues were reported by Sashiko.

Cc: "Clément Le Goffic" <clement.legoffic@foss.st.com>
Cc: "Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>
Cc: Aaro Koskinen <aaro.koskinen@iki.fi>
Cc: Akash Asthana <akashast@codeaurora.org>
Cc: Alain Volmat <alain.volmat@foss.st.com>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: Andi Shyti <andi.shyti@kernel.org>
Cc: Andreas Kemnade <andreas@kemnade.info>
Cc: Asmaa Mnebhi <asmaa@nvidia.com>
Cc: Bakulchandra Shah <Nehal-bakulchandra.shah@amd.com>
Cc: Carlos Munoz <carlos@kenati.com>
Cc: Carlos Song <carlos.song@nxp.com>
Cc: Cedric Madianga <cedric.madianga@gmail.com>
Cc: Dong Aisheng <aisheng.dong@nxp.com>
Cc: Elie Morisse <syniurge@gmail.com>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Felipe Balbi <balbi@ti.com>
Cc: Frank Li <Frank.Li@nxp.com>
Cc: Gao Pan <pandy.gao@nxp.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Hans de Goede <hansg@kernel.org>
Cc: Imre Deak <imre.deak@nokia.com>
Cc: imx@lists.linux.dev
Cc: Israel Cepeda <israel.a.cepeda.lopez@intel.com>
Cc: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Cc: Juha Yrjola <juha.yrjola@solidboot.com>
Cc: Kevin Hilman <khilman@baylibre.com>
Cc: Khalil Blaiech <kblaiech@nvidia.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-arm-msm@vger.kernel.org
Cc: linux-i2c@vger.kernel.org
Cc: linux-media@vger.kernel.org
Cc: linux-omap@vger.kernel.org
Cc: linux-renesas-soc@vger.kernel.org
Cc: linux-stm32@st-md-mailman.stormreply.com
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Mukesh Kumar Savaliya <mukesh.savaliya@oss.qualcomm.com>
Cc: Nishant Menon <nm@ti.com>
Cc: Pengutronix Kernel Team <kernel@pengutronix.de>
Cc: Pierre-Yves MORDRET <pierre-yves.mordret@foss.st.com>
Cc: Piyush Malgujar <pmalgujar@marvell.com>
Cc: Robert Richter <rric@kernel.org>
Cc: Roger Quadros <rogerq@kernel.org>
Cc: Roja Rani Yarubandi <rojay@codeaurora.org>
Cc: Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shubhrajyoti D <shubhrajyoti@ti.com>
Cc: Shyam Sundar S K <shyam-sundar.s-k@amd.com>
Cc: Siemens Networks <michael.lawnick.ext@nsn.com>
Cc: Suneel Garapati <sgarapati@marvell.com>
Cc: Syed Khasim <x0khasim@ti.com>
Cc: Tony Lindgren <tony@atomide.com>
Cc: Vadim Pasternak <vadimp@mellanox.com>
Cc: Vignesh R <vigneshr@ti.com>
Cc: Viken Dadhaniya <viken.dadhaniya@oss.qualcomm.com>
Cc: Wolfram Sang <wsa+renesas@sang-engineering.com>

Lee Jones (10):
  i2c: imx-lpi2c: Clear rx_cmd_buf pointer after freeing in
    lpi2c_imx_dma_xfer()
  i2c: qcom-geni: Clear dma_buf pointer after releasing DMA buffer
  i2c: sh_mobile: Terminate DMA before freeing bounce buffer in
    sh_mobile_xfer()
  i2c: omap: Check buf_len before buffer accesses in data transfer
    helpers
  i2c: stm32f7: Prevent duplicate execution of
    stm32f7_i2c_dma_callback()
  i2c: stm32f7: Allocate smbus_buf separately for DMA safety
  i2c: usbio: Validate full reply length in split-read loop
  i2c: amd-mp2: Synchronise IRQ completion with command timeout
  i2c: mlxbf: Reject zero-length SMBus reads to prevent stack overflow
  i2c: octeon: Guard to_pci_dev() with dev_is_pci() in
    octeon_i2c_set_clock()

 drivers/i2c/busses/i2c-amd-mp2-pci.c  | 29 ++++++++++++++----
 drivers/i2c/busses/i2c-amd-mp2-plat.c |  5 ----
 drivers/i2c/busses/i2c-amd-mp2.h      |  3 ++
 drivers/i2c/busses/i2c-imx-lpi2c.c    |  4 ++-
 drivers/i2c/busses/i2c-mlxbf.c        |  8 +++++
 drivers/i2c/busses/i2c-octeon-core.c  |  3 +-
 drivers/i2c/busses/i2c-omap.c         | 14 ++++++---
 drivers/i2c/busses/i2c-qcom-geni.c    |  2 ++
 drivers/i2c/busses/i2c-sh_mobile.c    | 18 ++++++-----
 drivers/i2c/busses/i2c-stm32f7.c      | 43 ++++++++++++++++++++++-----
 drivers/i2c/busses/i2c-usbio.c        |  4 +--
 11 files changed, 99 insertions(+), 34 deletions(-)

-- 
2.56.1.911.g883d8bcb20-goog


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

* [PATCH 02/10] i2c: qcom-geni: Clear dma_buf pointer after releasing DMA buffer
  2026-12-03 18:31 [PATCH 00/10] i2c: Fix Critical and High issues reported by Sashiko Lee Jones
@ 2026-12-03 18:31 ` Lee Jones
  2026-12-03 18:31 ` [PATCH 03/10] i2c: sh_mobile: Terminate DMA before freeing bounce buffer in sh_mobile_xfer() Lee Jones
  1 sibling, 0 replies; 3+ messages in thread
From: Lee Jones @ 2026-12-03 18:31 UTC (permalink / raw)
  To: lee, Mukesh Kumar Savaliya, Viken Dadhaniya, Andi Shyti,
	Sumit Semwal, Christian König, Philipp Stanner,
	Roja Rani Yarubandi, Akash Asthana, Wolfram Sang, linux-i2c,
	linux-arm-msm, linux-media, dri-devel, linaro-mm-sig
  Cc: linux-kernel, stable

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: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 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


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

* [PATCH 03/10] i2c: sh_mobile: Terminate DMA before freeing bounce buffer in sh_mobile_xfer()
  2026-12-03 18:31 [PATCH 00/10] i2c: Fix Critical and High issues reported by Sashiko Lee Jones
  2026-12-03 18:31 ` [PATCH 02/10] i2c: qcom-geni: Clear dma_buf pointer after releasing DMA buffer Lee Jones
@ 2026-12-03 18:31 ` Lee Jones
  1 sibling, 0 replies; 3+ messages in thread
From: Lee Jones @ 2026-12-03 18:31 UTC (permalink / raw)
  To: lee, Wolfram Sang, Andi Shyti, Sumit Semwal, Christian König,
	Philipp Stanner, Carlos Munoz, Niklas Söderlund,
	linux-renesas-soc, linux-i2c, linux-media, dri-devel,
	linaro-mm-sig
  Cc: linux-kernel, stable

In sh_mobile_xfer(), i2c_put_dma_safe_msg_buf() is called immediately
after wait_event_timeout(), before checking for a timeout or an active
DMA transfer and calling sh_mobile_i2c_cleanup_dma().  On a timeout or
early NACK wakeup while DMA is still running, the bounce buffer is
freed while still mapped for DMA.

Select the DMA channel from the immutable message direction flag rather
than mutable pd->dma_direction, always synchronise and terminate the
channel in sh_mobile_xfer() before calling i2c_put_dma_safe_msg_buf(),
re-check pd->dma_direction after dmaengine_terminate_sync() to avoid
double unmapping, and update pd->pos, pd->stop_after_dma, and ICIC
before clearing pd->dma_direction in sh_mobile_i2c_dma_callback().

Fixes: cebc07d84ad7 ("i2c: sh_mobile: fix leak when using DMA bounce buffer")
Closes: https://sashiko.dev/#/bug/linux-af86edab-c752-40c1-9d09-2abb42f140f3
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/i2c/busses/i2c-sh_mobile.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c
index 0d10742a8ec0..d7aa710767c7 100644
--- a/drivers/i2c/busses/i2c-sh_mobile.c
+++ b/drivers/i2c/busses/i2c-sh_mobile.c
@@ -445,12 +445,17 @@ static irqreturn_t sh_mobile_i2c_isr(int irq, void *dev_id)
 
 static void sh_mobile_i2c_cleanup_dma(struct sh_mobile_i2c_data *pd, bool terminate)
 {
-	struct dma_chan *chan = pd->dma_direction == DMA_FROM_DEVICE
+	struct dma_chan *chan = (pd->msg->flags & I2C_M_RD)
 				? pd->dma_rx : pd->dma_tx;
 
 	/* only allowed from thread context! */
-	if (terminate)
+	if (terminate) {
+		if (IS_ERR_OR_NULL(chan))
+			return;
 		dmaengine_terminate_sync(chan);
+		if (pd->dma_direction == DMA_NONE)
+			return;
+	}
 
 	dma_unmap_single(chan->device->dev, sg_dma_address(&pd->sg),
 			 pd->msg->len, pd->dma_direction);
@@ -462,11 +467,10 @@ static void sh_mobile_i2c_dma_callback(void *data)
 {
 	struct sh_mobile_i2c_data *pd = data;
 
-	sh_mobile_i2c_cleanup_dma(pd, false);
 	pd->pos = pd->msg->len;
 	pd->stop_after_dma = true;
-
 	iic_set_clr(pd, ICIC, 0, ICIC_TDMAE | ICIC_RDMAE);
+	sh_mobile_i2c_cleanup_dma(pd, false);
 }
 
 static struct dma_chan *sh_mobile_i2c_request_dma_chan(struct device *dev,
@@ -682,15 +686,15 @@ static int sh_mobile_xfer(struct sh_mobile_i2c_data *pd,
 					pd->sr & (ICSR_TACK | SW_DONE),
 					pd->adap.timeout);
 
+			if (pd->dma_buf)
+				sh_mobile_i2c_cleanup_dma(pd, true);
+
 			/* 'stop_after_dma' tells if DMA xfer was complete */
 			i2c_put_dma_safe_msg_buf(pd->dma_buf, pd->msg,
 						 pd->stop_after_dma);
 		}
 
 		if (!time_left) {
-			if (pd->dma_direction != DMA_NONE)
-				sh_mobile_i2c_cleanup_dma(pd, true);
-
 			err = -ETIMEDOUT;
 			break;
 		}
-- 
2.56.1.911.g883d8bcb20-goog


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

end of thread, other threads:[~2026-12-03 18:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 18:31 [PATCH 00/10] i2c: Fix Critical and High issues reported by Sashiko Lee Jones
2026-12-03 18:31 ` [PATCH 02/10] i2c: qcom-geni: Clear dma_buf pointer after releasing DMA buffer Lee Jones
2026-12-03 18:31 ` [PATCH 03/10] i2c: sh_mobile: Terminate DMA before freeing bounce buffer in sh_mobile_xfer() Lee Jones

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