From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Paul Elder <paul.elder@pitt.edu>,
linux-usb@vger.kernel.org, Roger Quadros <rogerq@ti.com>,
Felipe Balbi <balbi@kernel.org>
Subject: [2/4] usb: gadget: composite: add function to increment delayed_status
Date: Sat, 21 Apr 2018 14:00:05 +0300 [thread overview]
Message-ID: <2658992.BJfkddU6Jz@avalon> (raw)
Hi Alan,
On Friday, 20 April 2018 17:09:57 EEST Alan Stern wrote:
> On Thu, 19 Apr 2018, Laurent Pinchart wrote:
> > According to include/linux/usb/composite.h, the delayed_status field
> > should be protected by cdev->lock, which you should use here.
> >
> > I've read through the code and found out that, while all callers of
> > reset_config(), as well as usb_composite_setup_continue(), correctly take
> > the lock, it isn't taken around f->set_alt() in composite_setup(). This
> > causes the race condition. I wonder if a simpler fix wouldn't be to take
> > the lock before calling f->set_alt() and releasing it after incrementing
> > delayed_status. I am however worried that this could lead to deadlocks if
> > one of the existing set_alt() handlers calls a function that takes the
> > same lock. Another worry is that some of the .set_alt() handlers might
> > not expect to be called with interrupts disabled. This should be
> > analyzed, and I hope that Roger and/or Felipe will have some insight on
> > this.
>
> set_alt handlers generally have to disable and enable endpoints, which
> requires a process context. They cannot run with interrupts disabled.
Thank you for the information. Isn't the following code path problematic then
?
int
composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
{
...
case USB_REQ_SET_CONFIGURATION:
...
spin_lock(&cdev->lock);
value = set_config(cdev, ctrl, w_value);
spin_unlock(&cdev->lock);
...
}
static int set_config(struct usb_composite_dev *cdev,
const struct usb_ctrlrequest *ctrl, unsigned number)
{
...
/* Initialize all interfaces by setting them to altsetting zero. */
for (tmp = 0; tmp < MAX_CONFIG_INTERFACES; tmp++) {
...
result = f->set_alt(f, tmp, 0);
...
}
next reply other threads:[~2018-04-21 11:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-21 11:00 Laurent Pinchart [this message]
-- strict thread matches above, loose matches on Subject: below --
2018-04-21 15:38 [2/4] usb: gadget: composite: add function to increment delayed_status Alan Stern
2018-04-20 14:51 Roger Quadros
2018-04-20 14:09 Alan Stern
2018-04-19 19:42 Laurent Pinchart
2018-04-18 3:18 Paul Elder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2658992.BJfkddU6Jz@avalon \
--to=laurent.pinchart@ideasonboard.com \
--cc=balbi@kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=paul.elder@pitt.edu \
--cc=rogerq@ti.com \
--cc=stern@rowland.harvard.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.