diff mbox series

[v1,02/43] binman: Refactor binman_entry_find() to allow other nodes

Message ID 20200615035738.248710-3-sjg@chromium.org
State Accepted
Commit 956a9082d325fae2b8c840d6974b6d090a8a21a7
Headers show
Series x86: Programmatic generation of ACPI tables (Part C) | expand

Commit Message

Simon Glass June 15, 2020, 3:56 a.m. UTC
At present we can only read from a top-level binman node entry. Refactor
this function to produce a second local function which supports reading
from any node.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 lib/binman.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

Comments

Bin Meng June 30, 2020, 2:33 a.m. UTC | #1
Hi Simon,

On Mon, Jun 15, 2020 at 11:57 AM Simon Glass <sjg at chromium.org> wrote:
>
> At present we can only read from a top-level binman node entry. Refactor
> this function to produce a second local function which supports reading
> from any node.
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
>
>  lib/binman.c | 18 ++++++++++++------
>  1 file changed, 12 insertions(+), 6 deletions(-)
>
> diff --git a/lib/binman.c b/lib/binman.c
> index dc3a880882..79d01230dd 100644
> --- a/lib/binman.c
> +++ b/lib/binman.c
> @@ -29,25 +29,31 @@ struct binman_info {
>
>  static struct binman_info *binman;
>
> -int binman_entry_find(const char *name, struct binman_entry *entry)
> +int binman_entry_find_(ofnode node, const char *name, struct binman_entry *entry)

This one should be static. We really should agree on a naming
convention for such internal APIs. I would prefer adding _internal
suffix, or using __ prefix

>  {
> -       ofnode node;
>         int ret;
>
> -       node = ofnode_find_subnode(binman->image, name);
>         if (!ofnode_valid(node))
> -               return log_msg_ret("no binman node", -ENOENT);
> +               node = binman->image;
> +       node = ofnode_find_subnode(node, name);
> +       if (!ofnode_valid(node))
> +               return log_msg_ret("node", -ENOENT);
>
>         ret = ofnode_read_u32(node, "image-pos", &entry->image_pos);
>         if (ret)
> -               return log_msg_ret("bad binman node1", ret);
> +               return log_msg_ret("import-pos", ret);
>         ret = ofnode_read_u32(node, "size", &entry->size);
>         if (ret)
> -               return log_msg_ret("bad binman node2", ret);
> +               return log_msg_ret("size", ret);
>
>         return 0;
>  }
>
> +int binman_entry_find(const char *name, struct binman_entry *entry)
> +{
> +       return binman_entry_find_(binman->image, name, entry);
> +}
> +
>  void binman_set_rom_offset(int rom_offset)
>  {
>         binman->rom_offset = rom_offset;
> --

Regards,
Bin
diff mbox series

Patch

diff --git a/lib/binman.c b/lib/binman.c
index dc3a880882..79d01230dd 100644
--- a/lib/binman.c
+++ b/lib/binman.c
@@ -29,25 +29,31 @@  struct binman_info {
 
 static struct binman_info *binman;
 
-int binman_entry_find(const char *name, struct binman_entry *entry)
+int binman_entry_find_(ofnode node, const char *name, struct binman_entry *entry)
 {
-	ofnode node;
 	int ret;
 
-	node = ofnode_find_subnode(binman->image, name);
 	if (!ofnode_valid(node))
-		return log_msg_ret("no binman node", -ENOENT);
+		node = binman->image;
+	node = ofnode_find_subnode(node, name);
+	if (!ofnode_valid(node))
+		return log_msg_ret("node", -ENOENT);
 
 	ret = ofnode_read_u32(node, "image-pos", &entry->image_pos);
 	if (ret)
-		return log_msg_ret("bad binman node1", ret);
+		return log_msg_ret("import-pos", ret);
 	ret = ofnode_read_u32(node, "size", &entry->size);
 	if (ret)
-		return log_msg_ret("bad binman node2", ret);
+		return log_msg_ret("size", ret);
 
 	return 0;
 }
 
+int binman_entry_find(const char *name, struct binman_entry *entry)
+{
+	return binman_entry_find_(binman->image, name, entry);
+}
+
 void binman_set_rom_offset(int rom_offset)
 {
 	binman->rom_offset = rom_offset;