Skip to contentSkip to conversation

x86: fix off-by-one in nr_irqs_gsi calculation

PATCH Superseded Jan Beulich 3 participants 4 messages Jul 26, 2012

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: fix off-by-one in nr_irqs_gsi calculation

highest_gsi() returns the last valid GSI, not a count.

xen/arch/x86/io_apic.c +3 -1
@@ -2531,7 +2531,9 @@ void __init init_ioapic_mappings(void)
         }
     }
 
-    nr_irqs_gsi = max(nr_irqs_gsi, highest_gsi());
+    i = highest_gsi();
+    if ( i >= nr_irqs_gsi )
+        nr_irqs_gsi = i + 1;
 
     if ( max_gsi_irqs == 0 )
         max_gsi_irqs = nr_irqs ? nr_irqs / 8 : PAGE_SIZE;

x86: fix off-by-one in nr_irqs_gsi calculation

highest_gsi() returns the last valid GSI, not a count.

xen/arch/x86/io_apic.c +3 -1
@@ -2531,7 +2531,9 @@ void __init init_ioapic_mappings(void)
         }
     }
 
-    nr_irqs_gsi = max(nr_irqs_gsi, highest_gsi());
+    i = highest_gsi();
+    if ( i >= nr_irqs_gsi )
+        nr_irqs_gsi = i + 1;
 
     if ( max_gsi_irqs == 0 )
         max_gsi_irqs = nr_irqs ? nr_irqs / 8 : PAGE_SIZE;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#1 lore raw
Quoted 3 lines · Jan Beulich

highest_gsi() returns the last valid GSI, not a count.

Why not "nr_irqs_gsi = max(nr_irqs_gsi, highest_gsi()+1)"?

Quoted 20 lines
xen/arch/x86/io_apic.c +3 -1
@@ -2531,7 +2531,9 @@ void __init init_ioapic_mappings(void)
         }
     }
 
-    nr_irqs_gsi = max(nr_irqs_gsi, highest_gsi());
+    i = highest_gsi();
+    if ( i >= nr_irqs_gsi )
+        nr_irqs_gsi = i + 1;
 
     if ( max_gsi_irqs == 0 )
         max_gsi_irqs = nr_irqs ? nr_irqs / 8 : PAGE_SIZE;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw
Quoted 8 lines
Quoted 1 line
Quoted 1 line · Keir Fraser
Quoted 3 lines · Jan Beulich

highest_gsi() returns the last valid GSI, not a count.

Why not "nr_irqs_gsi = max(nr_irqs_gsi, highest_gsi()+1)"?

While I think x = max(y, z) is fine, I generally find x = max(x, y) pretty useless - what's the point of assigning a value to itself? This is __init code, so code size considerations probably don't matter, but I'd still like to not encourage inefficient code like this to be used elsewhere by giving a bad example...

Jan

Quoted 20 lines
Quoted 20 lines
xen/arch/x86/io_apic.c +3 -1
@@ -2531,7 +2531,9 @@ void __init init_ioapic_mappings(void)
         }
     }
 
-    nr_irqs_gsi = max(nr_irqs_gsi, highest_gsi());
+    i = highest_gsi();
+    if ( i >= nr_irqs_gsi )
+        nr_irqs_gsi = i + 1;
 
     if ( max_gsi_irqs == 0 )
         max_gsi_irqs = nr_irqs ? nr_irqs / 8 : PAGE_SIZE;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Keir Fraser
Quoted 3 lines · Jan Beulich

highest_gsi() returns the last valid GSI, not a count.

Quoted 7 lines
Quoted 1 line

Why not "nr_irqs_gsi = max(nr_irqs_gsi, highest_gsi()+1)"?

While I think x = max(y, z) is fine, I generally find x = max(x, y) pretty useless - what's the point of assigning a value to itself? This is __init code, so code size considerations probably don't matter, but I'd still like to not encourage inefficient code like this to be used elsewhere by giving a bad example...

I think the code is clearer with max(). An even stronger argument is that it makes the intent of the patch much more obvious too. I think you should leave the max() construct in place in this patch.

-- Keir

Quoted 25 lines

Jan

Quoted 20 lines
Quoted 20 lines
xen/arch/x86/io_apic.c +3 -1
@@ -2531,7 +2531,9 @@ void __init init_ioapic_mappings(void)
         }
     }
 
-    nr_irqs_gsi = max(nr_irqs_gsi, highest_gsi());
+    i = highest_gsi();
+    if ( i >= nr_irqs_gsi )
+        nr_irqs_gsi = i + 1;
 
     if ( max_gsi_irqs == 0 )
         max_gsi_irqs = nr_irqs ? nr_irqs / 8 : PAGE_SIZE;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel