Skip to content

Commit 4a03282

Browse files
Saravana Kannangregkh
authored andcommitted
of: property: Simplify of_link_to_phandle()
The driver core now: - Has the parent device of a supplier pick up the consumers if the supplier never has a device created for it. - Ignores a supplier if the supplier has no parent device and will never be probed by a driver And already prevents creating a device link with the consumer as a supplier of a parent. So, we no longer need to find the "compatible" node of the supplier or do any other checks in of_link_to_phandle(). We simply need to make sure that the supplier is available in DT. Signed-off-by: Saravana Kannan <[email protected]> Tested-by: Colin Foster <[email protected]> Tested-by: Sudeep Holla <[email protected]> Tested-by: Douglas Anderson <[email protected]> Tested-by: Geert Uytterhoeven <[email protected]> Tested-by: Luca Weiss <[email protected]> # qcom/sm7225-fairphone-fp4 Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 3fb1686 commit 4a03282

File tree

1 file changed

+13
-71
lines changed

1 file changed

+13
-71
lines changed

drivers/of/property.c

Lines changed: 13 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,20 +1062,6 @@ of_fwnode_device_get_match_data(const struct fwnode_handle *fwnode,
10621062
return of_device_get_match_data(dev);
10631063
}
10641064

1065-
static bool of_is_ancestor_of(struct device_node *test_ancestor,
1066-
struct device_node *child)
1067-
{
1068-
of_node_get(child);
1069-
while (child) {
1070-
if (child == test_ancestor) {
1071-
of_node_put(child);
1072-
return true;
1073-
}
1074-
child = of_get_next_parent(child);
1075-
}
1076-
return false;
1077-
}
1078-
10791065
static struct device_node *of_get_compat_node(struct device_node *np)
10801066
{
10811067
of_node_get(np);
@@ -1106,71 +1092,27 @@ static struct device_node *of_get_compat_node_parent(struct device_node *np)
11061092
return node;
11071093
}
11081094

1109-
/**
1110-
* of_link_to_phandle - Add fwnode link to supplier from supplier phandle
1111-
* @con_np: consumer device tree node
1112-
* @sup_np: supplier device tree node
1113-
*
1114-
* Given a phandle to a supplier device tree node (@sup_np), this function
1115-
* finds the device that owns the supplier device tree node and creates a
1116-
* device link from @dev consumer device to the supplier device. This function
1117-
* doesn't create device links for invalid scenarios such as trying to create a
1118-
* link with a parent device as the consumer of its child device. In such
1119-
* cases, it returns an error.
1120-
*
1121-
* Returns:
1122-
* - 0 if fwnode link successfully created to supplier
1123-
* - -EINVAL if the supplier link is invalid and should not be created
1124-
* - -ENODEV if struct device will never be create for supplier
1125-
*/
1126-
static int of_link_to_phandle(struct device_node *con_np,
1095+
static void of_link_to_phandle(struct device_node *con_np,
11271096
struct device_node *sup_np)
11281097
{
1129-
struct device *sup_dev;
1130-
struct device_node *tmp_np = sup_np;
1098+
struct device_node *tmp_np = of_node_get(sup_np);
11311099

1132-
/*
1133-
* Find the device node that contains the supplier phandle. It may be
1134-
* @sup_np or it may be an ancestor of @sup_np.
1135-
*/
1136-
sup_np = of_get_compat_node(sup_np);
1137-
if (!sup_np) {
1138-
pr_debug("Not linking %pOFP to %pOFP - No device\n",
1139-
con_np, tmp_np);
1140-
return -ENODEV;
1141-
}
1100+
/* Check that sup_np and its ancestors are available. */
1101+
while (tmp_np) {
1102+
if (of_fwnode_handle(tmp_np)->dev) {
1103+
of_node_put(tmp_np);
1104+
break;
1105+
}
11421106

1143-
/*
1144-
* Don't allow linking a device node as a consumer of one of its
1145-
* descendant nodes. By definition, a child node can't be a functional
1146-
* dependency for the parent node.
1147-
*/
1148-
if (of_is_ancestor_of(con_np, sup_np)) {
1149-
pr_debug("Not linking %pOFP to %pOFP - is descendant\n",
1150-
con_np, sup_np);
1151-
of_node_put(sup_np);
1152-
return -EINVAL;
1153-
}
1107+
if (!of_device_is_available(tmp_np)) {
1108+
of_node_put(tmp_np);
1109+
return;
1110+
}
11541111

1155-
/*
1156-
* Don't create links to "early devices" that won't have struct devices
1157-
* created for them.
1158-
*/
1159-
sup_dev = get_dev_from_fwnode(&sup_np->fwnode);
1160-
if (!sup_dev &&
1161-
(of_node_check_flag(sup_np, OF_POPULATED) ||
1162-
sup_np->fwnode.flags & FWNODE_FLAG_NOT_DEVICE)) {
1163-
pr_debug("Not linking %pOFP to %pOFP - No struct device\n",
1164-
con_np, sup_np);
1165-
of_node_put(sup_np);
1166-
return -ENODEV;
1112+
tmp_np = of_get_next_parent(tmp_np);
11671113
}
1168-
put_device(sup_dev);
11691114

11701115
fwnode_link_add(of_fwnode_handle(con_np), of_fwnode_handle(sup_np));
1171-
of_node_put(sup_np);
1172-
1173-
return 0;
11741116
}
11751117

11761118
/**

0 commit comments

Comments
 (0)