Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Fixes: 5b2c2f5a0ea3 ("of: overlay: add missing of_node_get() in __of_attach_node_sysfs")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Rob Herring <robh@kernel.org>

authored by

Dan Carpenter and committed by
Rob Herring
8a325dd0 9dae090f

+1 -2
+1 -2
drivers/of/kobj.c
··· 134 134 if (!name) 135 135 return -ENOMEM; 136 136 137 - of_node_get(np); 138 - 139 137 rc = kobject_add(&np->kobj, parent, "%s", name); 140 138 kfree(name); 141 139 if (rc) ··· 142 144 for_each_property_of_node(np, pp) 143 145 __of_add_property_sysfs(np, pp); 144 146 147 + of_node_get(np); 145 148 return 0; 146 149 } 147 150