Skip to contentSkip to conversation

soc: bcm: brcmstb: Don't leak device tree node reference

PATCH Applied Yangtao Li 2 participants 4 messages Nov 24, 2018 – Nov 28, 2018 Broadcom BCM7XXX Arm architecture

lore
Share & tools
lore

Yangtao Li

author
#0 lore raw

PATCH v2 1/1 soc: bcm: brcmstb: Don't leak device tree node reference

of_find_node_by_path() acquires a reference to the node returned by it and that reference needs to be dropped by its caller. soc_is_brcmstb() doesn't do that, so fix it.

[treding: slightly rewrite to avoid inline comparison]

---
Changes in v2:
-update changelog
-slightly rewrite to avoid inline comparison

---
 drivers/soc/bcm/brcmstb/common.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/soc/bcm/brcmstb/common.c +5 -1
index 14185451901d..bf9123f727e8 100644
@@ -31,13 +31,17 @@ static const struct of_device_id brcmstb_machine_match[] = {
 
 bool soc_is_brcmstb(void)
 {
+	const struct of_device_id *match;
 	struct device_node *root;
 
 	root = of_find_node_by_path("/");
 	if (!root)
 		return false;
 
-	return of_match_node(brcmstb_machine_match, root) != NULL;
+	match = of_match_node(brcmstb_machine_match, root);
+	of_node_put(root);
+
+	return match != NULL;
 }
 
 u32 brcmstb_get_family_id(void)
Signature · 1 line
2.17.0
author
#1 lore raw
Quoted 40 lines · Yangtao Li

of_find_node_by_path() acquires a reference to the node returned by it and that reference needs to be dropped by its caller. soc_is_brcmstb() doesn't do that, so fix it.

[treding: slightly rewrite to avoid inline comparison]

---
Changes in v2:

(quoted diff) +0 -3
-update changelog
-slightly rewrite to avoid inline comparison
---
 drivers/soc/bcm/brcmstb/common.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/soc/bcm/brcmstb/common.c +5 -2
index 14185451901d..bf9123f727e8 100644
@@ -31,13 +31,17 @@ static const struct of_device_id brcmstb_machine_match[] = {
 
 bool soc_is_brcmstb(void)
 {
+       const struct of_device_id *match;
        struct device_node *root;
 
        root = of_find_node_by_path("/");
        if (!root)
                return false;
 
-       return of_match_node(brcmstb_machine_match, root) != NULL;
+       match = of_match_node(brcmstb_machine_match, root);
+       of_node_put(root);
+
+       return match != NULL;
 }
 
 u32 brcmstb_get_family_id(void)
--
Quoted 2 lines

2.17.0

Hi Florian:

How about this ?

MBR,
Yangtao

#2 lore raw
Quoted 39 lines · Frank Lee
Quoted 38 lines · Yangtao Li

of_find_node_by_path() acquires a reference to the node returned by it and that reference needs to be dropped by its caller. soc_is_brcmstb() doesn't do that, so fix it.

[treding: slightly rewrite to avoid inline comparison]

---
Changes in v2:

(quoted diff) +0 -3
-update changelog
-slightly rewrite to avoid inline comparison
---
 drivers/soc/bcm/brcmstb/common.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/soc/bcm/brcmstb/common.c +5 -1
index 14185451901d..bf9123f727e8 100644
@@ -31,13 +31,17 @@ static const struct of_device_id brcmstb_machine_match[] = {
 
 bool soc_is_brcmstb(void)
 {
+       const struct of_device_id *match;
        struct device_node *root;
 
        root = of_find_node_by_path("/");
        if (!root)
                return false;
 
-       return of_match_node(brcmstb_machine_match, root) != NULL;
+       match = of_match_node(brcmstb_machine_match, root);
+       of_node_put(root);
+
+       return match != NULL;
 }
 
Quoted 7 lines
Quoted 4 lines
drivers/soc/bcm/brcmstb/common.c +0 -1
 u32 brcmstb_get_family_id(void)
--

2.17.0

Hi Florian:

How about this ?

This looks better, I will add:

Fixes d52fad262041 ("soc: add stubs for brcmstb SoC's")

while applying the patch.

Signature · 1 line
Florian
#3 lore raw
In reply to Yangtao Li
Quoted 7 lines · Yangtao Li

of_find_node_by_path() acquires a reference to the node returned by it and that reference needs to be dropped by its caller. soc_is_brcmstb() doesn't do that, so fix it.

[treding: slightly rewrite to avoid inline comparison]

Applied to drivers/next, thanks!

Signature · 1 line
Florian