dmaengine: dw: dmamux: Fix device reference leak in rzn1_dmamux_route_allocate
Subsystems (3)
PATCH 1/1 dmaengine: dw: dmamux: Fix device reference leak in rzn1_dmamux_route_allocate
The reference taken by of_find_device_by_node() must be released when not needed anymore.
Add missing put_device() call to fix device reference leaks.
--- drivers/dma/dw/rzn1-dmamux.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/dma/dw/rzn1-dmamux.c +11 -4
@@ -48,12 +48,16 @@ static void *rzn1_dmamux_route_allocate(struct of_phandle_args *dma_spec,u32 mask;int ret; -if (dma_spec->args_count !=RNZ1_DMAMUX_NCELLS ) -return ERR_PTR (-EINVAL ); +if (dma_spec->args_count !=RNZ1_DMAMUX_NCELLS ) { + ret = -EINVAL ; + goto put_device; + } map =kzalloc (sizeof (*map),GFP_KERNEL ); -if (!map) -return ERR_PTR (-ENOMEM ); +if (!map) { + ret = -ENOMEM ; + goto put_device; + } chan = dma_spec->args[0 ]; map->req_idx = dma_spec->args[4 ];
@@ -94,12 +98,15 @@ static void *rzn1_dmamux_route_allocate(struct of_phandle_args *dma_spec,if (ret) goto clear_bitmap; +put_device (&pdev->dev);return map; clear_bitmap:clear_bit (map->req_idx, dmamux->used_chans); free_map:kfree (map); +put_device: +put_device (&pdev->dev);return ERR_PTR (ret); }
Signature · 1 line
2.35.1
Hi,
Quoted 8 lines · Miaoqian Lin
The reference taken by
of_find_device_by_node()must be released when not needed anymore.
Add missingput_device()call to fix device reference leaks.Fixes 134d9c52fca2 ("dmaengine: dw: dmamux: Introduce RZN1 DMA router support")Signed-off-by Miaoqian Lin <[email protected]>---
Thanks,
Miquèl
Quoted 3 lines
The reference taken by
of_find_device_by_node()must be released when not needed anymore.
Add missingput_device()call to fix device reference leaks.
1. You may occasionally put more than 60 characters into text lines of such a change description.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.17-rc4#n638
2. Would you like to increase the application of scope-based resource management?
https://elixir.bootlin.com/linux/v6.17-rc4/source/include/linux/device.h#L1180
3. How do you think about to append parentheses to the function name in the summary phrase?
Regards,
Markus
Quoted 5 lines · Miaoqian Lin
The reference taken by
of_find_device_by_node()must be released when not needed anymore.
Add missingput_device()call to fix device reference leaks.
Applied, thanks!
[1/1] dmaengine: dw: dmamux: Fix device reference leak in rzn1_dmamux_route_allocate
commit: aa2e1e4563d3ab689ffa86ca1412ecbf9fd3b308
Best regards,
Signature · 1 line
~Vinod
Andy Shevchenko
reviewerQuoted 3 lines · Miaoqian Lin
The reference taken by
of_find_device_by_node()must be released when not needed anymore.
Add missingput_device()call to fix device reference leaks.
How is this being found? Do you have a stacktrace or kmemleak reports?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi,
Quoted 7 lines · Andy Shevchenko <[email protected]> 于2025年9月2日周二 17:37写道:
Quoted 3 lines · Miaoqian Lin
The reference taken by
of_find_device_by_node()must be released when not needed anymore.
Add missingput_device()call to fix device reference leaks.How is this being found? Do you have a stacktrace or kmemleak reports?
This was found through static code analysis.
The of_find_device_by_node() documentation states that it "takes a reference to the embedded struct device which needs to be dropped after use."
I cross-referenced other of_find_device_by_node() usage patterns to check the correct usage,
then audited this code and found the problem.
I don't have a stacktrace or kmemleak reports.
Quoted 6 lines
--
With Best Regards,
Andy Shevchenko
Andy Shevchenko
reviewerQuoted 8 lines · 林妙倩
Quoted 6 lines · Andy Shevchenko <[email protected]> 于2025年9月2日周二 17:37写道:
Quoted 3 lines · Miaoqian Lin
The reference taken by
of_find_device_by_node()must be released when not needed anymore.
Add missingput_device()call to fix device reference leaks.How is this being found? Do you have a stacktrace or kmemleak reports?
Quoted 8 lines
This was found through static code analysis.
Theof_find_device_by_node()documentation states that it "takes a reference to the embedded struct device which needs to be dropped after use."I cross-referenced other
of_find_device_by_node()usage patterns to check the correct usage,
then audited this code and found the problem.
You should summarise that in the commit message. But since it's already applied it's for the future and up to Vinos if he wants this to be updated.
Quoted 1 line
I don't have a stacktrace or kmemleak reports.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 15 lines · Andy Shevchenko <[email protected]> 于2025年9月2日周二 19:03写道:
Quoted 13 lines · 林妙倩
Quoted 6 lines · Andy Shevchenko <[email protected]> 于2025年9月2日周二 17:37写道:
Quoted 3 lines · Miaoqian Lin
The reference taken by
of_find_device_by_node()must be released when not needed anymore.
Add missingput_device()call to fix device reference leaks.How is this being found? Do you have a stacktrace or kmemleak reports?
This was found through static code analysis.
Theof_find_device_by_node()documentation states that it "takes a reference to the embedded struct device which needs to be dropped after use."
Quoted 7 lines
Quoted 3 lines
I cross-referenced other
of_find_device_by_node()usage patterns to check the correct usage,
then audited this code and found the problem.You should summarise that in the commit message. But since it's already applied it's for the future and up to Vinos if he wants this to be updated.
Thank you. I'll include such info in the commit messages for future patches.
Quoted 7 lines
Quoted 1 line
I don't have a stacktrace or kmemleak reports.
--
With Best Regards,
Andy Shevchenko
Quoted 1 line
This was found through static code analysis.
May you point the software tool name out?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/researcher-guidelines.rst?h=v6.17-rc4#n5
Regards,
Markus