Linux-PHY Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] phy: sun4i-usb: Avoid polling just for ID pin without OTG mode
@ 2026-12-06  4:31 Chen-Yu Tsai
  2026-12-06  4:59 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Chen-Yu Tsai @ 2026-12-06  4:31 UTC (permalink / raw)
  To: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam, Chen-Yu Tsai,
	Jernej Skrabec, Samuel Holland
  Cc: linux-phy, linux-arm-kernel, linux-sunxi, Ondřej Jirman,
	Andre Przywara

On some devices only the ID pin is hooked up, and there is no VBUS
sensing or control, with VBUS directly tied to system 5V. On these
devices we typically just force the OTG controller to host mode only.

There is no point in polling just the ID pin if the result is never
going to be used. So skip polling if the mode is not OTG and the ID pin
is the only thing that needs to be polled.

Signed-off-by: Chen-Yu Tsai <wens@kernel.org>
---
 drivers/phy/allwinner/phy-sun4i-usb.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/phy/allwinner/phy-sun4i-usb.c b/drivers/phy/allwinner/phy-sun4i-usb.c
index f26eed0db17e..66454653bfc4 100644
--- a/drivers/phy/allwinner/phy-sun4i-usb.c
+++ b/drivers/phy/allwinner/phy-sun4i-usb.c
@@ -441,8 +441,11 @@ static bool sun4i_usb_phy0_have_vbus_det(struct sun4i_usb_phy_data *data)
 
 static bool sun4i_usb_phy0_poll(struct sun4i_usb_phy_data *data)
 {
-	if ((data->id_det_gpio && data->id_det_irq <= 0) ||
-	    (data->vbus_det_gpio && data->vbus_det_irq <= 0))
+	if (data->dr_mode == USB_DR_MODE_OTG &&
+	    data->id_det_gpio && data->id_det_irq <= 0)
+		return true;
+
+	if (data->vbus_det_gpio && data->vbus_det_irq <= 0)
 		return true;
 
 	/*
-- 
2.53.0


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

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

* Re: [PATCH] phy: sun4i-usb: Avoid polling just for ID pin without OTG mode
  2026-12-06  4:31 [PATCH] phy: sun4i-usb: Avoid polling just for ID pin without OTG mode Chen-Yu Tsai
@ 2026-12-06  4:59 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-06  4:59 UTC (permalink / raw)
  To: Chen-Yu Tsai; +Cc: linux-phy, linux-sunxi, vkoul, neil.armstrong, olteanv

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] phy: sun4i-usb: data race on dr_mode in sun4i_usb_phy0_poll()
--

commit 1f5bbdcf708e3a86067fd33d7ce18d68f3e615ce
Author: Chen-Yu Tsai <wens@kernel.org>

phy: sun4i-usb: Avoid polling just for ID pin without OTG mode

This commit updates sun4i_usb_phy0_poll() to skip polling the ID pin GPIO
when dr_mode is not USB_DR_MODE_OTG.

> diff --git a/drivers/phy/allwinner/phy-sun4i-usb.c b/drivers/phy/allwinner/phy-sun4i-usb.c
> index e2fbf8ccf99e1..d136e4c0d8a3e 100644
> --- a/drivers/phy/allwinner/phy-sun4i-usb.c
> +++ b/drivers/phy/allwinner/phy-sun4i-usb.c
> @@ -441,8 +441,11 @@ static bool sun4i_usb_phy0_have_vbus_det(struct sun4i_usb_phy_data *data)
>  
>  static bool sun4i_usb_phy0_poll(struct sun4i_usb_phy_data *data)
>  {
> -	if ((data->id_det_gpio && data->id_det_irq <= 0) ||
> -	    (data->vbus_det_gpio && data->vbus_det_irq <= 0))
> +	if (data->dr_mode == USB_DR_MODE_OTG &&
> +	    data->id_det_gpio && data->id_det_irq <= 0)
> +		return true;

[Severity: Low]
Can this read of data->dr_mode race with sun4i_usb_phy_set_mode()?

sun4i_usb_phy0_id_vbus_det_scan() calls sun4i_usb_phy0_poll() after
releasing phy0->mutex, while switching the MUSB sysfs mode attribute
updates data->dr_mode under phy0->mutex on another workqueue:

CPU0 (system_percpu_wq)           CPU1 (system_wq)
sun4i_usb_phy0_id_vbus_det_scan()
  mutex_unlock(&phy0->mutex)
                                  sunxi_musb_work()
                                    phy_set_mode()
                                      mutex_lock(&phy0->mutex)
                                      sun4i_usb_phy_set_mode()
                                        data->dr_mode = new_mode
  sun4i_usb_phy0_poll()
    if (data->dr_mode == ...)     <-- data race

Neither side uses READ_ONCE()/WRITE_ONCE() or a shared lock, so this
triggers a KCSAN data-race report.  Polling cannot be permanently lost
because sun4i_usb_phy_set_mode() requeues data->detect, so at worst this
causes one extra poll iteration.

Using READ_ONCE()/WRITE_ONCE() for data->dr_mode, or evaluating
sun4i_usb_phy0_poll() while holding phy0->mutex, would avoid the race.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261206043129.1383610-1-wens@kernel.org?part=1

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

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

end of thread, other threads:[~2026-12-06  4:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-06  4:31 [PATCH] phy: sun4i-usb: Avoid polling just for ID pin without OTG mode Chen-Yu Tsai
2026-12-06  4:59 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox