Thread (47 messages) 47 messages, 5 authors, 27d ago

Re: [PATCH v2 02/16] device property: Add fwnode_graph_get_next_port_endpoint()

From: Chen-Yu Tsai <wenst@chromium.org>
Date: 2026-06-12 07:20:30
Also in: driver-core, linux-acpi, linux-devicetree, linux-mediatek, linux-pm, linux-usb, lkml

On Wed, Jun 10, 2026 at 11:08 PM Andy Shevchenko
[off-list ref] wrote:
On Wed, Jun 10, 2026 at 04:40:36PM +0800, Chen-Yu Tsai wrote:
quoted
Due to design constraints of the power sequencing API, the consumer
must first be sure that the other side is actually a provider, or it
will continually get -EPROBE_DEFER when requesting the power
sequencing descriptor.

In the upcoming USB power sequencing integration, the USB hub driver
first needs to check whether a graph connection exists, and whether
the other side of the connection is a supported connector type. The
USB port is tied to a "port" firmware node, and this new helper will
be used to get the endpoint under the known "port" firmware node.
...
quoted
+/**
+ * fwnode_graph_get_next_port_endpoint - Get next endpoint firmware node in port
+ * @port: Pointer to the target port firmware node
+ * @prev: Previous endpoint node or %NULL to get the first
+ *
+ * The caller is responsible for calling fwnode_handle_put() on the returned
+ * fwnode pointer. Note that this function also puts a reference to @prev
+ * unconditionally.
+ *
+ * Return: an endpoint firmware node pointer or %NULL if no more endpoints
+ * are available.
Yeah, you see, even here is inconsistency with previously added kernel-doc.
quoted
+ */
+struct fwnode_handle *fwnode_graph_get_next_port_endpoint(const struct fwnode_handle *port,
+                                                       struct fwnode_handle *prev)
+{
+     struct fwnode_handle *ep;
Unused?
quoted
+     while (1) {
This is usually harder to read and follow. It's like "pay much attention on
the code", but here no rocket science, no code to really pay attention to.
quoted
+             prev = fwnode_get_next_child_node(port, prev);
+             if (!prev)
+                     break;
+
+             if (WARN(!fwnode_name_eq(prev, "endpoint"),
+                      "non endpoint node is used (%pfw)", prev))
+                     continue;
+
+             break;
+     }
+
+     return prev;
+}
So, this can be rewritten as

        ep = prev;
        do {
                ep = fwnode_get_next_child_node(port, ep);
                if (fwnode_name_eq(ep, "endpoint"))
                        break;

                WARN_ON(ep, ...);
        } while (ep);

        return ep;

But also big question why? to WARN*(). There is no use in the entire
property.c.
Will drop. This function was lifted from drivers/of/property.c then
adapted to the fwnode APIs, so it still has the structure of its
origin. With the WARN() gone, rewriting it as do {} while() becomes:

do {
        prev = fwnode_get_next_child_node(port, prev);
        if (prev && fwnode_name_eq(prev, "endpoint"))
                break;
} while (prev);

return prev;


Thanks
ChenYu
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help