[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v4 1/6] device_tree: add qemu_fdt_setprop_strings() helper
From: |
Andrew Jones |
Subject: |
Re: [PATCH v4 1/6] device_tree: add qemu_fdt_setprop_strings() helper |
Date: |
Wed, 10 Aug 2022 14:19:42 +0200 |
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
- add qemu_fdt_setprop_strings() and use it in most places, Ben Dooks, 2022/08/09
- [PATCH v4 5/6] hw/mips: use qemu_fdt_setprop_strings(), Ben Dooks, 2022/08/09
- [PATCH v4 3/6] hw/riscv: use qemu_fdt_setprop_strings() for string arrays, Ben Dooks, 2022/08/09
- [PATCH v4 1/6] device_tree: add qemu_fdt_setprop_strings() helper, Ben Dooks, 2022/08/09
- Re: [PATCH v4 1/6] device_tree: add qemu_fdt_setprop_strings() helper,
Andrew Jones <=
- [PATCH v4 4/6] hw/core: use qemu_fdt_setprop_strings(), Ben Dooks, 2022/08/09
- [PATCH v4 6/6] hw/arm: change to use qemu_fdt_setprop_strings(), Ben Dooks, 2022/08/09
- [PATCH v4 2/6] hw/core: don't check return on qemu_fdt_setprop_string_array(), Ben Dooks, 2022/08/09
- Re: add qemu_fdt_setprop_strings() and use it in most places, Ben Dooks, 2022/08/09
- Re: add qemu_fdt_setprop_strings() and use it in most places, Peter Maydell, 2022/08/12