login
Header Space

 
 

Re: [RFC] Patch to option HSO driver to the kernel

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Paulius Zaleckas <paulius.zaleckas@...>
Cc: <netdev@...>, <linux-usb@...>
Date: Thursday, April 17, 2008 - 10:32 am

Am Mittwoch, 16. April 2008 15:55:02 schrieb Paulius Zaleckas:

Hi,

can you test this one as well. The method used to determine whether
a device is asleep is racy. This introduces a private test.

	Regards
		Oliver

---

--- linux-2.6.25hso/drivers/net/usb/hso.c.alt2	2008-04-17 14:15:32.000000000 +0200
+++ linux-2.6.25hso/drivers/net/usb/hso.c	2008-04-17 16:11:50.000000000 +0200
@@ -242,6 +242,7 @@ struct hso_device {
 	u8 is_active;
 	u8 suspend_disabled;
 	u8 usb_gone;
+	u8 sleeping;
 	struct work_struct async_get_intf;
 	struct work_struct async_put_intf;
 
@@ -252,6 +253,7 @@ struct hso_device {
 	struct device *dev;
 	struct kref ref;
 	struct mutex mutex;
+	spinlock_t lock;
 
 	/* TODO: Not sure about the ones below */
 	struct proc_dir_entry *ourproc;
@@ -2184,6 +2186,7 @@ static struct hso_device *hso_create_dev
 	hso_dev->interface = intf;
 	kref_init(&hso_dev->ref);
 	mutex_init(&hso_dev->mutex);
+	spin_lock_init(&hso_dev->lock);
 
 	INIT_WORK(&hso_dev->async_get_intf, async_get_intf);
 	INIT_WORK(&hso_dev->async_put_intf, async_put_intf);
@@ -2757,12 +2760,16 @@ static void async_put_intf(struct work_s
 
 static int hso_get_activity(struct hso_device *hso_dev)
 {
-	if (hso_dev->usb->state == USB_STATE_SUSPENDED) {
+	unsigned long flags;
+
+	spin_lock_irqsave(&hso_dev->lock, flags);
+	if (hso_dev->sleeping) {
 		if (!hso_dev->is_active) {
 			hso_dev->is_active = 1;
 			schedule_work(&hso_dev->async_get_intf);
 		}
 	}
+	spin_unlock_irqrestore(&hso_dev->lock, flags);
 
 	if (hso_dev->usb->state != USB_STATE_CONFIGURED)
 		return -EAGAIN;
@@ -2774,22 +2781,32 @@ static int hso_get_activity(struct hso_d
 
 static int hso_put_activity(struct hso_device *hso_dev)
 {
-	if (hso_dev->usb->state != USB_STATE_SUSPENDED) {
+	unsigned long flags;
+
+	spin_lock_irqsave(&hso_dev->lock, flags);
+	if (hso_dev->sleeping) {
 		if (hso_dev->is_active) {
 			hso_dev->is_active = 0;
 			schedule_work(&hso_dev->async_put_intf);
+			spin_unlock_irqrestore(&hso_dev->lock, flags);
 			return -EAGAIN;
 		}
 	}
 	hso_dev->is_active = 0;
+	spin_unlock_irqrestore(&hso_dev->lock, flags);
 	return 0;
 }
 
 /* called by kernel when we need to suspend device */
 static int hso_suspend(struct usb_interface *iface, pm_message_t message)
 {
+	struct hso_device *hso_dev = usb_get_intfdata(iface);
 	int i, result = 0;
 
+	spin_lock_irq(&hso_dev->lock);
+	hso_dev->sleeping = 1;
+	spin_unlock_irq(&hso_dev->lock);
+
 	/* Stop all serial ports */
 	for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
 		if (serial_table[i] && (serial_table[i]->interface == iface)) {
@@ -2816,9 +2833,14 @@ out:
 /* called by kernel when we need to resume device */
 static int hso_resume(struct usb_interface *iface)
 {
+	struct hso_device *hso_dev = usb_get_intfdata(iface);
 	int i, result = 0;
 	struct hso_net *hso_net;
 
+	spin_lock_irq(&hso_dev->lock);
+	hso_dev->sleeping = 0;
+	spin_unlock_irq(&hso_dev->lock);
+
 	/* Start all serial ports */
 	for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
 		if (serial_table[i] && (serial_table[i]->interface == iface)) {

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[RFC] Patch to option HSO driver to the kernel, Greg KH, (Mon Apr 14, 5:32 pm)
Re: [RFC] Patch to option HSO driver to the kernel, Paulius Zaleckas, (Wed Apr 16, 9:11 am)
Re: [RFC] Patch to option HSO driver to the kernel, Paulius Zaleckas, (Tue Apr 15, 6:49 pm)
Re: [RFC] Patch to option HSO driver to the kernel, Paulius Zaleckas, (Wed Apr 16, 5:18 am)
Re: [RFC] Patch to option HSO driver to the kernel, Paulius Zaleckas, (Wed Apr 16, 7:54 am)
Re: [RFC] Patch to option HSO driver to the kernel, Paulius Zaleckas, (Wed Apr 16, 11:15 am)
Re: [RFC] Patch to option HSO driver to the kernel, Oliver Neukum, (Wed Apr 16, 8:03 am)
Re: [RFC] Patch to option HSO driver to the kernel, Paulius Zaleckas, (Wed Apr 16, 8:12 am)
Re: [RFC] Patch to option HSO driver to the kernel, Oliver Neukum, (Wed Apr 16, 9:43 am)
Re: [RFC] Patch to option HSO driver to the kernel, Paulius Zaleckas, (Wed Apr 16, 9:55 am)
Re: [RFC] Patch to option HSO driver to the kernel, Oliver Neukum, (Thu Apr 17, 10:32 am)
Re: [RFC] Patch to option HSO driver to the kernel, Paulius Zaleckas, (Fri Apr 18, 11:18 am)
Re: [RFC] Patch to option HSO driver to the kernel, Oliver Neukum, (Mon Apr 21, 7:45 am)
Re: [RFC] Patch to option HSO driver to the kernel, Paulius Zaleckas, (Mon Apr 21, 8:38 am)
Re: [RFC] Patch to option HSO driver to the kernel, Oliver Neukum, (Mon Apr 21, 8:50 am)
Re: [RFC] Patch to option HSO driver to the kernel, Paulius Zaleckas, (Mon Apr 21, 9:00 am)
Re: [RFC] Patch to option HSO driver to the kernel, Paulius Zaleckas, (Thu Apr 17, 5:47 pm)
Re: [RFC] Patch to option HSO driver to the kernel, Oliver Neukum, (Fri Apr 18, 2:51 am)
RE: Re: [RFC] Patch to option HSO driver to the kernel, Chetty, Jay, (Thu Apr 17, 6:31 pm)
Re: [RFC] Patch to option HSO driver to the kernel, Oliver Neukum, (Tue Apr 15, 9:55 am)
Re: [RFC] Patch to option HSO driver to the kernel, Oliver Neukum, (Tue Apr 15, 9:25 am)
Re: [RFC] Patch to option HSO driver to the kernel, Filip Aben, (Tue Apr 15, 10:12 am)
Re: [RFC] Patch to option HSO driver to the kernel, Oliver Neukum, (Tue Apr 15, 10:14 am)
Re: [RFC] Patch to option HSO driver to the kernel, Filip Aben, (Tue Apr 15, 11:03 am)
Re: [RFC] Patch to option HSO driver to the kernel, Oliver Neukum, (Tue Apr 15, 2:46 pm)
Re: [RFC] Patch to option HSO driver to the kernel, Oliver Neukum, (Thu Apr 17, 8:15 am)
Re: [RFC] Patch to option HSO driver to the kernel, Oliver Neukum, (Tue Apr 15, 4:17 pm)
Re: [RFC] Patch to option HSO driver to the kernel, Stephen Hemminger, (Tue Apr 15, 3:14 pm)
Re: [RFC] Patch to option HSO driver to the kernel, Filip Aben, (Tue Apr 15, 12:24 pm)
Re: [RFC] Patch to option HSO driver to the kernel, Oliver Neukum, (Tue Apr 15, 1:58 pm)
Re: [RFC] Patch to option HSO driver to the kernel, Oliver Neukum, (Tue Apr 15, 9:06 am)
Re: [RFC] Patch to option HSO driver to the kernel, Oliver Neukum, (Tue Apr 15, 7:44 am)
Re: [RFC] Patch to option HSO driver to the kernel, Paulius Zaleckas, (Mon Apr 14, 7:20 pm)
Re: [RFC] Patch to option HSO driver to the kernel, Oliver Neukum, (Tue Apr 15, 4:10 am)
Re: [RFC] Patch to option HSO driver to the kernel, Paulius Zaleckas, (Tue Apr 15, 4:58 am)
Re: [RFC] Patch to option HSO driver to the kernel, Oliver Hartkopp, (Tue Apr 15, 12:30 am)
Re: [RFC] Patch to option HSO driver to the kernel, Oliver Hartkopp, (Tue Apr 15, 1:53 pm)
Re: [RFC] Patch to option HSO driver to the kernel, Matthew Dharm, (Mon Apr 14, 5:59 pm)
Re: [RFC] Patch to option HSO driver to the kernel, Andrew Bird (Sphere Systems)..., (Mon Apr 14, 6:42 pm)
Re: [RFC] Patch to option HSO driver to the kernel, Filip Aben, (Tue Apr 15, 4:01 am)
speck-geostationary