Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Vladimir Oltean" <vladimir.oltean@nxp.com>
Cc: wsa+renesas@sang-engineering.com, linux-pci@vger.kernel.org
Subject: Re: [PATCH v8 phy-next 10/31] scsi: ufs: exynos: use dedicated API for updating PHY bus width
Date: Thu, 07 May 2026 07:59:59 +0000	[thread overview]
Message-ID: <20260507075959.EC384C2BCC7@smtp.kernel.org> (raw)
In-Reply-To: <20260505100523.1922388-11-vladimir.oltean@nxp.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] In `samsung_ufs_phy_request_bus_width()`, if `samsung_ufs_phy_power_on()` fails, the PHY clocks are left disabled but the core `phy->power_count` remains elevated, causing unbalanced clock disables on teardown.
- [High] Early return on `phy_request_bus_width()` failure skips PHY power-on, causing fatal hardware bus errors when accessing unpowered PHY registers.
--

commit 69b368f4a4a2db532d3c3f014c5fffd55e2658d0
Author: Vladimir Oltean <vladimir.oltean@nxp.com>

scsi: ufs: exynos: use dedicated API for updating PHY bus width

This commit introduces a new dedicated phy_request_bus_width() API to the 
PHY core and updates the Exynos UFS driver to use it instead of hijacking
phy_set_bus_width() and phy_init(). This update allows the UFS HCD driver
to update the lane count cleanly without altering the PHY initialization and
power states unexpectedly.

> diff --git a/drivers/phy/samsung/phy-samsung-ufs.c b/drivers/phy/samsung/phy-samsung-ufs.c
> index ee665f26c2361..b09a35ab6acde 100644
> --- a/drivers/phy/samsung/phy-samsung-ufs.c
> +++ b/drivers/phy/samsung/phy-samsung-ufs.c
[ ... ]
> @@ -204,6 +203,31 @@ static int samsung_ufs_phy_power_off(struct phy *phy)
>  	return 0;
>  }
>  
> +static int samsung_ufs_phy_request_bus_width(struct phy *phy, int bus_width)
> +{
> +	struct samsung_ufs_phy *ss_phy = get_samsung_ufs_phy(phy);
> +	u8 old_lane_cnt = ss_phy->lane_cnt;
> +	int err = 0;
> +
> +	if (bus_width != 1 && bus_width != 2)
> +		return -EINVAL;
> +
> +	ss_phy->lane_cnt = bus_width;
> +
> +	if (phy->init_count)
> +		samsung_ufs_phy_init(phy);
> +
> +	/* If the init_count is 0, the power_count should also be 0 */
> +	if (phy->power_count) {
> +		samsung_ufs_phy_power_off(phy);
> +		err = samsung_ufs_phy_power_on(phy);

If samsung_ufs_phy_power_on() fails here, the PHY clocks are left disabled but
the core phy->power_count remains elevated because this cycle bypasses the core
PHY API.

When the UFS driver later cleans up and calls phy_power_off(), the PHY core
invokes samsung_ufs_phy_power_off() a second time.

Will this second call to samsung_ufs_phy_power_off() attempt to disable already
disabled clocks and cause a clock enable count underflow warning?

> +		if (err)
> +			ss_phy->lane_cnt = old_lane_cnt;
> +	}
> +
> +	return err;
> +}
[ ... ]
> diff --git a/drivers/ufs/host/ufs-exynos.c b/drivers/ufs/host/ufs-exynos.c
> index 77a6c8e44485b..b90876b268db7 100644
> --- a/drivers/ufs/host/ufs-exynos.c
> +++ b/drivers/ufs/host/ufs-exynos.c
[ ... ]
> @@ -947,30 +1009,11 @@ static int exynos_ufs_phy_init(struct exynos_ufs *ufs)
>  			ufs->avail_ln_rx, ufs->avail_ln_tx);
>  	}
>  
> -	phy_set_bus_width(generic_phy, ufs->avail_ln_rx);
> -
> -	if (generic_phy->power_count) {
> -		phy_power_off(generic_phy);
> -		phy_exit(generic_phy);
> -	}
> -
> -	ret = phy_init(generic_phy);
> -	if (ret) {
> -		dev_err(hba->dev, "%s: phy init failed, ret = %d\n",
> -			__func__, ret);
> -		return ret;
> -	}
> -
> -	ret = phy_power_on(generic_phy);
> +	ret = phy_request_bus_width(generic_phy, ufs->avail_ln_rx);
>  	if (ret)
> -		goto out_exit_phy;
> -
> -	return 0;
> -
> -out_exit_phy:
> -	phy_exit(generic_phy);
> +		return ret;
>  
> -	return ret;
> +	return exynos_ufs_phy_power_on(ufs);
>  }

If phy_request_bus_width() fails and returns an error (for example, -EINVAL
if ufs->avail_ln_rx is 0), this code will return early and skip the call to
exynos_ufs_phy_power_on().

However, looking at exynos_ufs_pre_link() which calls this function:

exynos_ufs_pre_link() {
...
	/* m-phy */
	exynos_ufs_phy_update_bus_width(ufs);
	if (!(ufs->opts & EXYNOS_UFS_OPT_SKIP_CONFIG_PHY_ATTR)) {
		exynos_ufs_config_phy_time_attr(ufs);
		exynos_ufs_config_phy_cap_attr(ufs);
	}
...
}

The return value of exynos_ufs_phy_update_bus_width() is ignored, and
exynos_ufs_pre_link() proceeds unconditionally to access PHY attributes via
exynos_ufs_config_phy_time_attr() and exynos_ufs_config_phy_cap_attr().

Can accessing these registers while the PHY power domains and clocks are off
cause unhandled faults, bus errors, or hardware hangs?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260505100523.1922388-1-vladimir.oltean@nxp.com?part=10

  reply	other threads:[~2026-05-07  8:00 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-05 10:04 [PATCH v8 phy-next 00/31] Split Generic PHY consumer and provider API Vladimir Oltean
2026-05-05 10:04 ` [PATCH v8 phy-next 01/31] PCI: cadence: Preserve all error codes in cdns_plat_pcie_probe() Vladimir Oltean
2026-05-05 16:26   ` Bjorn Helgaas
2026-05-07  7:59   ` sashiko-bot
2026-05-07 15:50     ` Bjorn Helgaas
2026-05-05 10:04 ` [PATCH v8 phy-next 02/31] ata: add <linux/pm_runtime.h> where missing Vladimir Oltean
2026-05-07  7:59   ` sashiko-bot
2026-05-05 10:04 ` [PATCH v8 phy-next 03/31] PCI: Add missing headers transitively included by <linux/phy/phy.h> Vladimir Oltean
2026-05-05 10:04 ` [PATCH v8 phy-next 04/31] usb: add " Vladimir Oltean
2026-05-05 10:04 ` [PATCH v8 phy-next 05/31] drm: add <linux/pm_runtime.h> where missing Vladimir Oltean
2026-05-05 10:04 ` [PATCH v8 phy-next 06/31] phy: " Vladimir Oltean
2026-05-05 10:04 ` [PATCH v8 phy-next 07/31] phy: spacemit: include missing <linux/phy/phy.h> Vladimir Oltean
2026-05-05 10:05 ` [PATCH v8 phy-next 08/31] net: lan969x: include missing <linux/of.h> Vladimir Oltean
2026-05-05 10:05 ` [PATCH v8 phy-next 09/31] PCI: Remove device links to PHY Vladimir Oltean
2026-05-07  7:59   ` sashiko-bot
2026-05-07 15:47     ` Bjorn Helgaas
2026-05-08  2:14       ` Hans Zhang
2026-05-05 10:05 ` [PATCH v8 phy-next 10/31] scsi: ufs: exynos: use dedicated API for updating PHY bus width Vladimir Oltean
2026-05-07  7:59   ` sashiko-bot [this message]
2026-05-05 10:05 ` [PATCH v8 phy-next 11/31] scsi: ufs: qcom: call phy_init() before phy_power_on() Vladimir Oltean
2026-05-07  8:00   ` sashiko-bot
2026-05-05 10:05 ` [PATCH v8 phy-next 12/31] scsi: ufs: qcom: make use of QMP PHY dynamic gear switching ability Vladimir Oltean
2026-05-07  8:00   ` sashiko-bot
2026-05-05 10:05 ` [PATCH v8 phy-next 13/31] scsi: ufs: qcom: keep separate track of PHY power state Vladimir Oltean
2026-05-07  8:00   ` sashiko-bot
2026-05-05 10:05 ` [PATCH v8 phy-next 14/31] scsi: ufs: qcom: include missing <linux/interrupt.h> Vladimir Oltean
2026-05-05 10:05 ` [PATCH v8 phy-next 15/31] drm/rockchip: dw_hdmi: avoid direct dereference of phy->dev.of_node Vladimir Oltean
2026-05-07  8:00   ` sashiko-bot
2026-05-05 10:05 ` [PATCH v8 phy-next 16/31] usb: host: tegra: " Vladimir Oltean
2026-05-07  8:00   ` sashiko-bot
2026-05-05 10:05 ` [PATCH v8 phy-next 17/31] usb: gadget: tegra-xudc: " Vladimir Oltean
2026-05-07  8:00   ` sashiko-bot
2026-05-05 10:05 ` [PATCH v8 phy-next 18/31] phy: move provider API out of public <linux/phy/phy.h> Vladimir Oltean
2026-05-05 10:05 ` [PATCH v8 phy-next 19/31] phy: make phy_get_mode(), phy_get_bus_width() NULL tolerant Vladimir Oltean
2026-05-05 10:05 ` [PATCH v8 phy-next 20/31] phy: introduce phy_get_max_link_rate() helper for consumers Vladimir Oltean
2026-05-05 10:05 ` [PATCH v8 phy-next 21/31] drm/rockchip: dsi: include PHY provider header Vladimir Oltean
2026-05-07  8:00   ` sashiko-bot
2026-05-05 10:05 ` [PATCH v8 phy-next 22/31] drm: bridge: cdns-mhdp8546: use consumer API for getting PHY bus width Vladimir Oltean
2026-05-05 10:05 ` [PATCH v8 phy-next 23/31] media: sunxi: a83-mips-csi2: include PHY provider header Vladimir Oltean
2026-05-05 10:05 ` [PATCH v8 phy-next 24/31] net: renesas: rswitch: " Vladimir Oltean
2026-05-07  8:00   ` sashiko-bot
2026-05-05 10:05 ` [PATCH v8 phy-next 25/31] pinctrl: tegra-xusb: " Vladimir Oltean
2026-05-05 10:05 ` [PATCH v8 phy-next 26/31] power: supply: cpcap-charger: include missing <linux/property.h> Vladimir Oltean
2026-05-05 10:05 ` [PATCH v8 phy-next 27/31] phy: move ulpi_phy.h from include/linux/phy/ to drivers/phy/ Vladimir Oltean
2026-05-05 10:05 ` [PATCH v8 phy-next 28/31] phy: include PHY provider header (1/2) Vladimir Oltean
2026-05-05 10:05 ` [PATCH v8 phy-next 29/31] phy: include PHY provider header (2/2) Vladimir Oltean
2026-05-05 10:05 ` [PATCH v8 phy-next 30/31] phy: remove temporary provider compatibility from consumer header Vladimir Oltean
2026-05-07  8:00   ` sashiko-bot
2026-05-05 10:05 ` [PATCH v8 phy-next 31/31] MAINTAINERS: add regexes for linux-phy Vladimir Oltean

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=20260507075959.EC384C2BCC7@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=sashiko@lists.linux.dev \
    --cc=vladimir.oltean@nxp.com \
    --cc=wsa+renesas@sang-engineering.com \
    /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