NetBSD Problem Report #48757

From kre@munnari.OZ.AU  Sat Apr 19 17:31:36 2014
Return-Path: <kre@munnari.OZ.AU>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	(using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 8944DA580F
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 19 Apr 2014 17:31:36 +0000 (UTC)
Message-Id: <201404191728.s3JHSsYf024368@perseus.noi.kre.to>
Date: Sun, 20 Apr 2014 00:28:54 +0700 (ICT)
From: kre@munnari.OZ.AU
To: gnats-bugs@gnats.NetBSD.org
Subject: sys/arch/i386/pci/pci_intr_fixup.c var set but not used (+FIX?)
X-Send-Pr-Version: 3.95

>Number:         48757
>Category:       kern
>Synopsis:       sys/arch/i386/pci/pci_intr_fixup.c var set but not used (+FIX?)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Apr 19 17:35:00 +0000 2014
>Closed-Date:    Thu Jun 09 15:41:44 +0000 2016
>Last-Modified:  Thu Jun 09 15:41:44 +0000 2016
>Originator:     Robert Elz
>Release:        NetBSD 6.99.40 (ie: -current ; as of 2014-04-18)
>Organization:
	Prince of Songkla University
>Environment:


System: NetBSD perseus.noi.kre.to 6.99.17 NetBSD 6.99.17 (GENERIC) #1: Fri Feb 22 22:09:50 ICT 2013 kre@jade.coe.psu.ac.th:/usr/obj/current/i386/sys/arch/i386/compile/GENERIC i386
Architecture: i386
Machine: i386
>Description:
	When compiled with just the right combination of options, an i386
	kernel compile fails as ...


/usr/obj/current/tools/bin/i486--netbsdelf-gcc -msoft-float -mno-mmx -mno-sse -mno-avx -ffreestanding -fno-zero-initialized-in-bss -O2 -fstack-protector -Wstack-protector --param ssp-buffer-size=1 -fno-strict-aliasing -fno-common -std=gnu99 -Werror -Wall -Wno-main -Wno-format-zero-length -Wpointer-arith -Wmissing-prototypes -Wstrict-prototypes -Wold-style-definition -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -Wno-unreachable-code -Wno-pointer-sign -Wno-attributes -Wextra -Wno-unused-parameter -Wold-style-definition -Wno-sign-compare --sysroot=/release/current/i386 -Di386 -I. -I/release/current/src/sys/../common/include -I/release/current/src/sys/arch -I/release/current/src/sys -nostdinc -DI686_CPU -DMATH_EMULATE -DUCONSOLE -DSYSTRACE -DLKM -DCOMPAT_30_PTHREAD -DSOFTDEP -DIPSEC_ESP -DPFIL_HOOKS -DWSDISPLAY_CHARFUNCS -DMAXUSERS=32 -D_KERNEL -D_KERNEL_OPT -std=gnu99 -I/release/current/src/sys/lib/libkern/../../../common/lib/libc/quad -I/release/current/src/sys/lib/libkern/..!
 /../../common/lib/libc/string -I/release/current/src/sys/lib/libkern/../../../common/lib/libc/arch/i386/string -D_FORTIFY_SOURCE=2 -I/release/current/src/sys/external/bsd/ipf -I/release/current/src/sys/external/bsd/acpica/dist/include -c /release/current/src/sys/arch/i386/pci/pci_intr_fixup.c
/release/current/src/sys/arch/i386/pci/pci_intr_fixup.c: In function 'pciintr_do_header_fixup':
/release/current/src/sys/arch/i386/pci/pci_intr_fixup.c:669:17: error: variable 'id' set but not used [-Werror=unused-but-set-variable]
  pcireg_t intr, id;
                 ^
cc1: all warnings being treated as errors

*** Failed target:  pci_intr_fixup.o

>How-To-Repeat:
	Not sure what option combination gets us to this point (other than
	that clearly PCIBIOSVERBOSE is not set) - in addition to the
	standard set of kernels, I compile about 10 more for various
	current, and past, local systems every time I do a build.   Exactly
	one of them failed this way, all the rest built successfully.
	I guess if it were important, I could work out what the option
	set is that causes this - and I can easily send anyone who asks the
	kernel config file - but as the problem is obvious, and I think,
	easy to fix, I am not sure it matters.

	But with the right kernel config file, just build an i386 kernel..
	(Or, once you are aimed at it [below] just read the source.)

	Also, note that the source file in question has not been touched in
	years, so this "error" has clearly been caused (or made visible) by a
	compiler, or build options, change - and one that happened fairly
	recently - a 6.99.37 build I did about 4 weeks ago (my last
	successful i386 build - for other reasons, now all corrected)
	did not have a problem with the file in question neither the kernel
	config file, nor the src file, have been changed in the interim).

>Fix:
	Appying the patch below allows the kernel to build successfully
	(and doesn't break any of my other 386 kernel builds).  However I can't
	test that this kernel still works - the system it was for has been
	gone for many years now (the kernel is still being built because
	that's just computer time - working out which ones I no longer need
	takes (would take) my time...)

	That caveat is relevant, as the fix deletes a call to pci_conf_read().
	The error comes because the result of that func call is
	(when PCIBIOSVERBOSE is not set) assigned to a variable that is
	never touched again ("id") - but I do not personally have enough
	knowledge of the NetBSD PCI config code to be sure that omiting that
	func call won't cause some other problem (non-obvious side effects
	perhaps - nb: this is not a claim that there is an issue, just ...).

	So, someone who does understand this stuff should give this a
	look over before comitting it.

	Also note, the variable "function" assigned in the call to
	pci_decompose_tag() is also never used again with PCIBIOSDEBUG
	undefined - the (current) compiler isn't picking up on that one
	(it should be able to tell that the var must be output from the
	func, as it is uninitialised before the call, but it is apparently
	not quite that smart yet) - but some later compiler "enhancement"
	might start to object to that one being set, but never used, as
	well, so figuring out how to fix that one - as long as we are going
	to keep using compilers, and compile options, that are this pedantic,
	mght be a good idea.

Index: pci_intr_fixup.c
===================================================================
RCS file: /cvsroot/NetBSD/src/sys/arch/i386/pci/pci_intr_fixup.c,v
retrieving revision 1.49
diff -u -r1.49 pci_intr_fixup.c
--- pci_intr_fixup.c	1 Jul 2011 17:37:26 -0000	1.49
+++ pci_intr_fixup.c	19 Apr 2014 16:37:10 -0000
@@ -666,10 +666,15 @@
 	struct pciintr_link_map *l;
 	int pin, irq, link;
 	int bus, device, function;
-	pcireg_t intr, id;
+	pcireg_t intr;
+#ifdef PCIBIOSVERBOSE
+	pcireg_t id;
+#endif

 	pci_decompose_tag(pc, tag, &bus, &device, &function);
+#ifdef PCIBIOSVERBOSE
 	id = pci_conf_read(pc, tag, PCI_ID_REG);
+#endif

 	intr = pci_conf_read(pc, tag, PCI_INTERRUPT_REG);
 	pin = PCI_INTERRUPT_PIN(intr);

>Release-Note:

>Audit-Trail:

State-Changed-From-To: open->closed
State-Changed-By: kre@NetBSD.org
State-Changed-When: Thu, 09 Jun 2016 15:41:44 +0000
State-Changed-Why:
I forgot this PR existed, and reported the same issue again as kern/49181
5 months later (Sep 2014).   It got fixed then within days.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.