of: Properly set the OF_POPULATED_BUS flag on root node
authorGrant Likely <grant.likely@linaro.org>
Wed, 19 Nov 2014 22:35:39 +0000 (22:35 +0000)
committerGrant Likely <grant.likely@linaro.org>
Thu, 20 Nov 2014 10:51:18 +0000 (10:51 +0000)
of_platform_populate() takes a subset of the device tree and turns it
into a set of platform_devices. At the same time it sets the
OF_POPULATED_BUS flag in each bus nodes so that of_platform_depopulate()
can undo the operation at a later time. However, it doesn't set the flag
on the root of the population tree which means that dynamic modifications
of the device tree at runtime will not create/destroy devices correctly.

Fix of_platform_populate() to set the OF_POPULATED_BUS flag on the node
it is called with.

Signed-off-by: Grant Likely <grant.likely@linaro.org>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Pawel Moll <pawel.moll@arm.com>
drivers/of/platform.c

index 7c6771986c061a7d7e1c00d6cf211866d6370636..656cccf0e6806800988c38a99bb5ef747becd916 100644 (file)
@@ -500,6 +500,7 @@ int of_platform_populate(struct device_node *root,
                if (rc)
                        break;
        }
+       of_node_set_flag(root, OF_POPULATED_BUS);
 
        of_node_put(root);
        return rc;
@@ -542,7 +543,10 @@ static int of_platform_device_destroy(struct device *dev, void *data)
  */
 void of_platform_depopulate(struct device *parent)
 {
-       device_for_each_child(parent, NULL, of_platform_device_destroy);
+       if (parent->of_node && of_node_check_flag(parent->of_node, OF_POPULATED_BUS)) {
+               device_for_each_child(parent, NULL, of_platform_device_destroy);
+               of_node_clear_flag(parent->of_node, OF_POPULATED_BUS);
+       }
 }
 EXPORT_SYMBOL_GPL(of_platform_depopulate);