]> git.hungrycats.org Git - linux/commit
i2c: imx-lpi2c: fix resource leaks switching to devm_dma_request_chan()
authorCarlos Song <carlos.song@nxp.com>
Wed, 20 May 2026 09:33:23 +0000 (17:33 +0800)
committerAndi Shyti <andi.shyti@kernel.org>
Tue, 9 Jun 2026 08:13:09 +0000 (10:13 +0200)
commit695fcefd4a81466ef9c529790b4e96f1ea2ba051
tree86ef8f290354ab81fc5ffa8742c3ccfc1e313978
parent656646b3847ac6a21b074a813223feef2aadd6e2
i2c: imx-lpi2c: fix resource leaks switching to devm_dma_request_chan()

The LPI2C driver requests DMA channels using dma_request_chan(), but
never releases them in lpi2c_imx_remove(), resulting in DMA channel
leaks every time the driver is unloaded.

Additionally, when lpi2c_dma_init() successfully requests the TX DMA
channel but fails to request the RX DMA channel, the probe falls back
to PIO mode and completes successfully. Since probe succeeds, the devres
framework will not trigger any cleanup, leaving the TX DMA channel and
the memory allocated for the dma structure held for the lifetime of the
device even though DMA is never used.

Switch to devm_dma_request_chan() to let the device core manage DMA
channel lifetime automatically. Wrap all allocations within a devres
group so that devres_release_group() can release all partially acquired
resources when DMA init fails and probe continues in PIO mode.

Fixes: a09c8b3f9047 ("i2c: imx-lpi2c: add eDMA mode support for LPI2C")
Signed-off-by: Carlos Song <carlos.song@nxp.com>
Cc: <stable@vger.kernel.org> # v6.14+
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
Link: https://lore.kernel.org/r/20260520093323.2882070-1-carlos.song@oss.nxp.com
drivers/i2c/busses/i2c-imx-lpi2c.c