diff --git a/hw/spapr_pci.c b/hw/spapr_pci.c
index 1108eea..b92583a 100644
--- a/hw/spapr_pci.c
+++ b/hw/spapr_pci.c
@@ -332,7 +332,7 @@ static void rtas_ibm_change_msi(sPAPREnvironment *spapr,
 
     /* Find a device number in the map to add or reuse the existing one */
     ndev = spapr_msicfg_find(phb, config_addr, true);
-    if (ndev >= SPAPR_MSIX_MAX_DEVS) {
+    if (ndev >= SPAPR_MSIX_MAX_DEVS || ndev < 0) {
         fprintf(stderr, "No free entry for a new MSI device\n");
         rtas_st(rets, 0, -1); /* Hardware error */
         return;
