lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Sun, 22 Jan 2017 14:51:15 +0100
From:   Nicolas Iooss <nicolas.iooss_linux@....org>
To:     Mauro Carvalho Chehab <mchehab@...nel.org>,
        Borislav Petkov <bp@...en8.de>, linux-edac@...r.kernel.org
Cc:     linux-kernel@...r.kernel.org,
        Nicolas Iooss <nicolas.iooss_linux@....org>
Subject: [PATCH 1/1] EDAC: always return an initialized value in knl_show_interleave_mode

When building drivers/edac/sb_edac.c with compiler warning flags which
aim to detect the use of uninitialized values at compile time, the
compiler reports that knl_show_interleave_mode() may return an
uninitialized value. This function indeed uses a switch statement to set
a local variable ("s"), which is not set to anything in the default
statement. Anyway this would be never reached as
knl_interleave_mode(reg) always returns a value between 0 and 3, but the
compiler has no way of knowing this.

Silent the compiler warning by initializing variable "s" too in the
default case. While at it, make knl_show_interleave_mode() and
show_interleave_mode() return const char* values as the returned
pointers refer to read-only memory.

Signed-off-by: Nicolas Iooss <nicolas.iooss_linux@....org>
---
 drivers/edac/sb_edac.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
index 54ae6dc45ab2..15a068744c25 100644
--- a/drivers/edac/sb_edac.c
+++ b/drivers/edac/sb_edac.c
@@ -304,7 +304,7 @@ struct sbridge_info {
 	u64		(*rir_limit)(u32 reg);
 	u64		(*sad_limit)(u32 reg);
 	u32		(*interleave_mode)(u32 reg);
-	char*		(*show_interleave_mode)(u32 reg);
+	const char*	(*show_interleave_mode)(u32 reg);
 	u32		(*dram_attr)(u32 reg);
 	const u32	*dram_rule;
 	const u32	*interleave_list;
@@ -811,7 +811,7 @@ static u32 interleave_mode(u32 reg)
 	return GET_BITFIELD(reg, 1, 1);
 }
 
-char *show_interleave_mode(u32 reg)
+static const char *show_interleave_mode(u32 reg)
 {
 	return interleave_mode(reg) ? "8:6" : "[8:6]XOR[18:16]";
 }
@@ -831,9 +831,9 @@ static u32 knl_interleave_mode(u32 reg)
 	return GET_BITFIELD(reg, 1, 2);
 }
 
-static char *knl_show_interleave_mode(u32 reg)
+static const char *knl_show_interleave_mode(u32 reg)
 {
-	char *s;
+	const char *s;
 
 	switch (knl_interleave_mode(reg)) {
 	case 0:
@@ -850,6 +850,7 @@ static char *knl_show_interleave_mode(u32 reg)
 		break;
 	default:
 		WARN_ON(1);
+		s = "";
 		break;
 	}
 
-- 
2.11.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ