All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sebastian Reichel" <sebastian.reichel@collabora.com>
Cc: linux-phy@lists.infradead.org, olteanv@gmail.com,
	vkoul@kernel.org, neil.armstrong@linaro.org
Subject: Re: [PATCH v16 4/6] usb: dwc3: rockchip: support PHY reset notifications
Date: Thu, 24 Sep 2026 17:38:31 +0000	[thread overview]
Message-ID: <20260924173832.538ED1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260924-b4-rockchip-dwc3-rockchip-glue-v16-4-126a2e9133c3@collabora.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] usb: dwc3: rockchip: PM usage counter underflow due to unbalanced put
- [High] usb: dwc3: rockchip: kernel panic on unclocked register access during removal
--

commit d23961727db1cf3094808a06fa4f08ec3b13900c
Author: Sebastian Reichel <sebastian.reichel@collabora.com>

    usb: dwc3: rockchip: support PHY reset notifications
    
    On recent Rockchip platforms (at least RK3588 & RK3576), DWC3 IP is used
    with a USBDP PHY providing USB3 and DP. This PHY needs to be reset when
    the mode changes, which may happen when plugging in different USB-C
    devices.

> diff --git a/drivers/usb/dwc3/dwc3-rockchip.c b/drivers/usb/dwc3/dwc3-rockchip.c
> index 4129aefd6a8b0..17b6c2ca9e192 100644
> --- a/drivers/usb/dwc3/dwc3-rockchip.c
> +++ b/drivers/usb/dwc3/dwc3-rockchip.c

[ ... ]

> +static int dwc3_usb3_phy_notify(struct notifier_block *nb,
> +				unsigned long action, void *data)
> +{
> +	struct dwc3_rk_phy_nb *pnb = container_of(nb, struct dwc3_rk_phy_nb, nb);
> +	struct dwc3_rockchip *dwc_rk = pnb->dwc_rk;
> +	struct dwc3 *dwc = &dwc_rk->dwc;
> +	int port = pnb->port_index;
> +	unsigned long flags;
> +	u32 reg;
> +	int ret;
> +
> +	switch (action) {
> +	case PHY_NOTIFY_PRE_RESET:
> +		/*
> +		 * If already suspended, the resume path will reinit GUSB3PIPECTL
> +		 * via dwc3_core_init(). A forced resume is not possible as that
> +		 * would call phy_init() resulting in a deadlock. Due to the
> +		 * phy_init() in the resume path there is also no need to block
> +		 * async RPM resume on our side, since the PHY synchronizes it
> +		 * for us.
> +		 *
> +		 * pm_runtime_get_if_active() returns 0 when suspended (skip),
> +		 * 1 when active (ref held), or -EINVAL when PM is disabled
> +		 * (device always active). In the -EINVAL case PM ref counting
> +		 * is a no-op, so the unconditional put in POST_RESET is safe.
> +		 */
> +		ret = pm_runtime_get_if_active(dwc->dev);
> +		if (!ret)
> +			return NOTIFY_OK;
> +

[Severity: High]
Does this error handling correctly account for -EINVAL?

When PM is disabled (such as during driver removal), 
pm_runtime_get_if_active() returns -EINVAL. Since the if (!ret) check
only evaluates to true for 0, the code falls through on -EINVAL without
holding a PM reference.

> +		/*
> +		 * Assert USB3 PHY soft reset within DWC3 before the external
> +		 * PHY resets. This disconnects the PIPE interface, preventing
> +		 * the DWC3 from interfering with PHY reinitialization and
> +		 * avoiding LCPLL lock failures.
> +		 */
> +		spin_lock_irqsave(&dwc->lock, flags);
> +		dwc_rk->phy_reset_active |= BIT(port);
> +		reg = dwc3_readl(dwc, DWC3_GUSB3PIPECTL(port));

[Severity: High]
Can accessing hardware registers here cause a kernel panic during removal?

Because dwc3_rk_phy_register_notifiers() uses devm_add_action_or_reset(),
the notifier is unregistered during devres cleanup, which happens after
dwc3_rockchip_remove() returns.

The dwc3_rockchip_remove() path calls dwc3_core_remove(), which disables PM
and shuts down hardware clocks via dwc3_core_exit().

If a PHY reset notification arrives during this window,
pm_runtime_get_if_active() returns -EINVAL, the code falls through to this
point, and we attempt to read registers via dwc3_readl() when clocks are
disabled. Accessing unclocked registers on ARM/Rockchip architectures causes
a synchronous external abort.

Should the driver explicitly unregister the hardware-accessing PHY notifiers
before tearing down the DWC3 core?

> +		reg |= DWC3_GUSB3PIPECTL_PHYSOFTRST;
> +		dwc3_writel(dwc, DWC3_GUSB3PIPECTL(port), reg);
> +		spin_unlock_irqrestore(&dwc->lock, flags);
> +		break;
> +
> +	case PHY_NOTIFY_POST_RESET:
> +		spin_lock_irqsave(&dwc->lock, flags);
> +		if (!(dwc_rk->phy_reset_active & BIT(port))) {
> +			spin_unlock_irqrestore(&dwc->lock, flags);
> +			return NOTIFY_OK;
> +		}
> +
> +		dwc_rk->phy_reset_active &= ~BIT(port);
> +
> +		/*
> +		 * Deassert PHY soft reset to reconnect the PIPE interface
> +		 * after PHY reinitialization.
> +		 */
> +		reg = dwc3_readl(dwc, DWC3_GUSB3PIPECTL(port));
> +		reg &= ~DWC3_GUSB3PIPECTL_PHYSOFTRST;
> +		dwc3_writel(dwc, DWC3_GUSB3PIPECTL(port), reg);
> +		spin_unlock_irqrestore(&dwc->lock, flags);
> +
> +		pm_runtime_put_autosuspend(dwc->dev);

[Severity: High]
Does this unconditional put cause a PM usage counter underflow if the initial
get returned -EINVAL?

As seen in __pm_runtime_suspend(), the usage counter is decremented via
rpm_drop_usage_count() before checking the PM enable status. If the counter
was > 0 (held by another component), dropping it prematurely could cause the
device to auto-suspend while in use.

> +		break;
> +	}
> +
> +	return NOTIFY_OK;
> +}
> +
> +static void dwc3_rk_phy_unregister_notifiers(void *data)
> +{
> +	struct dwc3_rockchip *dwc_rk = data;
> +	struct dwc3 *dwc = &dwc_rk->dwc;
> +	int i;
> +
> +	for (i = 0; i < dwc->num_usb3_ports; i++)
> +		phy_unregister_notifier(dwc->usb3_generic_phy[i],
> +					&dwc_rk->usb3_phy_nb[i].nb);
> +
> +	/* Release any PM references from in-flight resets */
> +	for (i = 0; i < dwc->num_usb3_ports; i++) {
> +		if (dwc_rk->phy_reset_active & BIT(i))
> +			pm_runtime_put_autosuspend(dwc->dev);

[Severity: High]
Similarly, can this unconditional cleanup put cause corruption if the initial
get failed with -EINVAL?

> +	}
> +	dwc_rk->phy_reset_active = 0;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260924-b4-rockchip-dwc3-rockchip-glue-v16-0-126a2e9133c3@collabora.com?part=4

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

  reply	other threads:[~2026-09-24 17:38 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-24 17:25 [PATCH v16 0/6] usb: dwc3: introduce Rockchip glue driver Sebastian Reichel
2026-09-24 17:25 ` Sebastian Reichel
2026-09-24 17:25 ` Sebastian Reichel
2026-09-24 17:25 ` [PATCH v16 1/6] phy: core: add notifier infrastructure Sebastian Reichel
2026-09-24 17:25   ` Sebastian Reichel
2026-09-24 17:25   ` Sebastian Reichel
2026-09-24 17:35   ` sashiko-bot
2026-09-26  7:47   ` Manivannan Sadhasivam
2026-09-26  7:47     ` Manivannan Sadhasivam
2026-09-26  7:47     ` Manivannan Sadhasivam
2026-10-03  9:04   ` Vinod Koul
2026-10-03  9:04     ` Vinod Koul
2026-10-03  9:04     ` Vinod Koul
2026-10-04 12:44     ` Sebastian Reichel
2026-10-04 12:44       ` Sebastian Reichel
2026-10-04 12:44       ` Sebastian Reichel
2026-10-05  8:30       ` Vinod Koul
2026-10-05  8:30         ` Vinod Koul
2026-10-05  8:30         ` Vinod Koul
2026-10-06  1:11         ` Sebastian Reichel
2026-10-06  1:11           ` Sebastian Reichel
2026-10-06  1:11           ` Sebastian Reichel
2026-09-24 17:25 ` [PATCH v16 2/6] usb: dwc3: rockchip: introduce glue driver Sebastian Reichel
2026-09-24 17:25   ` Sebastian Reichel
2026-09-24 17:25   ` Sebastian Reichel
2026-09-24 17:36   ` sashiko-bot
2026-09-24 17:25 ` [PATCH v16 3/6] usb: dwc3: core: add post PHY registration hook for platform glue Sebastian Reichel
2026-09-24 17:25   ` Sebastian Reichel
2026-09-24 17:25   ` Sebastian Reichel
2026-09-24 17:25 ` [PATCH v16 4/6] usb: dwc3: rockchip: support PHY reset notifications Sebastian Reichel
2026-09-24 17:25   ` Sebastian Reichel
2026-09-24 17:25   ` Sebastian Reichel
2026-09-24 17:38   ` sashiko-bot [this message]
2026-09-26  7:51   ` Manivannan Sadhasivam
2026-09-26  7:51     ` Manivannan Sadhasivam
2026-09-26  7:51     ` Manivannan Sadhasivam
2026-10-02 23:39   ` Thinh Nguyen
2026-10-02 23:39     ` Thinh Nguyen
2026-10-02 23:39     ` Thinh Nguyen
2026-09-24 17:25 ` [PATCH v16 5/6] usb: gadget: define stub for usb_udc_vbus_handler Sebastian Reichel
2026-09-24 17:25   ` Sebastian Reichel
2026-09-24 17:25   ` Sebastian Reichel
2026-09-24 17:25 ` [PATCH v16 6/6] usb: dwc3: rockchip: fix USB-C reconnect in gadget mode Sebastian Reichel
2026-09-24 17:25   ` Sebastian Reichel
2026-09-24 17:25   ` Sebastian Reichel
2026-09-24 17:40   ` sashiko-bot
2026-09-27 12:02   ` Igor Paunovic
2026-09-27 12:02     ` Igor Paunovic
2026-09-27 12:02     ` Igor Paunovic
2026-10-02 22:57   ` Thinh Nguyen
2026-10-02 22:57     ` Thinh Nguyen
2026-10-02 22:57     ` Thinh Nguyen
2026-09-27 12:02 ` [PATCH v16 0/6] usb: dwc3: introduce Rockchip glue driver Igor Paunovic
2026-09-27 12:02   ` Igor Paunovic
2026-09-27 12:02   ` Igor Paunovic

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=20260924173832.538ED1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=neil.armstrong@linaro.org \
    --cc=olteanv@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sebastian.reichel@collabora.com \
    --cc=vkoul@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.