Re: [PATCH 01/10] of: Fix alias name length calculating error in API of_find_node_opts_by_path()
From: Zijun Hu
Date: Mon Dec 09 2024 - 08:35:09 EST
On 2024/12/9 21:24, Rob Herring wrote:
> On Thu, Dec 5, 2024 at 6:53 PM Zijun Hu <zijun_hu@xxxxxxxxxx> wrote:
>>
>> From: Zijun Hu <quic_zijuhu@xxxxxxxxxxx>
>>
>> Alias name length calculated by of_find_node_opts_by_path() is wrong as
>> explained below:
>>
>> Take "alias/serial@llc500:115200n8" as its @patch argument for an example
>> ^ ^ ^
>> 0 5 19
>>
>> The right length of alias 'alias' is 5, but the API results in 19 which is
>> obvious wrong.
>>
>> The wrong length will cause finding device node failure for such paths.
>> Fix by using index of either '/' or ':' as the length who comes earlier.
>
> Can you add a test case in the unittest for this.
sure. let me try to do it.
>
>>
>> Fixes: 106937e8ccdc ("of: fix handling of '/' in options for of_find_node_by_path()")
>> Cc: stable@xxxxxxxxxxxxxxx
>> Signed-off-by: Zijun Hu <quic_zijuhu@xxxxxxxxxxx>
>> ---
>> drivers/of/base.c | 6 +++---
>> 1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/of/base.c b/drivers/of/base.c
>> index 7dc394255a0a14cd1aed02ec79c2f787a222b44c..9a9313183d1f1b61918fe7e6fa80c2726b099a1c 100644
>> --- a/drivers/of/base.c
>> +++ b/drivers/of/base.c
>> @@ -893,10 +893,10 @@ struct device_node *of_find_node_opts_by_path(const char *path, const char **opt
>> /* 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 */
>>
>> --
>> 2.34.1
>>