linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dmaengine: dw: dmamux: Fix device reference leak in rzn1_dmamux_route_allocate
@ 2025-09-02  9:03 Miaoqian Lin
  2025-09-02  9:18 ` Miquel Raynal
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Miaoqian Lin @ 2025-09-02  9:03 UTC (permalink / raw)
  To: Viresh Kumar, Andy Shevchenko, Vinod Koul, Miquel Raynal,
	Ilpo Järvinen, dmaengine, linux-kernel
  Cc: linmq006, stable

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);
 }
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] dmaengine: dw: dmamux: Fix device reference leak in rzn1_dmamux_route_allocate
  2025-09-02  9:03 [PATCH] dmaengine: dw: dmamux: Fix device reference leak in rzn1_dmamux_route_allocate Miaoqian Lin
@ 2025-09-02  9:18 ` Miquel Raynal
  2025-09-02  9:24 ` Markus Elfring
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Miquel Raynal @ 2025-09-02  9:18 UTC (permalink / raw)
  To: Miaoqian Lin
  Cc: Viresh Kumar, Andy Shevchenko, Vinod Koul, Ilpo Järvinen,
	dmaengine, linux-kernel, stable

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] dmaengine: dw: dmamux: Fix device reference leak in rzn1_dmamux_route_allocate
  2025-09-02  9:03 [PATCH] dmaengine: dw: dmamux: Fix device reference leak in rzn1_dmamux_route_allocate Miaoqian Lin
  2025-09-02  9:18 ` Miquel Raynal
@ 2025-09-02  9:24 ` Markus Elfring
  2025-09-02  9:35 ` Vinod Koul
  2025-09-02  9:37 ` Andy Shevchenko
  3 siblings, 0 replies; 9+ messages in thread
From: Markus Elfring @ 2025-09-02  9:24 UTC (permalink / raw)
  To: Miaoqian Lin, dmaengine
  Cc: stable, LKML, Andy Shevchenko, Ilpo Järvinen, Miquel Raynal,
	Vinod Koul, Viresh Kumar

> 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/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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] dmaengine: dw: dmamux: Fix device reference leak in rzn1_dmamux_route_allocate
  2025-09-02  9:03 [PATCH] dmaengine: dw: dmamux: Fix device reference leak in rzn1_dmamux_route_allocate Miaoqian Lin
  2025-09-02  9:18 ` Miquel Raynal
  2025-09-02  9:24 ` Markus Elfring
@ 2025-09-02  9:35 ` Vinod Koul
  2025-09-02  9:37 ` Andy Shevchenko
  3 siblings, 0 replies; 9+ messages in thread
From: Vinod Koul @ 2025-09-02  9:35 UTC (permalink / raw)
  To: Viresh Kumar, Andy Shevchenko, Miquel Raynal, Ilpo Järvinen,
	dmaengine, linux-kernel, Miaoqian Lin
  Cc: stable


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,
-- 
~Vinod



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] dmaengine: dw: dmamux: Fix device reference leak in rzn1_dmamux_route_allocate
  2025-09-02  9:03 [PATCH] dmaengine: dw: dmamux: Fix device reference leak in rzn1_dmamux_route_allocate Miaoqian Lin
                   ` (2 preceding siblings ...)
  2025-09-02  9:35 ` Vinod Koul
@ 2025-09-02  9:37 ` Andy Shevchenko
  2025-09-02 10:18   ` 林妙倩
  3 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2025-09-02  9:37 UTC (permalink / raw)
  To: Miaoqian Lin
  Cc: Viresh Kumar, Vinod Koul, Miquel Raynal, Ilpo Järvinen,
	dmaengine, linux-kernel, stable

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?

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] dmaengine: dw: dmamux: Fix device reference leak in rzn1_dmamux_route_allocate
  2025-09-02  9:37 ` Andy Shevchenko
@ 2025-09-02 10:18   ` 林妙倩
  2025-09-02 11:02     ` Andy Shevchenko
  2025-09-02 13:30     ` Markus Elfring
  0 siblings, 2 replies; 9+ messages in thread
From: 林妙倩 @ 2025-09-02 10:18 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Viresh Kumar, Vinod Koul, Miquel Raynal, Ilpo Järvinen,
	dmaengine, linux-kernel, stable

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
>
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] dmaengine: dw: dmamux: Fix device reference leak in rzn1_dmamux_route_allocate
  2025-09-02 10:18   ` 林妙倩
@ 2025-09-02 11:02     ` Andy Shevchenko
  2025-09-02 13:12       ` 林妙倩
  2025-09-02 13:30     ` Markus Elfring
  1 sibling, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2025-09-02 11:02 UTC (permalink / raw)
  To: 林妙倩
  Cc: Viresh Kumar, Vinod Koul, Miquel Raynal, Ilpo Järvinen,
	dmaengine, linux-kernel, stable

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.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] dmaengine: dw: dmamux: Fix device reference leak in rzn1_dmamux_route_allocate
  2025-09-02 11:02     ` Andy Shevchenko
@ 2025-09-02 13:12       ` 林妙倩
  0 siblings, 0 replies; 9+ messages in thread
From: 林妙倩 @ 2025-09-02 13:12 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Viresh Kumar, Vinod Koul, Miquel Raynal, Ilpo Järvinen,
	dmaengine, linux-kernel, stable

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
>
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: dmaengine: dw: dmamux: Fix device reference leak in rzn1_dmamux_route_allocate
  2025-09-02 10:18   ` 林妙倩
  2025-09-02 11:02     ` Andy Shevchenko
@ 2025-09-02 13:30     ` Markus Elfring
  1 sibling, 0 replies; 9+ messages in thread
From: Markus Elfring @ 2025-09-02 13:30 UTC (permalink / raw)
  To: 林妙倩, dmaengine
  Cc: stable, LKML, Andy Shevchenko, Ilpo Järvinen, Miquel Raynal,
	Vinod Koul, Viresh Kumar

> 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-09-02 13:31 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-02  9:03 [PATCH] dmaengine: dw: dmamux: Fix device reference leak in rzn1_dmamux_route_allocate Miaoqian Lin
2025-09-02  9:18 ` Miquel Raynal
2025-09-02  9:24 ` Markus Elfring
2025-09-02  9:35 ` Vinod Koul
2025-09-02  9:37 ` Andy Shevchenko
2025-09-02 10:18   ` 林妙倩
2025-09-02 11:02     ` Andy Shevchenko
2025-09-02 13:12       ` 林妙倩
2025-09-02 13:30     ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).