* [PATCH 0/3] i2c: fix DMA channel leaks on probe error and remove
@ 2026-08-27 15:43 Shengzhuo Wei
2026-08-27 15:43 ` [PATCH 1/3] i2c: at91: release DMA channels on remove and probe error Shengzhuo Wei
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Shengzhuo Wei @ 2026-08-27 15:43 UTC (permalink / raw)
To: Codrin Ciubotariu, Andi Shyti, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Wolfram Sang, Ludovic Desroches, Oleksij Rempel,
Pengutronix Kernel Team, Frank Li, Sascha Hauer, Fabio Estevam,
Yao Yuan, Mukesh Kumar Savaliya, Viken Dadhaniya, Bjorn Andersson,
Vinod Koul, Konrad Dybcio, Praveen Talari
Cc: linux-i2c, linux-arm-kernel, linux-kernel, imx, linux-arm-msm,
stable, Shengzhuo Wei
Three I2C bus drivers request exclusive DMA channels before
registering their adapter, but none of them releases the channels on
the probe error path (the remove callback is not invoked after a
failed probe), and the at91 driver never releases them on remove
either. Same class as 777979e62711 ("i2c: mxs: fix DMA channel leak on
probe error"), which used devm_dma_request_chan() for mxs; here the
drivers own non-devm state, so the fixes release the channels
explicitly on the error paths.
The three drivers are otherwise unrelated; the series exists only
because the bug shape and the fix shape are identical.
---
Shengzhuo Wei (3):
i2c: at91: release DMA channels on remove and probe error
i2c: imx: release DMA channels on probe error
i2c: qcom-geni: release DMA channels on probe error
drivers/i2c/busses/i2c-at91-core.c | 3 +++
drivers/i2c/busses/i2c-at91-master.c | 12 +++++++++++-
drivers/i2c/busses/i2c-at91.h | 1 +
drivers/i2c/busses/i2c-imx.c | 2 ++
drivers/i2c/busses/i2c-qcom-geni.c | 4 +++-
5 files changed, 20 insertions(+), 2 deletions(-)
---
base-commit: 45c13f3f9e3bb15fd89ff2864c6f627a3b4b4229
change-id: 20260827-i2c-dma-channel-leak-b58522243736
Best regards,
--
Shengzhuo Wei <me@cherr.cc>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] i2c: at91: release DMA channels on remove and probe error
2026-08-27 15:43 [PATCH 0/3] i2c: fix DMA channel leaks on probe error and remove Shengzhuo Wei
@ 2026-08-27 15:43 ` Shengzhuo Wei
2026-08-27 15:43 ` [PATCH 2/3] i2c: imx: release DMA channels on " Shengzhuo Wei
2026-08-27 15:43 ` [PATCH 3/3] i2c: qcom-geni: " Shengzhuo Wei
2 siblings, 0 replies; 5+ messages in thread
From: Shengzhuo Wei @ 2026-08-27 15:43 UTC (permalink / raw)
To: Codrin Ciubotariu, Andi Shyti, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Wolfram Sang, Ludovic Desroches, Oleksij Rempel,
Pengutronix Kernel Team, Frank Li, Sascha Hauer, Fabio Estevam,
Yao Yuan, Mukesh Kumar Savaliya, Viken Dadhaniya, Bjorn Andersson,
Vinod Koul, Konrad Dybcio, Praveen Talari
Cc: linux-i2c, linux-arm-kernel, linux-kernel, imx, linux-arm-msm,
stable, Shengzhuo Wei
at91_twi_configure_dma() requests exclusive tx/rx DMA channels, but
nothing ever releases them on driver detach, and the probe error path
after the channels are acquired (i2c_add_numbered_adapter() failure)
returns without releasing them either, because the remove callback is
not invoked after a failed probe.
Move the release into a helper, call it from the existing
configure-failure path, the adapter-registration failure path, and
at91_twi_remove().
Fixes: 60937b2cdbf9 ("i2c: at91: add dma support")
Cc: stable@vger.kernel.org
Signed-off-by: Shengzhuo Wei <me@cherr.cc>
Assisted-by: GLM:5.3
---
drivers/i2c/busses/i2c-at91-core.c | 3 +++
drivers/i2c/busses/i2c-at91-master.c | 12 +++++++++++-
drivers/i2c/busses/i2c-at91.h | 1 +
3 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/drivers/i2c/busses/i2c-at91-core.c b/drivers/i2c/busses/i2c-at91-core.c
index b64adef778d4..8ca4556d9664 100644
--- a/drivers/i2c/busses/i2c-at91-core.c
+++ b/drivers/i2c/busses/i2c-at91-core.c
@@ -255,6 +255,7 @@ static int at91_twi_probe(struct platform_device *pdev)
if (rc) {
pm_runtime_disable(dev->dev);
pm_runtime_set_suspended(dev->dev);
+ at91_twi_dma_release(dev);
return rc;
}
@@ -270,6 +271,8 @@ static void at91_twi_remove(struct platform_device *pdev)
i2c_del_adapter(&dev->adapter);
+ at91_twi_dma_release(dev);
+
pm_runtime_disable(dev->dev);
pm_runtime_set_suspended(dev->dev);
}
diff --git a/drivers/i2c/busses/i2c-at91-master.c b/drivers/i2c/busses/i2c-at91-master.c
index 894cedbca99f..68238cc8aee0 100644
--- a/drivers/i2c/busses/i2c-at91-master.c
+++ b/drivers/i2c/busses/i2c-at91-master.c
@@ -817,11 +817,21 @@ static int at91_twi_configure_dma(struct at91_twi_dev *dev, u32 phy_addr)
error:
if (ret != -EPROBE_DEFER)
dev_info(dev->dev, "can't get DMA channel, continue without DMA support\n");
+ at91_twi_dma_release(dev);
+ return ret;
+}
+
+void at91_twi_dma_release(struct at91_twi_dev *dev)
+{
+ struct at91_twi_dma *dma = &dev->dma;
+
if (dma->chan_rx)
dma_release_channel(dma->chan_rx);
if (dma->chan_tx)
dma_release_channel(dma->chan_tx);
- return ret;
+ dma->chan_rx = NULL;
+ dma->chan_tx = NULL;
+ dev->use_dma = false;
}
static int at91_init_twi_recovery_gpio(struct platform_device *pdev,
diff --git a/drivers/i2c/busses/i2c-at91.h b/drivers/i2c/busses/i2c-at91.h
index 942e9c3973bb..d68fcbbc3e0f 100644
--- a/drivers/i2c/busses/i2c-at91.h
+++ b/drivers/i2c/busses/i2c-at91.h
@@ -172,6 +172,7 @@ void at91_twi_irq_restore(struct at91_twi_dev *dev);
void at91_init_twi_bus(struct at91_twi_dev *dev);
void at91_init_twi_bus_master(struct at91_twi_dev *dev);
+void at91_twi_dma_release(struct at91_twi_dev *dev);
int at91_twi_probe_master(struct platform_device *pdev, u32 phy_addr,
struct at91_twi_dev *dev);
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] i2c: imx: release DMA channels on probe error
2026-08-27 15:43 [PATCH 0/3] i2c: fix DMA channel leaks on probe error and remove Shengzhuo Wei
2026-08-27 15:43 ` [PATCH 1/3] i2c: at91: release DMA channels on remove and probe error Shengzhuo Wei
@ 2026-08-27 15:43 ` Shengzhuo Wei
2026-08-27 16:01 ` Frank Li
2026-08-27 15:43 ` [PATCH 3/3] i2c: qcom-geni: " Shengzhuo Wei
2 siblings, 1 reply; 5+ messages in thread
From: Shengzhuo Wei @ 2026-08-27 15:43 UTC (permalink / raw)
To: Codrin Ciubotariu, Andi Shyti, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Wolfram Sang, Ludovic Desroches, Oleksij Rempel,
Pengutronix Kernel Team, Frank Li, Sascha Hauer, Fabio Estevam,
Yao Yuan, Mukesh Kumar Savaliya, Viken Dadhaniya, Bjorn Andersson,
Vinod Koul, Konrad Dybcio, Praveen Talari
Cc: linux-i2c, linux-arm-kernel, linux-kernel, imx, linux-arm-msm,
stable, Shengzhuo Wei
i2c_imx_dma_request() acquires exclusive tx/rx DMA channels and is
optional: on errors other than -EPROBE_DEFER the driver falls back to
PIO mode and probe continues. If i2c_add_numbered_adapter() then fails,
probe returns through clk_notifier_unregister without releasing the
channels, because the remove callback is not invoked after a failed
probe.
Release the channels on the probe error path, mirroring
i2c_imx_remove().
Fixes: ce1a78840ff7 ("i2c: imx: add DMA support for freescale i2c driver")
Cc: stable@vger.kernel.org
Signed-off-by: Shengzhuo Wei <me@cherr.cc>
Assisted-by: GLM:5.3
---
drivers/i2c/busses/i2c-imx.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 19ec056b00af..c24d9201a60e 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -1880,6 +1880,8 @@ static int i2c_imx_probe(struct platform_device *pdev)
clk_notifier_unregister:
clk_notifier_unregister(i2c_imx->clk, &i2c_imx->clk_change_nb);
+ if (i2c_imx->dma)
+ i2c_imx_dma_free(i2c_imx);
free_irq(irq, i2c_imx);
rpm_disable:
pm_runtime_put_noidle(&pdev->dev);
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] i2c: qcom-geni: release DMA channels on probe error
2026-08-27 15:43 [PATCH 0/3] i2c: fix DMA channel leaks on probe error and remove Shengzhuo Wei
2026-08-27 15:43 ` [PATCH 1/3] i2c: at91: release DMA channels on remove and probe error Shengzhuo Wei
2026-08-27 15:43 ` [PATCH 2/3] i2c: imx: release DMA channels on " Shengzhuo Wei
@ 2026-08-27 15:43 ` Shengzhuo Wei
2 siblings, 0 replies; 5+ messages in thread
From: Shengzhuo Wei @ 2026-08-27 15:43 UTC (permalink / raw)
To: Codrin Ciubotariu, Andi Shyti, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Wolfram Sang, Ludovic Desroches, Oleksij Rempel,
Pengutronix Kernel Team, Frank Li, Sascha Hauer, Fabio Estevam,
Yao Yuan, Mukesh Kumar Savaliya, Viken Dadhaniya, Bjorn Andersson,
Vinod Koul, Konrad Dybcio, Praveen Talari
Cc: linux-i2c, linux-arm-kernel, linux-kernel, imx, linux-arm-msm,
stable, Shengzhuo Wei
geni_i2c_init() grabs exclusive GPI tx/rx DMA channels when the serial
engine runs in GPI mode. If i2c_add_adapter() subsequently fails, probe
returns without releasing the channels, because the remove callback is
not invoked after a failed probe.
The adapter-registration failure path used to release the channels via
its err_dma label; that release was dropped when the probe tail was
restructured into geni_i2c_init().
Release the channels on the adapter-registration failure path, mirroring
geni_i2c_remove().
Fixes: d8d3bb127ad1 ("i2c: qcom-geni: Isolate serial engine setup")
Cc: stable@vger.kernel.org
Signed-off-by: Shengzhuo Wei <me@cherr.cc>
Assisted-by: GLM:5.3
---
drivers/i2c/busses/i2c-qcom-geni.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c
index 658636c1ee0e..45c770552bd2 100644
--- a/drivers/i2c/busses/i2c-qcom-geni.c
+++ b/drivers/i2c/busses/i2c-qcom-geni.c
@@ -1189,8 +1189,10 @@ static int geni_i2c_probe(struct platform_device *pdev)
return ret;
ret = i2c_add_adapter(&gi2c->adap);
- if (ret)
+ if (ret) {
+ release_gpi_dma(gi2c);
return dev_err_probe(dev, ret, "Error adding i2c adapter\n");
+ }
dev_dbg(dev, "Geni-I2C adaptor successfully added\n");
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/3] i2c: imx: release DMA channels on probe error
2026-08-27 15:43 ` [PATCH 2/3] i2c: imx: release DMA channels on " Shengzhuo Wei
@ 2026-08-27 16:01 ` Frank Li
0 siblings, 0 replies; 5+ messages in thread
From: Frank Li @ 2026-08-27 16:01 UTC (permalink / raw)
To: sashiko-reviews
Cc: Codrin Ciubotariu, Andi Shyti, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Wolfram Sang, Ludovic Desroches, Oleksij Rempel,
Pengutronix Kernel Team, Frank Li, Sascha Hauer, Fabio Estevam,
Yao Yuan, Mukesh Kumar Savaliya, Viken Dadhaniya, Bjorn Andersson,
Vinod Koul, Konrad Dybcio, Praveen Talari, linux-i2c,
linux-arm-kernel, linux-kernel, imx, linux-arm-msm, stable
On Thu, Aug 27, 2026 at 11:43:02PM +0800, Shengzhuo Wei wrote:
> i2c_imx_dma_request() acquires exclusive tx/rx DMA channels and is
> optional: on errors other than -EPROBE_DEFER the driver falls back to
> PIO mode and probe continues. If i2c_add_numbered_adapter() then fails,
> probe returns through clk_notifier_unregister without releasing the
> channels, because the remove callback is not invoked after a failed
> probe.
>
> Release the channels on the probe error path, mirroring
> i2c_imx_remove().
>
> Fixes: ce1a78840ff7 ("i2c: imx: add DMA support for freescale i2c driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Shengzhuo Wei <me@cherr.cc>
> Assisted-by: GLM:5.3
Nit: signed-off-by should be last tag
Reviewed-by: Frank Li <Frank.Li@nxp.com>
> ---
> drivers/i2c/busses/i2c-imx.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index 19ec056b00af..c24d9201a60e 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -1880,6 +1880,8 @@ static int i2c_imx_probe(struct platform_device *pdev)
>
> clk_notifier_unregister:
> clk_notifier_unregister(i2c_imx->clk, &i2c_imx->clk_change_nb);
> + if (i2c_imx->dma)
> + i2c_imx_dma_free(i2c_imx);
> free_irq(irq, i2c_imx);
> rpm_disable:
> pm_runtime_put_noidle(&pdev->dev);
>
> --
> 2.47.3
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-08-27 16:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-27 15:43 [PATCH 0/3] i2c: fix DMA channel leaks on probe error and remove Shengzhuo Wei
2026-08-27 15:43 ` [PATCH 1/3] i2c: at91: release DMA channels on remove and probe error Shengzhuo Wei
2026-08-27 15:43 ` [PATCH 2/3] i2c: imx: release DMA channels on " Shengzhuo Wei
2026-08-27 16:01 ` Frank Li
2026-08-27 15:43 ` [PATCH 3/3] i2c: qcom-geni: " Shengzhuo Wei
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox