[PATCH 3/6] usb/gadget: use a seperate lock activation counter

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

 



delayed_status counter and the deactivation share the same lock. This
patch splits the deactivation counter away from the delayed_status lock.

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

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index f6559d9..051db6f 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -274,14 +274,14 @@ int usb_function_deactivate(struct usb_function *function)
 	unsigned long			flags;
 	int				status = 0;
 
-	spin_lock_irqsave(&cdev->lock, flags);
+	spin_lock_irqsave(&cdev->deact_lock, flags);
 
 	if (cdev->deactivations == 0)
 		status = usb_gadget_disconnect(cdev->gadget);
 	if (status == 0)
 		cdev->deactivations++;
 
-	spin_unlock_irqrestore(&cdev->lock, flags);
+	spin_unlock_irqrestore(&cdev->deact_lock, flags);
 	return status;
 }
 
@@ -300,7 +300,7 @@ int usb_function_activate(struct usb_function *function)
 	struct usb_composite_dev	*cdev = function->config->cdev;
 	int				status = 0;
 
-	spin_lock(&cdev->lock);
+	spin_lock(&cdev->deact_lock);
 
 	if (WARN_ON(cdev->deactivations == 0))
 		status = -EINVAL;
@@ -310,7 +310,7 @@ int usb_function_activate(struct usb_function *function)
 			status = usb_gadget_connect(cdev->gadget);
 	}
 
-	spin_unlock(&cdev->lock);
+	spin_unlock(&cdev->deact_lock);
 	return status;
 }
 
@@ -1438,6 +1438,7 @@ static int composite_bind(struct usb_gadget *gadget)
 		return status;
 
 	spin_lock_init(&cdev->lock);
+	spin_lock_init(&cdev->deact_lock);
 	INIT_WORK(&cdev->wq, composite_delayed_setup);
 	cdev->gadget = gadget;
 	set_gadget_data(gadget, cdev);
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index f31e1d8..a332cc2 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -351,6 +351,7 @@ 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.
@@ -359,7 +360,7 @@ struct usb_composite_dev {
 	struct work_struct		wq;
 	struct usb_ctrlrequest		ctrl;
 
-	/* protects deactivations and delayed_status counts*/
+	/* protects delayed_status counts */
 	spinlock_t			lock;
 };
 
-- 
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