Skip to contentSkip to conversation

edac: versalnet: Fix device_node leak in mc_probe()

PATCH Applied Felix Gu 3 participants 4 messages Mar 22 – Mar 24

Subsystems (2)
lore
Share & tools
lore

Felix Gu

author
#0 lore raw

PATCH 1/1 edac: versalnet: Fix device_node leak in mc_probe()

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")
---
 drivers/edac/versalnet_edac.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/edac/versalnet_edac.c +2 -2
index 0b47ed7fed63..915bcd6166f7 100644
@@ -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,

Signature · 1 line
Felix Gu <[email protected]>
maintainer
#1 lore raw
Quoted 25 lines · 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")
---
 drivers/edac/versalnet_edac.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/edac/versalnet_edac.c +0 -1
index 0b47ed7fed63..915bcd6166f7 100644
@@ -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;

drivers/edac/versalnet_edac.c static void remove_versalnet(struct mc_priv *priv)

Quoted 10 lines
drivers/edac/versalnet_edac.c +2 -2
 	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.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer Reviewed-by
#2 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 50 lines

-----Original Message-----
From: Borislav Petkov <[email protected]>
Sent: Sunday, March 22, 2026 10:01 PM
To: Felix Gu <[email protected]>
Cc: Datta, Shubhrajyoti <[email protected]>; Tony Luck <[email protected]>; [email protected]; linux- [email protected]
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.

Quoted 36 lines · 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")

---
 drivers/edac/versalnet_edac.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/edac/versalnet_edac.c index 0b47ed7fed63..915bcd6166f7 100644

drivers/edac/versalnet_edac.c +2 -2
@@ -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;
Quoted 7 lines
Quoted 1 line

---

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:

Quoted 6 lines

--
Regards/Gruss,
Boris.

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

maintainer Applied
#3 lore raw
Quoted 56 lines · Shubhrajyoti

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 54 lines

-----Original Message-----
From: Borislav Petkov <[email protected]>
Sent: Sunday, March 22, 2026 10:01 PM
To: Felix Gu <[email protected]>
Cc: Datta, Shubhrajyoti <[email protected]>; Tony Luck <[email protected]>; [email protected]; linux- [email protected]
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.

Quoted 27 lines · 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")

---
 drivers/edac/versalnet_edac.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/edac/versalnet_edac.c index 0b47ed7fed63..915bcd6166f7 100644

drivers/edac/versalnet_edac.c +0 -1
@@ -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;

drivers/edac/versalnet_edac.c static void remove_versalnet(struct mc_priv

Quoted 10 lines
drivers/edac/versalnet_edac.c +2 -2
      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.

Quoted 7 lines
Quoted 3 lines

@Shubhrajyoti, can you pls test it?

Thx.

I tested this change on hardware and it works as expected. Please feel free to add:

Applied, thanks to both.

Signature · 4 lines
Regards/Gruss,
    Boris.

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