Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

of: Fix of_find_node_opts_by_path() handling of alias+path+options

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@vger.kernel.org
Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
Link: https://lore.kernel.org/r/20241216-of_core_fix-v2-1-e69b8f60da63@quicinc.com
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>

authored by

Zijun Hu and committed by
Rob Herring (Arm)
b9e58c93 c1b4b91a

+3 -3
+3 -3
drivers/of/base.c
··· 893 893 /* The path could begin with an alias */ 894 894 if (*path != '/') { 895 895 int len; 896 - const char *p = separator; 896 + const char *p = strchrnul(path, '/'); 897 897 898 - if (!p) 899 - p = strchrnul(path, '/'); 898 + if (separator && separator < p) 899 + p = separator; 900 900 len = p - path; 901 901 902 902 /* of_aliases must not be NULL */