public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Make sure gspca cleans up USB resources during disconnect
@ 2009-02-03 23:13 Adam Baker
  2009-02-04  1:12 ` kilgota
  2009-02-04 16:40 ` Jean-Francois Moine
  0 siblings, 2 replies; 8+ messages in thread
From: Adam Baker @ 2009-02-03 23:13 UTC (permalink / raw)
  To: Jean-Francois Moine; +Cc: kilgota, Alan Stern, linux-media

If a device using the gspca framework is unplugged while it is still streaming
then the call that is used to free the URBs that have been allocated occurs
after the pointer it uses becomes invalid at the end of gspca_disconnect.
Make another cleanup call in gspca_disconnect while the pointer is still
valid (multiple calls are OK as destroy_urbs checks for pointers already
being NULL.

Signed-off-by: Adam Baker <linux@baker-net.org.uk>

---
diff -r 4d0827823ebc linux/drivers/media/video/gspca/gspca.c
--- a/linux/drivers/media/video/gspca/gspca.c	Tue Feb 03 10:42:28 2009 +0100
+++ b/linux/drivers/media/video/gspca/gspca.c	Tue Feb 03 23:07:34 2009 +0000
@@ -434,6 +434,7 @@ static void destroy_urbs(struct gspca_de
 		if (urb == NULL)
 			break;
 
+		BUG_ON(!gspca_dev->dev);
 		gspca_dev->urb[i] = NULL;
 		if (gspca_dev->present)
 			usb_kill_urb(urb);
@@ -1953,8 +1954,12 @@ void gspca_disconnect(struct usb_interfa
 {
 	struct gspca_dev *gspca_dev = usb_get_intfdata(intf);
 
+	mutex_lock(&gspca_dev->usb_lock);
 	gspca_dev->present = 0;
+	mutex_unlock(&gspca_dev->usb_lock);
 
+	destroy_urbs(gspca_dev);
+	gspca_dev->dev = NULL;
 	usb_set_intfdata(intf, NULL);
 
 	/* release the device */

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-02-05 21:42 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-03 23:13 [PATCH] Make sure gspca cleans up USB resources during disconnect Adam Baker
2009-02-04  1:12 ` kilgota
2009-02-04 16:40 ` Jean-Francois Moine
2009-02-04 22:07   ` Adam Baker
2009-02-05 11:39     ` Jean-Francois Moine
2009-02-05 18:59       ` kilgota
2009-02-05 19:51         ` Jean-Francois Moine
2009-02-05 21:54           ` kilgota

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox