All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Louis-Alexis Eyraud" <louisalexis.eyraud@collabora.com>
Cc: linux-phy@lists.infradead.org, neil.armstrong@linaro.org,
	linux-scsi@vger.kernel.org, conor+dt@kernel.org, robh@kernel.org,
	vkoul@kernel.org, olteanv@gmail.com, devicetree@vger.kernel.org
Subject: Re: [PATCH v10 13/26] scsi: ufs: mediatek: Use the common PHY framework
Date: Thu, 30 Jul 2026 10:40:01 +0000	[thread overview]
Message-ID: <20260730104002.59D061F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260730-mt8196-ufs-v10-13-bc5ecef202dc@collabora.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [High] The driver now fails to probe on platforms where the UFS PHY is not defined in the device tree, breaking backward compatibility.
- [High] Returning an error late in PM runtime callbacks leaves the device in an inconsistent state and breaks PM state synchronization.

Pre-existing issues:
- [High] The return values of `phy_power_on()` and `phy_power_off()` are ignored, which can lead to unbalanced PM runtime counts and hardware state corruption.
--

--- Patch [13]: [PATCH v10 13/26] scsi: ufs: mediatek: Use the common PHY framework ---
commit 114da5212062d5f11b7f9274ba9701891ef82788
Author: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>

scsi: ufs: mediatek: Use the common PHY framework
    
This patch refactors the MediaTek UFS driver to use the common PHY framework 
to acquire the device's PHY during ufshcd init, ensuring it is device-linked 
to the correct device.

> diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c
> index e5527969a5e67..385f0180b2309 100644
> --- a/drivers/ufs/host/ufs-mediatek.c
> +++ b/drivers/ufs/host/ufs-mediatek.c

[ ... ]

> @@ -1185,13 +1147,21 @@ static int ufs_mtk_init(struct ufs_hba *hba)
>  
>  	ufs_mtk_init_mcq_irq(hba);
>  
> -	err = ufs_mtk_bind_mphy(hba);
> -	if (err)
> +	host->mphy = devm_phy_get(dev, NULL);
> +	if (IS_ERR(host->mphy)) {
> +		err = dev_err_probe(dev, PTR_ERR(host->mphy), "Failed to get PHY\n");

[Severity: High]
Will this cause the driver probe to fail on platforms where the UFS PHY
is not defined in the device tree?

The original ufs_mtk_bind_mphy() tolerated -ENODEV to allow for unbound 
mphys since not all platforms require specific mphy control. By switching 
to devm_phy_get() instead of devm_phy_optional_get(), won't this return 
-ENODEV and fail the probe if the "phys" property is missing, breaking 
backward compatibility with older device trees?

> +		goto out_variant_clear;
> +	}
> +
> +	err = phy_init(host->mphy);
> +	if (err) {
> +		dev_err_probe(dev, err, "Failed to initialize PHY\n");
>  		goto out_variant_clear;
> +	}

[ ... ]

> @@ -2448,9 +2393,8 @@ static int ufs_mtk_system_resume(struct device *dev)
>  static int ufs_mtk_runtime_suspend(struct device *dev)
>  {
>  	struct ufs_hba *hba = dev_get_drvdata(dev);
> -	struct ufs_mtk_host *host = ufshcd_get_variant(hba);
>  	struct arm_smccc_res res;
> -	int ret = 0;
> +	int ret;
>  
>  	ret = ufshcd_runtime_suspend(dev);
>  	if (ret)
> @@ -2461,8 +2405,11 @@ static int ufs_mtk_runtime_suspend(struct device *dev)
>  	if (ufs_mtk_is_rtff_mtcmos(hba))
>  		ufs_mtk_mtcmos_ctrl(false, res);
>  
> -	if (host->phy_dev)
> -		pm_runtime_put_sync(host->phy_dev);
> +	ret = ufs_mtk_mphy_power_on(hba, false);
> +	if (ret) {
> +		dev_err(dev, "Failed to power off PHY: %pe\n", ERR_PTR(ret));
> +		return ret;
> +	}

[Severity: High]
Does returning an error here leave the device in an inconsistent state?

If ufshcd_runtime_suspend() succeeds, the main UFS controller hardware is
fully suspended (clocks gated, link hibern8). If ufs_mtk_mphy_power_on() 
fails afterward, this returns the error to the PM core. 

Since the PM core intercepts the non-zero return as a runtime suspend 
failure, it leaves the software state as RPM_ACTIVE. If the software 
thinks the device is active while the hardware is actually suspended, 
won't the next hardware access skip runtime_resume and cause a system 
hang or bus error?

[Severity: High]
This is a pre-existing issue, but does ufs_mtk_mphy_power_on() safely
handle phy_power_on() failures?

Looking at ufs_mtk_mphy_power_on() in drivers/ufs/host/ufs-mediatek.c:

static int ufs_mtk_mphy_power_on(struct ufs_hba *hba, bool on)
{
        ...
        if (on) {
                ret = ufs_mtk_09v_on(host);
                if (ret)
                        return ret;
                phy_power_on(mphy);
        } else {
                phy_power_off(mphy);
        ...
        host->mphy_powered_on = on;
        return 0;
}

If phy_power_on() fails, it cleans up its runtime PM and does not 
increment the power_count, but ufs_mtk_mphy_power_on() ignores the return 
value and still sets host->mphy_powered_on = true. 

When ufs_mtk_mphy_power_on(hba, false) is called later, it will blindly 
call phy_power_off(). Won't this decrement the PHY's power_count 
(potentially underflowing it), corrupting the PHY driver's PM usage 
counter and causing an unbalanced PM state?

>  
>  	return 0;
>  }
> @@ -2470,14 +2417,17 @@ static int ufs_mtk_runtime_suspend(struct device *dev)
>  static int ufs_mtk_runtime_resume(struct device *dev)
>  {
>  	struct ufs_hba *hba = dev_get_drvdata(dev);
> -	struct ufs_mtk_host *host = ufshcd_get_variant(hba);
>  	struct arm_smccc_res res;
> +	int ret;
>  
>  	if (ufs_mtk_is_rtff_mtcmos(hba))
>  		ufs_mtk_mtcmos_ctrl(true, res);
>  
> -	if (host->phy_dev)
> -		pm_runtime_get_sync(host->phy_dev);
> +	ret = ufs_mtk_mphy_power_on(hba, true);
> +	if (ret) {
> +		dev_err(dev, "Failed to power on PHY: %pe\n", ERR_PTR(ret));
> +		return ret;
> +	}

[Severity: High]
Could a failure here cause similar PM state inconsistencies?

If ufs_mtk_mphy_power_on() fails during runtime resume, returning an 
error without rolling back the prior partial initialization (such as 
ufs_mtk_mtcmos_ctrl) might confuse the PM core. Does this need to clean 
up previously resumed components before returning?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260730-mt8196-ufs-v10-0-bc5ecef202dc@collabora.com?part=13

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

WARNING: multiple messages have this Message-ID (diff)
From: sashiko-bot@kernel.org
To: "Louis-Alexis Eyraud" <louisalexis.eyraud@collabora.com>
Cc: linux-phy@lists.infradead.org, neil.armstrong@linaro.org,
	linux-scsi@vger.kernel.org, conor+dt@kernel.org, robh@kernel.org,
	vkoul@kernel.org, olteanv@gmail.com, devicetree@vger.kernel.org
Subject: Re: [PATCH v10 13/26] scsi: ufs: mediatek: Use the common PHY framework
Date: Thu, 30 Jul 2026 10:40:01 +0000	[thread overview]
Message-ID: <20260730104002.59D061F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260730-mt8196-ufs-v10-13-bc5ecef202dc@collabora.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [High] The driver now fails to probe on platforms where the UFS PHY is not defined in the device tree, breaking backward compatibility.
- [High] Returning an error late in PM runtime callbacks leaves the device in an inconsistent state and breaks PM state synchronization.

Pre-existing issues:
- [High] The return values of `phy_power_on()` and `phy_power_off()` are ignored, which can lead to unbalanced PM runtime counts and hardware state corruption.
--

--- Patch [13]: [PATCH v10 13/26] scsi: ufs: mediatek: Use the common PHY framework ---
commit 114da5212062d5f11b7f9274ba9701891ef82788
Author: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>

scsi: ufs: mediatek: Use the common PHY framework
    
This patch refactors the MediaTek UFS driver to use the common PHY framework 
to acquire the device's PHY during ufshcd init, ensuring it is device-linked 
to the correct device.

> diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c
> index e5527969a5e67..385f0180b2309 100644
> --- a/drivers/ufs/host/ufs-mediatek.c
> +++ b/drivers/ufs/host/ufs-mediatek.c

[ ... ]

> @@ -1185,13 +1147,21 @@ static int ufs_mtk_init(struct ufs_hba *hba)
>  
>  	ufs_mtk_init_mcq_irq(hba);
>  
> -	err = ufs_mtk_bind_mphy(hba);
> -	if (err)
> +	host->mphy = devm_phy_get(dev, NULL);
> +	if (IS_ERR(host->mphy)) {
> +		err = dev_err_probe(dev, PTR_ERR(host->mphy), "Failed to get PHY\n");

[Severity: High]
Will this cause the driver probe to fail on platforms where the UFS PHY
is not defined in the device tree?

The original ufs_mtk_bind_mphy() tolerated -ENODEV to allow for unbound 
mphys since not all platforms require specific mphy control. By switching 
to devm_phy_get() instead of devm_phy_optional_get(), won't this return 
-ENODEV and fail the probe if the "phys" property is missing, breaking 
backward compatibility with older device trees?

> +		goto out_variant_clear;
> +	}
> +
> +	err = phy_init(host->mphy);
> +	if (err) {
> +		dev_err_probe(dev, err, "Failed to initialize PHY\n");
>  		goto out_variant_clear;
> +	}

[ ... ]

> @@ -2448,9 +2393,8 @@ static int ufs_mtk_system_resume(struct device *dev)
>  static int ufs_mtk_runtime_suspend(struct device *dev)
>  {
>  	struct ufs_hba *hba = dev_get_drvdata(dev);
> -	struct ufs_mtk_host *host = ufshcd_get_variant(hba);
>  	struct arm_smccc_res res;
> -	int ret = 0;
> +	int ret;
>  
>  	ret = ufshcd_runtime_suspend(dev);
>  	if (ret)
> @@ -2461,8 +2405,11 @@ static int ufs_mtk_runtime_suspend(struct device *dev)
>  	if (ufs_mtk_is_rtff_mtcmos(hba))
>  		ufs_mtk_mtcmos_ctrl(false, res);
>  
> -	if (host->phy_dev)
> -		pm_runtime_put_sync(host->phy_dev);
> +	ret = ufs_mtk_mphy_power_on(hba, false);
> +	if (ret) {
> +		dev_err(dev, "Failed to power off PHY: %pe\n", ERR_PTR(ret));
> +		return ret;
> +	}

[Severity: High]
Does returning an error here leave the device in an inconsistent state?

If ufshcd_runtime_suspend() succeeds, the main UFS controller hardware is
fully suspended (clocks gated, link hibern8). If ufs_mtk_mphy_power_on() 
fails afterward, this returns the error to the PM core. 

Since the PM core intercepts the non-zero return as a runtime suspend 
failure, it leaves the software state as RPM_ACTIVE. If the software 
thinks the device is active while the hardware is actually suspended, 
won't the next hardware access skip runtime_resume and cause a system 
hang or bus error?

[Severity: High]
This is a pre-existing issue, but does ufs_mtk_mphy_power_on() safely
handle phy_power_on() failures?

Looking at ufs_mtk_mphy_power_on() in drivers/ufs/host/ufs-mediatek.c:

static int ufs_mtk_mphy_power_on(struct ufs_hba *hba, bool on)
{
        ...
        if (on) {
                ret = ufs_mtk_09v_on(host);
                if (ret)
                        return ret;
                phy_power_on(mphy);
        } else {
                phy_power_off(mphy);
        ...
        host->mphy_powered_on = on;
        return 0;
}

If phy_power_on() fails, it cleans up its runtime PM and does not 
increment the power_count, but ufs_mtk_mphy_power_on() ignores the return 
value and still sets host->mphy_powered_on = true. 

When ufs_mtk_mphy_power_on(hba, false) is called later, it will blindly 
call phy_power_off(). Won't this decrement the PHY's power_count 
(potentially underflowing it), corrupting the PHY driver's PM usage 
counter and causing an unbalanced PM state?

>  
>  	return 0;
>  }
> @@ -2470,14 +2417,17 @@ static int ufs_mtk_runtime_suspend(struct device *dev)
>  static int ufs_mtk_runtime_resume(struct device *dev)
>  {
>  	struct ufs_hba *hba = dev_get_drvdata(dev);
> -	struct ufs_mtk_host *host = ufshcd_get_variant(hba);
>  	struct arm_smccc_res res;
> +	int ret;
>  
>  	if (ufs_mtk_is_rtff_mtcmos(hba))
>  		ufs_mtk_mtcmos_ctrl(true, res);
>  
> -	if (host->phy_dev)
> -		pm_runtime_get_sync(host->phy_dev);
> +	ret = ufs_mtk_mphy_power_on(hba, true);
> +	if (ret) {
> +		dev_err(dev, "Failed to power on PHY: %pe\n", ERR_PTR(ret));
> +		return ret;
> +	}

[Severity: High]
Could a failure here cause similar PM state inconsistencies?

If ufs_mtk_mphy_power_on() fails during runtime resume, returning an 
error without rolling back the prior partial initialization (such as 
ufs_mtk_mtcmos_ctrl) might confuse the PM core. Does this need to clean 
up previously resumed components before returning?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260730-mt8196-ufs-v10-0-bc5ecef202dc@collabora.com?part=13

  reply	other threads:[~2026-07-30 10:40 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-30  9:48 [PATCH v10 00/26] MediaTek UFS Cleanup and MT8196 Enablement Louis-Alexis Eyraud
2026-07-30  9:48 ` Louis-Alexis Eyraud
2026-07-30  9:48 ` [PATCH v10 01/26] dt-bindings: phy: Add mediatek,mt8196-ufsphy variant Louis-Alexis Eyraud
2026-07-30  9:48   ` Louis-Alexis Eyraud
2026-07-30  9:48 ` [PATCH v10 02/26] dt-bindings: ufs: mediatek,ufs: Complete the binding Louis-Alexis Eyraud
2026-07-30  9:48   ` Louis-Alexis Eyraud
2026-07-30  9:57   ` sashiko-bot
2026-07-30  9:57     ` sashiko-bot
2026-07-30  9:48 ` [PATCH v10 03/26] dt-bindings: ufs: mediatek,ufs: Add mt8196 variant Louis-Alexis Eyraud
2026-07-30  9:48   ` Louis-Alexis Eyraud
2026-07-30  9:59   ` sashiko-bot
2026-07-30  9:59     ` sashiko-bot
2026-07-30  9:49 ` [PATCH v10 04/26] scsi: ufs: mediatek: Move MTK_SIP_UFS_CONTROL to mtk_sip_svc.h Louis-Alexis Eyraud
2026-07-30  9:49   ` Louis-Alexis Eyraud
2026-07-30  9:49 ` [PATCH v10 05/26] phy: mediatek: ufs: Add support for resets Louis-Alexis Eyraud
2026-07-30  9:49   ` Louis-Alexis Eyraud
2026-07-30  9:49 ` [PATCH v10 06/26] scsi: ufs: mediatek: Rework resets Louis-Alexis Eyraud
2026-07-30  9:49   ` Louis-Alexis Eyraud
2026-07-30 10:29   ` sashiko-bot
2026-07-30 10:29     ` sashiko-bot
2026-07-30  9:49 ` [PATCH v10 07/26] scsi: ufs: mediatek: Rework 0.9V regulator Louis-Alexis Eyraud
2026-07-30  9:49   ` Louis-Alexis Eyraud
2026-07-30 10:13   ` sashiko-bot
2026-07-30 10:13     ` sashiko-bot
2026-07-30  9:49 ` [PATCH v10 08/26] scsi: ufs: mediatek: Rework init function Louis-Alexis Eyraud
2026-07-30  9:49   ` Louis-Alexis Eyraud
2026-07-30 10:07   ` sashiko-bot
2026-07-30 10:07     ` sashiko-bot
2026-07-30  9:49 ` [PATCH v10 09/26] scsi: ufs: mediatek: Rework the crypt-boost stuff Louis-Alexis Eyraud
2026-07-30  9:49   ` Louis-Alexis Eyraud
2026-07-30 10:16   ` sashiko-bot
2026-07-30 10:16     ` sashiko-bot
2026-07-30  9:49 ` [PATCH v10 10/26] scsi: ufs: mediatek: Handle misc host voltage regulators Louis-Alexis Eyraud
2026-07-30  9:49   ` Louis-Alexis Eyraud
2026-07-30 10:29   ` sashiko-bot
2026-07-30 10:29     ` sashiko-bot
2026-07-30  9:49 ` [PATCH v10 11/26] scsi: ufs: mediatek: Remove undocumented downstream reset cruft Louis-Alexis Eyraud
2026-07-30  9:49   ` Louis-Alexis Eyraud
2026-07-30 10:23   ` sashiko-bot
2026-07-30 10:23     ` sashiko-bot
2026-07-30  9:49 ` [PATCH v10 12/26] scsi: ufs: mediatek: Remove vendor kernel quirks cruft Louis-Alexis Eyraud
2026-07-30  9:49   ` Louis-Alexis Eyraud
2026-07-30 10:30   ` sashiko-bot
2026-07-30 10:30     ` sashiko-bot
2026-07-30  9:49 ` [PATCH v10 13/26] scsi: ufs: mediatek: Use the common PHY framework Louis-Alexis Eyraud
2026-07-30  9:49   ` Louis-Alexis Eyraud
2026-07-30 10:40   ` sashiko-bot [this message]
2026-07-30 10:40     ` sashiko-bot
2026-07-30  9:49 ` [PATCH v10 14/26] scsi: ufs: mediatek: Remove mediatek,ufs-broken-rtc property Louis-Alexis Eyraud
2026-07-30  9:49   ` Louis-Alexis Eyraud
2026-07-30  9:49 ` [PATCH v10 15/26] scsi: ufs: mediatek: Rework _ufs_mtk_clk_scale error paths Louis-Alexis Eyraud
2026-07-30  9:49   ` Louis-Alexis Eyraud
2026-07-30 10:34   ` sashiko-bot
2026-07-30 10:34     ` sashiko-bot
2026-07-30  9:49 ` [PATCH v10 16/26] scsi: ufs: mediatek: Clean up logging prints Louis-Alexis Eyraud
2026-07-30  9:49   ` Louis-Alexis Eyraud
2026-07-30  9:49 ` [PATCH v10 17/26] scsi: ufs: mediatek: Rework ufs_mtk_wait_idle_state Louis-Alexis Eyraud
2026-07-30  9:49   ` Louis-Alexis Eyraud
2026-07-30  9:49 ` [PATCH v10 18/26] scsi: ufs: mediatek: Don't acquire dvfsrc-vcore twice Louis-Alexis Eyraud
2026-07-30  9:49   ` Louis-Alexis Eyraud
2026-07-30 10:41   ` sashiko-bot
2026-07-30 10:41     ` sashiko-bot
2026-07-30  9:49 ` [PATCH v10 19/26] scsi: ufs: mediatek: Rework hardware version reading Louis-Alexis Eyraud
2026-07-30  9:49   ` Louis-Alexis Eyraud
2026-07-30  9:49 ` [PATCH v10 20/26] scsi: ufs: mediatek: Back up idle timer in per-instance struct Louis-Alexis Eyraud
2026-07-30  9:49   ` Louis-Alexis Eyraud
2026-07-30 10:53   ` sashiko-bot
2026-07-30 10:53     ` sashiko-bot
2026-07-30  9:49 ` [PATCH v10 21/26] scsi: ufs: mediatek: Remove ret local from link_startup_notify Louis-Alexis Eyraud
2026-07-30  9:49   ` Louis-Alexis Eyraud
2026-07-30  9:49 ` [PATCH v10 22/26] scsi: ufs: mediatek: Remove undocumented "clk-scale-up-vcore-min" Louis-Alexis Eyraud
2026-07-30  9:49   ` Louis-Alexis Eyraud
2026-07-30 10:49   ` sashiko-bot
2026-07-30 10:49     ` sashiko-bot
2026-07-30  9:49 ` [PATCH v10 23/26] scsi: ufs: mediatek: Add MT8196 compatible, update copyright Louis-Alexis Eyraud
2026-07-30  9:49   ` Louis-Alexis Eyraud
2026-07-30  9:49 ` [PATCH v10 24/26] arm64: dts: mediatek: mt8195: Align ufshci node to dt-bindings changes Louis-Alexis Eyraud
2026-07-30  9:49   ` Louis-Alexis Eyraud
2026-07-30 11:13   ` sashiko-bot
2026-07-30 11:13     ` sashiko-bot
2026-07-30  9:49 ` [PATCH v10 25/26] arm64: dts: mediatek: mt8395-genio-1200-evk-ufs: Complete UFS power supplies Louis-Alexis Eyraud
2026-07-30  9:49   ` Louis-Alexis Eyraud
2026-07-30  9:49 ` [PATCH v10 26/26] arm64: dts: mediatek: mt8395-radxa-nio-12l: " Louis-Alexis Eyraud
2026-07-30  9:49   ` Louis-Alexis Eyraud

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=20260730104002.59D061F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=louisalexis.eyraud@collabora.com \
    --cc=neil.armstrong@linaro.org \
    --cc=olteanv@gmail.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --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.