mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH master] phy: stm32-usbphyc: fix unbalanced phy exit
Date: Fri, 10 Nov 2023 14:16:45 +0100	[thread overview]
Message-ID: <20231110131645.GC3359458@pengutronix.de> (raw)
In-Reply-To: <20231109121012.1474536-1-a.fatoum@pengutronix.de>

On Thu, Nov 09, 2023 at 01:10:12PM +0100, Ahmad Fatoum wrote:
> On the STM32MP1, shutting down barebox can result in a
> 
>   ERROR: phy1: phy exit failed --> -22
> 
> message printed to the console. This is because the regulator is disabled
> more often than it was enabled, because stm32_usbphyc_pll_disable
> is called twice:
> 
>   - Once from stm32_usbphyc_remove calling stm32_usbphyc_phy_exit
>   - Once from dwc2_remove calling phy_exit -> stm32_usbphyc_phy_exit
> 
> The code is taken from Linux and likely causes no issues there, because
> devices are removed in reverse probe order, which barebox doesn't
> enforce. Properly solving this would be a larger endeavour, so for now
> just fix the stm32-usbphyc driver to ignore reference count dropping
> below zero and only call __stm32_usbphyc_pll_disable once.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  drivers/phy/phy-stm32-usbphyc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks

Sascha

> 
> diff --git a/drivers/phy/phy-stm32-usbphyc.c b/drivers/phy/phy-stm32-usbphyc.c
> index ac82b019f44c..91f4e7f7e08d 100644
> --- a/drivers/phy/phy-stm32-usbphyc.c
> +++ b/drivers/phy/phy-stm32-usbphyc.c
> @@ -277,7 +277,7 @@ static int __stm32_usbphyc_pll_disable(struct stm32_usbphyc *usbphyc)
>  static int stm32_usbphyc_pll_disable(struct stm32_usbphyc *usbphyc)
>  {
>  	/* Check if a phy port is still active or clk48 in use */
> -	if (atomic_dec_return(&usbphyc->n_pll_cons) > 0)
> +	if (atomic_dec_return(&usbphyc->n_pll_cons) != 1)
>  		return 0;
>  
>  	return __stm32_usbphyc_pll_disable(usbphyc);
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



      reply	other threads:[~2023-11-10 13:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-09 12:10 Ahmad Fatoum
2023-11-10 13:16 ` Sascha Hauer [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=20231110131645.GC3359458@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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