1
0
Fork 0

usb: udc: core: Use lock when write to soft_connect

commit c28095bc99 upstream.

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

Fixes: 2ccea03a8f ("usb: gadget: introduce UDC Class")
Cc: stable@vger.kernel.org
Acked-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Link: https://lore.kernel.org/r/338ea01fbd69b1985ef58f0f59af02c805ddf189.1610611437.git.Thinh.Nguyen@synopsys.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
5.4-rM2-2.2.x-imx-squashed
Thinh Nguyen 2021-01-14 00:09:51 -08:00 committed by Greg Kroah-Hartman
parent 564f3c5326
commit f764f90b0c
1 changed files with 10 additions and 3 deletions

View File

@ -1477,10 +1477,13 @@ static ssize_t soft_connect_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t n) struct device_attribute *attr, const char *buf, size_t n)
{ {
struct usb_udc *udc = container_of(dev, struct usb_udc, dev); struct usb_udc *udc = container_of(dev, struct usb_udc, dev);
ssize_t ret;
mutex_lock(&udc_lock);
if (!udc->driver) { if (!udc->driver) {
dev_err(dev, "soft-connect without a gadget driver\n"); dev_err(dev, "soft-connect without a gadget driver\n");
return -EOPNOTSUPP; ret = -EOPNOTSUPP;
goto out;
} }
if (sysfs_streq(buf, "connect")) { if (sysfs_streq(buf, "connect")) {
@ -1491,10 +1494,14 @@ static ssize_t soft_connect_store(struct device *dev,
usb_gadget_udc_stop(udc); usb_gadget_udc_stop(udc);
} else { } else {
dev_err(dev, "unsupported command '%s'\n", buf); dev_err(dev, "unsupported command '%s'\n", buf);
return -EINVAL; ret = -EINVAL;
goto out;
} }
return n; ret = n;
out:
mutex_unlock(&udc_lock);
return ret;
} }
static DEVICE_ATTR_WO(soft_connect); static DEVICE_ATTR_WO(soft_connect);