[PATCH v4 04/14] command: Narrow cmd_tbl.maxargs to a short
Simon Glass
sjg at chromium.org
Wed Jul 1 13:42:24 CEST 2026
maxargs holds the maximum argument count for a command and is currently
an int. The largest value any command actually needs is
CONFIG_SYS_MAXARGS (256 on the boards that raise it), so a short is
ample. Narrowing it frees two bytes in struct cmd_tbl which a later
change uses for a flags byte, with no growth in the per-command entry
size.
Two commands (the sound command and its play sub-command) pass INT_MAX
as maxargs to mean 'accept any number of arguments'. That no longer
fits in a short, so add a CMD_MAXARGS sentinel (SHRT_MAX) and use it in
those two places.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
Changes in v4:
- Add new patch to narrow maxargs to a short, freeing space in
struct cmd_tbl for the flags byte
cmd/sound.c | 4 ++--
include/command.h | 9 ++++++++-
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/cmd/sound.c b/cmd/sound.c
index 7546059022f..68b878641fe 100644
--- a/cmd/sound.c
+++ b/cmd/sound.c
@@ -67,7 +67,7 @@ err:
static struct cmd_tbl cmd_sound_sub[] = {
U_BOOT_CMD_MKENT(init, 0, 1, do_init, "", ""),
- U_BOOT_CMD_MKENT(play, INT_MAX, 1, do_play, "", ""),
+ U_BOOT_CMD_MKENT(play, CMD_MAXARGS, 1, do_play, "", ""),
};
/* process sound command */
@@ -92,7 +92,7 @@ static int do_sound(struct cmd_tbl *cmdtp, int flag, int argc,
}
U_BOOT_CMD(
- sound, INT_MAX, 1, do_sound,
+ sound, CMD_MAXARGS, 1, do_sound,
"sound sub-system",
"init - initialise the sound driver\n"
"sound play [len [freq [len [freq ...]]]] - play sounds\n"
diff --git a/include/command.h b/include/command.h
index 5d225cd197f..2e9646c97fb 100644
--- a/include/command.h
+++ b/include/command.h
@@ -11,6 +11,7 @@
#define __COMMAND_H
#include <linker_lists.h>
+#include <limits.h>
#include <linux/compiler_attributes.h>
@@ -34,7 +35,7 @@
struct cmd_tbl {
char *name; /* Command Name */
- int maxargs; /* maximum number of arguments */
+ short maxargs; /* maximum number of arguments */
/*
* Same as ->cmd() except the command
* tells us if it can be repeated.
@@ -59,6 +60,12 @@ struct cmd_tbl {
#endif
};
+/*
+ * Use this as a command's maxargs when it accepts any number of arguments.
+ * maxargs is a short, so this is the largest value it can hold.
+ */
+#define CMD_MAXARGS SHRT_MAX
+
/**
* cmd_arg_get() - Get a particular argument
*
--
2.43.0
More information about the U-Boot
mailing list