Index: sys/kern/subr_intr.c =================================================================== --- sys/kern/subr_intr.c +++ sys/kern/subr_intr.c @@ -103,6 +103,7 @@ /* Interrupt controller definition. */ struct intr_pic { SLIST_ENTRY(intr_pic) pic_next; +#define XREF_INVALID (-1) intptr_t pic_xref; /* hardware identification */ device_t pic_dev; /* Only one of FLAG_PIC or FLAG_MSI may be set */ @@ -696,8 +697,8 @@ mtx_assert(&pic_list_lock, MA_OWNED); - if (dev == NULL && xref == 0) - return (NULL); + KASSERT(dev != NULL || xref != XREF_INVALID, + ("pic_lookup_locked: Either the device or the xref must be valid")); /* Note that pic->pic_dev is never NULL on registered PIC. */ SLIST_FOREACH(pic, &pic_list, pic_next) { @@ -706,13 +707,17 @@ continue; if (dev == NULL) { + /* No dev, check the xref */ if (xref == pic->pic_xref) return (pic); - } else if (xref == 0 || pic->pic_xref == 0) { + } else if (xref == XREF_INVALID) { + /* No xref, check the dev */ if (dev == pic->pic_dev) return (pic); - } else if (xref == pic->pic_xref && dev == pic->pic_dev) - return (pic); + } else if (xref == pic->pic_xref && dev == pic->pic_dev) { + /* Have both, check both */ + return (pic); + } } return (NULL); } @@ -739,6 +744,8 @@ { struct intr_pic *pic; + KASSERT(xref != XREF_INVALID, ("%s: Invalid xref", __func__)); + mtx_lock(&pic_list_lock); pic = pic_lookup_locked(dev, xref, flags); if (pic != NULL) { @@ -768,6 +775,8 @@ { struct intr_pic *pic; + KASSERT(xref != XREF_INVALID, ("%s: Invalid xref", __func__)); + mtx_lock(&pic_list_lock); pic = pic_lookup_locked(dev, xref, flags); if (pic == NULL) { @@ -827,6 +836,7 @@ { struct intr_pic *pic; + KASSERT(xref != XREF_INVALID, ("%s: Invalid xref", __func__)); pic = pic_lookup(dev, xref, FLAG_PIC); if (pic == NULL) { device_printf(dev, "not registered\n"); @@ -876,7 +886,7 @@ #endif /* Find the parent PIC */ - parent_pic = pic_lookup(parent, 0, FLAG_PIC); + parent_pic = pic_lookup(parent, XREF_INVALID, FLAG_PIC); if (parent_pic == NULL) return (NULL); @@ -910,6 +920,7 @@ if (data == NULL) return (EINVAL); + KASSERT(xref != XREF_INVALID, ("%s: Invalid xref", __func__)); pic = pic_lookup(dev, xref, (data->type == INTR_MAP_DATA_MSI) ? FLAG_MSI : FLAG_PIC); if (pic == NULL) @@ -1281,6 +1292,7 @@ struct intr_map_data_msi *msi; int err, i; + KASSERT(xref != XREF_INVALID, ("%s: Invalid xref", __func__)); pic = pic_lookup(NULL, xref, FLAG_MSI); if (pic == NULL) return (ESRCH); @@ -1318,6 +1330,7 @@ struct intr_map_data_msi *msi; int i, err; + KASSERT(xref != XREF_INVALID, ("%s: Invalid xref", __func__)); pic = pic_lookup(NULL, xref, FLAG_MSI); if (pic == NULL) return (ESRCH); @@ -1357,6 +1370,7 @@ struct intr_map_data_msi *msi; int err; + KASSERT(xref != XREF_INVALID, ("%s: Invalid xref", __func__)); pic = pic_lookup(NULL, xref, FLAG_MSI); if (pic == NULL) return (ESRCH); @@ -1385,6 +1399,7 @@ struct intr_map_data_msi *msi; int err; + KASSERT(xref != XREF_INVALID, ("%s: Invalid xref", __func__)); pic = pic_lookup(NULL, xref, FLAG_MSI); if (pic == NULL) return (ESRCH); @@ -1418,6 +1433,7 @@ struct intr_pic *pic; int err; + KASSERT(xref != XREF_INVALID, ("%s: Invalid xref", __func__)); pic = pic_lookup(NULL, xref, FLAG_MSI); if (pic == NULL) return (ESRCH);