All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Jones <ajones@ventanamicro.com>
To: Ben Dooks <qemu@ben.fluff.org>
Cc: qemu-devel@nongnu.org, qemu-riscv@nongnu.org,
	Alistair.Francis@wdc.com, peter.maydell@linaro.org,
	qemu-arm@nongnu.org
Subject: Re: [PATCH v4 1/6] device_tree: add qemu_fdt_setprop_strings() helper
Date: Wed, 10 Aug 2022 14:19:42 +0200	[thread overview]
Message-ID: <20220810121942.rlegpjuprzj3qsvd@kamzik> (raw)
In-Reply-To: <20220809185639.750345-2-qemu@ben.fluff.org>

On Tue, Aug 09, 2022 at 07:56:35PM +0100, Ben Dooks wrote:
> Add a helper to set a property from a set of strings
> to reduce the following code:
> 
>     static const char * const clint_compat[2] = {
>         "sifive,clint0", "riscv,clint0"
>     };
> 
>     qemu_fdt_setprop_string_array(fdt, nodename, "compatible",
>         (char **)&clint_compat, ARRAY_SIZE(clint_compat));
> 
> Signed-off-by: Ben Dooks <qemu@ben.fluff.org>
> ---
> v4:
>  - go back to the non-return call, no-one is using the result
> v3;
>  - fix return value for the call
>  - add better help text
> v2:
>  - fix node/path in comment
> ---
>  include/sysemu/device_tree.h | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/include/sysemu/device_tree.h b/include/sysemu/device_tree.h
> index ef060a9759..d5c05b5ebb 100644
> --- a/include/sysemu/device_tree.h
> +++ b/include/sysemu/device_tree.h
> @@ -87,6 +87,25 @@ int qemu_fdt_setprop_string(void *fdt, const char *node_path,
>  int qemu_fdt_setprop_string_array(void *fdt, const char *node_path,
>                                    const char *prop, char **array, int len);
>  
> +/**
> + * qemu_fdt_setprop_strings: set a property from a set of strings
> + *
> + * @fdt: pointer to the dt blob
> + * @path: node name
> + * @prop: property array
> + *
> + * This is a helper for the qemu_fdt_setprop_string_array() function
> + * which takes a va-arg set of strings instead of having to setup a
> + * single use string array.
> + */
> +#define qemu_fdt_setprop_strings(fdt, path, prop, ...)          \
> +    do {                                                        \
> +        static const char * const __strs[] = { __VA_ARGS__ };   \

           ^^ We don't want that static there. That'll keep the storage
	   for each invocation and require that __VA_ARGS__ are always
	   constants only.

	   I'd drop the const's too since __strs is only used for a
	   single call where it immediately gets the const's cast'ed
	   away.

> +        qemu_fdt_setprop_string_array(fdt, path, prop,          \
> +                (char **)&__strs, ARRAY_SIZE(__strs));          \

                   ^^ And then this can just be __strs

> +     } while(0)
> +
> +
>  int qemu_fdt_setprop_phandle(void *fdt, const char *node_path,
>                               const char *property,
>                               const char *target_node_path);
> -- 
> 2.35.1
> 
> 

Thanks,
drew


  reply	other threads:[~2022-08-10 12:25 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-09 18:56 add qemu_fdt_setprop_strings() and use it in most places Ben Dooks
2022-08-09 18:56 ` [PATCH v4 1/6] device_tree: add qemu_fdt_setprop_strings() helper Ben Dooks
2022-08-10 12:19   ` Andrew Jones [this message]
2022-08-09 18:56 ` [PATCH v4 2/6] hw/core: don't check return on qemu_fdt_setprop_string_array() Ben Dooks
2022-08-10 12:28   ` Andrew Jones
2022-08-10 21:58   ` Alistair Francis
2022-08-09 18:56 ` [PATCH v4 3/6] hw/riscv: use qemu_fdt_setprop_strings() for string arrays Ben Dooks
2022-08-10 12:34   ` Andrew Jones
2022-08-10 22:02   ` Alistair Francis
2022-08-09 18:56 ` [PATCH v4 4/6] hw/core: use qemu_fdt_setprop_strings() Ben Dooks
2022-08-10 12:35   ` Andrew Jones
2022-08-10 21:59   ` Alistair Francis
2022-08-09 18:56 ` [PATCH v4 5/6] hw/mips: " Ben Dooks
2022-08-10 12:36   ` Andrew Jones
2022-08-10 22:07   ` Alistair Francis
2022-08-09 18:56 ` [PATCH v4 6/6] hw/arm: change to " Ben Dooks
2022-08-10 12:41   ` Andrew Jones
2022-08-09 19:12 ` add qemu_fdt_setprop_strings() and use it in most places Ben Dooks
2022-08-12 10:30 ` Peter Maydell

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=20220810121942.rlegpjuprzj3qsvd@kamzik \
    --to=ajones@ventanamicro.com \
    --cc=Alistair.Francis@wdc.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=qemu@ben.fluff.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 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.