From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 3/5] parameter: allow enum params to be set by numeric index
Date: Mon, 13 Apr 2026 12:06:58 +0200 [thread overview]
Message-ID: <20260413100710.1459468-3-a.fatoum@barebox.org> (raw)
In-Reply-To: <20260413100710.1459468-1-a.fatoum@barebox.org>
When no name matches the input string, fall back to parsing it as a
decimal index into the names array for backwards compatibility.
This lets scripts and users write e.g. "0" or "1" in addition to the
symbolic name, which can be useful if a boolean is turned into an enum
to allow for more options.
As the index isn't stable, we emit a warning to point out that this is
just to simplify migration.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
lib/parameter.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/lib/parameter.c b/lib/parameter.c
index 5c8b86d0dff3..f4e62cc1ae87 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -589,8 +589,17 @@ static int param_enum_set(struct bobject *bobj, struct param_d *p,
if (pe->names[i] && !strcmp(val, pe->names[i]))
break;
- if (i == pe->num_names)
- return -EINVAL;
+ if (i == pe->num_names) {
+ char *endp;
+ unsigned long idx = simple_strtoul(val, &endp, 0);
+
+ if (*endp || idx >= pe->num_names || !pe->names[idx])
+ return -EINVAL;
+
+ pr_warn("setting %s.%s by index is not stable, use \"%s\" instead\n",
+ bobj->name, p->name, pe->names[idx]);
+ i = idx;
+ }
*pe->value = i;
--
2.47.3
next prev parent reply other threads:[~2026-04-13 10:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-13 10:06 [PATCH 1/5] video: simplefb: add r5g5b5a1 and x8b8g8r8 formats to SIMPLEFB_FORMATS Ahmad Fatoum
2026-04-13 10:06 ` [PATCH 2/5] video: simplefb-fixup: use shared SIMPLEFB_FORMATS table Ahmad Fatoum
2026-04-13 10:06 ` Ahmad Fatoum [this message]
2026-04-13 10:06 ` [PATCH 4/5] video: simplefb-fixup: add stdout-path mode to register_simplefb param Ahmad Fatoum
2026-04-13 10:07 ` [PATCH 5/5] Documentation: add OpenBSD booting guide Ahmad Fatoum
2026-04-13 12:48 ` [PATCH 1/5] video: simplefb: add r5g5b5a1 and x8b8g8r8 formats to SIMPLEFB_FORMATS Sascha Hauer
2026-04-13 14:56 ` 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=20260413100710.1459468-3-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--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