linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: Michal Nazarewicz <mina86@mina86.com>
Cc: Wei.Yang@windriver.com, <balbi@ti.com>, <andrzej.p@samsung.com>,
	<linux-usb@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3] USB:gadget: Fix a warning while loading g_mass_storage
Date: Fri, 13 Jun 2014 09:43:00 -0400 (EDT)	[thread overview]
Message-ID: <Pine.LNX.4.44L0.1406130939540.1059-100000@iolanthe.rowland.org> (raw)
In-Reply-To: <xa1td2ednnxo.fsf@mina86.com>

On Fri, 13 Jun 2014, Michal Nazarewicz wrote:

> > The root cause is that the existing code fails to take into
> > account the possibility that common->new_fsg can change while
> > do_set_interface() is running, because the spinlock isn't held
> > at this point.
> 
> common->new_fsg is not protected by common->lock so this justification
> is not valid.

That's true.  A better justification would be that the same value of 
new_fsg should be used in do_set_interface() and in the test that 
follows.

> > @@ -2421,6 +2422,7 @@ static void handle_exception(struct fsg_common *common)
> >  		}
> >  		common->state = FSG_STATE_IDLE;
> >  	}
> > +	new_fsg = common->new_fsg;
> 
> Also, because common->new_fsg is not protected by common->lock, doing
> this under a lock is kinda pointless.

Yes, but it doesn't hurt.

> >  	spin_unlock_irq(&common->lock);
> >  
> >  	/* Carry out any extra actions required for the exception */
> > @@ -2460,8 +2462,8 @@ static void handle_exception(struct fsg_common *common)
> >  		break;
> >  
> >  	case FSG_STATE_CONFIG_CHANGE:
> > -		do_set_interface(common, common->new_fsg);
> > -		if (common->new_fsg)
> > +		do_set_interface(common, new_fsg);
> > +		if (new_fsg)
> >  			usb_composite_setup_continue(common->cdev);
> 
> As far as I can tell, it's safe to move the assignment to new_fsg here,
> e.g.:
> 
> 		new_fsg = common->new_fsg;
> 		do_set_interface(common, new_fsg);
> 		if (new_fsg)
> 			usb_composite_setup_continue(common->cdev);

That would be equally correct.  I don't see any strong reason for 
preferring one over the other.

> >  		break;
> 
> But perhaps new_fsg should be protected by the lock.  I think valid fix
> (which I did not test in *any* way) will be this:

No, I think this change is both too big and unnecessary.  
common->new_fsg does not need protection; in a sense it is "owned" by 
the composite driver.

Alan Stern


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

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-03  9:37 [PATCH v1] USB:gadget: Fix a warning while loading g_mass_storage Wei.Yang
2014-06-03 14:48 ` Alan Stern
2014-06-04  1:20   ` Yang,Wei
2014-06-04  1:45     ` Peter Chen
2014-06-04  3:16       ` Yang,Wei
2014-06-04  4:41         ` Peter Chen
2014-06-04 13:56         ` Alan Stern
2014-06-04 18:48           ` Paul Zimmerman
2014-06-05  1:30           ` Peter Chen
2014-06-05 14:21             ` Alan Stern
2014-06-04  2:34     ` Yang,Wei
2014-06-04 12:06   ` Andrzej Pietrasiewicz
2014-06-04 15:26     ` Alan Stern
2014-06-05 10:00       ` Andrzej Pietrasiewicz
2014-06-05 18:10         ` Alan Stern
2014-06-04  4:32 ` [PATCH v2] " Wei.Yang
2014-06-05 18:08   ` Alan Stern
2014-06-09  6:02     ` Yang,Wei
2014-06-09  6:19   ` [PATCH v3] " Wei.Yang
2014-06-13  6:22     ` Yang,Wei
2014-06-13 13:39       ` Alan Stern
2014-06-14 13:10         ` Yang,Wei
2014-06-13  9:44     ` Michal Nazarewicz
2014-06-13 13:43       ` Alan Stern [this message]
2014-06-13 14:57         ` Michal Nazarewicz
2014-06-15  2:40   ` [PATCH] " Wei.Yang
2014-06-15  2:42     ` Yang,Wei
2014-06-17  5:59       ` Yang,Wei
2014-06-17 14:18         ` Alan Stern
2014-06-18  1:08           ` Yang,Wei
2014-06-18 11:44             ` Michal Nazarewicz
2014-06-18 14:22               ` Alan Stern
2014-06-19  1:48               ` Yang,Wei
2014-06-17 18:20     ` Michal Nazarewicz

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=Pine.LNX.4.44L0.1406130939540.1059-100000@iolanthe.rowland.org \
    --to=stern@rowland.harvard.edu \
    --cc=Wei.Yang@windriver.com \
    --cc=andrzej.p@samsung.com \
    --cc=balbi@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mina86@mina86.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;
as well as URLs for NNTP newsgroup(s).