diff mbox series

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

Message ID 20181124145223.29208-1-tiny.windzz@gmail.com
State New, archived
Headers show
Series [v2] soc: bcm: brcmstb: Don't leak device tree node reference | expand

Commit Message

Frank Lee Nov. 24, 2018, 2:52 p.m. UTC
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]

Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
---
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(-)

Comments

Frank Lee Nov. 26, 2018, 2:42 p.m. UTC | #1
On Sat, Nov 24, 2018 at 10:52 PM Yangtao Li <tiny.windzz@gmail.com> wrote:
>
> 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]
>
> Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
> ---
> 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(-)
>
> diff --git a/drivers/soc/bcm/brcmstb/common.c b/drivers/soc/bcm/brcmstb/common.c
> index 14185451901d..bf9123f727e8 100644
> --- a/drivers/soc/bcm/brcmstb/common.c
> +++ b/drivers/soc/bcm/brcmstb/common.c
> @@ -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)
> --
> 2.17.0
>
Hi Florian:

How about this ?

MBR,
Yangtao
Florian Fainelli Nov. 28, 2018, 12:25 a.m. UTC | #2
On 11/26/18 6:42 AM, Frank Lee wrote:
> On Sat, Nov 24, 2018 at 10:52 PM Yangtao Li <tiny.windzz@gmail.com> wrote:
>>
>> 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]
>>
>> Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
>> ---
>> 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(-)
>>
>> diff --git a/drivers/soc/bcm/brcmstb/common.c b/drivers/soc/bcm/brcmstb/common.c
>> index 14185451901d..bf9123f727e8 100644
>> --- a/drivers/soc/bcm/brcmstb/common.c
>> +++ b/drivers/soc/bcm/brcmstb/common.c
>> @@ -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)
>> --
>> 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.
Florian Fainelli Nov. 28, 2018, 9:47 p.m. UTC | #3
On 11/24/18 6:52 AM, Yangtao Li wrote:
> 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]
> 
> Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>

Applied to drivers/next, thanks!
diff mbox series

Patch

diff --git a/drivers/soc/bcm/brcmstb/common.c b/drivers/soc/bcm/brcmstb/common.c
index 14185451901d..bf9123f727e8 100644
--- a/drivers/soc/bcm/brcmstb/common.c
+++ b/drivers/soc/bcm/brcmstb/common.c
@@ -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)