* [PATCH] dmaengine: dw-axi-dmac: Fix channel unregistration on remove
@ 2026-12-03 6:28 Yige Jiang
2026-12-03 17:10 ` Frank Li
0 siblings, 1 reply; 3+ messages in thread
From: Yige Jiang @ 2026-12-03 6:28 UTC (permalink / raw)
To: Eugeniy Paltsev, Vinod Koul
Cc: Yige Jiang, Frank Li, dmaengine, linux-kernel, stable
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.
Fixes: 1fe20f1b8454 ("dmaengine: Introduce DW AXI DMAC driver")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/all/20260727211146.D154F1F00A3A@smtp.kernel.org/
Signed-off-by: Yige Jiang <yigejiang86@gmail.com>
---
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(-)
diff --git a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
index 7520c78f55ccf69294fdbc055d683469cf8c3078..cf8c4403d7ddae3bd0f3028098346e9a0a526d33 100644
--- a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
+++ b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
@@ -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
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] dmaengine: dw-axi-dmac: Fix channel unregistration on remove
2026-12-03 6:28 [PATCH] dmaengine: dw-axi-dmac: Fix channel unregistration on remove Yige Jiang
@ 2026-12-03 17:10 ` Frank Li
2026-12-03 17:14 ` Yige Jiang
0 siblings, 1 reply; 3+ messages in thread
From: Frank Li @ 2026-12-03 17:10 UTC (permalink / raw)
To: Yige Jiang
Cc: Eugeniy Paltsev, Vinod Koul, Frank Li, dmaengine, linux-kernel,
stable
On Thu, Dec 03, 2026 at 02:28:00PM +0800, Yige Jiang wrote:
> 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.
>
> Fixes: 1fe20f1b8454 ("dmaengine: Introduce DW AXI DMAC driver")
> Cc: stable@vger.kernel.org
> Link: https://lore.kernel.org/all/20260727211146.D154F1F00A3A@smtp.kernel.org/
> Signed-off-by: Yige Jiang <yigejiang86@gmail.com>
> ---
Can you combine similar fixes of the same subsystem to one patch series
next time.
Reviewed-by: Frank Li <Frank.Li@nxp.com>
> 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(-)
>
> diff --git a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> index 7520c78f55ccf69294fdbc055d683469cf8c3078..cf8c4403d7ddae3bd0f3028098346e9a0a526d33 100644
> --- a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> +++ b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> @@ -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
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] dmaengine: dw-axi-dmac: Fix channel unregistration on remove
2026-12-03 17:10 ` Frank Li
@ 2026-12-03 17:14 ` Yige Jiang
0 siblings, 0 replies; 3+ messages in thread
From: Yige Jiang @ 2026-12-03 17:14 UTC (permalink / raw)
To: Frank Li
Cc: Eugeniy Paltsev, Vinod Koul, Frank Li, dmaengine, linux-kernel,
stable
Sorry for that. Will do so next time, thanks.
Best,
Yige
> On Dec 4, 2026, at 1:10 AM, Frank Li <Frank.li@oss.nxp.com> wrote:
>
> On Thu, Dec 03, 2026 at 02:28:00PM +0800, Yige Jiang wrote:
>> 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.
>>
>> Fixes: 1fe20f1b8454 ("dmaengine: Introduce DW AXI DMAC driver")
>> Cc: stable@vger.kernel.org
>> Link: https://lore.kernel.org/all/20260727211146.D154F1F00A3A@smtp.kernel.org/
>> Signed-off-by: Yige Jiang <yigejiang86@gmail.com>
>> ---
>
> Can you combine similar fixes of the same subsystem to one patch series
> next time.
>
> Reviewed-by: Frank Li <Frank.Li@nxp.com>
>
>> 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(-)
>>
>> diff --git a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
>> index 7520c78f55ccf69294fdbc055d683469cf8c3078..cf8c4403d7ddae3bd0f3028098346e9a0a526d33 100644
>> --- a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
>> +++ b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
>> @@ -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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-03 17:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 6:28 [PATCH] dmaengine: dw-axi-dmac: Fix channel unregistration on remove Yige Jiang
2026-12-03 17:10 ` Frank Li
2026-12-03 17:14 ` Yige Jiang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox