All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Chen-Yu Tsai" <wens@kernel.org>
Cc: linux-phy@lists.infradead.org, linux-sunxi@lists.linux.dev,
	vkoul@kernel.org, neil.armstrong@linaro.org, olteanv@gmail.com
Subject: Re: [PATCH] phy: sun4i-usb: Avoid polling just for ID pin without OTG mode
Date: Sun, 06 Dec 2026 04:59:15 +0000	[thread overview]
Message-ID: <sashiko-outbox-252152@kernel.org> (raw)
In-Reply-To: <20261206043129.1383610-1-wens@kernel.org>

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

WARNING: multiple messages have this Message-ID (diff)
From: sashiko-bot@kernel.org
To: "Chen-Yu Tsai" <wens@kernel.org>
Cc: linux-phy@lists.infradead.org, linux-sunxi@lists.linux.dev,
	vkoul@kernel.org, neil.armstrong@linaro.org, olteanv@gmail.com
Subject: Re: [PATCH] phy: sun4i-usb: Avoid polling just for ID pin without OTG mode
Date: Sun, 06 Dec 2026 04:59:15 +0000	[thread overview]
Message-ID: <sashiko-outbox-252152@kernel.org> (raw)
In-Reply-To: <20261206043129.1383610-1-wens@kernel.org>

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

  reply	other threads:[~2026-12-06  4:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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:31 ` Chen-Yu Tsai
2026-12-06  4:59 ` sashiko-bot [this message]
2026-12-06  4:59   ` sashiko-bot

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=sashiko-outbox-252152@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=neil.armstrong@linaro.org \
    --cc=olteanv@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vkoul@kernel.org \
    --cc=wens@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.