Skip to content

Commit 814cff5

Browse files
committed
of/platform: Allow overlays to create platform devices from the root node
We'd like to apply overlays to the root node in KUnit so we can test platform devices created as children of the root node. On some architectures (powerpc), the root node isn't marked with OF_POPULATED_BUS. If an overlay tries to modify the root node on these platforms it will fail, while on other platforms, such as ARM, it will succeed. This is because the root node is marked with OF_POPULATED_BUS by of_platform_default_populate_init() calling of_platform_default_populate() with NULL as the first argument. Loosen the requirement here so that platform devices can be created for nodes created as children of the root node via DT overlays even if the platform bus wasn't populated for the root node. Reviewed-by: Rob Herring (Arm) <[email protected]> Cc: Saravana Kannan <[email protected]> Signed-off-by: Geert Uytterhoeven <[email protected]> [[email protected]: Folded in condition fix] Signed-off-by: Stephen Boyd <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 8400291 commit 814cff5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/of/platform.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -732,11 +732,14 @@ static int of_platform_notify(struct notifier_block *nb,
732732
struct of_reconfig_data *rd = arg;
733733
struct platform_device *pdev_parent, *pdev;
734734
bool children_left;
735+
struct device_node *parent;
735736

736737
switch (of_reconfig_get_state_change(action, rd)) {
737738
case OF_RECONFIG_CHANGE_ADD:
738-
/* verify that the parent is a bus */
739-
if (!of_node_check_flag(rd->dn->parent, OF_POPULATED_BUS))
739+
parent = rd->dn->parent;
740+
/* verify that the parent is a bus (or the root node) */
741+
if (!of_node_is_root(parent) &&
742+
!of_node_check_flag(parent, OF_POPULATED_BUS))
740743
return NOTIFY_OK; /* not for us */
741744

742745
/* already populated? (driver using of_populate manually) */
@@ -749,7 +752,7 @@ static int of_platform_notify(struct notifier_block *nb,
749752
*/
750753
rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE;
751754
/* pdev_parent may be NULL when no bus platform device */
752-
pdev_parent = of_find_device_by_node(rd->dn->parent);
755+
pdev_parent = of_find_device_by_node(parent);
753756
pdev = of_platform_device_create(rd->dn, NULL,
754757
pdev_parent ? &pdev_parent->dev : NULL);
755758
platform_device_put(pdev_parent);

0 commit comments

Comments
 (0)