[PATCH v3 2/5] device property: Fix fwnode_name_eq() for empty node names

From: Alejandro Colomar

Date: Tue Nov 10 2026 - 11:25:36 EST


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.

Let's use strprefix() instead, which also makes this function simpler.

Fixes: a9c8c738066b7 ("device property: Add fwnode_name_eq()")
Reported-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxxxxxxxx>
Link: https://lore.kernel.org/linux-hardening/20261104-fwnode-for-each-prop-v1-1-6e28fe1c72c4@xxxxxxxxxxxxxxxx/
Cc: Andy Shevchenko <andy@xxxxxxxxxx>
Signed-off-by: Alejandro Colomar <alx@xxxxxxxxxx>
---
drivers/base/property.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/base/property.c b/drivers/base/property.c
index 51109794d727..7728116e2968 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -692,15 +692,12 @@ const char *fwnode_get_name_prefix(const struct fwnode_handle *fwnode)
bool fwnode_name_eq(const struct fwnode_handle *fwnode, const char *name)
{
const char *node_name;
- ptrdiff_t len;

node_name = fwnode_get_name(fwnode);
if (!node_name)
return false;

- len = strchrnul(node_name, '@') - node_name;
-
- return str_has_prefix(node_name, name) == len;
+ return strprefix(node_name, name) == strchrnul(node_name, '@');
}
EXPORT_SYMBOL_GPL(fwnode_name_eq);

--
2.55.0

Attachment: signature.asc
Description: PGP signature