> To: Felipe Balbi <balbi@xxxxxxxxxx>; Greg Kroah-Hartman > <gregkh@xxxxxxxxxxxxxxxxxxx>; linux-usb@xxxxxxxxxxxxxxx; Peter Chen > <peter.chen@xxxxxxx>; Lee Jones <lee.jones@xxxxxxxxxx>; Alan Stern > <stern@xxxxxxxxxxxxxxxxxxx>; Thomas Gleixner <tglx@xxxxxxxxxxxxx>; Dejin > Zheng <zhengdejin5@xxxxxxxxx>; Sebastian Andrzej Siewior > <bigeasy@xxxxxxxxxxxxx>; Ahmed S. Darwish <a.darwish@xxxxxxxxxxxxx>; > Marek Szyprowski <m.szyprowski@xxxxxxxxxxx>; Michal Nazarewicz > <mina86@xxxxxxxxxx> > Cc: stable@xxxxxxxxxxxxxxx > Subject: [PATCH] usb: udc: core: Use lock for soft_connect > > Use lock to guard against concurrent access for soft-connect/disconnect > operations when writing to soft_connect sysfs. > > Cc: stable@xxxxxxxxxxxxxxx > Fixes: 2ccea03a8f7e ("usb: gadget: introduce UDC Class") > Signed-off-by: Thinh Nguyen <Thinh.Nguyen@xxxxxxxxxxxx> Reviewed-by: Peter Chen <peter.chen@xxxxxxxxxx> Peter > --- > drivers/usb/gadget/udc/core.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c > index 6a62bbd01324..44c67e765167 100644 > --- a/drivers/usb/gadget/udc/core.c > +++ b/drivers/usb/gadget/udc/core.c > @@ -1530,7 +1530,9 @@ static ssize_t soft_connect_store(struct device *dev, > { > struct usb_udc *udc = container_of(dev, struct usb_udc, dev); > > + mutex_lock(&udc_lock); > if (!udc->driver) { > + mutex_unlock(&udc_lock); > dev_err(dev, "soft-connect without a gadget driver\n"); > return -EOPNOTSUPP; > } > @@ -1542,10 +1544,12 @@ static ssize_t soft_connect_store(struct device > *dev, > usb_gadget_disconnect(udc->gadget); > usb_gadget_udc_stop(udc); > } else { > + mutex_unlock(&udc_lock); > dev_err(dev, "unsupported command '%s'\n", buf); > return -EINVAL; > } > > + mutex_unlock(&udc_lock); > return n; > } > static DEVICE_ATTR_WO(soft_connect); > > base-commit: 4e0dcf62ab4cf917d0cbe751b8bf229a065248d4 > -- > 2.28.0