linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: musb: Fix runtime PM imbalance on error
@ 2020-05-21  7:35 Dinghao Liu
  2020-05-21 20:37 ` Bin Liu
  0 siblings, 1 reply; 3+ messages in thread
From: Dinghao Liu @ 2020-05-21  7:35 UTC (permalink / raw)
  To: dinghao.liu, kjlu; +Cc: Bin Liu, Greg Kroah-Hartman, linux-usb, linux-kernel

When copy_from_user() returns an error code, a pairing
runtime PM usage counter decrement is needed to keep
the counter balanced.

Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---
 drivers/usb/musb/musb_debugfs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/musb/musb_debugfs.c b/drivers/usb/musb/musb_debugfs.c
index 7b6281ab62ed..837c38a5e4ef 100644
--- a/drivers/usb/musb/musb_debugfs.c
+++ b/drivers/usb/musb/musb_debugfs.c
@@ -178,8 +178,11 @@ static ssize_t musb_test_mode_write(struct file *file,
 
 	memset(buf, 0x00, sizeof(buf));
 
-	if (copy_from_user(buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
+	if (copy_from_user(buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) {
+		pm_runtime_mark_last_busy(musb->controller);
+		pm_runtime_put_autosuspend(musb->controller);
 		return -EFAULT;
+	}
 
 	if (strstarts(buf, "force host full-speed"))
 		test = MUSB_TEST_FORCE_HOST | MUSB_TEST_FORCE_FS;
-- 
2.17.1


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

* Re: [PATCH] usb: musb: Fix runtime PM imbalance on error
  2020-05-21  7:35 [PATCH] usb: musb: Fix runtime PM imbalance on error Dinghao Liu
@ 2020-05-21 20:37 ` Bin Liu
  2020-05-22  1:23   ` dinghao.liu
  0 siblings, 1 reply; 3+ messages in thread
From: Bin Liu @ 2020-05-21 20:37 UTC (permalink / raw)
  To: Dinghao Liu; +Cc: kjlu, Greg Kroah-Hartman, linux-usb, linux-kernel

Hi,

On Thu, May 21, 2020 at 03:35:47PM +0800, Dinghao Liu wrote:
> When copy_from_user() returns an error code, a pairing
> runtime PM usage counter decrement is needed to keep
> the counter balanced.
> 
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> ---
>  drivers/usb/musb/musb_debugfs.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/musb/musb_debugfs.c b/drivers/usb/musb/musb_debugfs.c
> index 7b6281ab62ed..837c38a5e4ef 100644
> --- a/drivers/usb/musb/musb_debugfs.c
> +++ b/drivers/usb/musb/musb_debugfs.c
> @@ -178,8 +178,11 @@ static ssize_t musb_test_mode_write(struct file *file,
>  
>  	memset(buf, 0x00, sizeof(buf));
>  
> -	if (copy_from_user(buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
> +	if (copy_from_user(buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) {
> +		pm_runtime_mark_last_busy(musb->controller);
> +		pm_runtime_put_autosuspend(musb->controller);
>  		return -EFAULT;
> +	}

Thanks for catching the bug. Can you please instead move these lines to
the beginning of this function so that pm_runtime_get_sync() is not
called if copy_from_user() failed?

-Bin.

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

* Re: Re: [PATCH] usb: musb: Fix runtime PM imbalance on error
  2020-05-21 20:37 ` Bin Liu
@ 2020-05-22  1:23   ` dinghao.liu
  0 siblings, 0 replies; 3+ messages in thread
From: dinghao.liu @ 2020-05-22  1:23 UTC (permalink / raw)
  To: Bin Liu; +Cc: kjlu, Greg Kroah-Hartman, linux-usb, linux-kernel

Sure.

Regards,
Dinghao

> Hi,
> 
> On Thu, May 21, 2020 at 03:35:47PM +0800, Dinghao Liu wrote:
> > When copy_from_user() returns an error code, a pairing
> > runtime PM usage counter decrement is needed to keep
> > the counter balanced.
> > 
> > Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> > ---
> >  drivers/usb/musb/musb_debugfs.c | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/usb/musb/musb_debugfs.c b/drivers/usb/musb/musb_debugfs.c
> > index 7b6281ab62ed..837c38a5e4ef 100644
> > --- a/drivers/usb/musb/musb_debugfs.c
> > +++ b/drivers/usb/musb/musb_debugfs.c
> > @@ -178,8 +178,11 @@ static ssize_t musb_test_mode_write(struct file *file,
> >  
> >  	memset(buf, 0x00, sizeof(buf));
> >  
> > -	if (copy_from_user(buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
> > +	if (copy_from_user(buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) {
> > +		pm_runtime_mark_last_busy(musb->controller);
> > +		pm_runtime_put_autosuspend(musb->controller);
> >  		return -EFAULT;
> > +	}
> 
> Thanks for catching the bug. Can you please instead move these lines to
> the beginning of this function so that pm_runtime_get_sync() is not
> called if copy_from_user() failed?
> 
> -Bin.

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

end of thread, other threads:[~2020-05-22  1:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-21  7:35 [PATCH] usb: musb: Fix runtime PM imbalance on error Dinghao Liu
2020-05-21 20:37 ` Bin Liu
2020-05-22  1:23   ` dinghao.liu

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).