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, devicetree@vger.kernel.org,
	linux-scsi@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org,
	vkoul@kernel.org, neil.armstrong@linaro.org, olteanv@gmail.com
Subject: Re: [PATCH v16 14/23] scsi: ufs: mediatek: Use the common PHY framework
Date: Fri, 27 Nov 2026 16:14:35 +0000	[thread overview]
Message-ID: <sashiko-outbox-237853@kernel.org> (raw)
In-Reply-To: <20261127-mt8196-ufs-v16-14-6f2568f7c119@collabora.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] scsi: ufs: mediatek: premature phy_exit() and power leak in
  ufs_mtk_exit()
--

commit 7f178c3fbe09182cf227562674a16dbb3d7b6d01
Author: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>

scsi: ufs: mediatek: Use the common PHY framework

This commit replaces custom OF parsing and runtime PM management of the UFS
PHY device with devm_phy_optional_get(), phy_init(), and phy_exit() in
ufs_mtk_init() and ufs_mtk_exit().

> diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c
> index 33ed5e6dabfeb..9d7e4bc96203b 100644
> --- a/drivers/ufs/host/ufs-mediatek.c
> +++ b/drivers/ufs/host/ufs-mediatek.c

[ ... ]

> @@ -1336,8 +1308,15 @@ static void ufs_mtk_exit(struct ufs_hba *hba)
>  {
>  	struct ufs_mtk_host *host = ufshcd_get_variant(hba);
>  
> -	if (host)
> -		ufs_mtk_mphy_power_on(hba, false);
> +	if (!host)
> +		return;
> +
> +	ufs_mtk_mphy_power_on(hba, false);
> +
> +	phy_exit(host->mphy);
> +
> +	/* Set MPHY to null so it is not used anymore */
> +	host->mphy = NULL;
>  }

[Severity: High]
Does ufs_mtk_exit() call phy_exit(host->mphy) and clear host->mphy while a
second phy_power_on() reference is still held?

ufs_mtk_init() calls phy_power_on(host->mphy) twice: first in
ufs_mtk_mphy_power_on(hba, true) and then in ufs_mtk_setup_clocks(hba,
true, POST_CHANGE) -> ufs_mtk_pwr_ctrl(hba, true), leaving
mphy->power_count at 2.

During teardown, ufshcd_hba_exit() ungates clocks in
ufshcd_exit_clk_gating() and calls ufshcd_vops_exit() before
ufshcd_setup_clocks(hba, false):

drivers/ufs/core/ufshcd.c:ufshcd_hba_exit() {
    ...
		ufshcd_exit_clk_gating(hba);
		if (hba->eh_wq)
			destroy_workqueue(hba->eh_wq);
		ufshcd_vops_exit(hba);
		ufshcd_setup_vreg(hba, false);
		ufshcd_setup_clocks(hba, false);
    ...
}

ufs_mtk_mphy_power_on(hba, false) only drops mphy->power_count from 2 to 1
and turns off the 0.9V supply before phy_exit() runs and host->mphy is set
to NULL.  Because host->mphy is already NULL when ufshcd_setup_clocks(hba,
false) runs (and uic_link_state is still UIC_LINK_ACTIVE_STATE during
ufshcd_remove(), so ufs_mtk_setup_clocks() skips ufs_mtk_pwr_ctrl()
anyway), the second phy_power_off() is never called.  This leaks
mphy->power_count, the PHY runtime PM reference, and the PHY clocks, and
causes phy_init() to warn and phy_power_on() to skip powering on the PHY
if the driver is re-probed.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127-mt8196-ufs-v16-0-6f2568f7c119@collabora.com?part=14

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, devicetree@vger.kernel.org,
	linux-scsi@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org,
	vkoul@kernel.org, neil.armstrong@linaro.org, olteanv@gmail.com
Subject: Re: [PATCH v16 14/23] scsi: ufs: mediatek: Use the common PHY framework
Date: Fri, 27 Nov 2026 16:14:35 +0000	[thread overview]
Message-ID: <sashiko-outbox-237853@kernel.org> (raw)
In-Reply-To: <20261127-mt8196-ufs-v16-14-6f2568f7c119@collabora.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] scsi: ufs: mediatek: premature phy_exit() and power leak in
  ufs_mtk_exit()
--

commit 7f178c3fbe09182cf227562674a16dbb3d7b6d01
Author: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>

scsi: ufs: mediatek: Use the common PHY framework

This commit replaces custom OF parsing and runtime PM management of the UFS
PHY device with devm_phy_optional_get(), phy_init(), and phy_exit() in
ufs_mtk_init() and ufs_mtk_exit().

> diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c
> index 33ed5e6dabfeb..9d7e4bc96203b 100644
> --- a/drivers/ufs/host/ufs-mediatek.c
> +++ b/drivers/ufs/host/ufs-mediatek.c

[ ... ]

> @@ -1336,8 +1308,15 @@ static void ufs_mtk_exit(struct ufs_hba *hba)
>  {
>  	struct ufs_mtk_host *host = ufshcd_get_variant(hba);
>  
> -	if (host)
> -		ufs_mtk_mphy_power_on(hba, false);
> +	if (!host)
> +		return;
> +
> +	ufs_mtk_mphy_power_on(hba, false);
> +
> +	phy_exit(host->mphy);
> +
> +	/* Set MPHY to null so it is not used anymore */
> +	host->mphy = NULL;
>  }

[Severity: High]
Does ufs_mtk_exit() call phy_exit(host->mphy) and clear host->mphy while a
second phy_power_on() reference is still held?

ufs_mtk_init() calls phy_power_on(host->mphy) twice: first in
ufs_mtk_mphy_power_on(hba, true) and then in ufs_mtk_setup_clocks(hba,
true, POST_CHANGE) -> ufs_mtk_pwr_ctrl(hba, true), leaving
mphy->power_count at 2.

During teardown, ufshcd_hba_exit() ungates clocks in
ufshcd_exit_clk_gating() and calls ufshcd_vops_exit() before
ufshcd_setup_clocks(hba, false):

drivers/ufs/core/ufshcd.c:ufshcd_hba_exit() {
    ...
		ufshcd_exit_clk_gating(hba);
		if (hba->eh_wq)
			destroy_workqueue(hba->eh_wq);
		ufshcd_vops_exit(hba);
		ufshcd_setup_vreg(hba, false);
		ufshcd_setup_clocks(hba, false);
    ...
}

ufs_mtk_mphy_power_on(hba, false) only drops mphy->power_count from 2 to 1
and turns off the 0.9V supply before phy_exit() runs and host->mphy is set
to NULL.  Because host->mphy is already NULL when ufshcd_setup_clocks(hba,
false) runs (and uic_link_state is still UIC_LINK_ACTIVE_STATE during
ufshcd_remove(), so ufs_mtk_setup_clocks() skips ufs_mtk_pwr_ctrl()
anyway), the second phy_power_off() is never called.  This leaks
mphy->power_count, the PHY runtime PM reference, and the PHY clocks, and
causes phy_init() to warn and phy_power_on() to skip powering on the PHY
if the driver is re-probed.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127-mt8196-ufs-v16-0-6f2568f7c119@collabora.com?part=14

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

  reply	other threads:[~2026-11-27 16:14 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 16:00 [PATCH v16 00/23] MediaTek UFS Cleanup and MT8196 Enablement Louis-Alexis Eyraud
2026-11-27 16:00 ` Louis-Alexis Eyraud
2026-11-27 16:00 ` [PATCH v16 01/23] dt-bindings: phy: Add mediatek,mt8196-ufsphy variant Louis-Alexis Eyraud
2026-11-27 16:00   ` Louis-Alexis Eyraud
2026-11-27 16:00 ` [PATCH v16 02/23] dt-bindings: ufs: mediatek,ufs: Complete the binding Louis-Alexis Eyraud
2026-11-27 16:00   ` Louis-Alexis Eyraud
2026-11-27 16:17   ` sashiko-bot
2026-11-27 16:17     ` sashiko-bot
2026-11-27 16:00 ` [PATCH v16 03/23] dt-bindings: ufs: mediatek,ufs: Add mt8196 variant Louis-Alexis Eyraud
2026-11-27 16:00   ` Louis-Alexis Eyraud
2026-11-27 16:00 ` [PATCH v16 04/23] scsi: ufs: mediatek: Move MTK_SIP_UFS_CONTROL to mtk_sip_svc.h Louis-Alexis Eyraud
2026-11-27 16:00   ` Louis-Alexis Eyraud
2026-11-27 16:00 ` [PATCH v16 05/23] phy: mediatek: ufs: Add support for resets Louis-Alexis Eyraud
2026-11-27 16:00   ` Louis-Alexis Eyraud
2026-11-27 16:00 ` [PATCH v16 06/23] scsi: ufs: mediatek: Rework resets Louis-Alexis Eyraud
2026-11-27 16:00   ` Louis-Alexis Eyraud
2026-11-27 16:00 ` [PATCH v16 07/23] scsi: ufs: mediatek: Rework 0.9V regulator Louis-Alexis Eyraud
2026-11-27 16:00   ` Louis-Alexis Eyraud
2026-11-27 16:00 ` [PATCH v16 08/23] scsi: ufs: mediatek: Add dual 0.9V supply support Louis-Alexis Eyraud
2026-11-27 16:00   ` Louis-Alexis Eyraud
2026-11-27 16:00 ` [PATCH v16 09/23] scsi: ufs: mediatek: Rework init function Louis-Alexis Eyraud
2026-11-27 16:00   ` Louis-Alexis Eyraud
2026-11-27 16:00 ` [PATCH v16 10/23] scsi: ufs: mediatek: Rework the crypt-boost stuff Louis-Alexis Eyraud
2026-11-27 16:00   ` Louis-Alexis Eyraud
2026-11-27 16:00 ` [PATCH v16 11/23] scsi: ufs: mediatek: Handle misc host voltage regulators Louis-Alexis Eyraud
2026-11-27 16:00   ` Louis-Alexis Eyraud
2026-11-27 16:00 ` [PATCH v16 12/23] scsi: ufs: mediatek: Remove undocumented downstream reset cruft Louis-Alexis Eyraud
2026-11-27 16:00   ` Louis-Alexis Eyraud
2026-11-27 16:00 ` [PATCH v16 13/23] scsi: ufs: mediatek: Remove vendor kernel quirks cruft Louis-Alexis Eyraud
2026-11-27 16:00   ` Louis-Alexis Eyraud
2026-11-27 16:11   ` sashiko-bot
2026-11-27 16:11     ` sashiko-bot
2026-11-27 16:00 ` [PATCH v16 14/23] scsi: ufs: mediatek: Use the common PHY framework Louis-Alexis Eyraud
2026-11-27 16:00   ` Louis-Alexis Eyraud
2026-11-27 16:14   ` sashiko-bot [this message]
2026-11-27 16:14     ` sashiko-bot
2026-11-27 16:00 ` [PATCH v16 15/23] scsi: ufs: mediatek: Remove mediatek,ufs-broken-rtc property Louis-Alexis Eyraud
2026-11-27 16:00   ` Louis-Alexis Eyraud
2026-11-27 16:00 ` [PATCH v16 16/23] scsi: ufs: mediatek: Rework _ufs_mtk_clk_scale error paths Louis-Alexis Eyraud
2026-11-27 16:00   ` Louis-Alexis Eyraud
2026-11-27 16:00 ` [PATCH v16 17/23] scsi: ufs: mediatek: Clean up logging prints Louis-Alexis Eyraud
2026-11-27 16:00   ` Louis-Alexis Eyraud
2026-11-27 16:00 ` [PATCH v16 18/23] scsi: ufs: mediatek: Rework ufs_mtk_wait_idle_state Louis-Alexis Eyraud
2026-11-27 16:00   ` Louis-Alexis Eyraud
2026-11-27 16:00 ` [PATCH v16 19/23] scsi: ufs: mediatek: Don't acquire dvfsrc-vcore twice Louis-Alexis Eyraud
2026-11-27 16:00   ` Louis-Alexis Eyraud
2026-11-27 16:00 ` [PATCH v16 20/23] scsi: ufs: mediatek: Rework hardware version reading Louis-Alexis Eyraud
2026-11-27 16:00   ` Louis-Alexis Eyraud
2026-11-27 16:00 ` [PATCH v16 21/23] scsi: ufs: mediatek: Remove ret local from link_startup_notify Louis-Alexis Eyraud
2026-11-27 16:00   ` Louis-Alexis Eyraud
2026-11-27 16:00 ` [PATCH v16 22/23] scsi: ufs: mediatek: Remove undocumented "clk-scale-up-vcore-min" Louis-Alexis Eyraud
2026-11-27 16:00   ` Louis-Alexis Eyraud
2026-11-27 16:00 ` [PATCH v16 23/23] scsi: ufs: mediatek: Add MT8196 compatible, update copyright Louis-Alexis Eyraud
2026-11-27 16:00   ` 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=sashiko-outbox-237853@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.