Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/pci/pci.c
Show First 20 Lines • Show All 487 Lines • ▼ Show 20 Lines | if (dinfo->cfg.baseclass == class && | ||||
dinfo->cfg.subclass == subclass) { | dinfo->cfg.subclass == subclass) { | ||||
return (dinfo->cfg.dev); | return (dinfo->cfg.dev); | ||||
} | } | ||||
} | } | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
device_t | |||||
pci_find_class_from(uint8_t class, uint8_t subclass, device_t from) | |||||
jhb: I assume this isn't a hot path, so this approach is fine vs trying to restart the iteration… | |||||
{ | |||||
struct pci_devinfo *dinfo; | |||||
bool found = false; | |||||
STAILQ_FOREACH(dinfo, &pci_devq, pci_links) { | |||||
if (from != NULL && found == false) { | |||||
if (from != dinfo->cfg.dev) | |||||
continue; | |||||
found = true; | |||||
continue; | |||||
} | |||||
if (dinfo->cfg.baseclass == class && | |||||
dinfo->cfg.subclass == subclass) { | |||||
return (dinfo->cfg.dev); | |||||
} | |||||
} | |||||
return (NULL); | |||||
} | |||||
static int | static int | ||||
pci_printf(pcicfgregs *cfg, const char *fmt, ...) | pci_printf(pcicfgregs *cfg, const char *fmt, ...) | ||||
{ | { | ||||
va_list ap; | va_list ap; | ||||
int retval; | int retval; | ||||
retval = printf("pci%d:%d:%d:%d: ", cfg->domain, cfg->bus, cfg->slot, | retval = printf("pci%d:%d:%d:%d: ", cfg->domain, cfg->bus, cfg->slot, | ||||
cfg->func); | cfg->func); | ||||
▲ Show 20 Lines • Show All 6,186 Lines • Show Last 20 Lines |
I assume this isn't a hot path, so this approach is fine vs trying to restart the iteration from the existing device. That is, you could perhaps write this as:
But I think your current approach is fine assuming it's only used in things like attach, and it's a bit more robust against bogus input arguments.