From: David Gibson <david@gibson.dropbear.id.au> To: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v3 08/12] libfdt: Add fdt_path_offset_namelen Date: Mon, 27 Jun 2016 01:47:37 +1000 [thread overview] Message-ID: <20160626154737.GS15625@voom.fritz.box> (raw) In-Reply-To: <20160624142757.32735-9-maxime.ripard@free-electrons.com> 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 <maxime.ripard@free-electrons.com> 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160627/e766b777/attachment.sig>
WARNING: multiple messages have this Message-ID (diff)
From: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org> To: Maxime Ripard <maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org> Cc: "Pantelis Antoniou" <pantelis.antoniou-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>, "Simon Glass" <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>, "Boris Brezillon" <boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>, "Alexander Kaplan" <alex-MflLfwwFzuz+yO7R74ARew@public.gmane.org>, "Thomas Petazzoni" <thomas.petazzoni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>, devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, "Antoine Ténart" <antoine.tenart-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>, "Hans de Goede" <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>, "Tom Rini" <trini-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>, u-boot-0aAXYlwwYIKGBzrmiIFOJg@public.gmane.org, "Stefan Agner" <stefan-XLVq0VzYD2Y@public.gmane.org> Subject: Re: [PATCH v3 08/12] libfdt: Add fdt_path_offset_namelen Date: Mon, 27 Jun 2016 01:47:37 +1000 [thread overview] Message-ID: <20160626154737.GS15625@voom.fritz.box> (raw) In-Reply-To: <20160624142757.32735-9-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org> [-- Attachment #1: Type: text/plain, Size: 3986 bytes --] 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 <maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org> 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 [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 819 bytes --]
next prev parent reply other threads:[~2016-06-26 15:47 UTC|newest] Thread overview: 90+ messages / expand[flat|nested] mbox.gz Atom feed top 2016-06-24 14:27 [U-Boot] [PATCH v3 00/12] cmd: fdt: Add device tree overlays support Maxime Ripard 2016-06-24 14:27 ` Maxime Ripard 2016-06-24 14:27 ` [U-Boot] [PATCH v3 01/12] cmd: fdt: Narrow the check for fdt addr Maxime Ripard 2016-06-24 14:27 ` Maxime Ripard 2016-06-24 14:27 ` [U-Boot] [PATCH v3 02/12] scripts: Makefile.lib: Sanitize DTB names Maxime Ripard 2016-06-24 14:27 ` Maxime Ripard 2016-06-24 14:27 ` [U-Boot] [PATCH v3 03/12] vsprintf: Include stdarg for va_list Maxime Ripard 2016-06-24 14:27 ` Maxime Ripard 2016-06-24 14:27 ` [U-Boot] [PATCH v3 04/12] libfdt: Add new headers and defines Maxime Ripard 2016-06-24 14:27 ` Maxime Ripard 2016-06-26 2:53 ` [U-Boot] " Simon Glass 2016-06-26 2:53 ` Simon Glass 2016-06-26 15:39 ` [U-Boot] " David Gibson 2016-06-26 15:39 ` David Gibson 2016-06-27 7:25 ` [U-Boot] " Maxime Ripard 2016-06-27 7:25 ` Maxime Ripard 2016-06-28 3:02 ` [U-Boot] " David Gibson 2016-06-28 3:02 ` David Gibson 2016-06-24 14:27 ` [U-Boot] [PATCH v3 05/12] libfdt: Add iterator over properties Maxime Ripard 2016-06-24 14:27 ` Maxime Ripard 2016-06-26 2:53 ` [U-Boot] " Simon Glass 2016-06-26 2:53 ` Simon Glass 2016-06-24 14:27 ` [U-Boot] [PATCH v3 06/12] libfdt: Add max phandle retrieval function Maxime Ripard 2016-06-24 14:27 ` Maxime Ripard 2016-06-26 2:53 ` [U-Boot] " Simon Glass 2016-06-26 2:53 ` Simon Glass 2016-06-24 14:27 ` [U-Boot] [PATCH v3 07/12] libfdt: Add fdt_setprop_inplace_by_index Maxime Ripard 2016-06-24 14:27 ` Maxime Ripard 2016-06-26 2:53 ` [U-Boot] " Simon Glass 2016-06-26 2:53 ` Simon Glass 2016-06-26 8:09 ` [U-Boot] " Maxime Ripard 2016-06-26 8:09 ` Maxime Ripard 2016-06-26 15:45 ` [U-Boot] " David Gibson 2016-06-26 15:45 ` David Gibson 2016-06-27 9:16 ` [U-Boot] " Maxime Ripard 2016-06-27 9:16 ` Maxime Ripard 2016-06-28 3:05 ` [U-Boot] " David Gibson 2016-06-28 3:05 ` David Gibson 2016-06-24 14:27 ` [U-Boot] [PATCH v3 08/12] libfdt: Add fdt_path_offset_namelen Maxime Ripard 2016-06-24 14:27 ` Maxime Ripard 2016-06-26 2:53 ` [U-Boot] " Simon Glass 2016-06-26 2:53 ` Simon Glass 2016-06-26 8:10 ` [U-Boot] " Maxime Ripard 2016-06-26 8:10 ` Maxime Ripard 2016-06-29 3:27 ` [U-Boot] " Simon Glass 2016-06-29 3:27 ` Simon Glass 2016-06-26 15:47 ` David Gibson [this message] 2016-06-26 15:47 ` David Gibson 2016-06-24 14:27 ` [U-Boot] [PATCH v3 09/12] libfdt: Add fdt_getprop_namelen_w Maxime Ripard 2016-06-24 14:27 ` Maxime Ripard 2016-06-26 2:53 ` [U-Boot] " Simon Glass 2016-06-26 2:53 ` Simon Glass 2016-06-26 8:11 ` [U-Boot] " Maxime Ripard 2016-06-26 8:11 ` Maxime Ripard 2016-06-26 15:49 ` [U-Boot] " David Gibson 2016-06-26 15:49 ` David Gibson 2016-06-27 7:29 ` [U-Boot] " Maxime Ripard 2016-06-27 7:29 ` Maxime Ripard 2016-06-24 14:27 ` [U-Boot] [PATCH v3 10/12] libfdt: Add overlay application function Maxime Ripard 2016-06-24 14:27 ` Maxime Ripard 2016-06-26 2:53 ` [U-Boot] " Simon Glass 2016-06-26 2:53 ` Simon Glass 2016-06-27 7:13 ` [U-Boot] " Maxime Ripard 2016-06-27 7:13 ` Maxime Ripard 2016-06-27 5:26 ` [U-Boot] " David Gibson 2016-06-27 5:26 ` David Gibson 2016-06-27 11:40 ` [U-Boot] " Maxime Ripard 2016-06-27 11:40 ` Maxime Ripard 2016-06-28 3:12 ` [U-Boot] " David Gibson 2016-06-28 3:12 ` David Gibson 2016-06-30 2:34 ` [U-Boot] " Frank Rowand 2016-06-30 2:34 ` Frank Rowand 2016-06-30 5:08 ` [U-Boot] " David Gibson 2016-06-30 5:08 ` David Gibson 2016-06-24 14:27 ` [U-Boot] [PATCH v3 11/12] cmd: fdt: add fdt overlay application subcommand Maxime Ripard 2016-06-24 14:27 ` Maxime Ripard 2016-06-24 14:27 ` [U-Boot] [PATCH v3 12/12] tests: Introduce DT overlay tests Maxime Ripard 2016-06-24 14:27 ` Maxime Ripard 2016-06-27 5:26 ` [U-Boot] " David Gibson 2016-06-27 5:26 ` David Gibson 2016-06-27 6:30 ` [U-Boot] " Maxime Ripard 2016-06-27 6:30 ` Maxime Ripard 2016-06-27 6:47 ` [U-Boot] " David Gibson 2016-06-27 6:47 ` David Gibson 2016-06-26 15:37 ` [U-Boot] [PATCH v3 00/12] cmd: fdt: Add device tree overlays support David Gibson 2016-06-26 15:37 ` David Gibson 2016-06-27 6:29 ` [U-Boot] " Maxime Ripard 2016-06-27 6:29 ` Maxime Ripard 2016-06-29 3:28 ` [U-Boot] " Simon Glass 2016-06-29 3:28 ` Simon Glass
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20160626154737.GS15625@voom.fritz.box \ --to=david@gibson.dropbear.id.au \ --cc=u-boot@lists.denx.de \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.