Re: [U-Boot] [PATCH v3 08/12] libfdt: Add fdt_path_offset_namelen

2016-06-28 Thread Simon Glass
On 26 June 2016 at 01:10, Maxime Ripard
 wrote:
> Hi,
>
> On Sat, Jun 25, 2016 at 08:53:53PM -0600, Simon Glass wrote:
>> On 24 June 2016 at 08:27, Maxime Ripard
>>  wrote:
>> > Add a namelen variant of fdt_path_offset to retrieve the node offset using
>> > only a fixed number of characters.
>> >
>> > Signed-off-by: Maxime Ripard 
>> > ---
>> >  include/libfdt.h| 16 +++-
>> >  lib/libfdt/fdt_ro.c | 18 ++
>> >  2 files changed, 25 insertions(+), 9 deletions(-)
>>
>> fdt_setprop_inplace
>
> What do you mean?

That was a mistake. I meant:

Reviewed-by: Simon Glass 
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v3 08/12] libfdt: Add fdt_path_offset_namelen

2016-06-26 Thread David Gibson
On Fri, Jun 24, 2016 at 04:27:53PM +0200, Maxime Ripard wrote:
> Add a namelen variant of fdt_path_offset to retrieve the node offset using
> only a fixed number of characters.
> 
> Signed-off-by: Maxime Ripard 

Looks good for upstream.

> ---
>  include/libfdt.h| 16 +++-
>  lib/libfdt/fdt_ro.c | 18 ++
>  2 files changed, 25 insertions(+), 9 deletions(-)
> 
> diff --git a/include/libfdt.h b/include/libfdt.h
> index 2c8a42bcb667..dbe8a0efca87 100644
> --- a/include/libfdt.h
> +++ b/include/libfdt.h
> @@ -365,6 +365,17 @@ int fdt_subnode_offset_namelen(const void *fdt, int 
> parentoffset,
>   */
>  int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);
>  
> +/**
> + * fdt_path_offset_namelen - find a tree node based on substring
> + * @fdt: pointer to the device tree blob
> + * @path: full path of the node to locate
> + * @namelen: number of characters of name to consider
> + *
> + * Identical to fdt_path_offset(), but only examine the first
> + * namelen characters of path for matching the node path.
> + */
> +int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen);
> +
>  /**
>   * fdt_path_offset - find a tree node by its full path
>   * @fdt: pointer to the device tree blob
> @@ -387,7 +398,10 @@ int fdt_subnode_offset(const void *fdt, int 
> parentoffset, const char *name);
>   *   -FDT_ERR_BADSTRUCTURE,
>   *   -FDT_ERR_TRUNCATED, standard meanings.
>   */
> -int fdt_path_offset(const void *fdt, const char *path);
> +static inline int fdt_path_offset(const void *fdt, const char *path)
> +{
> + return fdt_path_offset_namelen(fdt, path, strlen(path));
> +}
>  
>  /**
>   * fdt_get_name - retrieve the name of a given node
> diff --git a/lib/libfdt/fdt_ro.c b/lib/libfdt/fdt_ro.c
> index 503150ef1dc5..05344d3eebfe 100644
> --- a/lib/libfdt/fdt_ro.c
> +++ b/lib/libfdt/fdt_ro.c
> @@ -145,10 +145,10 @@ int fdt_subnode_offset(const void *fdt, int 
> parentoffset,
>   * "foo/bar:option" and "bar:option/otheroption", both of which happen, so
>   * first searching for either ':' or '/' does not work.
>   */
> -static const char *fdt_path_next_seperator(const char *path)
> +static const char *fdt_path_next_seperator(const void *path, int len)

Not in scope for this patch, but I should fix that mispelling of 'separator'.

>  {
> - const char *sep1 = strchr(path, '/');
> - const char *sep2 = strchr(path, ':');
> + const void *sep1 = memchr(path, '/', len);
> + const void *sep2 = memchr(path, ':', len);
>  
>   if (sep1 && sep2)
>   return (sep1 < sep2) ? sep1 : sep2;
> @@ -158,9 +158,9 @@ static const char *fdt_path_next_seperator(const char 
> *path)
>   return sep2;
>  }
>  
> -int fdt_path_offset(const void *fdt, const char *path)
> +int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen)
>  {
> - const char *end = path + strlen(path);
> + const char *end = path + namelen;
>   const char *p = path;
>   int offset = 0;
>  
> @@ -168,7 +168,7 @@ int fdt_path_offset(const void *fdt, const char *path)
>  
>   /* see if we have an alias */
>   if (*path != '/') {
> - const char *q = fdt_path_next_seperator(path);
> + const char *q = fdt_path_next_seperator(path, namelen);
>  
>   if (!q)
>   q = end;
> @@ -181,14 +181,16 @@ int fdt_path_offset(const void *fdt, const char *path)
>   p = q;
>   }
>  
> - while (*p) {
> + while (*p && (p < end)) {
>   const char *q;
>  
>   while (*p == '/')
>   p++;
> +
>   if (*p == '\0' || *p == ':')
>   return offset;
> - q = fdt_path_next_seperator(p);
> +
> + q = fdt_path_next_seperator(p, end - p);
>   if (!q)
>   q = end;
>  

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: PGP signature
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v3 08/12] libfdt: Add fdt_path_offset_namelen

2016-06-26 Thread Maxime Ripard
Hi,

On Sat, Jun 25, 2016 at 08:53:53PM -0600, Simon Glass wrote:
> On 24 June 2016 at 08:27, Maxime Ripard
>  wrote:
> > Add a namelen variant of fdt_path_offset to retrieve the node offset using
> > only a fixed number of characters.
> >
> > Signed-off-by: Maxime Ripard 
> > ---
> >  include/libfdt.h| 16 +++-
> >  lib/libfdt/fdt_ro.c | 18 ++
> >  2 files changed, 25 insertions(+), 9 deletions(-)
> 
> fdt_setprop_inplace

What do you mean?

Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com


signature.asc
Description: PGP signature
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v3 08/12] libfdt: Add fdt_path_offset_namelen

2016-06-25 Thread Simon Glass
On 24 June 2016 at 08:27, Maxime Ripard
 wrote:
> Add a namelen variant of fdt_path_offset to retrieve the node offset using
> only a fixed number of characters.
>
> Signed-off-by: Maxime Ripard 
> ---
>  include/libfdt.h| 16 +++-
>  lib/libfdt/fdt_ro.c | 18 ++
>  2 files changed, 25 insertions(+), 9 deletions(-)

fdt_setprop_inplace
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v3 08/12] libfdt: Add fdt_path_offset_namelen

2016-06-24 Thread Maxime Ripard
Add a namelen variant of fdt_path_offset to retrieve the node offset using
only a fixed number of characters.

Signed-off-by: Maxime Ripard 
---
 include/libfdt.h| 16 +++-
 lib/libfdt/fdt_ro.c | 18 ++
 2 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/include/libfdt.h b/include/libfdt.h
index 2c8a42bcb667..dbe8a0efca87 100644
--- a/include/libfdt.h
+++ b/include/libfdt.h
@@ -365,6 +365,17 @@ int fdt_subnode_offset_namelen(const void *fdt, int 
parentoffset,
  */
 int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);
 
+/**
+ * fdt_path_offset_namelen - find a tree node based on substring
+ * @fdt: pointer to the device tree blob
+ * @path: full path of the node to locate
+ * @namelen: number of characters of name to consider
+ *
+ * Identical to fdt_path_offset(), but only examine the first
+ * namelen characters of path for matching the node path.
+ */
+int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen);
+
 /**
  * fdt_path_offset - find a tree node by its full path
  * @fdt: pointer to the device tree blob
@@ -387,7 +398,10 @@ int fdt_subnode_offset(const void *fdt, int parentoffset, 
const char *name);
  * -FDT_ERR_BADSTRUCTURE,
  * -FDT_ERR_TRUNCATED, standard meanings.
  */
-int fdt_path_offset(const void *fdt, const char *path);
+static inline int fdt_path_offset(const void *fdt, const char *path)
+{
+   return fdt_path_offset_namelen(fdt, path, strlen(path));
+}
 
 /**
  * fdt_get_name - retrieve the name of a given node
diff --git a/lib/libfdt/fdt_ro.c b/lib/libfdt/fdt_ro.c
index 503150ef1dc5..05344d3eebfe 100644
--- a/lib/libfdt/fdt_ro.c
+++ b/lib/libfdt/fdt_ro.c
@@ -145,10 +145,10 @@ int fdt_subnode_offset(const void *fdt, int parentoffset,
  * "foo/bar:option" and "bar:option/otheroption", both of which happen, so
  * first searching for either ':' or '/' does not work.
  */
-static const char *fdt_path_next_seperator(const char *path)
+static const char *fdt_path_next_seperator(const void *path, int len)
 {
-   const char *sep1 = strchr(path, '/');
-   const char *sep2 = strchr(path, ':');
+   const void *sep1 = memchr(path, '/', len);
+   const void *sep2 = memchr(path, ':', len);
 
if (sep1 && sep2)
return (sep1 < sep2) ? sep1 : sep2;
@@ -158,9 +158,9 @@ static const char *fdt_path_next_seperator(const char *path)
return sep2;
 }
 
-int fdt_path_offset(const void *fdt, const char *path)
+int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen)
 {
-   const char *end = path + strlen(path);
+   const char *end = path + namelen;
const char *p = path;
int offset = 0;
 
@@ -168,7 +168,7 @@ int fdt_path_offset(const void *fdt, const char *path)
 
/* see if we have an alias */
if (*path != '/') {
-   const char *q = fdt_path_next_seperator(path);
+   const char *q = fdt_path_next_seperator(path, namelen);
 
if (!q)
q = end;
@@ -181,14 +181,16 @@ int fdt_path_offset(const void *fdt, const char *path)
p = q;
}
 
-   while (*p) {
+   while (*p && (p < end)) {
const char *q;
 
while (*p == '/')
p++;
+
if (*p == '\0' || *p == ':')
return offset;
-   q = fdt_path_next_seperator(p);
+
+   q = fdt_path_next_seperator(p, end - p);
if (!q)
q = end;
 
-- 
2.9.0

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot