linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] USB: EHCI: ehci-mv: improve error handling in mv_ehci_enable()
@ 2021-07-08  8:30 Evgeny Novikov
  2021-07-08 13:40 ` Alan Stern
  0 siblings, 1 reply; 2+ messages in thread
From: Evgeny Novikov @ 2021-07-08  8:30 UTC (permalink / raw)
  To: Alan Stern
  Cc: Evgeny Novikov, Greg Kroah-Hartman, linux-usb, linux-kernel, ldv-project

mv_ehci_enable() did not disable and unprepare clocks in case of
failures of phy_init(). Besides, it did not take into account failures
of ehci_clock_enable() (in effect, failures of clk_prepare_enable()).
The patch fixes both issues and gets rid of redundant wrappers around
clk_prepare_enable() and clk_disable_unprepare() to simplify this a bit.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Evgeny Novikov <novikov@ispras.ru>
---
 drivers/usb/host/ehci-mv.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/host/ehci-mv.c b/drivers/usb/host/ehci-mv.c
index cffdc8d01b2a..8fd27249ad25 100644
--- a/drivers/usb/host/ehci-mv.c
+++ b/drivers/usb/host/ehci-mv.c
@@ -42,26 +42,25 @@ struct ehci_hcd_mv {
 	int (*set_vbus)(unsigned int vbus);
 };
 
-static void ehci_clock_enable(struct ehci_hcd_mv *ehci_mv)
+static int mv_ehci_enable(struct ehci_hcd_mv *ehci_mv)
 {
-	clk_prepare_enable(ehci_mv->clk);
-}
+	int retval;
 
-static void ehci_clock_disable(struct ehci_hcd_mv *ehci_mv)
-{
-	clk_disable_unprepare(ehci_mv->clk);
-}
+	retval = clk_prepare_enable(ehci_mv->clk);
+	if (retval)
+		return retval;
 
-static int mv_ehci_enable(struct ehci_hcd_mv *ehci_mv)
-{
-	ehci_clock_enable(ehci_mv);
-	return phy_init(ehci_mv->phy);
+	retval = phy_init(ehci_mv->phy);
+	if (retval)
+		clk_disable_unprepare(ehci_mv->clk);
+
+	return retval;
 }
 
 static void mv_ehci_disable(struct ehci_hcd_mv *ehci_mv)
 {
 	phy_exit(ehci_mv->phy);
-	ehci_clock_disable(ehci_mv);
+	clk_disable_unprepare(ehci_mv->clk);
 }
 
 static int mv_ehci_reset(struct usb_hcd *hcd)
-- 
2.26.2


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

* Re: [PATCH] USB: EHCI: ehci-mv: improve error handling in mv_ehci_enable()
  2021-07-08  8:30 [PATCH] USB: EHCI: ehci-mv: improve error handling in mv_ehci_enable() Evgeny Novikov
@ 2021-07-08 13:40 ` Alan Stern
  0 siblings, 0 replies; 2+ messages in thread
From: Alan Stern @ 2021-07-08 13:40 UTC (permalink / raw)
  To: Evgeny Novikov; +Cc: Greg Kroah-Hartman, linux-usb, linux-kernel, ldv-project

On Thu, Jul 08, 2021 at 11:30:56AM +0300, Evgeny Novikov wrote:
> mv_ehci_enable() did not disable and unprepare clocks in case of
> failures of phy_init(). Besides, it did not take into account failures
> of ehci_clock_enable() (in effect, failures of clk_prepare_enable()).
> The patch fixes both issues and gets rid of redundant wrappers around
> clk_prepare_enable() and clk_disable_unprepare() to simplify this a bit.
> 
> Found by Linux Driver Verification project (linuxtesting.org).
> 
> Signed-off-by: Evgeny Novikov <novikov@ispras.ru>
> ---

Acked-by: Alan Stern <stern@rowland.harvard.edu>

>  drivers/usb/host/ehci-mv.c | 23 +++++++++++------------
>  1 file changed, 11 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/usb/host/ehci-mv.c b/drivers/usb/host/ehci-mv.c
> index cffdc8d01b2a..8fd27249ad25 100644
> --- a/drivers/usb/host/ehci-mv.c
> +++ b/drivers/usb/host/ehci-mv.c
> @@ -42,26 +42,25 @@ struct ehci_hcd_mv {
>  	int (*set_vbus)(unsigned int vbus);
>  };
>  
> -static void ehci_clock_enable(struct ehci_hcd_mv *ehci_mv)
> +static int mv_ehci_enable(struct ehci_hcd_mv *ehci_mv)
>  {
> -	clk_prepare_enable(ehci_mv->clk);
> -}
> +	int retval;
>  
> -static void ehci_clock_disable(struct ehci_hcd_mv *ehci_mv)
> -{
> -	clk_disable_unprepare(ehci_mv->clk);
> -}
> +	retval = clk_prepare_enable(ehci_mv->clk);
> +	if (retval)
> +		return retval;
>  
> -static int mv_ehci_enable(struct ehci_hcd_mv *ehci_mv)
> -{
> -	ehci_clock_enable(ehci_mv);
> -	return phy_init(ehci_mv->phy);
> +	retval = phy_init(ehci_mv->phy);
> +	if (retval)
> +		clk_disable_unprepare(ehci_mv->clk);
> +
> +	return retval;
>  }
>  
>  static void mv_ehci_disable(struct ehci_hcd_mv *ehci_mv)
>  {
>  	phy_exit(ehci_mv->phy);
> -	ehci_clock_disable(ehci_mv);
> +	clk_disable_unprepare(ehci_mv->clk);
>  }
>  
>  static int mv_ehci_reset(struct usb_hcd *hcd)
> -- 
> 2.26.2
> 

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

end of thread, other threads:[~2021-07-08 13:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-08  8:30 [PATCH] USB: EHCI: ehci-mv: improve error handling in mv_ehci_enable() Evgeny Novikov
2021-07-08 13:40 ` Alan Stern

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