Re: [PATCH 1/9] device property: fix fwnode_name_eq() for empty node names

From: Sakari Ailus

Date: Thu Nov 05 2026 - 05:02:16 EST


Hi Bartosz,

On Wed, Nov 04, 2026 at 03:03:43PM +0100, Bartosz Golaszewski wrote:
> str_has_prefix() returns the prefix length on match and 0 on mismatch,
> so the mistmatch case can't be told from "empty prefix matched an empty
> string". For instance: the OF root node's name as returned by
> fwnode_get_name() is "" and will return 0 for any name matched against
> it and since len is 0 too, fwnode_name_eq() will return true.
>
> Do what OF code already does in of_node_name_eq(): check if the length
> of the expected name matches the length of the actual node name before
> comparing it.
>
> Fixes: a9c8c738066b ("device property: Add fwnode_name_eq()")

Is there a need to cc this to stable? I'm not sure if anything is affected
there, probably not, but it's hard to be sure.

> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxxxxxxxx>
> ---
> drivers/base/property.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/base/property.c b/drivers/base/property.c
> index 51109794d7275ddaf4571584d0e77d8573ebb475..a97575ff9199004b4f401f432aed6c95e40d0c25 100644
> --- a/drivers/base/property.c
> +++ b/drivers/base/property.c
> @@ -700,7 +700,7 @@ bool fwnode_name_eq(const struct fwnode_handle *fwnode, const char *name)
>
> len = strchrnul(node_name, '@') - node_name;
>
> - return str_has_prefix(node_name, name) == len;
> + return len == strlen(name) && !strncmp(node_name, name, len);

I'd test strncmp() first as it's more likely to return faster. I'd also put
the variable on the right side as that's the typically preferred order,
i.e.

return !strncmp(node_name, name, len) && strlen(name) == len;

Either way,

Reviewed-by: Sakari Ailus <sakari.ailus@xxxxxxxxxxxxxxx>

> }
> EXPORT_SYMBOL_GPL(fwnode_name_eq);
>
>

--
Regards,

Sakari Ailus