[PATCH 5/6] usb/gadget: convert the spinlock into a mutex for the wq user

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The lock is taken on two occasions:
- counting delayed_status
- synchronising between set config, reset config

This patch converts the latter user into a mutex since it has nothing to
do with the delayed_status counting. We could remove the lock since the
wq synchronies us but if it is more obvious that way.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>
---
 drivers/usb/gadget/composite.c |   10 ++++++----
 include/linux/usb/composite.h  |    1 +
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index f5c5bd8..317cad7 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -17,6 +17,7 @@
 #include <linux/module.h>
 #include <linux/device.h>
 #include <linux/utsname.h>
+#include <linux/mutex.h>
 
 #include <linux/usb/composite.h>
 #include <asm/unaligned.h>
@@ -1039,9 +1040,9 @@ static void composite_delayed_setup(struct work_struct *wq)
 			else
 				VDBG(cdev, "HNP inactive\n");
 		}
-		spin_lock_irq(&cdev->lock);
+		mutex_lock(&cdev->mutex);
 		value = set_config(cdev, ctrl, w_value);
-		spin_unlock_irq(&cdev->lock);
+		mutex_unlock(&cdev->mutex);
 	}
 
 	if (value == USB_GADGET_DELAYED_STATUS) {
@@ -1354,10 +1355,10 @@ static void composite_disconnect_wq(struct work_struct *wq)
 	/* REVISIT:  should we have config and device level
 	 * disconnect callbacks?
 	 */
-	spin_lock_irq(&cdev->lock);
+	mutex_lock(&cdev->mutex);
 	if (cdev->config)
 		reset_config(cdev);
-	spin_unlock_irq(&cdev->lock);
+	mutex_unlock(&cdev->mutex);
 	cdev->disc_pend = 0;
 }
 
@@ -1459,6 +1460,7 @@ static int composite_bind(struct usb_gadget *gadget)
 
 	spin_lock_init(&cdev->lock);
 	spin_lock_init(&cdev->deact_lock);
+	mutex_init(&cdev->mutex);
 	INIT_WORK(&cdev->wq, composite_delayed_setup);
 	INIT_WORK(&cdev->disc_work, composite_disconnect_wq);
 	cdev->gadget = gadget;
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index 576432d..21b7887 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -364,6 +364,7 @@ struct usb_composite_dev {
 
 	/* protects delayed_status counts */
 	spinlock_t			lock;
+	struct mutex			mutex;
 };
 
 extern int usb_string_id(struct usb_composite_dev *c);
-- 
1.7.8.3

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux