mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] usb: hub: wrong order of putting interfaces when processing hub events
@ 2014-09-12 12:20 Petr Mladek
  2014-09-12 14:06 ` Alan Stern
  0 siblings, 1 reply; 3+ messages in thread
From: Petr Mladek @ 2014-09-12 12:20 UTC (permalink / raw)
  To: Alan Stern, Greg Kroah-Hartman
  Cc: Tejun Heo, Joe Lawrence, Jiri Kosina, linux-usb, linux-kernel,
	Petr Mladek

usb_autopm_put_interface() must be called only when usb_autopm_get_interface()
succeeded before. There was wrong ordering of the goto targets.

The funny thing is that the names of the goto targets and the related comments
were correct.

Signed-off-by: Petr Mladek <pmladek@suse.cz>
---
 drivers/usb/core/hub.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index d481c99a20d7..6afd79ee3340 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -5132,12 +5132,12 @@ static void hub_events(void)
 
  loop_autopm:
 		/* Balance the usb_autopm_get_interface() above */
-		usb_autopm_put_interface_no_suspend(intf);
+		usb_autopm_put_interface(intf);
  loop:
 		/* Balance the usb_autopm_get_interface_no_resume() in
 		 * kick_khubd() and allow autosuspend.
 		 */
-		usb_autopm_put_interface(intf);
+		usb_autopm_put_interface_no_suspend(intf);
  loop_disconnected:
 		usb_unlock_device(hdev);
 		usb_put_dev(hdev);
-- 
1.8.4


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: hub: wrong order of putting interfaces when processing hub events
  2014-09-12 12:20 [PATCH] usb: hub: wrong order of putting interfaces when processing hub events Petr Mladek
@ 2014-09-12 14:06 ` Alan Stern
  2014-09-12 14:21   ` Petr Mladek
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Stern @ 2014-09-12 14:06 UTC (permalink / raw)
  To: Petr Mladek
  Cc: Greg Kroah-Hartman, Tejun Heo, Joe Lawrence, Jiri Kosina,
	linux-usb, linux-kernel

On Fri, 12 Sep 2014, Petr Mladek wrote:

> usb_autopm_put_interface() must be called only when usb_autopm_get_interface()
> succeeded before. There was wrong ordering of the goto targets.

No, you are wrong.  The code is correct as it stands.

> The funny thing is that the names of the goto targets and the related comments
> were correct.

That's because the whole thing is correct.  Go back and read the 
comments more carefully -- especially the comment following the "loop:" 
label.

> Signed-off-by: Petr Mladek <pmladek@suse.cz>
> ---
>  drivers/usb/core/hub.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
> index d481c99a20d7..6afd79ee3340 100644
> --- a/drivers/usb/core/hub.c
> +++ b/drivers/usb/core/hub.c
> @@ -5132,12 +5132,12 @@ static void hub_events(void)
>  
>   loop_autopm:
>  		/* Balance the usb_autopm_get_interface() above */
> -		usb_autopm_put_interface_no_suspend(intf);
> +		usb_autopm_put_interface(intf);

There's no point to this change.  Now this call will decrement the
usage counter and try to suspend -- but the suspend is bound to fail
because the usage counter is still > 0.

>   loop:
>  		/* Balance the usb_autopm_get_interface_no_resume() in
>  		 * kick_khubd() and allow autosuspend.
>  		 */
> -		usb_autopm_put_interface(intf);
> +		usb_autopm_put_interface_no_suspend(intf);

And now this call will decrement the usage counter down to 0, but won't 
try to suspend -- so the hub won't autosuspend at all!

>   loop_disconnected:
>  		usb_unlock_device(hdev);
>  		usb_put_dev(hdev);

Alan Stern


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: hub: wrong order of putting interfaces when processing hub events
  2014-09-12 14:06 ` Alan Stern
@ 2014-09-12 14:21   ` Petr Mladek
  0 siblings, 0 replies; 3+ messages in thread
From: Petr Mladek @ 2014-09-12 14:21 UTC (permalink / raw)
  To: Alan Stern
  Cc: Greg Kroah-Hartman, Tejun Heo, Joe Lawrence, Jiri Kosina,
	linux-usb, linux-kernel

On Fri 2014-09-12 10:06:03, Alan Stern wrote:
> On Fri, 12 Sep 2014, Petr Mladek wrote:
> 
> > usb_autopm_put_interface() must be called only when usb_autopm_get_interface()
> > succeeded before. There was wrong ordering of the goto targets.
> 
> No, you are wrong.  The code is correct as it stands.
> 
> > The funny thing is that the names of the goto targets and the related comments
> > were correct.
> 
> That's because the whole thing is correct.  Go back and read the 
> comments more carefully -- especially the comment following the "loop:" 
> label.
> 
> > Signed-off-by: Petr Mladek <pmladek@suse.cz>
> > ---
> >  drivers/usb/core/hub.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
> > index d481c99a20d7..6afd79ee3340 100644
> > --- a/drivers/usb/core/hub.c
> > +++ b/drivers/usb/core/hub.c
> > @@ -5132,12 +5132,12 @@ static void hub_events(void)
> >  
> >   loop_autopm:
> >  		/* Balance the usb_autopm_get_interface() above */
> > -		usb_autopm_put_interface_no_suspend(intf);
> > +		usb_autopm_put_interface(intf);
> 
> There's no point to this change.  Now this call will decrement the
> usage counter and try to suspend -- but the suspend is bound to fail
> because the usage counter is still > 0.
> 
> >   loop:
> >  		/* Balance the usb_autopm_get_interface_no_resume() in
> >  		 * kick_khubd() and allow autosuspend.
> >  		 */
> > -		usb_autopm_put_interface(intf);
> > +		usb_autopm_put_interface_no_suspend(intf);
> 
> And now this call will decrement the usage counter down to 0, but won't 
> try to suspend -- so the hub won't autosuspend at all!

Ah, shame on me. It makes perfect sense. I was more focused on the
kthread/workqueue conversion and function of the locks. I should have
thought more about this as well :-(

It means that the patchset "usb: hub: convert khubd into workqueue"
needs refreshing. But I will wait for some feedback first.


Best Regards,
Petr

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-09-12 14:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-12 12:20 [PATCH] usb: hub: wrong order of putting interfaces when processing hub events Petr Mladek
2014-09-12 14:06 ` Alan Stern
2014-09-12 14:21   ` Petr Mladek

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®