qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Isaku Yamahata <isaku.yamahata@intel.com>,
	Peter Maydell <peter.maydell@linaro.org>
Subject: [PULL 9/9] pci: sprinkle assert in PCI pin number
Date: Thu, 1 Apr 2021 14:03:13 -0400	[thread overview]
Message-ID: <20210401180235.226321-10-mst@redhat.com> (raw)
In-Reply-To: <20210401180235.226321-1-mst@redhat.com>

From: Isaku Yamahata <isaku.yamahata@intel.com>

If a device model
(a) doesn't set the value to a correct interrupt number and then
(b) triggers an interrupt for itself,
it's device model bug. Add assert on interrupt pin number to catch
this kind of bug more obviously.

Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
Message-Id: <9cf8ac3b17e162daac0971d7be32deb6a33ae6ec.1616532563.git.isaku.yamahata@intel.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/pci/pci.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index ac9a24889c..8f35e13a0c 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -1450,6 +1450,8 @@ static void pci_irq_handler(void *opaque, int irq_num, int level)
     PCIDevice *pci_dev = opaque;
     int change;
 
+    assert(0 <= irq_num && irq_num < PCI_NUM_PINS);
+    assert(level == 0 || level == 1);
     change = level - pci_irq_state(pci_dev, irq_num);
     if (!change)
         return;
@@ -1469,6 +1471,7 @@ static inline int pci_intx(PCIDevice *pci_dev)
 qemu_irq pci_allocate_irq(PCIDevice *pci_dev)
 {
     int intx = pci_intx(pci_dev);
+    assert(0 <= intx && intx < PCI_NUM_PINS);
 
     return qemu_allocate_irq(pci_irq_handler, pci_dev, intx);
 }
-- 
MST



  parent reply	other threads:[~2021-04-01 18:21 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-01 18:02 [PULL 0/9] pc,virtio,pci: bugfixes Michael S. Tsirkin
2021-04-01 18:02 ` [PULL 1/9] vhost-user-blk: use different event handlers on initialization Michael S. Tsirkin
2021-04-01 18:02 ` [PULL 2/9] vhost-user-blk: perform immediate cleanup if disconnect " Michael S. Tsirkin
2021-04-01 18:02 ` [PULL 3/9] vhost-user-blk: add immediate cleanup on shutdown Michael S. Tsirkin
2021-04-01 18:03 ` [PULL 4/9] virtio-pci: add check for vdev in virtio_pci_isr_read Michael S. Tsirkin
2021-04-01 18:03 ` [PULL 5/9] virtio-pci: remove explicit initialization of val Michael S. Tsirkin
2021-04-01 18:03 ` [PULL 6/9] acpi/piix4: reinitialize acpi PM device on reset Michael S. Tsirkin
2021-04-01 18:03 ` [PULL 7/9] vt82c686.c: don't raise SCI when PCI_INTERRUPT_PIN isn't setup Michael S. Tsirkin
2021-04-01 18:03 ` [PULL 8/9] isa/v582c686: Reinitialize ACPI PM device on reset Michael S. Tsirkin
2021-04-01 18:03 ` Michael S. Tsirkin [this message]
2021-04-04 20:47 ` [PULL 0/9] pc,virtio,pci: bugfixes Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210401180235.226321-10-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=isaku.yamahata@intel.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).