Received: from eggs.gnu.org ([2001:4830:134:3::10]:50660) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZBdy6-0004ft-DR for qemu-devel@nongnu.org; Sun, 05 Jul 2015 03:04:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZBdy2-00088d-Pt for qemu-devel@nongnu.org; Sun, 05 Jul 2015 03:04:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49492) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZBdy2-00088U-L6 for qemu-devel@nongnu.org; Sun, 05 Jul 2015 03:03:58 -0400 Date: Sun, 5 Jul 2015 09:03:54 +0200 From: "Michael S. Tsirkin" Message-ID: <20150705084150-mutt-send-email-mst@redhat.com> References: <1436052508.3948.41.camel@kernel.crashing.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1436052508.3948.41.camel@kernel.crashing.org> Subject: Re: [Qemu-devel] [PATCH] pci: Don't call pci_irq_handler() for a negative intx List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Benjamin Herrenschmidt Cc: qemu-devel@nongnu.org, Marcel Apfelbaum On Sun, Jul 05, 2015 at 09:28:28AM +1000, Benjamin Herrenschmidt wrote: > Under some circumstances, pci_intx() can return -1 (when the interrupt > pin in the config space is 0 which normally means no interrupt). > > I have seen cases of pci_set_irq() being called on such devices, in > turn causing pci_irq_handler() to be called with "-1" as an argument > which doesn't seem like a terribly good idea. > > Signed-off-by: Benjamin Herrenschmidt Isn't this a device bug though? I did a grep over all callers of pci_set_irq and didn't find any that fails to set an interrupt pin. So how about an assert instead? And maybe stick it in pci_intx to make sure all callers get checked. > --- > hw/pci/pci.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/hw/pci/pci.c b/hw/pci/pci.c > index 8185bbc..eea6f5d 100644 > --- a/hw/pci/pci.c > +++ b/hw/pci/pci.c > @@ -1281,7 +1281,9 @@ qemu_irq pci_allocate_irq(PCIDevice *pci_dev) > void pci_set_irq(PCIDevice *pci_dev, int level) > { > int intx = pci_intx(pci_dev); > - pci_irq_handler(pci_dev, intx, level); > + if (intx >= 0) { > + pci_irq_handler(pci_dev, intx, level); > + } > } > > /* Special hooks used by device assignment */ >