On Fri, Sep 19, 2003 at 05:17:22PM -0400, Alan Stern wrote: > On Thu, 18 Sep 2003, David Brownell wrote: > > > You might be right that another put_device() is needed, but > > if so I've to to suspect that's because there's an extra > > get_device() ... like the one in "config.c". Isn't the > > object initialized to count == 1, so that get_device() makes > > usbcore track count == 2 for just one copy of that pointer? > > That's right, and you're also right that there's an extra get_device(). > In fact, there are two extra. The first is indeed in config.c; this patch > (as111) gets rid of it. > > ===== config.c 1.25 vs edited ===== > --- 1.25/drivers/usb/core/config.c Mon Sep 15 10:14:46 2003 > +++ edited/drivers/usb/core/config.c Fri Sep 19 17:07:29 2003 > @@ -237,9 +237,6 @@ > memset(interface, 0, sizeof(struct usb_interface)); > interface->dev.release = usb_release_intf; > device_initialize(&interface->dev); > - > - /* put happens in usb_destroy_configuration */ > - get_device(&interface->dev); > } > > /* Go through the descriptors, checking their length and counting the >
No, taking this out is wrong. Read the comment :) We need to increment the count by one, as we want the interfaces to stick around until the whole device is cleaned up. That happens from a call to usb_release_dev when the final kobject put is called on the struct usb_device. Then that calls usb_destroy_configuration() which cleans up the raw descriptors of the interfaces that were owned by the struct usb_device, and then calls the last put on the struct usb_interface, which then will finally free that memory. If this patch goes in, the interface memory will be freed when the interface is unregistered from the driver core (with the call to device_unregister(&interface->dev); in usb_disconnect) which is way too early in the cleanup sequence. Did you test that patch? What happened when you unplugged a device? > The other is in usb.c:usb_new_device(). Neither the get_device() nor the > put_device() in the function should be there. The patch below, which > applies on top of David's usb_set_configuration() rework patch, takes care > of them. No, that was added for another reason too, can't remember what it was right this second though, gotta go pick up my daughter from school... > Probably both of these mistakes arose from someone not realizing that > device_initialize() already sets the reference count to 1. No, this someone was aware of that :) I run my boxes with kobject and driver core debugging enabled all the time to make sure bugs like this don't happen. thanks, greg k-h ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ [EMAIL PROTECTED] To unsubscribe, use the last form field at: https://lists.sourceforge.net/lists/listinfo/linux-usb-devel
