Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "AngeloGioacchino Del Regno" <angelogioacchino.delregno@collabora.com>
Cc: conor+dt@kernel.org, robh@kernel.org, devicetree@vger.kernel.org,
	dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v3 06/11] drm/mediatek: mtk_dp: Use PHY API for PHY power sequences
Date: Thu, 09 Jul 2026 11:00:24 +0000	[thread overview]
Message-ID: <20260709110024.69E531F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260709103431.46616-7-angelogioacchino.delregno@collabora.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Double unregistration of the `mtk_dp->phy_dev` platform device on the `devm_phy_get()` error path causes a use-after-free.
- [Medium] The newly added `phy_power_on()`/`phy_power_off()` calls are dead code, and if reachable, they would violate the PHY API contract and leak reference counts.
--

--- Patch [6]: [PATCH v3 06/11] drm/mediatek: mtk_dp: Use PHY API for PHY power sequences ---
commit e6bfbadbdfc23b97fa303c95119a421df2604e0a
Author: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>

drm/mediatek: mtk_dp: Use PHY API for PHY power sequences

The PHY driver has gained support for .power_on() and .power_off()
callbacks: use the API provided phy_power_on(), phy_power_off()
functions instead of writing into PHY registers from this driver.

I noticed an issue in mtk_dp_register_phy() from patch 4 of this series:

drivers/gpu/drm/mediatek/mtk_dp.c:mtk_dp_register_phy() {
    ...
	ret = devm_add_action_or_reset(dev, mtk_dp_unregister_pdevs, mtk_dp->phy_dev);
	if (ret)
		return dev_err_probe(dev, ret,
				     "Failed to add phy unregister devm action");
    ...
	mtk_dp->phy = devm_phy_get(&mtk_dp->phy_dev->dev, "dp");
	if (IS_ERR(mtk_dp->phy)) {
		platform_device_unregister(mtk_dp->phy_dev);
		return dev_err_probe(dev, PTR_ERR(mtk_dp->phy), "Failed to get phy\n");
	}
    ...
}

[Severity: High]
Does this explicit unregister conflict with the devm action registered earlier?

If devm_phy_get() fails, platform_device_unregister() is called on
mtk_dp->phy_dev, and then an error is returned. Returning an error triggers
the devres cleanup, which executes the registered devm action and calls
platform_device_unregister() on the exact same pointer a second time, causing
a double-free and use-after-free.

> diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c b/drivers/gpu/drm/mediatek/mtk_dp.c
> index 409d089550a90..b4cb1996a3314 100644
> --- a/drivers/gpu/drm/mediatek/mtk_dp.c
> +++ b/drivers/gpu/drm/mediatek/mtk_dp.c
> @@ -1414,20 +1416,35 @@ static void mtk_dp_power_enable(struct mtk_dp *mtk_dp)
>  			   SW_RST_B_PHYD, SW_RST_B_PHYD);
>  	mtk_dp_update_bits(mtk_dp, MTK_DP_TOP_PWR_STATE,
>  			   DP_PWR_STATE_BANDGAP_TPLL, DP_PWR_STATE_MASK);
> -	regmap_write(mtk_dp->regs, DP_PHY_AUX_RX_CTL,
> -		     RG_DPAUX_RX_VALID_DEGLITCH_EN | RG_XTP_GLB_CKDET_EN |
> -		     RG_DPAUX_RX_EN);
> -	regmap_clear_bits(mtk_dp->regs, MTK_DP_0034, DA_CKM_CKTX0_EN_FORCE_EN);
> +
> +	if (mtk_dp->phy_dev) {

[Severity: Medium]
The commit message claims this patch replaces manual PHY register writes with
phy_power_on() and phy_power_off(). However, these API calls are placed in
the else branch of if (mtk_dp->phy_dev).

Because mtk_dp_register_phy() unconditionally registers the dummy platform
device unless it fails (which would abort the probe), mtk_dp->phy_dev is
always a valid pointer.

This makes the if-condition always true, so the new phy_power_on() and
phy_power_off() API calls are never reached, and the legacy manual writes
continue to execute. Are these new calls unreachable dead code?

Additionally, if this code were reachable (for example, for a future
DT-provided PHY), does phy_power_on() get called during eDP probe before
phy_init() is called, violating the PHY API contract? 

And if phy_power_on() fails, the failure is warned but not propagated, leaving
the PHY power count un-incremented. This could cause a subsequent
phy_power_off() to underflow the reference count.

> +		regmap_write(mtk_dp->regs, DP_PHY_AUX_RX_CTL,
> +			     RG_DPAUX_RX_VALID_DEGLITCH_EN | RG_XTP_GLB_CKDET_EN |
> +			     RG_DPAUX_RX_EN);
> +		regmap_clear_bits(mtk_dp->regs, MTK_DP_0034, DA_CKM_CKTX0_EN_FORCE_EN);
> +	} else {
> +		ret = phy_power_on(mtk_dp->phy);
> +		if (ret)
> +			dev_warn(mtk_dp->dev, "Could not power on PHY!\n");
> +	}
>  }
>  
>  static void mtk_dp_power_disable(struct mtk_dp *mtk_dp)
>  {
> +	int ret;
> +
>  	mtk_dp_write(mtk_dp, MTK_DP_TOP_PWR_STATE, 0);
>  
> -	regmap_set_bits(mtk_dp->regs, MTK_DP_0034, DA_CKM_CKTX0_EN_FORCE_EN);
> +	if (unlikely(mtk_dp->phy_dev)) {
> +		regmap_set_bits(mtk_dp->regs, MTK_DP_0034, DA_CKM_CKTX0_EN_FORCE_EN);
>  
> -	/* Disable RX */
> -	regmap_write(mtk_dp->regs, DP_PHY_AUX_RX_CTL, 0);
> +		/* Disable RX */
> +		regmap_write(mtk_dp->regs, DP_PHY_AUX_RX_CTL, 0);
> +	} else {
> +		ret = phy_power_off(mtk_dp->phy);
> +		if (ret)
> +			dev_warn(mtk_dp->dev, "Could not power off PHY!\n");
> +	}
>  
>  	mtk_dp_write(mtk_dp, MTK_DP_TOP_MEM_PD,
>  		     0x550 | FUSE_SEL | MEM_ISO_EN);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260709103431.46616-1-angelogioacchino.delregno@collabora.com?part=6

  reply	other threads:[~2026-07-09 11:00 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-09 10:34 [PATCH v3 00/11] drm: MediaTek DisplayPort cleanups and MT8196 eDP AngeloGioacchino Del Regno
2026-07-09 10:34 ` [PATCH v3 01/11] dt-bindings: display: mediatek: dp: Deprecate nvmem efuse data AngeloGioacchino Del Regno
2026-07-09 10:34 ` [PATCH v3 02/11] dt-bindings: display: mediatek: dp: Add compatible for MT8196 eDP AngeloGioacchino Del Regno
2026-07-09 10:34 ` [PATCH v3 03/11] drm/mediatek: mtk_dp: Fix hdmi codec and phy driver unregistration AngeloGioacchino Del Regno
2026-07-09 10:46   ` sashiko-bot
2026-07-09 11:10     ` AngeloGioacchino Del Regno
2026-07-09 10:34 ` [PATCH v3 04/11] drm/mediatek: mtk_dp: Clarify SMC eDP/DP video unmute commands AngeloGioacchino Del Regno
2026-07-09 10:34 ` [PATCH v3 05/11] drm/mediatek: mtk_dp: Rework register offsets for proper PHY usage AngeloGioacchino Del Regno
2026-07-09 10:34 ` [PATCH v3 06/11] drm/mediatek: mtk_dp: Use PHY API for PHY power sequences AngeloGioacchino Del Regno
2026-07-09 11:00   ` sashiko-bot [this message]
2026-07-09 10:34 ` [PATCH v3 07/11] drm/mediatek: mtk_dp: Add support for PHY from devicetree AngeloGioacchino Del Regno
2026-07-09 10:55   ` sashiko-bot
2026-07-09 10:34 ` [PATCH v3 08/11] drm/mediatek: mtk_dp: Move max link rate to SoC specific data AngeloGioacchino Del Regno
2026-07-09 10:47   ` sashiko-bot
2026-07-09 10:34 ` [PATCH v3 09/11] drm/mediatek: mtk_dp: Add support for HotPlug Detection in DP AUX AngeloGioacchino Del Regno
2026-07-09 10:49   ` sashiko-bot
2026-07-09 10:34 ` [PATCH v3 10/11] drm/mediatek: mtk_dp: Add support for eDP1.5 IPs and MT8196 SoC AngeloGioacchino Del Regno
2026-07-09 10:51   ` sashiko-bot
2026-07-09 10:34 ` [PATCH v3 11/11] drm/mediatek: mtk_dp: Clarify XTAL freq and Debounce registers AngeloGioacchino Del Regno
2026-07-09 10:42   ` 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=20260709110024.69E531F00A3D@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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