mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Lars Schmidt <l.schmidt@pengutronix.de>,
	Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH] fixup! bootchooser: extend cmd tool by option to set attempts_locked
Date: Mon, 23 Jun 2025 08:22:53 +0200	[thread overview]
Message-ID: <20250623062253.3528292-1-a.fatoum@barebox.org> (raw)

commands: bootchooser: fix new locking/unlocking options

The bootchooser instance is reference counted and the command releases
it again when it's done. Setting the struct bootchooser::lock_attempts
member in the command is thus without effect if the reference count
drops to zero when the command terminates.

Fix the issue by setting a global bootchooser instance independent flag
that forces locking until disabled. This is also the way that
bootchooser_last_boot_successful() is implemented.

This also drops the check for existence of the attempts_locked variable
in the boot state as the command doesn't interact with the state anyway.

Cc: Lars Schmidt <l.schmidt@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 commands/bootchooser.c |  2 +-
 common/bootchooser.c   | 25 ++++++++-----------------
 include/bootchooser.h  |  2 +-
 3 files changed, 10 insertions(+), 19 deletions(-)

diff --git a/commands/bootchooser.c b/commands/bootchooser.c
index 4199085f352b..a59b5ebf7cce 100644
--- a/commands/bootchooser.c
+++ b/commands/bootchooser.c
@@ -117,7 +117,7 @@ static int do_bootchooser(int argc, char *argv[])
 	}
 
 	if (lock_state >= 0) {
-		ret = bootchooser_lock_attempts(bootchooser, lock_state);
+		bootchooser_lock_attempts(lock_state);
 		done_something = true;
 	}
 
diff --git a/common/bootchooser.c b/common/bootchooser.c
index f2beed543db0..623cb8ce7714 100644
--- a/common/bootchooser.c
+++ b/common/bootchooser.c
@@ -41,6 +41,7 @@ static int global_default_priority = 1;
 static int disable_on_zero_attempts;
 static int retry;
 static int last_boot_successful;
+static bool attempts_locked;
 
 struct bootchooser {
 	struct list_head targets;
@@ -400,12 +401,13 @@ struct bootchooser *bootchooser_get(void)
 	}
 
 	/* this is an optional value */
-	bc->attempts_locked = false;
+	bc->attempts_locked = attempts_locked;
 	ret = getenv_u32(bc->state_prefix, "attempts_locked", &locked);
-	if (!ret && locked) {
+	if (!ret && locked)
 		bc->attempts_locked = true;
+
+	if (bc->attempts_locked)
 		pr_debug("remaining attempt counter is locked\n");
-	}
 
 	INIT_LIST_HEAD(&bc->targets);
 
@@ -632,7 +634,7 @@ void bootchooser_info(struct bootchooser *bc)
 	printf("\nlast booted target: %s\n", bc->last_chosen ?
 	       bc->last_chosen->name : "unknown");
 
-	printf("Locking of boot attempt counter: %s",
+	printf("Locking of boot attempt counter: %s\n",
 	       bc->attempts_locked ? "enabled" : "disabled");
 }
 
@@ -822,7 +824,6 @@ struct bootchooser_target *bootchooser_get_last_chosen(struct bootchooser *bc)
 
 /**
  * bootchooser_lock_attempts - lock the bootchooser attempt counter
- * @bc:		The bootchooser
  * @locked:     Whether the attempt counter is locked or not.
  *
  * Instruct bootchooser to lock the boot attempts counter.
@@ -830,19 +831,9 @@ struct bootchooser_target *bootchooser_get_last_chosen(struct bootchooser *bc)
  *
  * Return: 0 for success, negative error code otherwise
  */
-int bootchooser_lock_attempts(struct bootchooser *bc, bool locked)
+void bootchooser_lock_attempts(bool locked)
 {
-	uint32_t not_needed;
-	/* We just need to check here, if the value exists in the device tree
-	 * So if it doesn't exist, inform user about it for easier debugging
-	 */
-	if (getenv_u32(bc->state_prefix, "attempts_locked", &not_needed)) {
-		pr_warn("Missing attempts_locked property in state DT node\n");
-		return -ENOENT;
-	}
-
-	bc->attempts_locked = locked;
-	return 0;
+	attempts_locked = locked;
 }
 
 static int bootchooser_boot_one(struct bootchooser *bc, int *tryagain)
diff --git a/include/bootchooser.h b/include/bootchooser.h
index 69783b0b7494..36cbd0dd0a01 100644
--- a/include/bootchooser.h
+++ b/include/bootchooser.h
@@ -17,7 +17,7 @@ void bootchooser_info(struct bootchooser *bootchooser);
 int bootchooser_boot(struct bootchooser *bc);
 
 struct bootchooser_target *bootchooser_get_last_chosen(struct bootchooser *bootchooser);
-int bootchooser_lock_attempts(struct bootchooser *bc, bool locked);
+void bootchooser_lock_attempts(bool locked);
 const char *bootchooser_target_name(struct bootchooser_target *target);
 struct bootchooser_target *bootchooser_target_by_name(struct bootchooser *bootchooser,
 						      const char *name);
-- 
2.39.5




                 reply	other threads:[~2025-06-23  6:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20250623062253.3528292-1-a.fatoum@barebox.org \
    --to=a.fatoum@barebox.org \
    --cc=barebox@lists.infradead.org \
    --cc=l.schmidt@pengutronix.de \
    /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