Both bootloader spec entries and boot spec maintain a path to the file
the struct bootentry was generated from. Add this member to the struct
bootentry directly to allow referencing it from the boot command in a
follow-up commit.

No functional change intended.

Signed-off-by: Ahmad Fatoum <[email protected]>
---
 common/blspec.c | 12 ++++--------
 common/boot.c   | 17 +++++++----------
 include/boot.h  |  1 +
 3 files changed, 12 insertions(+), 18 deletions(-)

diff --git a/common/blspec.c b/common/blspec.c
index f13e44f1de71..c07e3a2d672d 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -27,7 +27,7 @@ struct blspec_entry {
        struct device_node *node;
        struct cdev *cdev;
        const char *rootpath;
-       const char *configpath;
+       /* configpath is entry.path */
        char *sortkey;
 };
 
@@ -180,7 +180,6 @@ static void blspec_entry_free(struct bootentry *be)
        struct blspec_entry *entry = container_of(be, struct blspec_entry, 
entry);
 
        of_delete_node(entry->node);
-       free_const(entry->configpath);
        free_const(entry->rootpath);
        free(entry->sortkey);
        free(entry);
@@ -305,7 +304,7 @@ static int blspec_have_entry(struct bootentries 
*bootentries, const char *path)
                if (!is_blspec_entry(be))
                        continue;
                e = container_of(be, struct blspec_entry, entry);
-               if (e->configpath && !strcmp(e->configpath, path))
+               if (e->entry.path && !strcmp(e->entry.path, path))
                        return 1;
        }
 
@@ -426,8 +425,8 @@ static int blspec_compare(struct list_head *list_a, struct 
list_head *list_b)
 {
        struct bootentry *be_a = container_of(list_a, struct bootentry, list);
        struct bootentry *be_b = container_of(list_b, struct bootentry, list);
+       const char *a_version = be_a->path, *b_version = be_b->path;
        struct blspec_entry *a, *b;
-       const char *a_version, *b_version;
        int r;
 
        /* The boot entry providers are called one by one and passed an empty
@@ -439,9 +438,6 @@ static int blspec_compare(struct list_head *list_a, struct 
list_head *list_b)
        a = container_of(be_a, struct blspec_entry, entry);
        b = container_of(be_b, struct blspec_entry, entry);
 
-       a_version = a->configpath;
-       b_version = b->configpath;
-
        if (a->sortkey && b->sortkey) {
                const char *a_machine_id, *b_machine_id;
 
@@ -489,7 +485,7 @@ static int __blspec_scan_file(struct bootentries 
*bootentries, const char *root,
 
        root = root ?: get_blspec_prefix_path(configname);
        entry->rootpath = xstrdup_const(root);
-       entry->configpath = xstrdup_const(configname);
+       entry->entry.path = xstrdup_const(configname);
        entry->cdev = get_cdev_by_mountpath(root);
 
        if (!entry_is_of_compatible(entry)) {
diff --git a/common/boot.c b/common/boot.c
index 2e5294ffa2f0..a325f350a80c 100644
--- a/common/boot.c
+++ b/common/boot.c
@@ -64,6 +64,7 @@ void bootentries_free(struct bootentries *bootentries)
                list_del(&be->list);
                free_const(be->title);
                free(be->description);
+               free_const(be->path);
                free_const(be->me.display);
                be->release(be);
        }
@@ -81,7 +82,6 @@ void bootentries_free(struct bootentries *bootentries)
 
 struct bootentry_script {
        struct bootentry entry;
-       const char *scriptpath;
 };
 
 /*
@@ -96,7 +96,7 @@ static int bootscript_boot(struct bootentry *entry, int 
verbose, int dryrun)
        struct bootm_data backup = {}, data = {};
 
        if (dryrun == 1) {
-               printf("Would run %s\n", bs->scriptpath);
+               printf("Would run %s\n", bs->entry.path);
                return 0;
        }
 
@@ -107,9 +107,9 @@ static int bootscript_boot(struct bootentry *entry, int 
verbose, int dryrun)
 
        bootm_nattempts = bootm_command_attempts();
 
-       ret = run_command(bs->scriptpath);
+       ret = run_command(bs->entry.path);
        if (ret) {
-               pr_err("Running script '%s' failed: %pe\n", bs->scriptpath, 
ERR_PTR(ret));
+               pr_err("Running script '%s' failed: %s\n", bs->entry.path, 
strerror(-ret));
                goto out;
        }
 
@@ -222,10 +222,7 @@ static void bootsource_action(struct menu *m, struct 
menu_entry *me)
 
 static void bootscript_entry_release(struct bootentry *entry)
 {
-       struct bootentry_script *bs = container_of(entry, struct 
bootentry_script, entry);
-
-       free_const(bs->scriptpath);
-       free(bs);
+       free(entry);
 }
 
 /*
@@ -248,8 +245,8 @@ static int bootscript_create_entry(struct bootentries 
*bootentries, const char *
        bs->entry.me.type = MENU_ENTRY_NORMAL;
        bs->entry.release = bootscript_entry_release;
        bs->entry.boot = bootscript_boot;
-       bs->scriptpath = xstrdup_const(name);
-       bs->entry.title = xstrdup_const(kbasename(bs->scriptpath));
+       bs->entry.path = xstrdup_const(name);
+       bs->entry.title = xstrdup_const(kbasename(bs->entry.path));
        bs->entry.description = basprintf("script: %s", name);
        bootentries_add_entry(bootentries, &bs->entry);
 
diff --git a/include/boot.h b/include/boot.h
index fdc108b7a21d..836a180a0c7b 100644
--- a/include/boot.h
+++ b/include/boot.h
@@ -18,6 +18,7 @@ struct bootentry {
        struct menu_entry me;
        const char *title;
        char *description;
+       const char *path;
        int (*boot)(struct bootentry *entry, int verbose, int dryrun);
        void (*release)(struct bootentry *entry);
        struct bootm_overrides overrides;
-- 
2.47.3


Reply via email to