device property: Check fwnode->secondary in fwnode_graph_get_next_endpoint()
authorDaniel Scally <djrscally@gmail.com>
Fri, 6 Aug 2021 22:09:05 +0000 (23:09 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 16 Aug 2021 16:35:41 +0000 (18:35 +0200)
Sensor drivers often check for an endpoint to make sure that they're
connected to a consuming device like a CIO2 during .probe(). Some of
those endpoints might be in the form of software_nodes assigned as
a secondary to the device's fwnode_handle. Account for this possibility
in fwnode_graph_get_next_endpoint() to avoid having to do it in the
sensor drivers themselves.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Daniel Scally <djrscally@gmail.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/base/property.c

index d0874f6..fcf1a38 100644 (file)
@@ -1033,7 +1033,26 @@ struct fwnode_handle *
 fwnode_graph_get_next_endpoint(const struct fwnode_handle *fwnode,
                               struct fwnode_handle *prev)
 {
-       return fwnode_call_ptr_op(fwnode, graph_get_next_endpoint, prev);
+       const struct fwnode_handle *parent;
+       struct fwnode_handle *ep;
+
+       /*
+        * If this function is in a loop and the previous iteration returned
+        * an endpoint from fwnode->secondary, then we need to use the secondary
+        * as parent rather than @fwnode.
+        */
+       if (prev)
+               parent = fwnode_graph_get_port_parent(prev);
+       else
+               parent = fwnode;
+
+       ep = fwnode_call_ptr_op(parent, graph_get_next_endpoint, prev);
+
+       if (IS_ERR_OR_NULL(ep) &&
+           !IS_ERR_OR_NULL(parent) && !IS_ERR_OR_NULL(parent->secondary))
+               ep = fwnode_graph_get_next_endpoint(parent->secondary, NULL);
+
+       return ep;
 }
 EXPORT_SYMBOL_GPL(fwnode_graph_get_next_endpoint);