Skip to contentSkip to conversation

x86: fix warning of uninitialized variable

PATCH NAK Jianjun Kong 2 participants 3 messages Dec 4, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 x86: fix warning of uninitialized variable

fix warning of uninitialized 'base' in arch/x86/kernel/scx200_32.c

arch/x86/kernel/scx200_32.c: In function ‘scx200_probe’:
arch/x86/kernel/scx200_32.c:82: warning: ‘base’ may be used uninitialized in this function

---
 arch/x86/kernel/scx200_32.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/scx200_32.c +1 -1
index 7e004ac..e9e3a24 100644
@@ -58,7 +58,7 @@ static void __devinit scx200_init_shadow(void)
 
 static int __devinit scx200_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
-	unsigned base;
+	unsigned base = 0;
 
 	if (pdev->device == PCI_DEVICE_ID_NS_SCx200_BRIDGE ||
 	    pdev->device == PCI_DEVICE_ID_NS_SC1100_BRIDGE) {
Signature · 6 lines
1.5.6.3

-- 
Jianjun Kong | Happy Hacking
HOMEPAGE: http://kongove.cn/
GTALK: [email protected]
#1 lore raw
Quoted 10 lines · Jianjun Kong

fix warning of uninitialized 'base' in arch/x86/kernel/scx200_32.c

arch/x86/kernel/scx200_32.c: In function ‘scx200_probe’:
arch/x86/kernel/scx200_32.c:82: warning: ‘base’ may be used uninitialized in this function

---
 arch/x86/kernel/scx200_32.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

this patch is wrong, and your analysis-free commit log is wrong as well!

i fixed this a few weeks ago, and GCC pinpointed a _real_ bug - which you hacked around instead of fixing. See the real fix below.

Ingo

---------------------->

Quoted 1 line

From 6f9fecb3d70400c5f99c1a1d09ffcce84483f611 Mon Sep 17 00:00:00 2001

From: Ingo Molnar <[email protected]>
Date: Sat, 18 Oct 2008 17:37:39 +0200
Subject: [PATCH] fix warning in arch/x86/kernel/scx200_32.c
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

fix this warning:

arch/x86/kernel/scx200_32.c: In function ‘scx200_probe’:
arch/x86/kernel/scx200_32.c:82: warning: ‘base’ may be used uninitialized in this function

gcc is right: pci_read_config_dword() can fail, and this code did not handle it.

Add proper error handling.

---
 arch/x86/kernel/scx200_32.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
arch/x86/kernel/scx200_32.c +4 -2
index 7e004ac..1b6e3d1 100644
@@ -78,8 +78,10 @@ static int __devinit scx200_probe(struct pci_dev *pdev, const struct pci_device_
 		if (scx200_cb_probe(SCx200_CB_BASE_FIXED)) {
 			scx200_cb_base = SCx200_CB_BASE_FIXED;
 		} else {
-			pci_read_config_dword(pdev, SCx200_CBA_SCRATCH, &base);
-			if (scx200_cb_probe(base)) {
+			int err;
+
+			err = pci_read_config_dword(pdev, SCx200_CBA_SCRATCH, &base);
+			if (!err && scx200_cb_probe(base)) {
 				scx200_cb_base = base;
 			} else {
 				printk(KERN_WARNING NAME ": Configuration Block not found\n");
#2 lore raw
Quoted 14 lines · Ingo Molnar
Quoted 10 lines · Jianjun Kong

fix warning of uninitialized 'base' in arch/x86/kernel/scx200_32.c

arch/x86/kernel/scx200_32.c: In function ‘scx200_probe’:
arch/x86/kernel/scx200_32.c:82: warning: ‘base’ may be used uninitialized in this function

---
 arch/x86/kernel/scx200_32.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Quoted 5 lines

this patch is wrong, and your analysis-free commit log is wrong as well!

i fixed this a few weeks ago, and GCC pinpointed a _real_ bug - which you hacked around instead of fixing. See the real fix below.

Also, see an example below of the case where GCC is wrong about a warning, and how it is annotated.

Ingo

------------->

Quoted 1 line

From af4d2994e0e8e6e529b0e87f4e436dad062a9c05 Mon Sep 17 00:00:00 2001

From: Ingo Molnar <[email protected]>
Date: Tue, 25 Nov 2008 13:14:19 +0100
Subject: [PATCH] fix warning in fs/ocfs2/stack_user.c
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

this warning:

fs/ocfs2/stack_user.c: In function ‘user_cluster_connect’:
fs/ocfs2/stack_user.c:807: warning: ‘control’ may be used uninitialized in this function

triggers because GCC does not recognize the (correct) error flow between:

- ocfs2_live_connection_new() and 'control'

Annotate it.

---
 fs/ocfs2/stack_user.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/ocfs2/stack_user.c +1 -1
index faec2d8..55e2cdc 100644
@@ -804,7 +804,7 @@ static int fs_protocol_compare(struct ocfs2_protocol_version *existing,
 static int user_cluster_connect(struct ocfs2_cluster_connection *conn)
 {
 	dlm_lockspace_t *fsdlm;
-	struct ocfs2_live_connection *control;
+	struct ocfs2_live_connection *uninitialized_var(control);
 	int rc = 0;
 
 	BUG_ON(conn == NULL);