mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-30 08:07:59 +00:00
input: avoid NULL dereference
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: 985ca3945f
("spl: input: Allow input in SPL and TPL")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
This commit is contained in:
parent
4860ee9b09
commit
2d307fb9ed
1 changed files with 15 additions and 10 deletions
|
@ -669,17 +669,22 @@ int input_stdio_register(struct stdio_dev *dev)
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
error = stdio_register(dev);
|
error = stdio_register(dev);
|
||||||
#if !defined(CONFIG_SPL_BUILD) || CONFIG_IS_ENABLED(ENV_SUPPORT)
|
|
||||||
/* check if this is the standard input device */
|
if (!CONFIG_IS_ENABLED(ENV_SUPPORT))
|
||||||
if (!error && strcmp(env_get("stdin"), dev->name) == 0) {
|
return 0;
|
||||||
/* reassign the console */
|
|
||||||
if (OVERWRITE_CONSOLE ||
|
if (!error) {
|
||||||
console_assign(stdin, dev->name))
|
const char *cstdin;
|
||||||
return -1;
|
|
||||||
|
/* 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue