1) In devclass_alloc_unit(), skip duplicated wired devices (i.e. with fixed
number) instead of allocating next free unit for them. If someone needs fixed place, he must specify it correctly. "Allocating next" is especially bad because leads to double device detection and to "repeat make_dev panic" as result. This can happens if the same devices present somewhere on PCI bus, hints and ACPI. Making them present in one place only not always possible, "sc" f.e. can't be removed from hints, it results to no console at all. 2) In make_device(), detect when devclass_add_device() fails, free dev and return. I.e. add missing error checking. This part needed to finish fix in 1), but must be done this way in anycase, with old variant too.
This commit is contained in:
parent
0cd9461353
commit
e9c044bd9e
@ -353,13 +353,10 @@ devclass_alloc_unit(devclass_t dc, int *unitp)
|
||||
if (unit != -1) {
|
||||
if (unit >= 0 && unit < dc->maxunit &&
|
||||
dc->devices[unit] != NULL) {
|
||||
/* find the next available slot */
|
||||
while (++unit < dc->maxunit &&
|
||||
dc->devices[unit] != NULL)
|
||||
continue;
|
||||
if (bootverbose)
|
||||
printf("%s-: %s%d already exists, using %s%d instead\n",
|
||||
dc->name, dc->name, *unitp, dc->name, unit);
|
||||
printf("%s-: %s%d already exists, skipping it\n",
|
||||
dc->name, dc->name, *unitp);
|
||||
return (EEXIST);
|
||||
}
|
||||
} else {
|
||||
/* Unwired device, find the next available slot for it */
|
||||
@ -460,7 +457,7 @@ make_device(device_t parent, const char *name, int unit)
|
||||
|
||||
dev = malloc(sizeof(struct device), M_BUS, M_NOWAIT|M_ZERO);
|
||||
if (!dev)
|
||||
return (0);
|
||||
return (NULL);
|
||||
|
||||
dev->parent = parent;
|
||||
TAILQ_INIT(&dev->children);
|
||||
@ -478,7 +475,10 @@ make_device(device_t parent, const char *name, int unit)
|
||||
dev->flags |= DF_WILDCARD;
|
||||
if (name) {
|
||||
dev->flags |= DF_FIXEDCLASS;
|
||||
devclass_add_device(dc, dev);
|
||||
if (devclass_add_device(dc, dev)) {
|
||||
kobj_delete((kobj_t) dev, M_BUS);
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
dev->ivars = NULL;
|
||||
dev->softc = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user