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 07/12] libfdt: Add fdt_setprop_inplace_by_index
Date: Mon, 27 Jun 2016 01:45:11 +1000 [thread overview]
Message-ID: <20160626154510.GR15625@voom.fritz.box> (raw)
In-Reply-To: <20160624142757.32735-8-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 4582 bytes --]
On Fri, Jun 24, 2016 at 04:27:52PM +0200, Maxime Ripard wrote:
> Add a function to modify inplace a property starting from a given index.
>
> This is especially useful when the property is an array of values, and you
> want to update one of them without changing the DT size.
>
> Signed-off-by: Maxime Ripard <maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
> ---
> include/libfdt.h | 34 +++++++++++++++++++++++++++++++---
> lib/libfdt/fdt_wip.c | 13 ++++++++-----
> 2 files changed, 39 insertions(+), 8 deletions(-)
>
> diff --git a/include/libfdt.h b/include/libfdt.h
> index 4643be5adf39..2c8a42bcb667 100644
> --- a/include/libfdt.h
> +++ b/include/libfdt.h
> @@ -1032,6 +1032,27 @@ int fdt_size_cells(const void *fdt, int nodeoffset);
> /* Write-in-place functions */
> /**********************************************************************/
>
> +/**
> + * fdt_setprop_inplace_namelen_by_index - change a property's value,
> + * but not its size
> + * @fdt: pointer to the device tree blob
> + * @nodeoffset: offset of the node whose property to change
> + * @name: name of the property to change
> + * @namelen: number of characters of name to consider
> + * @index: index of the property to change in the array
> + * @val: pointer to data to replace the property value with
> + * @len: length of the property value
> + *
> + * Identical to fdt_setprop_inplace(), but modifies the given property
> + * starting from the given index, and using only the first characters
> + * of the name. It is useful when you want to manipulate only one value of
> + * an array and you have a string that doesn't end with \0.
> + */
> +int fdt_setprop_inplace_namelen_by_index(void *fdt, int nodeoffset,
> + const char *name, int namelen,
> + uint32_t index, const void *val,
> + int len);
This looks like a good addition to upstream, but I don't like the
name. I'd suggest fdt_setprop_inplace_namelen_partial() because it
only overwrite part of the existing property value.
> +
> /**
> * fdt_setprop_inplace - change a property's value, but not its size
> * @fdt: pointer to the device tree blob
> @@ -1060,8 +1081,13 @@ int fdt_size_cells(const void *fdt, int nodeoffset);
> * -FDT_ERR_BADSTRUCTURE,
> * -FDT_ERR_TRUNCATED, standard meanings
> */
> -int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
> - const void *val, int len);
> +static inline int fdt_setprop_inplace(void *fdt, int nodeoffset,
> + const char *name, const void *val,
> + int len)
> +{
> + return fdt_setprop_inplace_namelen_by_index(fdt, nodeoffset, name,
> + strlen(name), 0, val, len);
This effectively removes the error if len is not equal to the existing
property length, so that needs to be put back.
> +}
>
> /**
> * fdt_setprop_inplace_u32 - change the value of a 32-bit integer property
> @@ -1095,7 +1121,9 @@ static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset,
> const char *name, uint32_t val)
> {
> fdt32_t tmp = cpu_to_fdt32(val);
> - return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
> + return fdt_setprop_inplace_namelen_by_index(fdt, nodeoffset,
> + name, strlen(name),
> + 0, &tmp, sizeof(tmp));
> }
>
> /**
> diff --git a/lib/libfdt/fdt_wip.c b/lib/libfdt/fdt_wip.c
> index 9fe988655fe3..737769fa59e2 100644
> --- a/lib/libfdt/fdt_wip.c
> +++ b/lib/libfdt/fdt_wip.c
> @@ -14,20 +14,23 @@
>
> #include "libfdt_internal.h"
>
> -int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
> - const void *val, int len)
> +int fdt_setprop_inplace_namelen_by_index(void *fdt, int nodeoffset,
> + const char *name, int namelen,
> + uint32_t index, const void *val,
> + int len)
> {
> void *propval;
> int proplen;
>
> - propval = fdt_getprop_w(fdt, nodeoffset, name, &proplen);
> + propval = fdt_getprop_namelen_w(fdt, nodeoffset, name, namelen,
> + &proplen);
> if (!propval)
> return proplen;
>
> - if (proplen != len)
> + if (proplen < (len + index))
> return -FDT_ERR_NOSPACE;
>
> - memcpy(propval, val, len);
> + memcpy(propval + index, val, len);
> return 0;
> }
>
--
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:45 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-24 14:27 [PATCH v3 00/12] cmd: fdt: Add device tree overlays support Maxime Ripard
[not found] ` <20160624142757.32735-1-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-06-24 14:27 ` [PATCH v3 01/12] cmd: fdt: Narrow the check for fdt addr Maxime Ripard
2016-06-24 14:27 ` [PATCH v3 02/12] scripts: Makefile.lib: Sanitize DTB names Maxime Ripard
2016-06-24 14:27 ` [PATCH v3 03/12] vsprintf: Include stdarg for va_list Maxime Ripard
2016-06-24 14:27 ` [PATCH v3 04/12] libfdt: Add new headers and defines Maxime Ripard
[not found] ` <20160624142757.32735-5-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-06-26 2:53 ` Simon Glass
2016-06-26 15:39 ` David Gibson
[not found] ` <20160626153906.GQ15625-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
2016-06-27 7:25 ` Maxime Ripard
2016-06-28 3:02 ` David Gibson
2016-06-24 14:27 ` [PATCH v3 05/12] libfdt: Add iterator over properties Maxime Ripard
[not found] ` <20160624142757.32735-6-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-06-26 2:53 ` Simon Glass
2016-06-24 14:27 ` [PATCH v3 06/12] libfdt: Add max phandle retrieval function Maxime Ripard
[not found] ` <20160624142757.32735-7-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-06-26 2:53 ` Simon Glass
2016-06-24 14:27 ` [PATCH v3 07/12] libfdt: Add fdt_setprop_inplace_by_index Maxime Ripard
[not found] ` <20160624142757.32735-8-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-06-26 2:53 ` Simon Glass
[not found] ` <CAPnjgZ2iperwdKGa=+BF8ypH+yRJ8NnP24Fti-PbXDs5bfg3dA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-06-26 8:09 ` Maxime Ripard
2016-06-26 15:45 ` David Gibson [this message]
[not found] ` <20160626154510.GR15625-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
2016-06-27 9:16 ` Maxime Ripard
2016-06-28 3:05 ` David Gibson
2016-06-24 14:27 ` [PATCH v3 08/12] libfdt: Add fdt_path_offset_namelen Maxime Ripard
[not found] ` <20160624142757.32735-9-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-06-26 2:53 ` Simon Glass
2016-06-26 8:10 ` Maxime Ripard
2016-06-29 3:27 ` Simon Glass
2016-06-26 15:47 ` David Gibson
2016-06-24 14:27 ` [PATCH v3 09/12] libfdt: Add fdt_getprop_namelen_w Maxime Ripard
[not found] ` <20160624142757.32735-10-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-06-26 2:53 ` Simon Glass
[not found] ` <CAPnjgZ32sm6PHXYHmqrb59XM1NiNeF5+4V-V35hn=YSmLjNMtQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-06-26 8:11 ` Maxime Ripard
2016-06-26 15:49 ` David Gibson
[not found] ` <20160626154929.GT15625-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
2016-06-27 7:29 ` Maxime Ripard
2016-06-24 14:27 ` [PATCH v3 10/12] libfdt: Add overlay application function Maxime Ripard
[not found] ` <20160624142757.32735-11-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-06-26 2:53 ` Simon Glass
[not found] ` <CAPnjgZ0dg-CX0XAxCirB-xLO2Jf_Q9T7rc5vu2qznDkYwA54ew-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-06-27 7:13 ` Maxime Ripard
2016-06-27 5:26 ` David Gibson
[not found] ` <20160627052607.GK4242-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
2016-06-27 11:40 ` Maxime Ripard
2016-06-28 3:12 ` David Gibson
[not found] ` <20160628031252.GZ4242-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
2016-06-30 2:34 ` Frank Rowand
2016-06-30 5:08 ` David Gibson
2016-06-24 14:27 ` [PATCH v3 11/12] cmd: fdt: add fdt overlay application subcommand Maxime Ripard
2016-06-24 14:27 ` [PATCH v3 12/12] tests: Introduce DT overlay tests Maxime Ripard
[not found] ` <20160624142757.32735-13-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-06-27 5:26 ` David Gibson
[not found] ` <20160627052658.GL4242-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
2016-06-27 6:30 ` Maxime Ripard
2016-06-27 6:47 ` David Gibson
2016-06-26 15:37 ` [PATCH v3 00/12] cmd: fdt: Add device tree overlays support David Gibson
[not found] ` <20160626153719.GP15625-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
2016-06-27 6:29 ` Maxime Ripard
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=20160626154510.GR15625@voom.fritz.box \
--to=david-xt8fgy+axnrb3ne2bgzf6laj5h9x9tb+@public.gmane.org \
--cc=alex-MflLfwwFzuz+yO7R74ARew@public.gmane.org \
--cc=antoine.tenart-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org \
--cc=boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org \
--cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org \
--cc=pantelis.antoniou-OWPKS81ov/FWk0Htik3J/w@public.gmane.org \
--cc=sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
--cc=stefan-XLVq0VzYD2Y@public.gmane.org \
--cc=thomas.petazzoni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org \
--cc=trini-OWPKS81ov/FWk0Htik3J/w@public.gmane.org \
--cc=u-boot-0aAXYlwwYIKGBzrmiIFOJg@public.gmane.org \
/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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).