linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] USB: apple-mfi-fastcharge: fix reference leak in apple_mfi_fc_set_property
@ 2020-10-31 10:11 Zhang Qilong
  2020-10-31 10:16 ` Greg KH
  2020-10-31 10:48 ` Johan Hovold
  0 siblings, 2 replies; 3+ messages in thread
From: Zhang Qilong @ 2020-10-31 10:11 UTC (permalink / raw)
  To: hadess, gregkh; +Cc: linux-usb

pm_runtime_get_sync() will increment pm usage at first and it
will resume the device later. If runtime of the device is
active or has error(else....), resume operation will fail. If
we do not call put operation to decrease the reference, the
result is that this device cannot enter the idle state and
always stay busy or other non-idle state.

Fixes: 249fa8217b846 ("USB: Add driver to control USB fast charge for iOS devices")
Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
---
 drivers/usb/misc/apple-mfi-fastcharge.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/misc/apple-mfi-fastcharge.c b/drivers/usb/misc/apple-mfi-fastcharge.c
index b403094a6b3a..9e1ad4536e36 100644
--- a/drivers/usb/misc/apple-mfi-fastcharge.c
+++ b/drivers/usb/misc/apple-mfi-fastcharge.c
@@ -120,8 +120,10 @@ static int apple_mfi_fc_set_property(struct power_supply *psy,
 	dev_dbg(&mfi->udev->dev, "prop: %d\n", psp);
 
 	ret = pm_runtime_get_sync(&mfi->udev->dev);
-	if (ret < 0)
+	if (ret < 0) {
+		pm_runtime_put_noidle(&mfi->udev->dev);
 		return ret;
+	}
 
 	switch (psp) {
 	case POWER_SUPPLY_PROP_CHARGE_TYPE:
-- 
2.17.1


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

* Re: [PATCH v2] USB: apple-mfi-fastcharge: fix reference leak in apple_mfi_fc_set_property
  2020-10-31 10:11 [PATCH v2] USB: apple-mfi-fastcharge: fix reference leak in apple_mfi_fc_set_property Zhang Qilong
@ 2020-10-31 10:16 ` Greg KH
  2020-10-31 10:48 ` Johan Hovold
  1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2020-10-31 10:16 UTC (permalink / raw)
  To: Zhang Qilong; +Cc: hadess, linux-usb

On Sat, Oct 31, 2020 at 06:11:44PM +0800, Zhang Qilong wrote:
> pm_runtime_get_sync() will increment pm usage at first and it
> will resume the device later. If runtime of the device is
> active or has error(else....), resume operation will fail. If
> we do not call put operation to decrease the reference, the
> result is that this device cannot enter the idle state and
> always stay busy or other non-idle state.
> 
> Fixes: 249fa8217b846 ("USB: Add driver to control USB fast charge for iOS devices")
> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
> ---
>  drivers/usb/misc/apple-mfi-fastcharge.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

What changed from v1?  Always put that below the --- line.

Can you fix that up and send a v3?

thanks,

greg k-h

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

* Re: [PATCH v2] USB: apple-mfi-fastcharge: fix reference leak in apple_mfi_fc_set_property
  2020-10-31 10:11 [PATCH v2] USB: apple-mfi-fastcharge: fix reference leak in apple_mfi_fc_set_property Zhang Qilong
  2020-10-31 10:16 ` Greg KH
@ 2020-10-31 10:48 ` Johan Hovold
  1 sibling, 0 replies; 3+ messages in thread
From: Johan Hovold @ 2020-10-31 10:48 UTC (permalink / raw)
  To: Zhang Qilong; +Cc: hadess, gregkh, linux-usb

On Sat, Oct 31, 2020 at 06:11:44PM +0800, Zhang Qilong wrote:
> pm_runtime_get_sync() will increment pm usage at first and it
> will resume the device later. If runtime of the device is
> active or has error(else....), resume operation will fail. 

That's not a correct description; pm_runtime_get_sync() returns positive
if the device was already active and that's not a failure (there's
nothing to resume).

Please fix up when resending.

> If
> we do not call put operation to decrease the reference, the
> result is that this device cannot enter the idle state and
> always stay busy or other non-idle state.
> 
> Fixes: 249fa8217b846 ("USB: Add driver to control USB fast charge for iOS devices")
> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
> ---
>  drivers/usb/misc/apple-mfi-fastcharge.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/misc/apple-mfi-fastcharge.c b/drivers/usb/misc/apple-mfi-fastcharge.c
> index b403094a6b3a..9e1ad4536e36 100644
> --- a/drivers/usb/misc/apple-mfi-fastcharge.c
> +++ b/drivers/usb/misc/apple-mfi-fastcharge.c
> @@ -120,8 +120,10 @@ static int apple_mfi_fc_set_property(struct power_supply *psy,
>  	dev_dbg(&mfi->udev->dev, "prop: %d\n", psp);
>  
>  	ret = pm_runtime_get_sync(&mfi->udev->dev);
> -	if (ret < 0)
> +	if (ret < 0) {
> +		pm_runtime_put_noidle(&mfi->udev->dev);
>  		return ret;
> +	}
>  
>  	switch (psp) {
>  	case POWER_SUPPLY_PROP_CHARGE_TYPE:

Johan

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

end of thread, other threads:[~2020-10-31 10:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-31 10:11 [PATCH v2] USB: apple-mfi-fastcharge: fix reference leak in apple_mfi_fc_set_property Zhang Qilong
2020-10-31 10:16 ` Greg KH
2020-10-31 10:48 ` Johan Hovold

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