Skip to contentSkip to conversation

pci: assert that irqnum is between 0 and bus->nirqs in pci_change_irq_level()

PATCH In review Philippe Mathieu-Daudé 2 participants 4 messages Oct 24, 2020 – Oct 25, 2020

lore
Share & tools
lore
#0 lore raw

v2 cover pci: assert that irqnum is between 0 and bus->nirqs in pci_change_irq_level()

Respin of Mark's patch:
https://www.mail-archive.com/[email protected]/msg749459.html

Supersedes: <[email protected]>

Mark Cave-Ayland (1):
pci: Assert irqnum is between 0 and bus->nirqs in
pci_bus_change_irq_level

Philippe Mathieu-Daudé (1):
hw/pci: Extract pci_bus_change_irq_level() from pci_change_irq_level()

 hw/pci/pci.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH v2 1/2 hw/pci: Extract pci_bus_change_irq_level() from pci_change_irq_level()

Extract pci_bus_change_irq_level() from pci_change_irq_level() to make it clearer it operates on the bus.

---
 hw/pci/pci.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
hw/pci/pci.c +7 -2
index 100c9381c2f..081ddcadd15 100644
@@ -248,6 +248,12 @@ static inline void pci_set_irq_state(PCIDevice *d, int irq_num, int level)
         d->irq_state |= level << irq_num;
 }
 
+static void pci_bus_change_irq_level(PCIBus *bus, int irq_num, int change)
+{
+    bus->irq_count[irq_num] += change;
+    bus->set_irq(bus->irq_opaque, irq_num, bus->irq_count[irq_num] != 0);
+}
+
 static void pci_change_irq_level(PCIDevice *pci_dev, int irq_num, int change)
 {
     PCIBus *bus;
@@ -258,8 +264,7 @@ static void pci_change_irq_level(PCIDevice *pci_dev, int irq_num, int change)
             break;
         pci_dev = bus->parent_dev;
     }
-    bus->irq_count[irq_num] += change;
-    bus->set_irq(bus->irq_opaque, irq_num, bus->irq_count[irq_num] != 0);
+    pci_bus_change_irq_level(bus, irq_num, change);
 }
 
 int pci_bus_get_irq_level(PCIBus *bus, int irq_num)
Signature · 1 line
2.26.2
#2 lore raw

PATCH v2 2/2 pci: Assert irqnum is between 0 and bus->nirqs in pci_bus_change_irq_level

In reply to Philippe Mathieu-Daudé

From: Mark Cave-Ayland <[email protected]>

These assertions similar to those in the adjacent pci_bus_get_irq_level() function ensure that irqnum lies within the valid PCI bus IRQ range.

Message-Id: <[email protected]>

---
 hw/pci/pci.c | 2 ++
 1 file changed, 2 insertions(+)
hw/pci/pci.c +2 -0
index 081ddcadd15..dc4019865be 100644
@@ -250,6 +250,8 @@ static inline void pci_set_irq_state(PCIDevice *d, int irq_num, int level)
 
 static void pci_bus_change_irq_level(PCIBus *bus, int irq_num, int change)
 {
+    assert(irq_num >= 0);
+    assert(irq_num < bus->nirq);
     bus->irq_count[irq_num] += change;
     bus->set_irq(bus->irq_opaque, irq_num, bus->irq_count[irq_num] != 0);
 }
Signature · 1 line
2.26.2
Reviewed-by on the v2 series
#3 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 9 lines · Philippe Mathieu-Daudé

Respin of Mark's patch:
https://www.mail-archive.com/[email protected]/msg749459.html

Supersedes: <[email protected]>

Mark Cave-Ayland (1):
pci: Assert irqnum is between 0 and bus->nirqs in
pci_bus_change_irq_level

Quoted 5 lines

Philippe Mathieu-Daudé (1):
hw/pci: Extract pci_bus_change_irq_level() from pci_change_irq_level()

  hw/pci/pci.c | 11 +++++++++--
  1 file changed, 9 insertions(+), 2 deletions(-)

This version LGTM - I think it's just waiting on review from the PCI folks to see whether they agree with the change.

ATB,

Mark.