mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: unlisted-recipients:; (no To-header on input)
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Arnd Bergmann <arnd@arndb.de>,
	reiserfs-devel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] reiserfs: avoid uninitialized variable use
Date: Fri, 27 May 2016 22:22:36 +0200	[thread overview]
Message-ID: <1464380569-3493380-1-git-send-email-arnd@arndb.de> (raw)

I got this warning on an ARM64 allmodconfig build with gcc-5.3:

fs/reiserfs/ibalance.c: In function 'balance_internal':
fs/reiserfs/ibalance.c:1158:3: error: 'new_insert_key' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   memcpy(new_insert_key_addr, &new_insert_key, KEY_SIZE);

The warning is correct, in fact both new_insert_key and new_insert_ptr
are only updated inside of an if() block, but used at the end of
the function.

Looking at how the balance_internal() function gets called, it
is clear that this is harmless because the caller never uses the
updated arrays, they are initialized from balance_leaf_new_nodes()
and then passed into balance_internal().

This has not changed at all since the start of the git history,
but apparently the warning has only recently appeared.

This modifies the function to only update the two argument variables
when the new_insert_key and new_insert_ptr have been updated, to
get rid of the warning.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
I thought I had send this on May 12 when I first became aware of
the warning, but I can't find a reference to that now on any
mailing list archives, and I'm not sure who is picking up
reiserfs patches these days.

The warning is now one of the few 'allmodconfig' warnings for
arm64 and possibly some other architectures.

 fs/reiserfs/ibalance.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/reiserfs/ibalance.c b/fs/reiserfs/ibalance.c
index b751eea32e20..6dcc38f132f5 100644
--- a/fs/reiserfs/ibalance.c
+++ b/fs/reiserfs/ibalance.c
@@ -1138,6 +1138,9 @@ int balance_internal(struct tree_balance *tb,
 		       S_new);
 
 		/* S_new is released in unfix_nodes */
+
+		memcpy(new_insert_key_addr, &new_insert_key, KEY_SIZE);
+		insert_ptr[0] = new_insert_ptr;
 	}
 
 	n = B_NR_ITEMS(tbSh);	/*number of items in S[h] */
@@ -1153,8 +1156,5 @@ int balance_internal(struct tree_balance *tb,
 				       insert_ptr);
 	}
 
-	memcpy(new_insert_key_addr, &new_insert_key, KEY_SIZE);
-	insert_ptr[0] = new_insert_ptr;
-
 	return order;
 }
-- 
2.7.0

             reply	other threads:[~2016-05-27 20:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-27 20:22 Arnd Bergmann [this message]
2016-06-15  9:06 ` Paul Bolle
2016-06-15 12:15   ` Arnd Bergmann
2016-06-15 16:39     ` Paul Bolle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1464380569-3493380-1-git-send-email-arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=reiserfs-devel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®