Add comments about why we're freeing subdevs (which is completely

redundant at this point and should be retired).  Don't free subdevs if
we don't attach any devices.  This was leaving stale device_t's
around.  Don't touch the device if it isn't attached since the name
isn't meaningful then.  Switch from strncpy (properly used) to
strlcpy.

From a patch submitted by Peter Pentchev
This commit is contained in:
imp 2004-09-09 20:47:28 +00:00
parent 50c75b4cae
commit 4c20551f64

View File

@ -905,6 +905,10 @@ usbd_probe_and_attach(device_ptr_t parent, usbd_device_handle dev,
if (dv) {
return (USBD_NORMAL_COMPLETION);
}
/*
* Free subdevs so we can reallocate it larger for the number of
* interfaces
*/
tmpdv = dev->subdevs;
dev->subdevs = NULL;
free(tmpdv, M_USB);
@ -1016,9 +1020,6 @@ usbd_probe_and_attach(device_ptr_t parent, usbd_device_handle dev,
if (dv != NULL) {
return (USBD_NORMAL_COMPLETION);
}
tmpdv = dev->subdevs;
dev->subdevs = 0;
free(tmpdv, M_USB);
/*
* The generic attach failed, but leave the device as it is.
@ -1346,11 +1347,13 @@ usbd_fill_deviceinfo(usbd_device_handle dev, struct usb_device_info *di,
di->udi_speed = dev->speed;
if (dev->subdevs != NULL) {
for (i = 0; dev->subdevs[i] &&
i < USB_MAX_DEVNAMES; i++) {
strncpy(di->udi_devnames[i], USBDEVPTRNAME(dev->subdevs[i]),
USB_MAX_DEVNAMELEN);
di->udi_devnames[i][USB_MAX_DEVNAMELEN-1] = '\0';
for (i = 0; dev->subdevs[i] && i < USB_MAX_DEVNAMES; i++) {
if (device_is_attached(dev->subdevs[i]))
strlcpy(di->udi_devnames[i],
USBDEVPTRNAME(dev->subdevs[i]),
USB_MAX_DEVNAMELEN);
else
di->udi_devnames[i][0] = 0;
}
} else {
i = 0;