]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
ubifs: Fix uninitialized variable in search_dh_cookie()
authorGeert Uytterhoeven <geert@linux-m68k.org>
Sun, 17 Sep 2017 08:32:20 +0000 (10:32 +0200)
committerRichard Weinberger <richard@nod.at>
Wed, 17 Jan 2018 18:28:53 +0000 (19:28 +0100)
fs/ubifs/tnc.c: In function ‘search_dh_cookie’:
fs/ubifs/tnc.c:1893: warning: ‘err’ is used uninitialized in this function

Indeed, err is always used uninitialized.

According to an original review comment from Hyunchul, acknowledged by
Richard, err should be initialized to -ENOENT to avoid the first call to
tnc_next().  But we can achieve the same by reordering the code.

Fixes: 781f675e2d7e ("ubifs: Fix unlink code wrt. double hash lookups")
Reported-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Richard Weinberger <richard@nod.at>
fs/ubifs/tnc.c

index 0a213dcba2a1f0f5938552d874e2f31888f9d57f..ba3d0e0f86151e533d98fb656910665a0da61e3c 100644 (file)
@@ -1890,35 +1890,28 @@ static int search_dh_cookie(struct ubifs_info *c, const union ubifs_key *key,
        union ubifs_key *dkey;
 
        for (;;) {
-               if (!err) {
-                       err = tnc_next(c, &znode, n);
-                       if (err)
-                               goto out;
-               }
-
                zbr = &znode->zbranch[*n];
                dkey = &zbr->key;
 
                if (key_inum(c, dkey) != key_inum(c, key) ||
                    key_type(c, dkey) != key_type(c, key)) {
-                       err = -ENOENT;
-                       goto out;
+                       return -ENOENT;
                }
 
                err = tnc_read_hashed_node(c, zbr, dent);
                if (err)
-                       goto out;
+                       return err;
 
                if (key_hash(c, key) == key_hash(c, dkey) &&
                    le32_to_cpu(dent->cookie) == cookie) {
                        *zn = znode;
-                       goto out;
+                       return 0;
                }
-       }
-
-out:
 
-       return err;
+               err = tnc_next(c, &znode, n);
+               if (err)
+                       return err;
+       }
 }
 
 static int do_lookup_dh(struct ubifs_info *c, const union ubifs_key *key,