[PATCH 1/1] ubifs: do not decide upon uninitialized variable
Chris Packham
judge.packham at gmail.com
Sat Dec 26 08:08:52 CET 2020
(note replying on mobile device only code access is via git.denx.de)
On Sat, 26 Dec 2020, 3:19 AM Heinrich Schuchardt, <xypron.glpk at gmx.de>
wrote:
> Before 'if (err)' we have to initialize the variable otherwise we use a
> random value from the stack.
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
> ---
>
In all the cases below err might be uninitialised because the code that
would otherwise initialise it has been conditionally excluded with #ifndef
__UBOOT__. I wonder if we could do something cleaner by making
dbg_leb_change() etc do something suitable (return 0 or -Esomething).
fs/ubifs/io.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
> index eb14b89544..9962cbe7eb 100644
> --- a/fs/ubifs/io.c
> +++ b/fs/ubifs/io.c
> @@ -114,7 +114,7 @@ int ubifs_leb_read(const struct ubifs_info *c, int
> lnum, void *buf, int offs,
> int ubifs_leb_write(struct ubifs_info *c, int lnum, const void *buf, int
> offs,
> int len)
> {
> - int err;
> + int err = 0;
>
> ubifs_assert(!c->ro_media && !c->ro_mount);
> if (c->ro_error)
> @@ -136,7 +136,7 @@ int ubifs_leb_write(struct ubifs_info *c, int lnum,
> const void *buf, int offs,
>
> int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int
> len)
> {
> - int err;
> + int err = 0;
>
> ubifs_assert(!c->ro_media && !c->ro_mount);
> if (c->ro_error)
> @@ -158,7 +158,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum,
> const void *buf, int len)
>
> int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
> {
> - int err;
> + int err = 0;
>
> ubifs_assert(!c->ro_media && !c->ro_mount);
> if (c->ro_error)
> @@ -179,7 +179,7 @@ int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
>
> int ubifs_leb_map(struct ubifs_info *c, int lnum)
> {
> - int err;
> + int err = 0;
>
> ubifs_assert(!c->ro_media && !c->ro_mount);
> if (c->ro_error)
> --
> 2.29.2
>
>
More information about the U-Boot
mailing list