Skip to content

Commit c28095b

Browse files
Thinh Nguyengregkh
authored andcommitted
usb: udc: core: Use lock when write to soft_connect
Use lock to guard against concurrent access for soft-connect/disconnect operations when writing to soft_connect sysfs. Fixes: 2ccea03 ("usb: gadget: introduce UDC Class") Cc: [email protected] Acked-by: Felipe Balbi <[email protected]> Signed-off-by: Thinh Nguyen <[email protected]> Link: https://lore.kernel.org/r/338ea01fbd69b1985ef58f0f59af02c805ddf189.1610611437.git.Thinh.Nguyen@synopsys.com Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6e6aa61 commit c28095b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

drivers/usb/gadget/udc/core.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,10 +1529,13 @@ static ssize_t soft_connect_store(struct device *dev,
15291529
struct device_attribute *attr, const char *buf, size_t n)
15301530
{
15311531
struct usb_udc *udc = container_of(dev, struct usb_udc, dev);
1532+
ssize_t ret;
15321533

1534+
mutex_lock(&udc_lock);
15331535
if (!udc->driver) {
15341536
dev_err(dev, "soft-connect without a gadget driver\n");
1535-
return -EOPNOTSUPP;
1537+
ret = -EOPNOTSUPP;
1538+
goto out;
15361539
}
15371540

15381541
if (sysfs_streq(buf, "connect")) {
@@ -1543,10 +1546,14 @@ static ssize_t soft_connect_store(struct device *dev,
15431546
usb_gadget_udc_stop(udc);
15441547
} else {
15451548
dev_err(dev, "unsupported command '%s'\n", buf);
1546-
return -EINVAL;
1549+
ret = -EINVAL;
1550+
goto out;
15471551
}
15481552

1549-
return n;
1553+
ret = n;
1554+
out:
1555+
mutex_unlock(&udc_lock);
1556+
return ret;
15501557
}
15511558
static DEVICE_ATTR_WO(soft_connect);
15521559

0 commit comments

Comments
 (0)