From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 1/2] bootchooser: put bootchooser after creating a boot entry
Date: Thu, 18 Oct 2018 13:43:50 +0200 [thread overview]
Message-ID: <20181018114351.29022-1-s.hauer@pengutronix.de> (raw)
Between creating a boot entry for bootchooser and actually using it the
underlying state may have been modified, so make sure to get a current
bootchooser when booting it, thus do a bootchooser_put after having
created the entry and a bootchooser_get again when booting it.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/bootchooser.c | 36 +++++++++++++++++++++++-------------
1 file changed, 23 insertions(+), 13 deletions(-)
diff --git a/common/bootchooser.c b/common/bootchooser.c
index 83b15e0f78..29f61aec7f 100644
--- a/common/bootchooser.c
+++ b/common/bootchooser.c
@@ -52,7 +52,6 @@ static int retry;
static int last_boot_successful;
struct bootchooser {
- struct bootentry entry;
struct list_head targets;
struct bootchooser_target *last_chosen;
@@ -841,20 +840,26 @@ int bootchooser_boot(struct bootchooser *bc)
static int bootchooser_entry_boot(struct bootentry *entry, int verbose, int dryrun)
{
- struct bootchooser *bc = container_of(entry, struct bootchooser,
- entry);
+ struct bootchooser *bc;
+ int ret;
+
+ bc = bootchooser_get();
+ if (IS_ERR(bc))
+ return PTR_ERR(bc);
+
bc->verbose = verbose;
bc->dryrun = dryrun;
- return bootchooser_boot(bc);
+ ret = bootchooser_boot(bc);
+
+ bootchooser_put(bc);
+
+ return ret;
}
static void bootchooser_release(struct bootentry *entry)
{
- struct bootchooser *bc = container_of(entry, struct bootchooser,
- entry);
-
- bootchooser_put(bc);
+ free(entry);
}
/**
@@ -869,6 +874,7 @@ static void bootchooser_release(struct bootentry *entry)
static int bootchooser_add_entry(struct bootentries *entries, const char *name)
{
struct bootchooser *bc;
+ struct bootentry *entry;
if (strcmp(name, "bootchooser"))
return 0;
@@ -877,12 +883,16 @@ static int bootchooser_add_entry(struct bootentries *entries, const char *name)
if (IS_ERR(bc))
return PTR_ERR(bc);
- bc->entry.boot = bootchooser_entry_boot;
- bc->entry.release = bootchooser_release;
- bc->entry.title = xstrdup("bootchooser");
- bc->entry.description = xstrdup("bootchooser");
+ entry = xzalloc(sizeof(*entry));
+
+ entry->boot = bootchooser_entry_boot;
+ entry->release = bootchooser_release;
+ entry->title = xstrdup("bootchooser");
+ entry->description = xstrdup("bootchooser");
- bootentries_add_entry(entries, &bc->entry);
+ bootentries_add_entry(entries, entry);
+
+ bootchooser_put(bc);
return 1;
}
--
2.19.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next reply other threads:[~2018-10-18 11:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-18 11:43 Sascha Hauer [this message]
2018-10-18 11:43 ` [PATCH 2/2] bootchooser: Add reference counting Sascha Hauer
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=20181018114351.29022-1-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox