mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: Yinbo Zhu <zhuyinbo@loongson.cn>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	Greg Kroah-Hartman <greg@kroah.com>,
	Patchwork Bot <patchwork-bot@kernel.org>
Subject: Re: [PATCH v2] usb: ohci-platform: fix usb disconnect issue after s4
Date: Wed, 31 Aug 2022 10:31:18 -0400	[thread overview]
Message-ID: <Yw9wtv5TtEr209j0@rowland.harvard.edu> (raw)
In-Reply-To: <20220831045910.12203-1-zhuyinbo@loongson.cn>

On Wed, Aug 31, 2022 at 12:59:10PM +0800, Yinbo Zhu wrote:
> Avoid retaining bogus hardware states during resume-from-hibernation.
> Previously we had reset the hardware as part of preparing to reinstate
> the snapshot image. But we can do better now with the new PM framework,
> since we know exactly which resume operations are from hibernation.
> 
> According to the commit 'cd1965db054e ("USB: ohci: move ohci_pci_{
> suspend,resume} to ohci-hcd.c")' and commit '6ec4beb5c701 ("USB: new
> flag for resume-from-hibernation")', the flag "hibernated" is for
> resume-from-hibernation and it should be true when usb resume from disk.
> 
> When this flag "hibernated" is set, the drivers will reset the hardware
> to get rid of any existing state and make sure resume from hibernation
> re-enumerates everything for ohci.
> 
> Signed-off-by: Yinbo Zhu <zhuyinbo@loongson.cn>
> ---
> Change in v2:
> 		1. Revise the commit log infomation.	
> 		2. Wrap the ohci_platform_renew() function with two 
> 		   helpers that are ohci_platform_renew_hibernated() 
> 		   and ohci_platform_renew().
> 
>  drivers/usb/host/ohci-platform.c | 49 ++++++++++++++++++++++++++++++--
>  1 file changed, 46 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/host/ohci-platform.c b/drivers/usb/host/ohci-platform.c
> index 0adae6265127..56cb424d3bb0 100644
> --- a/drivers/usb/host/ohci-platform.c
> +++ b/drivers/usb/host/ohci-platform.c
> @@ -289,7 +289,7 @@ static int ohci_platform_suspend(struct device *dev)
>  	return ret;
>  }
>  
> -static int ohci_platform_resume(struct device *dev)
> +static int ohci_platform_renew(struct device *dev)
>  {
>  	struct usb_hcd *hcd = dev_get_drvdata(dev);
>  	struct usb_ohci_pdata *pdata = dev_get_platdata(dev);
> @@ -297,6 +297,7 @@ static int ohci_platform_resume(struct device *dev)
>  
>  	if (pdata->power_on) {
>  		int err = pdata->power_on(pdev);
> +
>  		if (err < 0)
>  			return err;
>  	}
> @@ -309,6 +310,38 @@ static int ohci_platform_resume(struct device *dev)
>  
>  	return 0;
>  }
> +
> +static int ohci_platform_renew_hibernated(struct device *dev)
> +{
> +	struct usb_hcd *hcd = dev_get_drvdata(dev);
> +	struct usb_ohci_pdata *pdata = dev_get_platdata(dev);
> +	struct platform_device *pdev = to_platform_device(dev);
> +
> +	if (pdata->power_on) {
> +		int err = pdata->power_on(pdev);
> +
> +		if (err < 0)
> +			return err;
> +	}
> +
> +	ohci_resume(hcd, true);
> +
> +	pm_runtime_disable(dev);
> +	pm_runtime_set_active(dev);
> +	pm_runtime_enable(dev);
> +
> +	return 0;
> +}
> +
> +static int ohci_platform_resume(struct device *dev)
> +{
> +	return ohci_platform_renew(dev);
> +}
> +
> +static int ohci_platform_restore(struct device *dev)
> +{
> +	return ohci_platform_renew_hibernated(dev);
> +}

I really do not see any point in these helper routines.  Why not just 
use these names (ohci_platform_resume and ohci_platform_restore) for the 
actual routines and forget about the _renew names?

Although if it were me, I'd do it more like this:

static int ohci_platform_resume_common(struct device *dev, bool hibernated)
{ ... }

static int ohci_platform_resume(struct device *dev)
{
	return ohci_platform_resume_common(dev, false);
}

static int ohci_platform_restore(struct device *dev)
{
	return ohci_platform_resume_common(dev, true);
}

Alan Stern

      reply	other threads:[~2022-08-31 14:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-31  4:59 Yinbo Zhu
2022-08-31 14:31 ` Alan Stern [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=Yw9wtv5TtEr209j0@rowland.harvard.edu \
    --to=stern@rowland.harvard.edu \
    --cc=greg@kroah.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=patchwork-bot@kernel.org \
    --cc=zhuyinbo@loongson.cn \
    /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®