Commit d0106939 authored by Chunfeng Yun's avatar Chunfeng Yun Committed by Kleber Sacilotto de Souza

usb: gadget: composite: fix delayed_status race condition when set_interface

BugLink: https://bugs.launchpad.net/bugs/1792377

[ Upstream commit 980900d6 ]

It happens when enable debug log, if set_alt() returns
USB_GADGET_DELAYED_STATUS and usb_composite_setup_continue()
is called before increasing count of @delayed_status,
so fix it by using spinlock of @cdev->lock.
Signed-off-by: default avatarChunfeng Yun <chunfeng.yun@mediatek.com>
Tested-by: default avatarJay Hsu <shih-chieh.hsu@mediatek.com>
Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarStefan Bader <stefan.bader@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent 391387ff
...@@ -1619,6 +1619,8 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) ...@@ -1619,6 +1619,8 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
*/ */
if (w_value && !f->get_alt) if (w_value && !f->get_alt)
break; break;
spin_lock(&cdev->lock);
value = f->set_alt(f, w_index, w_value); value = f->set_alt(f, w_index, w_value);
if (value == USB_GADGET_DELAYED_STATUS) { if (value == USB_GADGET_DELAYED_STATUS) {
DBG(cdev, DBG(cdev,
...@@ -1628,6 +1630,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) ...@@ -1628,6 +1630,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
DBG(cdev, "delayed_status count %d\n", DBG(cdev, "delayed_status count %d\n",
cdev->delayed_status); cdev->delayed_status);
} }
spin_unlock(&cdev->lock);
break; break;
case USB_REQ_GET_INTERFACE: case USB_REQ_GET_INTERFACE:
if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE)) if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment