[Concept,v2,13/16] console: Refactor handling of the result in on_console()

Message ID 20250825162727.3185381-14-sjg@u-boot.org
State New
Headers
Series console: Refactor in preparation for the pager |

Commit Message

Simon Glass Aug. 25, 2025, 4:27 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

This function has lots of return statements in a switch statement. Move
them out so we can (later) do something else in this function.

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

Changes in v2:
- Add new patch to refactor handling of the result in on_console()

 common/console.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
  

Patch

diff --git a/common/console.c b/common/console.c
index 51f646d9fd4..e986fa0f3e5 100644
--- a/common/console.c
+++ b/common/console.c
@@ -1040,6 +1040,7 @@  static int on_console(const char *name, const char *value, enum env_op op,
 		      int flags)
 {
 	int console = -1;
+	int result = 0;
 
 	/* Check for console redirection */
 	if (strcmp(name, "stdin") == 0)
@@ -1056,26 +1057,25 @@  static int on_console(const char *name, const char *value, enum env_op op,
 	switch (op) {
 	case env_op_create:
 	case env_op_overwrite:
-
 		if (CONFIG_IS_ENABLED(CONSOLE_MUX)) {
 			if (iomux_doenv(console, value))
-				return 1;
+				result = 1;
 		} else {
 			/* Try assigning specified device */
 			if (console_assign(console, value) < 0)
-				return 1;
+				result = 1;
 		}
-
-		return 0;
-
+		break;
 	case env_op_delete:
 		if ((flags & H_FORCE) == 0)
 			printf("Can't delete \"%s\"\n", name);
-		return 1;
-
+		result = 1;
+		break;
 	default:
-		return 0;
+		break;
 	}
+
+	return result;
 }
 U_BOOT_ENV_CALLBACK(console, on_console);