From 741a6d010d09b5bafca8e4cdfb6b2f8a2c07994d Mon Sep 17 00:00:00 2001 From: Jon Loeliger Date: Thu, 25 Sep 2008 11:02:17 -0500 Subject: Fix an overflow case in fdt_offset_ptr() detected by GCC 4.3. Using Gcc 4.3 detected this problem: ../dtc/libfdt/fdt.c: In function 'fdt_next_tag': ../dtc/libfdt/fdt.c:82: error: assuming signed overflow does not occur when assuming that (X + c) < X is always false To fix the problem, treat the offset as an unsigned int. The problem report and proposed fix were provided by Steve Papacharalambous . Signed-off-by: Jon Loeliger --- include/libfdt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/libfdt.h') diff --git a/include/libfdt.h b/include/libfdt.h index 94c35e330..5492a5352 100644 --- a/include/libfdt.h +++ b/include/libfdt.h @@ -122,7 +122,7 @@ /* Low-level functions (you probably don't need these) */ /**********************************************************************/ -const void *fdt_offset_ptr(const void *fdt, int offset, int checklen); +const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen); static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen) { return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen); -- cgit v1.2.3 From 9a6cf73a88ddab2e1ac39088f2806177982cc62c Mon Sep 17 00:00:00 2001 From: David Gibson Date: Wed, 20 Aug 2008 16:55:14 +1000 Subject: libfdt: Add function to explicitly expand aliases Kumar has already added alias expansion to fdt_path_offset(). However, in some circumstances it may be convenient for the user of libfdt to explicitly get the string expansion of an alias. This patch adds a function to do this, fdt_get_alias(), and uses it to implement fdt_path_offset(). Signed-off-by: David Gibson --- include/libfdt.h | 26 ++++++++++++++++++++++++++ libfdt/fdt_ro.c | 26 +++++++++++++++++++------- 2 files changed, 45 insertions(+), 7 deletions(-) (limited to 'include/libfdt.h') diff --git a/include/libfdt.h b/include/libfdt.h index 5492a5352..7cad68c3c 100644 --- a/include/libfdt.h +++ b/include/libfdt.h @@ -458,6 +458,32 @@ static inline void *fdt_getprop_w(void *fdt, int nodeoffset, */ uint32_t fdt_get_phandle(const void *fdt, int nodeoffset); +/** + * fdt_get_namelen - get alias based on substring + * @fdt: pointer to the device tree blob + * @name: name of the alias th look up + * @namelen: number of characters of name to consider + * + * Identical to fdt_get_alias(), but only examine the first namelen + * characters of name for matching the alias name. + */ +const char *fdt_get_alias_namelen(const void *fdt, + const char *name, int namelen); + +/** + * fdt_get_alias - retreive the path referenced by a given alias + * @fdt: pointer to the device tree blob + * @name: name of the alias th look up + * + * fdt_get_alias() retrieves the value of a given alias. That is, the + * value of the property named 'name' in the node /aliases. + * + * returns: + * a pointer to the expansion of the alias named 'name', of it exists + * NULL, if the given alias or the /aliases node does not exist + */ +const char *fdt_get_alias(const void *fdt, const char *name); + /** * fdt_get_path - determine the full path of a node * @fdt: pointer to the device tree blob diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c index f559eeda0..b705f91ec 100644 --- a/libfdt/fdt_ro.c +++ b/libfdt/fdt_ro.c @@ -145,17 +145,12 @@ int fdt_path_offset(const void *fdt, const char *path) /* see if we have an alias */ if (*path != '/') { - const char *q; - int aliasoffset = fdt_path_offset(fdt, "/aliases"); - - if (aliasoffset < 0) - return -FDT_ERR_BADPATH; + const char *q = strchr(path, '/'); - q = strchr(path, '/'); if (!q) q = end; - p = fdt_getprop_namelen(fdt, aliasoffset, path, q - p, NULL); + p = fdt_get_alias_namelen(fdt, p, q - p); if (!p) return -FDT_ERR_BADPATH; offset = fdt_path_offset(fdt, p); @@ -306,6 +301,23 @@ uint32_t fdt_get_phandle(const void *fdt, int nodeoffset) return fdt32_to_cpu(*php); } +const char *fdt_get_alias_namelen(const void *fdt, + const char *name, int namelen) +{ + int aliasoffset; + + aliasoffset = fdt_path_offset(fdt, "/aliases"); + if (aliasoffset < 0) + return NULL; + + return fdt_getprop_namelen(fdt, aliasoffset, name, namelen, NULL); +} + +const char *fdt_get_alias(const void *fdt, const char *name) +{ + return fdt_get_alias_namelen(fdt, name, strlen(name)); +} + int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen) { int pdepth = 0, p = 0; -- cgit v1.2.3 From cd3cb0d9269d155276b00207e3816a9347fd1c92 Mon Sep 17 00:00:00 2001 From: Gerald Van Baren Date: Sat, 4 Oct 2008 07:56:06 -0400 Subject: libfdt: Fix error in documentation for fdt_get_alias_namelen() Oops, screwed up the function name in the documenting comment for this function. Trivial correction in this patch. Signed-off-by: David Gibson Acked-by: Gerald Van Baren --- include/libfdt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/libfdt.h') diff --git a/include/libfdt.h b/include/libfdt.h index 7cad68c3c..ce374fded 100644 --- a/include/libfdt.h +++ b/include/libfdt.h @@ -459,7 +459,7 @@ static inline void *fdt_getprop_w(void *fdt, int nodeoffset, uint32_t fdt_get_phandle(const void *fdt, int nodeoffset); /** - * fdt_get_namelen - get alias based on substring + * fdt_get_alias_namelen - get alias based on substring * @fdt: pointer to the device tree blob * @name: name of the alias th look up * @namelen: number of characters of name to consider -- cgit v1.2.3