Skip to contentSkip to conversation

arch/i386/kernel/io_apic.c: handle a negative return value

PATCH In review Adrian Bunk 3 participants 4 messages Nov 12, 2006 – Nov 14, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arch/i386/kernel/io_apic.c: handle a negative return value

The Coverity checker noted that bad things might happen if find_isa_irq_apic() returned -1.

arch/i386/kernel/io_apic.c renamed from arch/i386/kernel/io_apic.c.old +2 -1
@@ -2160,7 +2160,8 @@ static inline void unlock_ExtINT_logic(v
 
 	pin  = find_isa_irq_pin(8, mp_INT);
 	apic = find_isa_irq_apic(8, mp_INT);
-	if (pin == -1)
+
+	if ((pin == -1) || (apic == -1))
 		return;
 
 	entry0 = ioapic_read_entry(apic, pin);
#1 lore raw
Quoted 4 lines · Adrian Bunk

The Coverity checker noted that bad things might happen if find_isa_irq_apic() returned -1.

hm, it seems the checker did not notice the following:
find_isa_irq_apic() can return -1 /only/ if find_isa_irq_pin() returns -1 too. So this is not a bug - it's rather a bit unclean code (and adding a check for -1 apic does not make the code cleaner).

Ingo

#2 lore raw
In reply to Adrian Bunk
Quoted 8 lines · On Sun, 12 Nov 2006 18:48:26 +0100 Adrian Bunk <[email protected]> wrote:

The Coverity checker noted that bad things might happen if find_isa_irq_apic() returned -1.

arch/i386/kernel/io_apic.c static inline void unlock_ExtINT_logic(v · line 2166

Quoted 8 lines
arch/i386/kernel/io_apic.c renamed from arch/i386/kernel/io_apic.c.old +2 -1
@@ -2160,7 +2160,8 @@ static inline void unlock_ExtINT_logic(v
 
 	pin  = find_isa_irq_pin(8, mp_INT);
 	apic = find_isa_irq_apic(8, mp_INT);
-	if (pin == -1)
+
+	if ((pin == -1) || (apic == -1))
 		return;
 

I dunno about this. For some reason I don't trust the apic code much. At present if find_isa_irq_apic() fails we at least have a chance of blundering into a nnice oops or something. By adding correct error-checking we increase the chance of things just silently not working.

So let's see what this does...

From: Adrian Bunk <[email protected]>

The Coverity checker noted that bad things might happen if find_isa_irq_apic() returned -1.

---

 arch/i386/kernel/io_apic.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletion(-)
arch/i386/kernel/io_apic.c renamed from arch/i386/kernel/io_apic.c~arch-i386-kernel-io_apicc-handle-a-negative-return-value +9 -1
diff -puN arch/i386/kernel/io_apic.c~arch-i386-kernel-io_apicc-handle-a-negative-return-value arch/i386/kernel/io_apic.c
@@ -2166,9 +2166,17 @@ static inline void unlock_ExtINT_logic(v
 	unsigned char save_control, save_freq_select;
 
 	pin  = find_isa_irq_pin(8, mp_INT);
+	if (pin == -1) {
+		printk(KERN_ERR "unlock_ExtINT_logic: find_isa_irq_pin()
+				"failed\n");
+		return;
+	}
 	apic = find_isa_irq_apic(8, mp_INT);
-	if (pin == -1)
+	if (apic == -1) {
+		printk(KERN_ERR "unlock_ExtINT_logic: find_isa_irq_apic()
+				"failed\n");
 		return;
+	}
 
 	entry0 = ioapic_read_entry(apic, pin);
 	clear_IO_APIC_pin(apic, pin);

_

Acked-by
#3 lore raw
Quoted 12 lines · Andrew Morton
        pin  = find_isa_irq_pin(8, mp_INT);
(quoted diff) +2 -0
+       if (pin == -1) {
+               printk(KERN_ERR "unlock_ExtINT_logic:

find_isa_irq_pin()

arch/i386/kernel/io_apic.c renamed from arch/i386/kernel/io_apic.c~arch-i386-kernel-io_apicc-handle-a-negative-return-value +5 -1
+                               "failed\n");
+               return;
+       }
        apic = find_isa_irq_apic(8, mp_INT);
-       if (pin == -1)
+       if (apic == -1) {
+               printk(KERN_ERR "unlock_ExtINT_logic:

find_isa_irq_apic()

arch/i386/kernel/io_apic.c static inline void unlock_ExtINT_logic(v · line 2179

Quoted 3 lines
arch/i386/kernel/io_apic.c renamed from arch/i386/kernel/io_apic.c~arch-i386-kernel-io_apicc-handle-a-negative-return-value +2 -0
+                               "failed\n");
                return;
+       } 

as i mentioned it in my mail yesterday, if find_isa_irq_apic() returns -1 then find_isa_irq_pin() has to return -1 too. But this is obscure and needs to be documented at least - and your patch is good for documentation purposes too :-)

Ingo