mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] edac: versalnet: Fix device_node leak in mc_probe()
@ 2026-03-22 16:04 Felix Gu
  2026-03-22 16:30 ` Borislav Petkov
  0 siblings, 1 reply; 4+ messages in thread
From: Felix Gu @ 2026-03-22 16:04 UTC (permalink / raw)
  To: Shubhrajyoti Datta, Borislav Petkov, Tony Luck
  Cc: linux-edac, linux-kernel, Felix Gu

of_parse_phandle() returns a device_node reference that must be released
with of_node_put(). The original code never freed r5_core_node on any
exit path, causing a memory leak.

Fix this by using the automatic cleanup attribute __free(device_node)
which ensures of_node_put() is called when the variable goes out of
scope.

Fixes: d5fe2fec6c40 ("EDAC: Add a driver for the AMD Versal NET DDR controller")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
 drivers/edac/versalnet_edac.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/edac/versalnet_edac.c b/drivers/edac/versalnet_edac.c
index 0b47ed7fed63..915bcd6166f7 100644
--- a/drivers/edac/versalnet_edac.c
+++ b/drivers/edac/versalnet_edac.c
@@ -888,12 +888,12 @@ static void remove_versalnet(struct mc_priv *priv)
 
 static int mc_probe(struct platform_device *pdev)
 {
-	struct device_node *r5_core_node;
 	struct mc_priv *priv;
 	struct rproc *rp;
 	int rc;
 
-	r5_core_node = of_parse_phandle(pdev->dev.of_node, "amd,rproc", 0);
+	struct device_node *r5_core_node __free(device_node) =
+		of_parse_phandle(pdev->dev.of_node, "amd,rproc", 0);
 	if (!r5_core_node) {
 		dev_err(&pdev->dev, "amd,rproc: invalid phandle\n");
 		return -EINVAL;

---
base-commit: 785f0eb2f85decbe7c1ef9ae922931f0194ffc2e
change-id: 20260322-versalnet-ee4feebc280e

Best regards,
-- 
Felix Gu <ustc.gu@gmail.com>


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

* Re: [PATCH] edac: versalnet: Fix device_node leak in mc_probe()
  2026-03-22 16:04 [PATCH] edac: versalnet: Fix device_node leak in mc_probe() Felix Gu
@ 2026-03-22 16:30 ` Borislav Petkov
  2026-03-24 12:19   ` Datta, Shubhrajyoti
  0 siblings, 1 reply; 4+ messages in thread
From: Borislav Petkov @ 2026-03-22 16:30 UTC (permalink / raw)
  To: Felix Gu; +Cc: Shubhrajyoti Datta, Tony Luck, linux-edac, linux-kernel

On Mon, Mar 23, 2026 at 12:04:08AM +0800, Felix Gu wrote:
> of_parse_phandle() returns a device_node reference that must be released
> with of_node_put(). The original code never freed r5_core_node on any
> exit path, causing a memory leak.
> 
> Fix this by using the automatic cleanup attribute __free(device_node)
> which ensures of_node_put() is called when the variable goes out of
> scope.
> 
> Fixes: d5fe2fec6c40 ("EDAC: Add a driver for the AMD Versal NET DDR controller")
> Signed-off-by: Felix Gu <ustc.gu@gmail.com>
> ---
>  drivers/edac/versalnet_edac.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/edac/versalnet_edac.c b/drivers/edac/versalnet_edac.c
> index 0b47ed7fed63..915bcd6166f7 100644
> --- a/drivers/edac/versalnet_edac.c
> +++ b/drivers/edac/versalnet_edac.c
> @@ -888,12 +888,12 @@ static void remove_versalnet(struct mc_priv *priv)
>  
>  static int mc_probe(struct platform_device *pdev)
>  {
> -	struct device_node *r5_core_node;
>  	struct mc_priv *priv;
>  	struct rproc *rp;
>  	int rc;
>  
> -	r5_core_node = of_parse_phandle(pdev->dev.of_node, "amd,rproc", 0);
> +	struct device_node *r5_core_node __free(device_node) =
> +		of_parse_phandle(pdev->dev.of_node, "amd,rproc", 0);
>  	if (!r5_core_node) {
>  		dev_err(&pdev->dev, "amd,rproc: invalid phandle\n");
>  		return -EINVAL;
> 
> ---

Looks correct to me.

@Shubhrajyoti, can you pls test it?

Thx.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

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

* RE: [PATCH] edac: versalnet: Fix device_node leak in mc_probe()
  2026-03-22 16:30 ` Borislav Petkov
@ 2026-03-24 12:19   ` Datta, Shubhrajyoti
  2026-03-24 15:07     ` Borislav Petkov
  0 siblings, 1 reply; 4+ messages in thread
From: Datta, Shubhrajyoti @ 2026-03-24 12:19 UTC (permalink / raw)
  To: Borislav Petkov, Felix Gu; +Cc: Tony Luck, linux-edac, linux-kernel

[AMD Official Use Only - AMD Internal Distribution Only]

> -----Original Message-----
> From: Borislav Petkov <bp@alien8.de>
> Sent: Sunday, March 22, 2026 10:01 PM
> To: Felix Gu <ustc.gu@gmail.com>
> Cc: Datta, Shubhrajyoti <shubhrajyoti.datta@amd.com>; Tony Luck
> <tony.luck@intel.com>; linux-edac@vger.kernel.org; linux-
> kernel@vger.kernel.org
> Subject: Re: [PATCH] edac: versalnet: Fix device_node leak in mc_probe()
>
> Caution: This message originated from an External Source. Use proper caution
> when opening attachments, clicking links, or responding.
>
>
> On Mon, Mar 23, 2026 at 12:04:08AM +0800, Felix Gu wrote:
> > of_parse_phandle() returns a device_node reference that must be
> > released with of_node_put(). The original code never freed
> > r5_core_node on any exit path, causing a memory leak.
> >
> > Fix this by using the automatic cleanup attribute __free(device_node)
> > which ensures of_node_put() is called when the variable goes out of
> > scope.
> >
> > Fixes: d5fe2fec6c40 ("EDAC: Add a driver for the AMD Versal NET DDR
> > controller")
> > Signed-off-by: Felix Gu <ustc.gu@gmail.com>
> > ---
> >  drivers/edac/versalnet_edac.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/edac/versalnet_edac.c
> > b/drivers/edac/versalnet_edac.c index 0b47ed7fed63..915bcd6166f7
> > 100644
> > --- a/drivers/edac/versalnet_edac.c
> > +++ b/drivers/edac/versalnet_edac.c
> > @@ -888,12 +888,12 @@ static void remove_versalnet(struct mc_priv
> > *priv)
> >
> >  static int mc_probe(struct platform_device *pdev)  {
> > -     struct device_node *r5_core_node;
> >       struct mc_priv *priv;
> >       struct rproc *rp;
> >       int rc;
> >
> > -     r5_core_node = of_parse_phandle(pdev->dev.of_node, "amd,rproc", 0);
> > +     struct device_node *r5_core_node __free(device_node) =
> > +             of_parse_phandle(pdev->dev.of_node, "amd,rproc", 0);
> >       if (!r5_core_node) {
> >               dev_err(&pdev->dev, "amd,rproc: invalid phandle\n");
> >               return -EINVAL;
> >
> > ---
>
> Looks correct to me.
>
> @Shubhrajyoti, can you pls test it?
>
> Thx.

I tested this change on hardware and it works as expected.
Please feel free to add:
Reviewed-by: Shubhrajyoti Datta <shubhrajyoti.datta@amd.com>

>
> --
> Regards/Gruss,
>     Boris.
>
> https://people.kernel.org/tglx/notes-about-netiquette

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

* Re: [PATCH] edac: versalnet: Fix device_node leak in mc_probe()
  2026-03-24 12:19   ` Datta, Shubhrajyoti
@ 2026-03-24 15:07     ` Borislav Petkov
  0 siblings, 0 replies; 4+ messages in thread
From: Borislav Petkov @ 2026-03-24 15:07 UTC (permalink / raw)
  To: Datta, Shubhrajyoti, Felix Gu; +Cc: Tony Luck, linux-edac, linux-kernel

On Tue, Mar 24, 2026 at 12:19:25PM +0000, Datta, Shubhrajyoti wrote:
> [AMD Official Use Only - AMD Internal Distribution Only]
> 
> > -----Original Message-----
> > From: Borislav Petkov <bp@alien8.de>
> > Sent: Sunday, March 22, 2026 10:01 PM
> > To: Felix Gu <ustc.gu@gmail.com>
> > Cc: Datta, Shubhrajyoti <shubhrajyoti.datta@amd.com>; Tony Luck
> > <tony.luck@intel.com>; linux-edac@vger.kernel.org; linux-
> > kernel@vger.kernel.org
> > Subject: Re: [PATCH] edac: versalnet: Fix device_node leak in mc_probe()
> >
> > Caution: This message originated from an External Source. Use proper caution
> > when opening attachments, clicking links, or responding.
> >
> >
> > On Mon, Mar 23, 2026 at 12:04:08AM +0800, Felix Gu wrote:
> > > of_parse_phandle() returns a device_node reference that must be
> > > released with of_node_put(). The original code never freed
> > > r5_core_node on any exit path, causing a memory leak.
> > >
> > > Fix this by using the automatic cleanup attribute __free(device_node)
> > > which ensures of_node_put() is called when the variable goes out of
> > > scope.
> > >
> > > Fixes: d5fe2fec6c40 ("EDAC: Add a driver for the AMD Versal NET DDR
> > > controller")
> > > Signed-off-by: Felix Gu <ustc.gu@gmail.com>
> > > ---
> > >  drivers/edac/versalnet_edac.c | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/edac/versalnet_edac.c
> > > b/drivers/edac/versalnet_edac.c index 0b47ed7fed63..915bcd6166f7
> > > 100644
> > > --- a/drivers/edac/versalnet_edac.c
> > > +++ b/drivers/edac/versalnet_edac.c
> > > @@ -888,12 +888,12 @@ static void remove_versalnet(struct mc_priv
> > > *priv)
> > >
> > >  static int mc_probe(struct platform_device *pdev)  {
> > > -     struct device_node *r5_core_node;
> > >       struct mc_priv *priv;
> > >       struct rproc *rp;
> > >       int rc;
> > >
> > > -     r5_core_node = of_parse_phandle(pdev->dev.of_node, "amd,rproc", 0);
> > > +     struct device_node *r5_core_node __free(device_node) =
> > > +             of_parse_phandle(pdev->dev.of_node, "amd,rproc", 0);
> > >       if (!r5_core_node) {
> > >               dev_err(&pdev->dev, "amd,rproc: invalid phandle\n");
> > >               return -EINVAL;
> > >
> > > ---
> >
> > Looks correct to me.
> >
> > @Shubhrajyoti, can you pls test it?
> >
> > Thx.
> 
> I tested this change on hardware and it works as expected.
> Please feel free to add:
> Reviewed-by: Shubhrajyoti Datta <shubhrajyoti.datta@amd.com>

Applied, thanks to both.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

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

end of thread, other threads:[~2026-03-24 15:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-22 16:04 [PATCH] edac: versalnet: Fix device_node leak in mc_probe() Felix Gu
2026-03-22 16:30 ` Borislav Petkov
2026-03-24 12:19   ` Datta, Shubhrajyoti
2026-03-24 15:07     ` Borislav Petkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®