* [PATCH v2] i2c: mxs: fix DMA channel leak on probe error
@ 2026-08-15 15:17 Ruoyu Wang
2026-08-17 15:57 ` Frank Li
0 siblings, 1 reply; 2+ messages in thread
From: Ruoyu Wang @ 2026-08-15 15:17 UTC (permalink / raw)
To: Andi Shyti, Frank Li, Sascha Hauer, Pengutronix Kernel Team,
Fabio Estevam, Marek Vasut, Wolfram Sang
Cc: linux-i2c, imx, linux-arm-kernel, linux-kernel, Ruoyu Wang
mxs_i2c_probe() requests an exclusive DMA channel before resetting the
controller and registering the I2C adapter. If either later operation
fails, probe returns without releasing the channel because the remove
callback is not invoked after a failed probe.
Use devm_dma_request_chan() so the device core releases the channel on
probe failure and driver detach. Remove the manual release from the
remove callback because the channel is now device-managed.
This issue was found by a static analysis checker and confirmed by
manual source review.
Fixes: 62885f59a261 ("MXS: Implement DMA support into mxs-i2c")
Assisted-by: unnamed:claude-opus-4.8 typestate
Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
---
Changes in v2:
- Use devm_dma_request_chan() instead of explicit error unwinding.
- Remove the now-redundant manual release in remove().
- Add the Assisted-by tag.
v1: https://lore.kernel.org/r/20260814134033.1386874-1-ruoyuw560@gmail.com/
---
drivers/i2c/busses/i2c-mxs.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/i2c/busses/i2c-mxs.c b/drivers/i2c/busses/i2c-mxs.c
index 4e07babea9c3f4..eee4fdcd9df31a 100644
--- a/drivers/i2c/busses/i2c-mxs.c
+++ b/drivers/i2c/busses/i2c-mxs.c
@@ -839,7 +839,7 @@ static int mxs_i2c_probe(struct platform_device *pdev)
}
/* Setup the DMA */
- i2c->dmach = dma_request_chan(dev, "rx-tx");
+ i2c->dmach = devm_dma_request_chan(dev, "rx-tx");
if (IS_ERR(i2c->dmach)) {
return dev_err_probe(dev, PTR_ERR(i2c->dmach),
"Failed to request dma\n");
@@ -877,9 +877,6 @@ static void mxs_i2c_remove(struct platform_device *pdev)
i2c_del_adapter(&i2c->adapter);
- if (i2c->dmach)
- dma_release_channel(i2c->dmach);
-
writel(MXS_I2C_CTRL0_SFTRST, i2c->regs + MXS_I2C_CTRL0_SET);
}
--
2.51.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v2] i2c: mxs: fix DMA channel leak on probe error
2026-08-15 15:17 [PATCH v2] i2c: mxs: fix DMA channel leak on probe error Ruoyu Wang
@ 2026-08-17 15:57 ` Frank Li
0 siblings, 0 replies; 2+ messages in thread
From: Frank Li @ 2026-08-17 15:57 UTC (permalink / raw)
To: Ruoyu Wang
Cc: Andi Shyti, Frank Li, Sascha Hauer, Pengutronix Kernel Team,
Fabio Estevam, Marek Vasut, Wolfram Sang, linux-i2c, imx,
linux-arm-kernel, linux-kernel
On Sat, Aug 15, 2026 at 11:17:20PM +0800, Ruoyu Wang wrote:
> mxs_i2c_probe() requests an exclusive DMA channel before resetting the
> controller and registering the I2C adapter. If either later operation
> fails, probe returns without releasing the channel because the remove
> callback is not invoked after a failed probe.
>
> Use devm_dma_request_chan() so the device core releases the channel on
> probe failure and driver detach. Remove the manual release from the
> remove callback because the channel is now device-managed.
>
> This issue was found by a static analysis checker and confirmed by
> manual source review.
>
> Fixes: 62885f59a261 ("MXS: Implement DMA support into mxs-i2c")
> Assisted-by: unnamed:claude-opus-4.8 typestate
> Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.com>
> Changes in v2:
> - Use devm_dma_request_chan() instead of explicit error unwinding.
> - Remove the now-redundant manual release in remove().
> - Add the Assisted-by tag.
>
> v1: https://lore.kernel.org/r/20260814134033.1386874-1-ruoyuw560@gmail.com/
> ---
> drivers/i2c/busses/i2c-mxs.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-mxs.c b/drivers/i2c/busses/i2c-mxs.c
> index 4e07babea9c3f4..eee4fdcd9df31a 100644
> --- a/drivers/i2c/busses/i2c-mxs.c
> +++ b/drivers/i2c/busses/i2c-mxs.c
> @@ -839,7 +839,7 @@ static int mxs_i2c_probe(struct platform_device *pdev)
> }
>
> /* Setup the DMA */
> - i2c->dmach = dma_request_chan(dev, "rx-tx");
> + i2c->dmach = devm_dma_request_chan(dev, "rx-tx");
> if (IS_ERR(i2c->dmach)) {
> return dev_err_probe(dev, PTR_ERR(i2c->dmach),
> "Failed to request dma\n");
> @@ -877,9 +877,6 @@ static void mxs_i2c_remove(struct platform_device *pdev)
>
> i2c_del_adapter(&i2c->adapter);
>
> - if (i2c->dmach)
> - dma_release_channel(i2c->dmach);
> -
> writel(MXS_I2C_CTRL0_SFTRST, i2c->regs + MXS_I2C_CTRL0_SET);
> }
>
> --
> 2.51.0
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-08-17 15:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-15 15:17 [PATCH v2] i2c: mxs: fix DMA channel leak on probe error Ruoyu Wang
2026-08-17 15:57 ` Frank Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox