mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master] phy: stm32-usbphyc: fix unbalanced phy exit
Date: Thu,  9 Nov 2023 13:10:12 +0100	[thread overview]
Message-ID: <20231109121012.1474536-1-a.fatoum@pengutronix.de> (raw)

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

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




             reply	other threads:[~2023-11-09 12:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-09 12:10 Ahmad Fatoum [this message]
2023-11-10 13:16 ` Sascha Hauer

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=20231109121012.1474536-1-a.fatoum@pengutronix.de \
    --to=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