[PATCH] i2c: mxs: fix DMA channel leak on probe error

Ruoyu Wang posted 1 patch an hour ago
drivers/i2c/busses/i2c-mxs.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
[PATCH] i2c: mxs: fix DMA channel leak on probe error
Posted by Ruoyu Wang an hour ago
dma_request_chan() grants the driver exclusive use of the channel until
dma_release_channel() is called. If controller reset or I2C adapter
registration fails after the request, mxs_i2c_probe() returns without
releasing it. The failed probe does not invoke mxs_i2c_remove(), so the
channel remains allocated and can prevent a later probe from acquiring
it.

Release the DMA channel on both post-request error paths. Keep the
adapter-registration unwind ordered after the existing controller reset.

This issue was found by a static analysis checker and confirmed by
manual source review.

Fixes: 62885f59a261 ("MXS: Implement DMA support into mxs-i2c")
Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
---
 drivers/i2c/busses/i2c-mxs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-mxs.c b/drivers/i2c/busses/i2c-mxs.c
index 4e07babea9c3f..a5c8b44ec8142 100644
--- a/drivers/i2c/busses/i2c-mxs.c
+++ b/drivers/i2c/busses/i2c-mxs.c
@@ -849,8 +849,10 @@ static int mxs_i2c_probe(struct platform_device *pdev)
 
 	/* Do reset to enforce correct startup after pinmuxing */
 	err = mxs_i2c_reset(i2c);
-	if (err)
+	if (err) {
+		dma_release_channel(i2c->dmach);
 		return err;
+	}
 
 	adap = &i2c->adapter;
 	strscpy(adap->name, "MXS I2C adapter", sizeof(adap->name));
@@ -865,6 +867,7 @@ static int mxs_i2c_probe(struct platform_device *pdev)
 	if (err) {
 		writel(MXS_I2C_CTRL0_SFTRST,
 				i2c->regs + MXS_I2C_CTRL0_SET);
+		dma_release_channel(i2c->dmach);
 		return err;
 	}
 
-- 
2.51.0
Re: [PATCH] i2c: mxs: fix DMA channel leak on probe error
Posted by Frank Li 24 minutes ago
On Fri, Aug 14, 2026 at 09:40:33PM +0800, Ruoyu Wang wrote:
> [You don't often get email from ruoyuw560@gmail.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> dma_request_chan() grants the driver exclusive use of the channel until
> dma_release_channel() is called. If controller reset or I2C adapter
> registration fails after the request, mxs_i2c_probe() returns without
> releasing it. The failed probe does not invoke mxs_i2c_remove(), so the
> channel remains allocated and can prevent a later probe from acquiring
> it.
>
> Release the DMA channel on both post-request error paths. Keep the
> adapter-registration unwind ordered after the existing controller reset.
>
> This issue was found by a static analysis checker and confirmed by
> manual source review.
>
> Fixes: 62885f59a261 ("MXS: Implement DMA support into mxs-i2c")
> Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
> ---
>  drivers/i2c/busses/i2c-mxs.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/i2c/busses/i2c-mxs.c b/drivers/i2c/busses/i2c-mxs.c
> index 4e07babea9c3f..a5c8b44ec8142 100644
> --- a/drivers/i2c/busses/i2c-mxs.c
> +++ b/drivers/i2c/busses/i2c-mxs.c
> @@ -849,8 +849,10 @@ static int mxs_i2c_probe(struct platform_device *pdev)
>
>         /* Do reset to enforce correct startup after pinmuxing */
>         err = mxs_i2c_reset(i2c);
> -       if (err)
> +       if (err) {
> +               dma_release_channel(i2c->dmach);

Please use devm_dma_request_chan() to fix this problem

Frank
>                 return err;
> +       }
>
>         adap = &i2c->adapter;
>         strscpy(adap->name, "MXS I2C adapter", sizeof(adap->name));
> @@ -865,6 +867,7 @@ static int mxs_i2c_probe(struct platform_device *pdev)
>         if (err) {
>                 writel(MXS_I2C_CTRL0_SFTRST,
>                                 i2c->regs + MXS_I2C_CTRL0_SET);
> +               dma_release_channel(i2c->dmach);
>                 return err;
>         }
>
> --
> 2.51.0
>
>