of: drop a reference on error in __of_attach_node_sysfs()
Subsystems (2)
PATCH 1/1 of: drop a reference on error in __of_attach_node_sysfs()
We add a new of_node_get() to this function, but we should drop the reference if kobject_add().
---
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(-)
drivers/of/kobj.c +3 -1
@@ -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);
Signature · 1 line
2.26.2
Quoted 2 lines · Dan Carpenter
We add a new
of_node_get()to this function, but we should drop the reference ifkobject_add().
^
fails?Quoted 6 lines
Fixes 5b2c2f5a0ea3 ("of: overlay: add missing of_node_get() in __of_attach_node_sysfs")Signed-off-by Dan Carpenter <[email protected]>---
From static analysis. Maybe we should just callof_node_get()right before we return 0?
Yeah that would be simpler and equally correct AFAICS.
cheers
Quoted 18 lines
drivers/of/kobj.c +3
-1@@ -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);Signature · 1 line
2.26.2
PATCH v2 1/1 of: Fix a refcounting bug in __of_attach_node_sysfs()
The problem in this code is that if kobject_add() fails, then it should call of_node_put(np) to drop the reference count. I've actually moved the of_node_get(np) later in the function to avoid needing to do clean up.
---
v2: move the of_node_get() instead of doing clean up. Also the v1 had a
confusing typo in the commit message.
drivers/of/kobj.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/of/kobj.c +1 -2
@@ -134,8 +134,6 @@ int __of_attach_node_sysfs(struct device_node *np)if (!name)return -ENOMEM ; -of_node_get (np); - rc =kobject_add (&np->kobj, parent,"%s" , name);kfree (name);if (rc)
@@ -144,6 +142,7 @@ int __of_attach_node_sysfs(struct device_node *np)for_each_property_of_node (np, pp)__of_add_property_sysfs (np, pp); +of_node_get (np);return 0 ; }
Signature · 1 line
2.26.2
Re: [PATCH v2] of: Fix a refcounting bug in __of_attach_node_sysfs()
Quoted 5 lines · Dan Carpenter
The problem in this code is that if
kobject_add()fails, then it should callof_node_put(np)to drop the reference count. I've actually moved theof_node_get(np)later in the function to avoid needing to do clean up.
Quoted 9 lines
Fixes 5b2c2f5a0ea3 ("of: overlay: add missing of_node_get() in __of_attach_node_sysfs")Signed-off-by Dan Carpenter <[email protected]>---
v2: move theof_node_get()instead of doing clean up. Also the v1 had a
confusing typo in the commit message.drivers/of/kobj.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Applied, thanks!