All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] usb: udc: core: Use lock when write to soft_connect
@ 2021-01-14  3:38 Thinh Nguyen
  2021-01-14  6:41 ` Ahmed S. Darwish
  2021-01-14  8:56 ` Felipe Balbi
  0 siblings, 2 replies; 5+ messages in thread
From: Thinh Nguyen @ 2021-01-14  3:38 UTC (permalink / raw)
  To: Felipe Balbi, Greg Kroah-Hartman, linux-usb, Peter Chen,
	Lee Jones, Alan Stern, Dejin Zheng, Sebastian Andrzej Siewior,
	Ahmed S. Darwish, Michal Nazarewicz
  Cc: stable

Use lock to guard against concurrent access for soft-connect/disconnect
operations when writing to soft_connect sysfs.

Cc: stable@vger.kernel.org
Fixes: 2ccea03a8f7e ("usb: gadget: introduce UDC Class")
Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
---
 Changes in v2:
 - Consolidate mutex_unlock to a single place using "goto out"

 drivers/usb/gadget/udc/core.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
index 6a62bbd01324..3363f5c282f1 100644
--- a/drivers/usb/gadget/udc/core.c
+++ b/drivers/usb/gadget/udc/core.c
@@ -1529,10 +1529,13 @@ static ssize_t soft_connect_store(struct device *dev,
 		struct device_attribute *attr, const char *buf, size_t n)
 {
 	struct usb_udc		*udc = container_of(dev, struct usb_udc, dev);
+	ssize_t			ret = n;
 
+	mutex_lock(&udc_lock);
 	if (!udc->driver) {
 		dev_err(dev, "soft-connect without a gadget driver\n");
-		return -EOPNOTSUPP;
+		ret = -EOPNOTSUPP;
+		goto out;
 	}
 
 	if (sysfs_streq(buf, "connect")) {
@@ -1543,10 +1546,12 @@ static ssize_t soft_connect_store(struct device *dev,
 		usb_gadget_udc_stop(udc);
 	} else {
 		dev_err(dev, "unsupported command '%s'\n", buf);
-		return -EINVAL;
+		ret = -EINVAL;
 	}
 
-	return n;
+out:
+	mutex_unlock(&udc_lock);
+	return ret;
 }
 static DEVICE_ATTR_WO(soft_connect);
 

base-commit: 4e0dcf62ab4cf917d0cbe751b8bf229a065248d4
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-01-14  9:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-14  3:38 [PATCH v2] usb: udc: core: Use lock when write to soft_connect Thinh Nguyen
2021-01-14  6:41 ` Ahmed S. Darwish
     [not found]   ` <CAHp75Vf3eZjg20QEr6YqdY7R1Eu=D2za+sKb0vVBaAmETg1z4Q@mail.gmail.com>
2021-01-14  8:00     ` Thinh Nguyen
2021-01-14  9:06     ` Greg Kroah-Hartman
2021-01-14  8:56 ` Felipe Balbi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.