aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>2023-10-03 03:09:01 +0200
committerTom Rini <trini@konsulko.com>2023-10-03 17:44:51 -0400
commitee2dbf0dd9562d015a6c6f30cdf8e8acd29026ef (patch)
tree1d2300178c78b01f1590c457ed50d14374da7b9b
parent65b9b3462bec2966911658836983819ab4e4823e (diff)
downloadu-boot-TEST/input-rework.zip
u-boot-TEST/input-rework.tar.gz
u-boot-TEST/input-rework.tar.bz2
input: avoid NULL dereferenceTEST/input-rework
Before using the result of env_get("stdin") we must check if it is NULL. Avoid #if. This resolves the -Wunused-but-set-variable issue and we don't need a dummy assignment in the else branch. Anyway this warning is disabled in the Makefile. For sake of readability use an early return after the configuration check. Checking CONFIG_SPL_BUILD is incorrect as env_get() is only defined if CONFIG_$(SPL_TPL)ENV_SUPPORT=y. Fixes: 985ca3945fa3 ("spl: input: Allow input in SPL and TPL") Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
-rw-r--r--drivers/input/input.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/drivers/input/input.c b/drivers/input/input.c
index a4341e8..8a6506e 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -669,17 +669,22 @@ int input_stdio_register(struct stdio_dev *dev)
int error;
error = stdio_register(dev);
-#if !defined(CONFIG_SPL_BUILD) || CONFIG_IS_ENABLED(ENV_SUPPORT)
- /* check if this is the standard input device */
- if (!error && strcmp(env_get("stdin"), dev->name) == 0) {
- /* reassign the console */
- if (OVERWRITE_CONSOLE ||
- console_assign(stdin, dev->name))
- return -1;
+
+ if (!CONFIG_IS_ENABLED(ENV_SUPPORT))
+ return 0;
+
+ if (!error) {
+ const char *cstdin;
+
+ /* check if this is the standard input device */
+ cstdin = env_get("stdin");
+ if (cstdin && !strcmp(cstdin, dev->name)) {
+ /* reassign the console */
+ if (OVERWRITE_CONSOLE ||
+ console_assign(stdin, dev->name))
+ return -1;
+ }
}
-#else
- error = error;
-#endif
return 0;
}