dmaengine: dw-axi-dmac: Fix channel unregistration on remove
Subsystems (3)
PATCH 1/1 dmaengine: dw-axi-dmac: Fix channel unregistration on remove
dw_remove() deletes every channel from dw->dma.channels. The managed dma_async_device_unregister() subsequently walks that list to unregister the channel devices. It finds none, leaving the dma<N>chan<M> devices registered and their chan_dev->chan pointers uncleared.
Devres then frees dw->chan[], which embeds each dma_chan. Reading the remaining channel devices' sysfs attributes can dereference freed memory. The channel devices and their per-CPU counters also leak. The list was already emptied too early before the conversion to managed DMA device registration.
Keep the channels on the list and only kill their tasklets in remove. The interrupts have already been freed, so they cannot schedule more tasklets. The managed unregister can then clear chan_dev->chan and unregister the channel devices before the channel array is freed.
---
Based on dmaengine next as merged in next-20261201. Compile-tested on next-20261104: arm64, GCC 14.2.0, W=1, CONFIG_DW_AXI_DMAC=y and CONFIG_COMPILE_TEST=y. Baseline and patched objects built without warnings. The code changes are the same as in that build. No hardware or runtime test was performed.
drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c +2 -5
@@ -1630,7 +1630,7 @@ static void dw_remove(struct platform_device *pdev) {struct axi_dma_chip *chip =platform_get_drvdata (pdev);struct dw_axi_dma *dw = chip->dw; -struct axi_dma_chan *chan, *_chan; +struct axi_dma_chan *chan;u32 i;int ret;
@@ -1655,11 +1655,8 @@ static void dw_remove(struct platform_device *pdev)of_dma_controller_free (chip->dev->of_node); -list_for_each_entry_safe (chan, _chan, &dw->dma.channels, - vc.chan.device_node) { -list_del (&chan->vc.chan.device_node); +list_for_each_entry (chan, &dw->dma.channels, vc.chan.device_node)tasklet_kill (&chan->vc.task); - } }static const struct dev_pm_ops dw_axi_dma_pm_ops = {
base-commit: 2e02fb103be058cf8b2fb24112a74a2715e090f0
Quoted 16 lines · Yige Jiang
dw_remove()deletes every channel fromdw->dma.channels. The manageddma_async_device_unregister()subsequently walks that list to unregister the channel devices. It finds none, leaving the dma<N>chan<M> devices registered and theirchan_dev->chanpointers uncleared.Devres then frees dw->chan[], which embeds each
dma_chan. Reading the remaining channel devices' sysfs attributes can dereference freed memory. The channel devices and their per-CPU counters also leak. The list was already emptied too early before the conversion to managed DMA device registration.Keep the channels on the list and only kill their tasklets in remove. The interrupts have already been freed, so they cannot schedule more tasklets. The managed unregister can then clear
chan_dev->chanand unregister the channel devices before the channel array is freed.
Quoted 5 lines
Fixes 1fe20f1b8454 ("dmaengine: Introduce DW AXI DMAC driver")Signed-off-by Yige Jiang <[email protected]>---
Can you combine similar fixes of the same subsystem to one patch series next time.
Quoted 38 lines
Based on dmaengine next as merged in next-20261201. Compile-tested on next-20261104: arm64, GCC 14.2.0, W=1,
CONFIG_DW_AXI_DMAC=yandCONFIG_COMPILE_TEST=y. Baseline and patched objects built without warnings. The code changes are the same as in that build. No hardware or runtime test was performed.drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c +2
-5@@ -1630,7 +1630,7 @@ static void dw_remove(struct platform_device *pdev) {struct axi_dma_chip *chip =platform_get_drvdata (pdev);struct dw_axi_dma *dw = chip->dw; -struct axi_dma_chan *chan, *_chan; +struct axi_dma_chan *chan;u32 i;int ret;@@ -1655,11 +1655,8 @@ static void dw_remove(struct platform_device *pdev)of_dma_controller_free (chip->dev->of_node); -list_for_each_entry_safe (chan, _chan, &dw->dma.channels, - vc.chan.device_node) { -list_del (&chan->vc.chan.device_node); +list_for_each_entry (chan, &dw->dma.channels, vc.chan.device_node)tasklet_kill (&chan->vc.task); - } }static const struct dev_pm_ops dw_axi_dma_pm_ops = {base-commit:
2e02fb103be058cf8b2fb24112a74a2715e090f0
Sorry for that. Will do so next time, thanks.
Best,
Yige
Quoted 68 lines · Frank Li
Quoted 16 lines · Yige Jiang
dw_remove()deletes every channel fromdw->dma.channels. The manageddma_async_device_unregister()subsequently walks that list to unregister the channel devices. It finds none, leaving the dma<N>chan<M> devices registered and theirchan_dev->chanpointers uncleared.Devres then frees dw->chan[], which embeds each
dma_chan. Reading the remaining channel devices' sysfs attributes can dereference freed memory. The channel devices and their per-CPU counters also leak. The list was already emptied too early before the conversion to managed DMA device registration.Keep the channels on the list and only kill their tasklets in remove. The interrupts have already been freed, so they cannot schedule more tasklets. The managed unregister can then clear
chan_dev->chanand unregister the channel devices before the channel array is freed.Quoted 5 lines
Fixes 1fe20f1b8454 ("dmaengine: Introduce DW AXI DMAC driver")Signed-off-by Yige Jiang <[email protected]>---
Can you combine similar fixes of the same subsystem to one patch series next time.
Reviewed-by Frank Li <[email protected]>Quoted 38 lines
Based on dmaengine next as merged in next-20261201. Compile-tested on next-20261104: arm64, GCC 14.2.0, W=1,
CONFIG_DW_AXI_DMAC=yandCONFIG_COMPILE_TEST=y. Baseline and patched objects built without warnings. The code changes are the same as in that build. No hardware or runtime test was performed.
drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c| 7 ++-----1 file changed, 2 insertions(+), 5 deletions(-)drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c +2
-5@@ -1630,7 +1630,7 @@ static void dw_remove(struct platform_device *pdev) {struct axi_dma_chip *chip =platform_get_drvdata (pdev);struct dw_axi_dma *dw = chip->dw; -struct axi_dma_chan *chan, *_chan; +struct axi_dma_chan *chan;u32 i;int ret;@@ -1655,11 +1655,8 @@ static void dw_remove(struct platform_device *pdev)of_dma_controller_free (chip->dev->of_node); -list_for_each_entry_safe (chan, _chan, &dw->dma.channels, - vc.chan.device_node) { -list_del (&chan->vc.chan.device_node); +list_for_each_entry (chan, &dw->dma.channels, vc.chan.device_node)tasklet_kill (&chan->vc.task); - } }static const struct dev_pm_ops dw_axi_dma_pm_ops = {base-commit:
2e02fb103be058cf8b2fb24112a74a2715e090f0