From 3dbe65baaacab00634b27237d2189c174d61fcba Mon Sep 17 00:00:00 2001 From: Wayne Chang Date: Thu, 25 May 2023 08:05:01 +0000 Subject: [PATCH] NVIDIA: SAUCE: usb: typec: ucsi: Find connector fwnode without relying on order BugLink: https://bugs.launchpad.net/bugs/2072591 The previous code relied on the order of "connector" nodes under the ucsi device node to determine the correct fwnode handle for a connector. However, the order of nodes should not be relied upon when parsing device trees, especially when using live DT overlays. This change modifies ucsi_find_fwnode() to find the correct connector fwnode by reading the "reg" property of each connector node and comparing it to the connector number. If only a single connector node exists without a "reg" property, that single node is returned. This ensures the correct connector fwnode is found regardless of node order in the DT. http://nvbugs/3960851 http://nvbugs/4063694 Signed-off-by: Wayne Chang Reviewed-by: Prathamesh Shete Tested-by: Prathamesh Shete Signed-off-by: Laxman Dewangan Acked-by: Jacob Martin Acked-by: Noah Wager Signed-off-by: Noah Wager --- drivers/usb/typec/ucsi/ucsi.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 140ac6c15b64..6497a826df7b 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -1186,11 +1186,14 @@ static const struct typec_operations ucsi_ops = { static struct fwnode_handle *ucsi_find_fwnode(struct ucsi_connector *con) { struct fwnode_handle *fwnode; - int i = 1; + u32 index; + + device_for_each_child_node(con->ucsi->dev, fwnode) { + if (!fwnode_property_read_u32(fwnode, "reg", &index) && index+1 != con->num) + continue; + return fwnode; + } - device_for_each_child_node(con->ucsi->dev, fwnode) - if (i++ == con->num) - return fwnode; return NULL; }