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.
Fixes: 134d9c52fca2 ("dmaengine: dw: dmamux: Introduce RZN1 DMA router support") Cc: stable@vger.kernel.org Signed-off-by: Miaoqian Lin linmq006@gmail.com --- drivers/dma/dw/rzn1-dmamux.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/drivers/dma/dw/rzn1-dmamux.c b/drivers/dma/dw/rzn1-dmamux.c index 4fb8508419db..deadf135681b 100644 --- a/drivers/dma/dw/rzn1-dmamux.c +++ b/drivers/dma/dw/rzn1-dmamux.c @@ -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); }
Hi,
On 02/09/2025 at 17:03:58 +08, Miaoqian Lin linmq006@gmail.com wrote:
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.
Fixes: 134d9c52fca2 ("dmaengine: dw: dmamux: Introduce RZN1 DMA router support") Cc: stable@vger.kernel.org Signed-off-by: Miaoqian Lin linmq006@gmail.com
Reviewed-by: Miquel Raynal miquel.raynal@bootlin.com
Thanks, Miquèl
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.
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/Docu...
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#L11...
3. How do you think about to append parentheses to the function name in the summary phrase?
Regards, Markus
On Tue, 02 Sep 2025 17:03:58 +0800, Miaoqian Lin wrote:
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.
Applied, thanks!
[1/1] dmaengine: dw: dmamux: Fix device reference leak in rzn1_dmamux_route_allocate commit: aa2e1e4563d3ab689ffa86ca1412ecbf9fd3b308
Best regards,
On Tue, Sep 02, 2025 at 05:03:58PM +0800, Miaoqian Lin wrote:
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.
How is this being found? Do you have a stacktrace or kmemleak reports?
Hi,
Andy Shevchenko andriy.shevchenko@linux.intel.com 于2025年9月2日周二 17:37写道:
On Tue, Sep 02, 2025 at 05:03:58PM +0800, Miaoqian Lin wrote:
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.
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.
-- With Best Regards, Andy Shevchenko
On Tue, Sep 02, 2025 at 06:18:18PM +0800, 林妙倩 wrote:
Andy Shevchenko andriy.shevchenko@linux.intel.com 于2025年9月2日周二 17:37写道:
On Tue, Sep 02, 2025 at 05:03:58PM +0800, Miaoqian Lin wrote:
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.
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.
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.
I don't have a stacktrace or kmemleak reports.
Andy Shevchenko andriy.shevchenko@linux.intel.com 于2025年9月2日周二 19:03写道:
On Tue, Sep 02, 2025 at 06:18:18PM +0800, 林妙倩 wrote:
Andy Shevchenko andriy.shevchenko@linux.intel.com 于2025年9月2日周二 17:37写道:
On Tue, Sep 02, 2025 at 05:03:58PM +0800, Miaoqian Lin wrote:
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.
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.
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.
I don't have a stacktrace or kmemleak reports.
-- With Best Regards, Andy Shevchenko
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/Docu...
Regards, Markus
linux-stable-mirror@lists.linaro.org