Skip to contentSkip to conversation

bogus semicolon behind if()

2.6.4-rc2 Thomas Schlichter 7 participants 21 messages Mar 8, 2004 – Mar 21, 2004

lore
Share & tools
lore
#0 lore raw

Hi,

recently I found a bogus semicolon an if statement. So I was searching for other possible problems with following command:

find linux-2.6.4-rc2 -name "*.c" -exec grep -Hn "\<if[[:space:]]*(\([^()]\| ([^()]*)\)*)[[:space:]]*;" {} \;

That found following possible problems:

linux-2.6.4-rc2/arch/um/kernel/tt/tracer.c:257: if(WIFEXITED(status)) ;
linux-2.6.4-rc2/arch/i386/kernel/io_apic.c:2200: if (check_nmi_watchdog() <
0);
linux-2.6.4-rc2/arch/i386/kernel/io_apic.c:2224: if (check_nmi_watchdog() <
0);
linux-2.6.4-rc2/drivers/atm/iphase.c:155: if (!desc1) ;
linux-2.6.4-rc2/drivers/net/wan/pc300_drv.c:3664: if (card->chan[i].d.dev);
linux-2.6.4-rc2/drivers/net/tokenring/ibmtr.c:613: else if
(ti->shared_ram_paging == 0xf); /* No paging in adapter */
linux-2.6.4-rc2/drivers/usb/misc/speedtch.c:92:#define DEBUG_ON(x) do { if
(x); } while (0)
linux-2.6.4-rc2/drivers/usb/media/w9968cf.c:3374: if (tuner.tuner != 0);
linux-2.6.4-rc2/drivers/isdn/capi/capiutil.c:438: else if (c <= 0x0f);
linux-2.6.4-rc2/drivers/isdn/hisax/hfc_sx.c:385: if (Read_hfc(cs,
HFCSX_INT_S1));
linux-2.6.4-rc2/drivers/isdn/hisax/hfc_sx.c:415: if (Read_hfc(cs,
HFCSX_INT_S2));
linux-2.6.4-rc2/drivers/isdn/hisax/hfc_sx.c:1290: if (Read_hfc(cs,
HFCSX_INT_S1));
linux-2.6.4-rc2/drivers/isdn/hisax/hfc_pci.c:131: if (Read_hfc(cs,
HFCPCI_INT_S1));
linux-2.6.4-rc2/drivers/isdn/hisax/hfc_pci.c:161: if (Read_hfc(cs,
HFCPCI_INT_S1));
linux-2.6.4-rc2/drivers/isdn/hisax/hfc_pci.c:1543: if (Read_hfc(cs,
HFCPCI_INT_S1));
linux-2.6.4-rc2/drivers/s390/scsi/zfcp_erp.c:2057: if (status ==
ZFCP_ERP_SUCCEEDED) ; /* no further action */
linux-2.6.4-rc2/drivers/scsi/sg.c:356: if (ppos != &filp->f_pos) ; /* FIXME:
Hmm. Seek to the right place, or fail? */
linux-2.6.4-rc2/drivers/scsi/sg.c:514: if (ppos != &filp->f_pos) ; /* FIXME:
Hmm. Seek to the right place, or fail? */

Best regards
Thomas Schlichter

P.S.: Wouldn't it be nice if gcc complained about these mistakes?

#1 lore raw
Quoted 1 line · Thomas Schlichter

P.S.: Wouldn't it be nice if gcc complained about these mistakes?

Among these 18 cases are 13 false positives. :-)

Andreas.

Signature · 4 lines
Andreas Schwab, SuSE Labs, [email protected]
SuSE Linux AG, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
#2 lore raw

Am Dienstag, 9. März 2004 00:43 schrieb Andreas Schwab:

Quoted 4 lines
Quoted 1 line · Thomas Schlichter

P.S.: Wouldn't it be nice if gcc complained about these mistakes?

Among these 18 cases are 13 false positives. :-)

Yes, but at least it's a very bad coding style, and a warning may be useful to find the _real_ bugs...

Thomas

#3 lore raw
In reply to Andreas Schwab
Quoted 6 lines · Andreas Schwab
Quoted 1 line · Thomas Schlichter

P.S.: Wouldn't it be nice if gcc complained about these mistakes?

Among these 18 cases are 13 false positives. :-)

Rename Thomas's script to crappy-code-detector.sh and its hit rate goes to 100% ;)

#4 lore raw
Quoted 11 lines · Andrew Morton
Quoted 6 lines · Andreas Schwab
Quoted 1 line · Thomas Schlichter

P.S.: Wouldn't it be nice if gcc complained about these mistakes?

Among these 18 cases are 13 false positives. :-)

Rename Thomas's script to crappy-code-detector.sh and its hit rate goes to 100% ;)

Was this patch so crappy ? http://tinyurl.com/2jbe4 ,

- check_nmi_watchdog();
+ if (check_nmi_watchdog() < 0);
+ timer_ack = !cpu_has_tsc

regards,
Phil

#5 lore raw

Am Dienstag, 9. März 2004 08:01 schrieb Philippe Elie:

Quoted 1 line · Andrew Morton

~~ snip ~~

Review

Quoted 8 lines
Quoted 2 lines

Rename Thomas's script to crappy-code-detector.sh and its hit rate goes to 100% ;)

Was this patch so crappy ? http://tinyurl.com/2jbe4 ,

(quoted diff) +2 -1
-				check_nmi_watchdog();
+				if (check_nmi_watchdog() < 0);
+					timer_ack = !cpu_has_tsc

Well, exactly this code made me look for other possible problems... ;-) As I wrote a few days ago I have problems with that ChangeSet,
(http://marc.theaimsgroup.com/?l=linux-kernel&m=107840458123059&w=2)
so I did examine it closer.

My results are:
1. The semicolons behind the if()'s cannot be there intentionally.
2. To fix my problem, timer_ack must be set to 1 for my (integrated) APIC, and as my CPU has a TSC, this cannot be correct for me:
- timer_ack = 1;
+ if (nmi_watchdog == NMI_IO_APIC && !APIC_INTEGRATED(ver))
+ timer_ack = 1;
+ else
+ timer_ack = !cpu_has_tsc;

I changed that if(...) to

	if (nmi_watchdog == NMI_IO_APIC || APIC_INTEGRATED(ver))

which works fine for me here, but I am not 100% sure if this is what the author of the original patch ment and if it still fixes the original problem...

The patch which makes these changes is attached. Perhaps someone else wants to test it, too...

Thomas Schlichter

P.S.: I tested it with an AMD Athlon 3000+ on a board with a VIA KT400 chipset and enabled ACPI and IO-APIC.

arch/i386/kernel/io_apic.c renamed from arch/i386/kernel/io_apic.c.orig +3 -3
@@ -2181,7 +2181,7 @@ static inline void check_timer(void)
 	 */
 	apic_write_around(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT);
 	init_8259A(1);
-	if (nmi_watchdog == NMI_IO_APIC && !APIC_INTEGRATED(ver))
+	if (nmi_watchdog == NMI_IO_APIC || APIC_INTEGRATED(ver))
 		timer_ack = 1;
 	else
 		timer_ack = !cpu_has_tsc;
@@ -2202,7 +2202,7 @@ static inline void check_timer(void)
 				disable_8259A_irq(0);
 				setup_nmi();
 				enable_8259A_irq(0);
-				if (check_nmi_watchdog() < 0);
+				if (check_nmi_watchdog() < 0)
 					timer_ack = !cpu_has_tsc;
 			}
 			return;
@@ -2226,7 +2226,7 @@ static inline void check_timer(void)
 				add_pin_to_irq(0, 0, pin2);
 			if (nmi_watchdog == NMI_IO_APIC) {
 				setup_nmi();
-				if (check_nmi_watchdog() < 0);
+				if (check_nmi_watchdog() < 0)
 					timer_ack = !cpu_has_tsc;
 			}
 			return;
#6 lore raw
Quoted 3 lines · Thomas Schlichter

As I wrote a few days ago I have problems with that ChangeSet,
(http://marc.theaimsgroup.com/?l=linux-kernel&m=107840458123059&w=2)
so I did examine it closer.

errmm, http://tinyurl.com/2jbe4

Maciej, you wrote this patch, any comment ?

Review

Quoted 11 lines

so I did examine it closer.

My results are:
1. The semicolons behind the if()'s cannot be there intentionally.
2. To fix my problem, timer_ack must be set to 1 for my (integrated) APIC, and as my CPU has a TSC, this cannot be correct for me:

(quoted diff) +4 -1
-	timer_ack = 1;
+	if (nmi_watchdog == NMI_IO_APIC && !APIC_INTEGRATED(ver))
+		timer_ack = 1;
+	else
+		timer_ack = !cpu_has_tsc;

I don't get the figure, this code in check_timer() is called by setup_IO_APIC so APIC_INTEGRATED(ver) is always 0 ?

Quoted 5 lines

I changed that if(...) to

	if (nmi_watchdog == NMI_IO_APIC || APIC_INTEGRATED(ver))

which works fine for me here, but I am not 100% sure if this is what the author of the original patch ment and if it still fixes the original problem...

regards,
Phil

#7 lore raw
Quoted 11 lines · Philippe Elie

Review

Quoted 8 lines

1. The semicolons behind the if()'s cannot be there intentionally.
2. To fix my problem, timer_ack must be set to 1 for my (integrated) APIC, and as my CPU has a TSC, this cannot be correct for me:

(quoted diff) +4 -1
-	timer_ack = 1;
+	if (nmi_watchdog == NMI_IO_APIC && !APIC_INTEGRATED(ver))
+		timer_ack = 1;
+	else
+		timer_ack = !cpu_has_tsc;

I don't get the figure, this code in check_timer() is called by setup_IO_APIC so APIC_INTEGRATED(ver) is always 0 ?

Nope, that will catch the older external "local" APICs like the 82489s (P5 etc), most IOAPICs will return 0x11 or higher for version#

#8 lore raw
In reply to Philippe Elie
Quoted 7 lines · Philippe Elie
Quoted 3 lines

As I wrote a few days ago I have problems with that ChangeSet,
(http://marc.theaimsgroup.com/?l=linux-kernel&m=107840458123059&w=2)
so I did examine it closer.

errmm, http://tinyurl.com/2jbe4

Maciej, you wrote this patch, any comment ?

Yep, that's a stupid typo, but the bug would only trigger for a system
that would have:

1. a discrete 82489DX APIC,

2. a functional TSC,

3. a timer interrupt working through the I/O APIC,

4. a working I/O APIC NMI watchdog.

Such systems used to actually exist, but you'd have a hard time trying to find one.

Here's an obvious update. Thomas, thanks for spotting it.

Maciej

Signature · 26 lines
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: [email protected], PGP key available        +

patch-2.6.4-timer_ack-fix-0
diff -up --recursive --new-file linux-2.6.4.macro/arch/i386/kernel/io_apic.c linux-2.6.4/arch/i386/kernel/io_apic.c
--- linux-2.6.4.macro/arch/i386/kernel/io_apic.c	2004-03-17 17:09:29.000000000 +0000
+++ linux-2.6.4/arch/i386/kernel/io_apic.c	2004-03-17 17:11:07.000000000 +0000
@@ -2195,7 +2195,7 @@ static inline void check_timer(void)
 				disable_8259A_irq(0);
 				setup_nmi();
 				enable_8259A_irq(0);
-				if (check_nmi_watchdog() < 0);
+				if (check_nmi_watchdog() < 0)
 					timer_ack = !cpu_has_tsc;
 			}
 			return;
@@ -2219,7 +2219,7 @@ static inline void check_timer(void)
 				add_pin_to_irq(0, 0, pin2);
 			if (nmi_watchdog == NMI_IO_APIC) {
 				setup_nmi();
-				if (check_nmi_watchdog() < 0);
+				if (check_nmi_watchdog() < 0)
 					timer_ack = !cpu_has_tsc;
 			}
 			return;
#9 lore raw
In reply to Thomas Schlichter
Quoted 8 lines · Thomas Schlichter

2. To fix my problem, timer_ack must be set to 1 for my (integrated) APIC, and as my CPU has a TSC, this cannot be correct for me:

(quoted diff) +4 -1
-	timer_ack = 1;
+	if (nmi_watchdog == NMI_IO_APIC && !APIC_INTEGRATED(ver))
+		timer_ack = 1;
+	else
+		timer_ack = !cpu_has_tsc;
Quoted 5 lines

I changed that if(...) to

	if (nmi_watchdog == NMI_IO_APIC || APIC_INTEGRATED(ver))

which works fine for me here, but I am not 100% sure if this is what the author of the original patch ment and if it still fixes the original problem...

You need timer_ack set to one when either:

1. you use the I/O APIC NMI watchdog and you have a discrete APIC chip (i.e. the 82489DX),

or:

2. the timer interrupt (IRQ 0) goes through one of the APICs (whatever way; we check three variations) and the TSC is non-functional (absent or disabled).

Since you have an integrated APIC and you use the TSC, you may have timer_ack set to zero. That saves a few (possibly slow) I/O accesses and works around problems that may arise due 8259A clone (in)compatibility or bugs in SMM firmware.

Maciej

Signature · 3 lines
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: [email protected], PGP key available        +
#10 lore raw
Quoted 12 lines · Maciej W. Rozycki

You need timer_ack set to one when either:

1. you use the I/O APIC NMI watchdog and you have a discrete APIC chip (i.e. the 82489DX),

or:

2. the timer interrupt (IRQ 0) goes through one of the APICs (whatever way; we check three variations) and the TSC is non-functional (absent or disabled).

I still have a couple of NMI patches in -mm:

ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.5-rc1/2.6.5-rc1-mm1/broken-out/nmi_watchdog-local-apic-fix.patch ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.5-rc1/2.6.5-rc1-mm1/broken-out/nmi-1-hz.patch

What should we do with these?

#11 lore raw
Quoted 6 lines · Andrew Morton

I still have a couple of NMI patches in -mm:

ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.5-rc1/2.6.5-rc1-mm1/broken-out/nmi_watchdog-local-apic-fix.patch ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.5-rc1/2.6.5-rc1-mm1/broken-out/nmi-1-hz.patch

What should we do with these?

I think we should ask Mikael Pettersson as he is the local APIC watchdog
expert. Mikael?

Signature · 3 lines
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: [email protected], PGP key available        +
#12 lore raw
Quoted 11 lines · Maciej W. Rozycki
Quoted 6 lines · Andrew Morton

I still have a couple of NMI patches in -mm:

ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.5-rc1/2.6.5-rc1-mm1/broken-out/nmi_watchdog-local-apic-fix.patch ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.5-rc1/2.6.5-rc1-mm1/broken-out/nmi-1-hz.patch

What should we do with these?

I think we should ask Mikael Pettersson as he is the local APIC watchdog
expert. Mikael?

Will do. Is there a problem with them, or do you just want them reviewed for merging into 2.6.5-rc?

/Mikael

#13 lore raw
Quoted 9 lines · Mikael Pettersson
Quoted 7 lines · Maciej W. Rozycki
Quoted 5 lines · Andrew Morton

I still have a couple of NMI patches in -mm:

ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.5-rc1/2.6.5-rc1-mm1/broken-out/nmi_watchdog-local-apic-fix.patch ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.5-rc1/2.6.5-rc1-mm1/broken-out/nmi-1-hz.patch

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

What should we do with these?

I think we should ask Mikael Pettersson as he is the local APIC watchdog
expert. Mikael?

Will do. Is there a problem with them, or do you just want them reviewed for merging into 2.6.5-rc?

They seem to work OK - I did a batch of testing with various setups. But a retest wouldn't hurt.

We mainly need a review and general finish-it-off-and-bless-it please.

#14 lore raw
In reply to Andrew Morton
Quoted 3 lines · Andrew Morton

I still have a couple of NMI patches in -mm:

ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.5-rc1/2.6.5-rc1-mm1/broken-out/nmi_watchdog-local-apic-fix.patch

That looks like a decent bug fix.

Quoted 1 line

ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.5-rc1/2.6.5-rc1-mm1/broken-out/nmi-1-hz.patch

Didn't _you_ want that one? ;)

#15 lore raw
Quoted 11 lines · Zwane Mwaikambo
Quoted 3 lines · Andrew Morton

I still have a couple of NMI patches in -mm:

ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.5-rc1/2.6.5-rc1-mm1/broken-out/nmi_watchdog-local-apic-fix.patch

That looks like a decent bug fix.

Quoted 1 line

ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.5-rc1/2.6.5-rc1-mm1/broken-out/nmi-1-hz.patch

Didn't _you_ want that one? ;)

Excuse this little outburt, i seem to be reading an old mbox.

#16 lore raw
In reply to Maciej W. Rozycki

Am Mittwoch, 17. März 2004 17:51 schrieb Maciej W. Rozycki:

~~ snip ~~

Quoted 11 lines

You need timer_ack set to one when either:

1. you use the I/O APIC NMI watchdog and you have a discrete APIC chip (i.e. the 82489DX),

or:

2. the timer interrupt (IRQ 0) goes through one of the APICs (whatever way; we check three variations) and the TSC is non-functional (absent or disabled).

Quoted 6 lines

Since you have an integrated APIC and you use the TSC, you may have timer_ack set to zero. That saves a few (possibly slow) I/O accesses and works around problems that may arise due 8259A clone (in)compatibility or bugs in SMM firmware.

Maciej

Well, my timer interrupt goes through the IO-APIC but I do have a functional TSC. Nevertheless my system requires timer_ack to be set... If it isn't, my CPU does not utilize its C2 state...

Thomas

#17 lore raw
Quoted 3 lines · Thomas Schlichter

Well, my timer interrupt goes through the IO-APIC but I do have a functional TSC. Nevertheless my system requires timer_ack to be set... If it isn't, my CPU does not utilize its C2 state...

Hmm, I wonder if there's any relationship between the state of the local
APIC and your observation. Can you please see if the following hack changes anything (this assumes you have your timer IRQ directly connected to an I/O APIC input)?

Signature · 15 lines
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: [email protected], PGP key available        +

--- io_apic.c.macro	2004-03-19 20:13:44.000000000 +0000
+++ io_apic.c	2004-03-19 20:15:23.000000000 +0000
@@ -1613,7 +1613,7 @@ static inline void check_timer(void)
 		timer_ack = 1;
 	else
 		timer_ack = !cpu_has_tsc;
-	enable_8259A_irq(0);
+	disable_8259A_irq(0);
 
 	pin1 = find_isa_irq_pin(0, mp_INT);
 	pin2 = find_isa_irq_pin(0, mp_ExtINT);
#18 lore raw

Am Freitag, 19. März 2004 21:30 schrieb Maciej W. Rozycki:

Quoted 9 lines · Thomas Schlichter
Quoted 3 lines

Well, my timer interrupt goes through the IO-APIC but I do have a functional TSC. Nevertheless my system requires timer_ack to be set... If it isn't, my CPU does not utilize its C2 state...

Hmm, I wonder if there's any relationship between the state of the local
APIC and your observation. Can you please see if the following hack changes anything (this assumes you have your timer IRQ directly connected to an I/O APIC input)?

I had to apply this hack by hand as your line numbers don't match mine (I use 2.6.4-mm2) but I' sorry, this hack doesn't change anything for me... ;-(

Thomas

#20 lore raw

Am Dienstag, 9. März 2004 01:33 schrieb Andrew Morton:

Quoted 4 lines
Quoted 1 line · Thomas Schlichter

P.S.: Wouldn't it be nice if gcc complained about these mistakes?

It does, with -W. But -W creates vast amounts of less useful warnings.

Ah, OK... Thanks!