From 4c20551f649ebf1cfd04aa6e91891cbfdcb50dbc Mon Sep 17 00:00:00 2001 From: imp Date: Thu, 9 Sep 2004 20:47:28 +0000 Subject: 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 --- sys/dev/usb/usb_subr.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/sys/dev/usb/usb_subr.c b/sys/dev/usb/usb_subr.c index 6b930d1..adeb436 100644 --- a/sys/dev/usb/usb_subr.c +++ b/sys/dev/usb/usb_subr.c @@ -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; -- cgit v1.1