From: Zijun Hu <quic_zijuhu@xxxxxxxxxxx> commit b9e58c934c56aa35b0fb436d9afd86ef326bae0e upstream. of_find_node_opts_by_path() fails to find OF device node when its @path parameter have pattern below: "alias-name/node-name-1/.../node-name-N:options". The reason is that alias name length calculated by the API is wrong, as explained by example below: "testcase-alias/phandle-tests/consumer-a:testaliasoption". ^ ^ ^ 0 14 39 The right length of alias 'testcase-alias' is 14, but the result worked out by the API is 39 which is obvious wrong. Fix by using index of either '/' or ':' as the length who comes earlier. Fixes: 75c28c09af99 ("of: add optional options parameter to of_find_node_by_path()") Cc: stable@xxxxxxxxxxxxxxx Signed-off-by: Zijun Hu <quic_zijuhu@xxxxxxxxxxx> Link: https://lore.kernel.org/r/20241216-of_core_fix-v2-1-e69b8f60da63@xxxxxxxxxxx Signed-off-by: Rob Herring (Arm) <robh@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/of/base.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -988,10 +988,10 @@ struct device_node *of_find_node_opts_by /* The path could begin with an alias */ if (*path != '/') { int len; - const char *p = separator; + const char *p = strchrnul(path, '/'); - if (!p) - p = strchrnul(path, '/'); + if (separator && separator < p) + p = separator; len = p - path; /* of_aliases must not be NULL */ Patches currently in stable-queue which might be from quic_zijuhu@xxxxxxxxxxx are queue-5.4/of-reserved-memory-fix-using-wrong-number-of-cells-to-get-property-alignment.patch queue-5.4/of-fix-of_find_node_opts_by_path-handling-of-alias-path-options.patch queue-5.4/pci-endpoint-destroy-the-epc-device-in-devm_pci_epc_.patch queue-5.4/of-correct-child-specifier-used-as-input-of-the-2nd-nexus-node.patch