mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Felipe Balbi <balbi@ti.com>
To: David Laight <David.Laight@ACULAB.COM>
Cc: "'Robert Baldyga'" <r.baldyga@samsung.com>,
	"balbi@ti.com" <balbi@ti.com>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"m.szyprowski@samsung.com" <m.szyprowski@samsung.com>,
	"andrzej.p@samsung.com" <andrzej.p@samsung.com>
Subject: Re: [PATCH] usb: gadget: composite: unlock spinlock before usb_gadget_disconnect()
Date: Thu, 19 Jun 2014 08:48:05 -0500	[thread overview]
Message-ID: <20140619134805.GC23782@saruman.home> (raw)
In-Reply-To: <063D6719AE5E284EB5DD2968C1650D6D1725C37A@AcuExch.aculab.com>

[-- Attachment #1: Type: text/plain, Size: 1246 bytes --]

On Fri, Jun 13, 2014 at 11:36:24AM +0000, David Laight wrote:
> From: Robert Baldyga
> > usb_gadget_disconnect() shouldn't be called under spinlock to avoid
> > spinlock recursion. Function usb_gadget_disconnect() calls pullup(),
> > which is callback from UDC driver, usually calling composite_disconnect().
> > This function wants to lock spinlock used in usb_function_deactivate()
> > causing spinlock recursion.
> ...
> > +++ b/drivers/usb/gadget/composite.c
> > @@ -260,8 +260,11 @@ int usb_function_deactivate(struct usb_function *function)
> > 
> >  	spin_lock_irqsave(&cdev->lock, flags);
> > 
> > -	if (cdev->deactivations == 0)
> > +	if (cdev->deactivations == 0) {
> > +		spin_unlock_irqrestore(&cdev->lock, flags);
> >  		status = usb_gadget_disconnect(cdev->gadget);
> > +		spin_lock_irqsave(&cdev->lock, flags);
> > +	}
> >  	if (status == 0)
> >  		cdev->deactivations++;
> 
> That sort of change rings big alarm bells.
> You've effectively isolated the usb_gadget_disconnect() call
> from the check that cdev->deactivations == 0.
> And then you increment cdev->deactivations below.
> 
> Looks like it will be racy to me.

yes, it will. Fixing this requires a much more involved change.

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

      reply	other threads:[~2014-06-19 13:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-13 11:28 Robert Baldyga
2014-06-13 11:36 ` David Laight
2014-06-19 13:48   ` Felipe Balbi [this message]

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=20140619134805.GC23782@saruman.home \
    --to=balbi@ti.com \
    --cc=David.Laight@ACULAB.COM \
    --cc=andrzej.p@samsung.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=r.baldyga@samsung.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®