Unbinding the DMA provider can free the channel while the I2C driver still owns it. I2C removal then accesses the freed channel in dma_release_channel(). Add a managed device link after DMA setup so the I2C driver is removed before the provider, even without firmware device links. If the link cannot be created, release the DMA resources and use the existing PIO fallback. This issue was found by our static analysis tool under development. Fixes: 86c92b9965ff ("i2c: tegra: Add DMA support") Cc: stable@vger.kernel.org Signed-off-by: Guangshuo Li --- drivers/i2c/busses/i2c-tegra.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 76d21bc51c61..306658e40d4b 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -731,6 +731,12 @@ static int tegra_i2c_init_dma(struct tegra_i2c_dev *i2c_dev) i2c_dev->dma_buf = dma_buf; i2c_dev->dma_phys = dma_phys; + if (!device_link_add(i2c_dev->dev, i2c_dev->dma_chan->device->dev, + DL_FLAG_AUTOREMOVE_CONSUMER)) { + err = -ENOMEM; + goto err_out; + } + return 0; err_out: base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4 -- 2.43.0