summaryrefslogtreecommitdiffstats
path: root/drivers/of/base.c
diff options
context:
space:
mode:
authorPantelis Antoniou <panto@antoniou-consulting.com>2013-12-13 20:08:59 +0200
committerGrant Likely <grant.likely@linaro.org>2014-03-19 14:58:40 +0000
commit0829f6d1f69e4f2fae4062987ae6531a9af1a2e3 (patch)
tree4081a4bee4a9e193b4de690735b5a3782d100eac /drivers/of/base.c
parent8357041a69b368991d1b04d9f1d297f8d71e1314 (diff)
downloadop-kernel-dev-0829f6d1f69e4f2fae4062987ae6531a9af1a2e3.zip
op-kernel-dev-0829f6d1f69e4f2fae4062987ae6531a9af1a2e3.tar.gz
of: device_node kobject lifecycle fixes
After the move to having device nodes be proper kobjects the lifecycle of the node needs to be controlled better. At first convert of_add_node() in the unflattened functions to of_init_node() which initializes the kobject so that of_node_get/put work correctly even before of_init is called. Afterwards introduce of_node_is_initialized & of_node_is_attached that query the underlying kobject about the state (attached means kobj is visible in sysfs) Using that make sure the lifecycle of the tree is correct at all times. Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com> [grant.likely: moved of_node_init() calls, fixed up locking, and dropped __of_populate() hunks] Signed-off-by: Grant Likely <grant.likely@linaro.org>
Diffstat (limited to 'drivers/of/base.c')
-rw-r--r--drivers/of/base.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index ed3e70b..418a4ff9 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -246,10 +246,19 @@ static int __of_node_add(struct device_node *np)
int of_node_add(struct device_node *np)
{
int rc = 0;
- kobject_init(&np->kobj, &of_node_ktype);
+
+ BUG_ON(!of_node_is_initialized(np));
+
+ /*
+ * Grab the mutex here so that in a race condition between of_init() and
+ * of_node_add(), node addition will still be consistent.
+ */
mutex_lock(&of_aliases_mutex);
if (of_kset)
rc = __of_node_add(np);
+ else
+ /* This scenario may be perfectly valid, but report it anyway */
+ pr_info("of_node_add(%s) before of_init()\n", np->full_name);
mutex_unlock(&of_aliases_mutex);
return rc;
}
@@ -259,10 +268,17 @@ static void of_node_remove(struct device_node *np)
{
struct property *pp;
- for_each_property_of_node(np, pp)
- sysfs_remove_bin_file(&np->kobj, &pp->attr);
+ BUG_ON(!of_node_is_initialized(np));
+
+ /* only remove properties if on sysfs */
+ if (of_node_is_attached(np)) {
+ for_each_property_of_node(np, pp)
+ sysfs_remove_bin_file(&np->kobj, &pp->attr);
+ kobject_del(&np->kobj);
+ }
- kobject_del(&np->kobj);
+ /* finally remove the kobj_init ref */
+ of_node_put(np);
}
#endif
@@ -1631,6 +1647,10 @@ static int of_property_notify(int action, struct device_node *np,
{
struct of_prop_reconfig pr;
+ /* only call notifiers if the node is attached */
+ if (!of_node_is_attached(np))
+ return 0;
+
pr.dn = np;
pr.prop = prop;
return of_reconfig_notify(action, &pr);
@@ -1682,11 +1702,8 @@ int of_add_property(struct device_node *np, struct property *prop)
if (rc)
return rc;
- /* at early boot, bail hear and defer setup to of_init() */
- if (!of_kset)
- return 0;
-
- __of_add_property_sysfs(np, prop);
+ if (of_node_is_attached(np))
+ __of_add_property_sysfs(np, prop);
return rc;
}
OpenPOWER on IntegriCloud