Hi,

in the appletouch driver open() races with suspend(). This should
fix it. Nicolas, could you please test it?

        Regards
                Oliver

Signed-off-by: Oliver Neukum <[EMAIL PROTECTED]>
--- current/drivers/usb/input/appletouch.c	2006-10-03 00:22:56.000000000 +0200
+++ linux-2.6.18/drivers/usb/input/appletouch.c	2006-10-03 00:58:04.000000000 +0200
@@ -77,6 +77,8 @@
 };
 MODULE_DEVICE_TABLE (usb, atp_table);
 
+static DEFINE_MUTEX(appletouch_open_mutex);
+
 /*
  * number of sensors. Note that only 16 instead of 26 X (horizontal)
  * sensors exist on 12" and 15" PowerBooks. All models have 16 Y
@@ -134,6 +136,7 @@
 	int			xy_acc[ATP_XSENSORS + ATP_YSENSORS];
 	int			overflowwarn;	/* overflow warning printed? */
 	int			datalen;	/* size of an USB urb transfer */
+	unsigned char		suspended;	/* is the device suspended ? */
 };
 
 #define dbg_dump(msg, tab) \
@@ -404,11 +407,17 @@
 static int atp_open(struct input_dev *input)
 {
 	struct atp *dev = input->private;
+	int rv = 0;
 
-	if (usb_submit_urb(dev->urb, GFP_ATOMIC))
-		return -EIO;
+	mutex_lock(&appletouch_open_mutex);
+	if (!dev->suspended && usb_submit_urb(dev->urb, GFP_KERNEL)) { 
+		rv = -EIO;
+		goto done;
+	}
 
 	dev->open = 1;
+done:
+	mutex_unlock(&appletouch_open_mutex);
 	return 0;
 }
 
@@ -416,8 +425,8 @@
 {
 	struct atp *dev = input->private;
 
-	usb_kill_urb(dev->urb);
 	dev->open = 0;
+	usb_kill_urb(dev->urb);
 }
 
 static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id)
@@ -609,18 +618,27 @@
 static int atp_suspend(struct usb_interface *iface, pm_message_t message)
 {
 	struct atp *dev = usb_get_intfdata(iface);
+
+	mutex_lock(&appletouch_open_mutex);
 	usb_kill_urb(dev->urb);
 	dev->valid = 0;
+	dev->suspended = 1;
+	mutex_unlock(&appletouch_open_mutex);
 	return 0;
 }
 
 static int atp_resume(struct usb_interface *iface)
 {
 	struct atp *dev = usb_get_intfdata(iface);
+	int rv = 0;
+
+	mutex_lock(&appletouch_open_mutex);
+	dev->suspended = 0;
 	if (dev->open && usb_submit_urb(dev->urb, GFP_ATOMIC))
-		return -EIO;
+		rv = -EIO;
+	mutex_unlock(&appletouch_open_mutex);
 
-	return 0;
+	return rv;
 }
 
 static struct usb_driver atp_driver = {
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to