Skip to contentSkip to conversation

dmaengine: ti: k3-udma-private: Fix refcount leak bug in of_xudma_dev_get()

PATCH Superseded Liang He 2 participants 3 messages Jul 16, 2022 – Jul 20, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Liang He

author
#0 lore raw

PATCH 1/1 dmaengine: ti: k3-udma-private: Fix refcount leak bug in of_xudma_dev_get()

We should call of_node_put() for the reference returned by of_parse_phandle() in fail path or when it is not used anymore. Here we only need to move the of_node_put() before the check.

Fixes d70241913413 ("dmaengine: ti: k3-udma: Add glue layer for non DMAengine users")

---

I cannot find the 'k3-udma-private.c' comiple item in drivers/dma/ti/Makefile, I wonder if the author has forgotten the compile item and the k3-udma-private.c has not been compiled before.

I have tried to add k3-udma-private.o in the Makefile, but there are lots of compile errors.
Please check it carefully and if possbile please teach me how to compile it, thanks.

 drivers/dma/ti/k3-udma-private.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/dma/ti/k3-udma-private.c +2 -3
index d4f1e4e9603a..ec274ef7d5ea 100644
@@ -31,14 +31,13 @@ struct udma_dev *of_xudma_dev_get(struct device_node *np, const char *property)
 	}
 
 	pdev = of_find_device_by_node(udma_node);
+	if (np != udma_node)
+		of_node_put(udma_node);
 	if (!pdev) {
 		pr_debug("UDMA device not found\n");
 		return ERR_PTR(-EPROBE_DEFER);
 	}
 
-	if (np != udma_node)
-		of_node_put(udma_node);
-
 	ud = platform_get_drvdata(pdev);
 	if (!ud) {
 		pr_debug("UDMA has not been probed\n");
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw

Hi,

Quoted 3 lines · Liang He

We should call of_node_put() for the reference returned by of_parse_phandle() in fail path or when it is not used anymore. Here we only need to move the of_node_put() before the check.

Thank you for the analysis, yes, this is a bug.

If you add the missing blank line, you can attach my:

Quoted 11 lines
Fixes d70241913413 ("dmaengine: ti: k3-udma: Add glue layer for non DMAengine users")

---

I cannot find the 'k3-udma-private.c' comiple item in drivers/dma/ti/Makefile, I wonder if the author has forgotten the compile item and the k3-udma-private.c has not been compiled before.

I have tried to add k3-udma-private.o in the Makefile, but there are lots of compile errors.
Please check it carefully and if possbile please teach me how to compile it, thanks.

the k3-udma-private.c is included in to k3-udma.c (see end of file). When the UDMA stack was introduced we needed to have a glue layer to service the networking users due to the lack of infrastructure via DMAengine.
The glue layer needs to tap in to the DMAengine driver, but I did not wanted to expose low level interfaces, structs, ops in order to be able to get rid of the glue layer when we have all the needed features in DMAengine.

The k3-udma-private.c is part of the k3-udma.c but kept as separate file to make it explicit that it is suppose to go away and to not mix it with the DMAengine driver.

drivers/dma/ti/k3-udma-private.c struct udma_dev *of_xudma_dev_get(struct device_node *np, const char *property) · line 35

Quoted 13 lines
 drivers/dma/ti/k3-udma-private.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/dma/ti/k3-udma-private.c +2 -0
index d4f1e4e9603a..ec274ef7d5ea 100644
@@ -31,14 +31,13 @@ struct udma_dev *of_xudma_dev_get(struct device_node *np, const char *property)
 	}
 
 	pdev = of_find_device_by_node(udma_node);
+	if (np != udma_node)
+		of_node_put(udma_node);

Can you add a blank line here for readability?

Quoted 11 lines
drivers/dma/ti/k3-udma-private.c +0 -3
 	if (!pdev) {
 		pr_debug("UDMA device not found\n");
 		return ERR_PTR(-EPROBE_DEFER);
 	}
 
-	if (np != udma_node)
-		of_node_put(udma_node);
-
 	ud = platform_get_drvdata(pdev);
 	if (!ud) {
 		pr_debug("UDMA has not been probed\n");
Signature · 1 line
Péter
author
#2 lore raw
Quoted 12 lines · Péter Ujfalusi

Hi,

Quoted 3 lines · Liang He

We should call of_node_put() for the reference returned by of_parse_phandle() in fail path or when it is not used anymore. Here we only need to move the of_node_put() before the check.

Thank you for the analysis, yes, this is a bug.

If you add the missing blank line, you can attach my:

Thanks very much for your effort to review my patch.

I will do that in new version soon.

Quoted 21 lines
Quoted 11 lines
Fixes d70241913413 ("dmaengine: ti: k3-udma: Add glue layer for non DMAengine users")

---

I cannot find the 'k3-udma-private.c' comiple item in drivers/dma/ti/Makefile, I wonder if the author has forgotten the compile item and the k3-udma-private.c has not been compiled before.

I have tried to add k3-udma-private.o in the Makefile, but there are lots of compile errors.
Please check it carefully and if possbile please teach me how to compile it, thanks.

the k3-udma-private.c is included in to k3-udma.c (see end of file). When the UDMA stack was introduced we needed to have a glue layer to service the networking users due to the lack of infrastructure via DMAengine.
The glue layer needs to tap in to the DMAengine driver, but I did not wanted to expose low level interfaces, structs, ops in order to be able to get rid of the glue layer when we have all the needed features in DMAengine.

Quoted 4 lines

The k3-udma-private.c is part of the k3-udma.c but kept as separate file to make it explicit that it is suppose to go away and to not mix it with the DMAengine driver.

Thanks for you explaination, this is a great lesson!

Quoted 10 lines
Quoted 10 lines
 drivers/dma/ti/k3-udma-private.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/dma/ti/k3-udma-private.c +0 -0
index d4f1e4e9603a..ec274ef7d5ea 100644
@@ -31,14 +31,13 @@ struct udma_dev *of_xudma_dev_get(struct device_node *np, const char *property)
 	}
 
Quoted 6 lines

drivers/dma/ti/k3-udma-private.c struct udma_dev *of_xudma_dev_get(struct device_node *np, const char *property) · line 35

Quoted 3 lines
drivers/dma/ti/k3-udma-private.c +2 -0
 	pdev = of_find_device_by_node(udma_node);
+	if (np != udma_node)
+		of_node_put(udma_node);

Can you add a blank line here for readability?

Thanks, I will do it.

Quoted 14 lines
Quoted 11 lines
drivers/dma/ti/k3-udma-private.c +0 -3
 	if (!pdev) {
 		pr_debug("UDMA device not found\n");
 		return ERR_PTR(-EPROBE_DEFER);
 	}
 
-	if (np != udma_node)
-		of_node_put(udma_node);
-
 	ud = platform_get_drvdata(pdev);
 	if (!ud) {
 		pr_debug("UDMA has not been probed\n");
Signature · 1 line
Péter