diff mbox series

[1/1] log: check argument of 'log level' command

Message ID 20200531134451.23595-1-xypron.glpk@gmx.de
State Accepted
Commit 77007f9543a0fac8c4f60800de6ddccfacd9af5d
Delegated to: Simon Glass
Headers show
Series [1/1] log: check argument of 'log level' command | expand

Commit Message

Heinrich Schuchardt May 31, 2020, 1:44 p.m. UTC
Check that the argument provided to the 'log level' command is in the range
between zero and CONFIG_LOG_MAX_LEVEL.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 cmd/log.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

--
2.20.1

Comments

Simon Glass May 31, 2020, 4:14 p.m. UTC | #1
On Sun, 31 May 2020 at 07:44, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> Check that the argument provided to the 'log level' command is in the range
> between zero and CONFIG_LOG_MAX_LEVEL.
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
>  cmd/log.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

Then we should have a little test for the log command, perhaps
run_command() and then check that the default log level is set (or
not, on error).
Simon Glass June 13, 2020, 3:11 a.m. UTC | #2
On Sun, 31 May 2020 at 07:44, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> Check that the argument provided to the 'log level' command is in the range
> between zero and CONFIG_LOG_MAX_LEVEL.
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
>  cmd/log.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

Then we should have a little test for the log command, perhaps
run_command() and then check that the default log level is set (or
not, on error).

Applied to u-boot-dm, thanks!
diff mbox series

Patch

diff --git a/cmd/log.c b/cmd/log.c
index 664f7bd7ac..78352b2cb9 100644
--- a/cmd/log.c
+++ b/cmd/log.c
@@ -14,10 +14,18 @@  static char log_fmt_chars[LOGF_COUNT] = "clFLfm";
 static int do_log_level(struct cmd_tbl *cmdtp, int flag, int argc,
 			char *const argv[])
 {
-	if (argc > 1)
-		gd->default_log_level = simple_strtol(argv[1], NULL, 10);
-	else
+	if (argc > 1) {
+		long log_level = simple_strtol(argv[1], NULL, 10);
+
+		if (log_level < 0 || log_level > _LOG_MAX_LEVEL) {
+			printf("Only log levels <= %d are supported\n",
+			       _LOG_MAX_LEVEL);
+			return CMD_RET_FAILURE;
+		}
+		gd->default_log_level = log_level;
+	} else {
 		printf("Default log level: %d\n", gd->default_log_level);
+	}

 	return 0;
 }