* [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; 4+ 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] 4+ 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; 4+ 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] 4+ 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
2026-12-03 19:34 ` sashiko-bot
1 sibling, 1 reply; 4+ 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] 4+ messages in thread* Re: [PATCH 03/10] i2c: sh_mobile: Terminate DMA before freeing bounce buffer in sh_mobile_xfer()
2026-12-03 18:31 ` [PATCH 03/10] i2c: sh_mobile: Terminate DMA before freeing bounce buffer in sh_mobile_xfer() Lee Jones
@ 2026-12-03 19:34 ` sashiko-bot
0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-12-03 19:34 UTC (permalink / raw)
To: Lee Jones, dri-devel; +Cc: media-ci, wsa+renesas
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] i2c: sh_mobile: data race on dma_direction in
sh_mobile_i2c_dma_callback()
--
commit c6b6af1c3ce9c1df00cdd2b1dc80f991c809d4d9
Author: Lee Jones <lee@kernel.org>
i2c: sh_mobile: Terminate DMA before freeing bounce buffer in sh_mobile_xfer()
This commit terminates and synchronizes any active DMA channel in
sh_mobile_xfer() before freeing the bounce buffer with
i2c_put_dma_safe_msg_buf(). It also selects the DMA channel from
pd->msg->flags, re-checks pd->dma_direction after dmaengine_terminate_sync(),
and reorders sh_mobile_i2c_dma_callback().
> diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c
> index 0d10742a8ec0c..d7aa710767c75 100644
> --- a/drivers/i2c/busses/i2c-sh_mobile.c
> +++ b/drivers/i2c/busses/i2c-sh_mobile.c
[ ... ]
> @@ -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);
> }
[Severity: Low]
Does moving sh_mobile_i2c_cleanup_dma() after iic_set_clr() introduce a data
race on pd->dma_direction?
Clearing ICIC_TDMAE and ICIC_RDMAE unmasks the I2C hardware interrupt before
dma_unmap_single() and the store to pd->dma_direction complete:
CPU0 (DMAC threaded IRQ) CPU1 (<hardirq>)
sh_mobile_i2c_dma_callback()
iic_set_clr(pd, ICIC, 0, ...)
sh_mobile_i2c_cleanup_dma() sh_mobile_i2c_isr()
dma_unmap_single(...)
pd->dma_direction = DMA_NONE if (pd->dma_direction == ...)
<-- data race
sh_mobile_i2c_isr() reads pd->dma_direction unconditionally without locking
or READ_ONCE(), triggering a KCSAN data race on every normal DMA completion.
It can also wake sh_mobile_xfer() before dma_unmap_single() finishes, forcing
dmaengine_terminate_sync() to wait on the callback.
Calling sh_mobile_i2c_cleanup_dma(pd, false) after setting pd->pos and
pd->stop_after_dma, but before iic_set_clr(), avoids both the data race and
the premature wakeup.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203183214.1939736-1-lee@kernel.org?part=3
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-03 19:35 UTC | newest]
Thread overview: 4+ 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
2026-12-03 19:34 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox