[PATCH v2 13/41] dm: core: Add a way to obtain a string list

Ilias Apalodimas ilias.apalodimas at linaro.org
Tue Oct 26 21:20:32 CEST 2021


On Sun, 24 Oct 2021 at 02:26, Simon Glass <sjg at chromium.org> wrote:
>
> At present we support reading a string list a string at a time. Apart
> from being inefficient, this makes it impossible to separate reading of
> the devicetree into the of_to_plat() method where it belongs, since any
> code which needs access to the string must read it from the devicetree.
>
> Add a function which returns the string property as an array of pointers
> to the strings, which is easily used by clients.
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
>
> (no changes since v1)
>
>  drivers/core/ofnode.c | 26 ++++++++++++++++++++++++++
>  drivers/core/read.c   |  6 ++++++
>  include/dm/ofnode.h   | 20 ++++++++++++++++++++
>  include/dm/read.h     | 28 ++++++++++++++++++++++++++++
>  test/dm/ofnode.c      | 20 ++++++++++++++++++++
>  5 files changed, 100 insertions(+)
>
> diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
> index 08705ef8d99..709bea272a6 100644
> --- a/drivers/core/ofnode.c
> +++ b/drivers/core/ofnode.c
> @@ -456,6 +456,32 @@ int ofnode_read_string_count(ofnode node, const char *property)
>         }
>  }
>
> +int ofnode_read_string_list(ofnode node, const char *property,
> +                           const char ***listp)
> +{
> +       const char **prop;
> +       int count;
> +       int i;
> +
> +       *listp = NULL;
> +       count = ofnode_read_string_count(node, property);
> +       if (count < 0)
> +               return count;
> +       if (!count)
> +               return 0;

Those can fold into a single if and always return 'count'.
if (count <= 0)
    return count;

> +
> +       prop = calloc(count + 1, sizeof(char *));
[...]

Regards
/Ilias


More information about the U-Boot mailing list