diff mbox series

of: drop a reference on error in __of_attach_node_sysfs()

Message ID 20200518113021.GB48709@mwanda
State Changes Requested, archived
Headers show
Series of: drop a reference on error in __of_attach_node_sysfs() | expand

Checks

Context Check Description
robh/checkpatch warning total: 0 errors, 1 warnings, 11 lines checked

Commit Message

Dan Carpenter May 18, 2020, 11:30 a.m. UTC
We add a new of_node_get() to this function, but we should drop the
reference if kobject_add().

Fixes: 5b2c2f5a0ea3 ("of: overlay: add missing of_node_get() in __of_attach_node_sysfs")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
From static analysis.  Maybe we should just call of_node_get() right
before we return 0?

 drivers/of/kobj.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Michael Ellerman May 20, 2020, 10:06 a.m. UTC | #1
Dan Carpenter <dan.carpenter@oracle.com> writes:
> We add a new of_node_get() to this function, but we should drop the
> reference if kobject_add().
                            ^
                            fails?
>
> Fixes: 5b2c2f5a0ea3 ("of: overlay: add missing of_node_get() in __of_attach_node_sysfs")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> From static analysis.  Maybe we should just call of_node_get() right
> before we return 0?

Yeah that would be simpler and equally correct AFAICS.

cheers

> diff --git a/drivers/of/kobj.c b/drivers/of/kobj.c
> index c72eef988041..a90dc4b3b060 100644
> --- a/drivers/of/kobj.c
> +++ b/drivers/of/kobj.c
> @@ -138,8 +138,10 @@ int __of_attach_node_sysfs(struct device_node *np)
>  
>  	rc = kobject_add(&np->kobj, parent, "%s", name);
>  	kfree(name);
> -	if (rc)
> +	if (rc) {
> +		of_node_put(np);
>  		return rc;
> +	}
>  
>  	for_each_property_of_node(np, pp)
>  		__of_add_property_sysfs(np, pp);
> -- 
> 2.26.2
diff mbox series

Patch

diff --git a/drivers/of/kobj.c b/drivers/of/kobj.c
index c72eef988041..a90dc4b3b060 100644
--- a/drivers/of/kobj.c
+++ b/drivers/of/kobj.c
@@ -138,8 +138,10 @@  int __of_attach_node_sysfs(struct device_node *np)
 
 	rc = kobject_add(&np->kobj, parent, "%s", name);
 	kfree(name);
-	if (rc)
+	if (rc) {
+		of_node_put(np);
 		return rc;
+	}
 
 	for_each_property_of_node(np, pp)
 		__of_add_property_sysfs(np, pp);