[PATCH] fdt_ro: Fix fdt_get_property_namelen() length bug

Peter Tyser ptyser at xes-inc.com
Tue Mar 29 09:19:35 EST 2011


fdt_get_property_namelen() should only compare 'namelen' characters when
matching a property name.  The previous code compared 'namelen'
characters correctly, but also required the property name length to
exactly match 'namelen'.

This length matching requirement would result in bugs such as
"ethernet0" not being found when using fdt_get_property_namelen() to
find properties starting with "ethernet".

Fix the bug by allowing the property name length to be greater than or
equal to 'namelen'.

Also, fix a typo in the fdt_get_property_namelen() description.

Signed-off-by: Peter Tyser <ptyser at xes-inc.com>
Reported-by: Chris Anacker <canacker at xes-inc.com>
---
Let me know if this isn't the right mailing list for dtc/libfdt fixes.
This issue isn't in the Linux kernel since it differs from the dtc
tree, but is in other packages, eg U-Boot.  Please keep me on CC,
I'm not subscribed to this list.

 libfdt/fdt_ro.c |    2 +-
 libfdt/libfdt.h |    4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
index 02b6d68..8e03eb6 100644
--- a/libfdt/fdt_ro.c
+++ b/libfdt/fdt_ro.c
@@ -85,7 +85,7 @@ static int _fdt_string_eq(const void *fdt, int stroffset,
 {
 	const char *p = fdt_string(fdt, stroffset);
 
-	return (strlen(p) == len) && (memcmp(p, s, len) == 0);
+	return (strlen(p) >= len) && (memcmp(p, s, len) == 0);
 }
 
 int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size)
diff --git a/libfdt/libfdt.h b/libfdt/libfdt.h
index 55f3eb3..1762c27 100644
--- a/libfdt/libfdt.h
+++ b/libfdt/libfdt.h
@@ -419,8 +419,8 @@ const struct fdt_property *fdt_get_property_by_offset(const void *fdt,
  * @namelen: number of characters of name to consider
  * @lenp: pointer to an integer variable (will be overwritten) or NULL
  *
- * Identical to fdt_get_property_namelen(), but only examine the first
- * namelen characters of name for matching the property name.
+ * Identical to fdt_get_property(), but only examine the first namelen
+ * characters of name for matching the property name.
  */
 const struct fdt_property *fdt_get_property_namelen(const void *fdt,
 						    int nodeoffset,
-- 
1.7.0.4



More information about the devicetree-discuss mailing list