[PATCH 6/6] usb/composite: merge the two spinlocks

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

 



We have one spin lock for delayed status. This patch simply merges them
into one. This leaves the mutex to only protect against list
manipulation of set config & function entries.
Adding entries to this list happens in single thread context and removal
happens on device removal once everything is gone. So we don't need it
in those places right now.

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

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 317cad7..2ac3770 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -275,14 +275,14 @@ int usb_function_deactivate(struct usb_function *function)
 	unsigned long			flags;
 	int				status = 0;
 
-	spin_lock_irqsave(&cdev->deact_lock, flags);
+	spin_lock_irqsave(&cdev->count_lock, flags);
 
 	if (cdev->deactivations == 0)
 		status = usb_gadget_disconnect(cdev->gadget);
 	if (status == 0)
 		cdev->deactivations++;
 
-	spin_unlock_irqrestore(&cdev->deact_lock, flags);
+	spin_unlock_irqrestore(&cdev->count_lock, flags);
 	return status;
 }
 
@@ -301,7 +301,7 @@ int usb_function_activate(struct usb_function *function)
 	struct usb_composite_dev	*cdev = function->config->cdev;
 	int				status = 0;
 
-	spin_lock(&cdev->deact_lock);
+	spin_lock(&cdev->count_lock);
 
 	if (WARN_ON(cdev->deactivations == 0))
 		status = -EINVAL;
@@ -311,7 +311,7 @@ int usb_function_activate(struct usb_function *function)
 			status = usb_gadget_connect(cdev->gadget);
 	}
 
-	spin_unlock(&cdev->deact_lock);
+	spin_unlock(&cdev->count_lock);
 	return status;
 }
 
@@ -1458,8 +1458,7 @@ static int composite_bind(struct usb_gadget *gadget)
 	if (!cdev)
 		return status;
 
-	spin_lock_init(&cdev->lock);
-	spin_lock_init(&cdev->deact_lock);
+	spin_lock_init(&cdev->count_lock);
 	mutex_init(&cdev->mutex);
 	INIT_WORK(&cdev->wq, composite_delayed_setup);
 	INIT_WORK(&cdev->disc_work, composite_disconnect_wq);
@@ -1698,7 +1697,7 @@ void usb_composite_setup_continue(struct usb_composite_dev *cdev)
 	unsigned long		flags;
 
 	DBG(cdev, "%s\n", __func__);
-	spin_lock_irqsave(&cdev->lock, flags);
+	spin_lock_irqsave(&cdev->count_lock, flags);
 
 	if (cdev->delayed_status == 0) {
 		WARN(cdev, "%s: Unexpected call\n", __func__);
@@ -1714,6 +1713,6 @@ void usb_composite_setup_continue(struct usb_composite_dev *cdev)
 		}
 	}
 
-	spin_unlock_irqrestore(&cdev->lock, flags);
+	spin_unlock_irqrestore(&cdev->count_lock, flags);
 }
 
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index 21b7887..683422e 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -353,7 +353,6 @@ struct usb_composite_dev {
 	 * while the deactivation count is nonzero.
 	 */
 	unsigned			deactivations;
-	spinlock_t			deact_lock;
 
 	/* the composite driver won't complete the control transfer's
 	 * data/status stages till delayed_status is zero.
@@ -362,8 +361,9 @@ struct usb_composite_dev {
 	struct work_struct		wq;
 	struct usb_ctrlrequest		ctrl;
 
-	/* protects delayed_status counts */
-	spinlock_t			lock;
+	/* protects counting delayed_status and deactivation */
+	spinlock_t			count_lock;
+	/* protects list manipulations (config, function) */
 	struct mutex			mutex;
 };
 
-- 
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