Linux-PHY Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ronald Claveau" <linux-kernel-dev@aliel.fr>
Cc: devicetree@vger.kernel.org, linux-amlogic@lists.infradead.org,
	linux-phy@lists.infradead.org, dri-devel@lists.freedesktop.org,
	robh@kernel.org, conor+dt@kernel.org, neil.armstrong@linaro.org,
	vkoul@kernel.org, olteanv@gmail.com
Subject: Re: [PATCH 07/10] drm/meson: dw-hdmi: Use the generic PHY framework for the HDMI TX PHY
Date: Tue, 17 Nov 2026 20:03:27 +0000	[thread overview]
Message-ID: <sashiko-outbox-219549@kernel.org> (raw)
In-Reply-To: <20261117-meson-drm-create-hdmitx-phy-v1-7-9e0ac931381c@aliel.fr>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] drm/meson: dw-hdmi: suspend/resume order breaks PHY state and
  HDMI output
- [Medium] drm/meson: dw-hdmi: missing phy_exit() on dw_hdmi_probe()
  failure
- [Medium] drm/meson: dw-hdmi: premature PHY teardown in
  meson_dw_hdmi_unbind()
--

commit 91e31ad4e0b36171e791e7c0487c9a4c66b12b31
Author: Ronald Claveau <linux-kernel-dev@aliel.fr>

drm/meson: dw-hdmi: Use the generic PHY framework for the HDMI TX PHY

This commit converts meson_dw_hdmi from direct HHI_HDMI_PHY_CNTL0..5
register writes to the generic PHY API, with a legacy fallback when the
device tree lacks a "phys" property.

> diff --git a/drivers/gpu/drm/meson/meson_dw_hdmi.c b/drivers/gpu/drm/meson/meson_dw_hdmi.c
> index 20a821936b3af..f28cc1e6ee1df 100644
> --- a/drivers/gpu/drm/meson/meson_dw_hdmi.c
> +++ b/drivers/gpu/drm/meson/meson_dw_hdmi.c

[ ... ]

> @@ -590,13 +504,13 @@ static const struct meson_dw_hdmi_data meson_dw_hdmi_g12a_data = {
>  	.top_write = dw_hdmi_g12a_top_write,
>  	.dwc_read = dw_hdmi_g12a_dwc_read,
>  	.dwc_write = dw_hdmi_g12a_dwc_write,
> -	.cntl0_init = 0x000b4242, /* Bandgap */
> -	.cntl1_init = PHY_CNTL1_INIT,
> +	.phy_soc = MESON_HDMI_PHY_G12A,
>  };
>  
> -static void meson_dw_hdmi_init(struct meson_dw_hdmi *meson_dw_hdmi)
> +static int meson_dw_hdmi_init(struct meson_dw_hdmi *meson_dw_hdmi)
>  {
>  	struct meson_drm *priv = meson_dw_hdmi->priv;
> +	int ret;
>  
>  	/* Reset HDMITX APB & TX & PHY */
>  	reset_control_reset(meson_dw_hdmi->hdmitx_apb);
> @@ -624,8 +538,9 @@ static void meson_dw_hdmi_init(struct meson_dw_hdmi *meson_dw_hdmi)
>  	meson_dw_hdmi->data->top_write(meson_dw_hdmi, HDMITX_TOP_BIST_CNTL, BIT(12));
>  
>  	/* Setup PHY */
> -	regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL1, meson_dw_hdmi->data->cntl1_init);
> -	regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL0, meson_dw_hdmi->data->cntl0_init);
> +	ret = phy_init(meson_dw_hdmi->phy);
> +	if (ret)
> +		return ret;
>  
>  	/* Enable HDMI-TX Interrupt */
>  	meson_dw_hdmi->data->top_write(meson_dw_hdmi, HDMITX_TOP_INTR_STAT_CLR,
> @@ -634,6 +549,7 @@ static void meson_dw_hdmi_init(struct meson_dw_hdmi *meson_dw_hdmi)
>  	meson_dw_hdmi->data->top_write(meson_dw_hdmi, HDMITX_TOP_INTR_MASKN,
>  				       HDMITX_TOP_INTR_CORE);
>  
> +	return 0;
>  }
>  
>  static void meson_disable_clk(void *data)
> @@ -746,7 +662,26 @@ static int meson_dw_hdmi_bind(struct device *dev, struct device *master,
>  		return ret;
>  	}
>  
> -	meson_dw_hdmi_init(meson_dw_hdmi);
> +	meson_dw_hdmi->phy = devm_phy_optional_get(dev, "hdmi");
> +	if (IS_ERR(meson_dw_hdmi->phy))
> +		return dev_err_probe(dev, PTR_ERR(meson_dw_hdmi->phy),
> +				     "failed to get HDMI PHY\n");
> +
> +	if (!meson_dw_hdmi->phy) {
> +		/* DEPRECATED: DT without "phys" */
> +		dev_warn(dev, "missing \"phys\", using legacy HDMI PHY\n");
> +		meson_dw_hdmi->phy = meson_hdmi_phy_create_legacy(dev, priv->hhi,
> +						meson_dw_hdmi->data->phy_soc);
> +		if (IS_ERR(meson_dw_hdmi->phy))
> +			return dev_err_probe(dev, PTR_ERR(meson_dw_hdmi->phy),
> +					     "failed to create legacy HDMI PHY\n");
> +
> +		meson_dw_hdmi->legacy_phy = true;
> +	}
> +
> +	ret = meson_dw_hdmi_init(meson_dw_hdmi);
> +	if (ret)
> +		return ret;
>  
>  	/* Bridge / Connector */

[Severity: Medium]
Does meson_dw_hdmi_bind() leak a phy_init() reference if dw_hdmi_probe()
fails later in this function (for example with -EPROBE_DEFER when the DDC
I2C bus is not ready)?

When the PHY comes from the external PHY provider, devres cleanup on a
failed component bind only calls phy_put(), leaving phy->init_count at 1.
On the next bind attempt, meson_dw_hdmi_init() resets hdmitx_phy and calls
phy_init(), which sees init_count > 0 and skips phy->ops->init(), leaving
HHI_HDMI_PHY_CNTL0 and HHI_HDMI_PHY_CNTL1 uninitialized after the hardware
reset.

> @@ -784,6 +719,10 @@ static void meson_dw_hdmi_unbind(struct device *dev, struct device *master,
>  	struct platform_device *pdev = to_platform_device(dev);
>  	int irq = platform_get_irq(pdev, 0);
>  
> +	phy_exit(meson_dw_hdmi->phy);
> +	if (meson_dw_hdmi->legacy_phy)
> +		devm_phy_destroy(dev, meson_dw_hdmi->phy);
> +
>  	devm_free_irq(dev, irq, meson_dw_hdmi);
>  	dw_hdmi_unbind(meson_dw_hdmi->hdmi);
>  	drm_bridge_put(meson_dw_hdmi->bridge);

[Severity: Medium]
Can tearing down meson_dw_hdmi->phy before devm_free_irq() and
dw_hdmi_unbind() cause a use-after-free in dw_hdmi_top_thread_irq()?

CPU0                                    CPU1
meson_dw_hdmi_unbind()
  phy_exit(meson_dw_hdmi->phy)
  devm_phy_destroy(..., meson_dw_hdmi->phy)
                                        dw_hdmi_top_thread_irq()
                                          dw_hdmi_setup_rx_sense()
                                            ...
                                              dw_hdmi_phy_init()
                                                phy_configure(dw_hdmi->phy, ...)
                                                  <-- use-after-free
  devm_free_irq(...)
  dw_hdmi_unbind(...)

In the legacy PHY path, devm_phy_destroy() immediately unregisters and
frees meson_dw_hdmi->phy while the threaded HPD interrupt handler is still
active and can invoke dw_hdmi_phy_init() or dw_hdmi_phy_disable().  Even
with a DT PHY, HPD handling or dw_hdmi_unbind() can access the PHY after
phy_exit().  Should phy_exit() and devm_phy_destroy() run after
devm_free_irq() and dw_hdmi_unbind()?

> @@ -801,6 +740,8 @@ static int __maybe_unused meson_dw_hdmi_pm_suspend(struct device *dev)
>  	if (!meson_dw_hdmi)
>  		return 0;
>  
> +	phy_exit(meson_dw_hdmi->phy);
> +
>  	/* Reset TOP */
>  	meson_dw_hdmi->data->top_write(meson_dw_hdmi,
>  				       HDMITX_TOP_SW_RESET, 0);
> @@ -811,11 +752,14 @@ static int __maybe_unused meson_dw_hdmi_pm_suspend(struct device *dev)
>  static int __maybe_unused meson_dw_hdmi_pm_resume(struct device *dev)
>  {
>  	struct meson_dw_hdmi *meson_dw_hdmi = dev_get_drvdata(dev);
> +	int ret;
>  
>  	if (!meson_dw_hdmi)
>  		return 0;
>  
> -	meson_dw_hdmi_init(meson_dw_hdmi);
> +	ret = meson_dw_hdmi_init(meson_dw_hdmi);
> +	if (ret)
> +		return ret;
>  
>  	dw_hdmi_resume(meson_dw_hdmi->hdmi);

[Severity: High]
Does calling phy_exit() in meson_dw_hdmi_pm_suspend() and phy_init() in
meson_dw_hdmi_pm_resume() break HDMI output across system suspend/resume?

Because the HDMI TX platform device sits after the VPU master device on
dpm_list (both from DT node order and because devm_phy_optional_get() adds
a stateless device link to the PHY that reorders the consumer to the tail
of dpm_list), system suspend runs meson_dw_hdmi_pm_suspend() before
meson_drv_pm_suspend(), and system resume runs meson_drv_pm_resume()
before meson_dw_hdmi_pm_resume().

On suspend, meson_dw_hdmi_pm_suspend() calls phy_exit() while the PHY is
still powered on, before meson_drv_pm_suspend() ->
drm_mode_config_helper_suspend() -> dw_hdmi_phy_disable() calls
phy_power_off().

On resume, meson_drv_pm_resume() -> drm_mode_config_helper_resume() ->
dw_hdmi_phy_init() calls phy_configure() and phy_power_on() while
phy->init_count is still 0.  Then meson_dw_hdmi_pm_resume() runs
meson_dw_hdmi_init(), which resets hdmitx_phy and calls phy_init(); since
phy->power_count > phy->init_count, phy_init() warns ("phy_power_on was
called before phy_init") and runs meson_hdmi_phy_init(), overwriting
HHI_HDMI_PHY_CNTL0 and HHI_HDMI_PHY_CNTL1 with cntl0_init and cntl1_init
and clobbering the mode that meson_drv_pm_resume() just configured and
powered on.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117-meson-drm-create-hdmitx-phy-v1-0-9e0ac931381c@aliel.fr?part=7

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

  reply	other threads:[~2026-11-17 20:03 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 19:33 [PATCH 00/10] phy/drm: amlogic: Extract Meson HDMI TX PHY into a dedicated driver Ronald Claveau via B4 Relay
2026-11-17 19:33 ` [PATCH 01/10] dt-bindings: soc: amlogic: meson-gx-hhi-sysctrl: Fix compatible matching in conditionals Ronald Claveau via B4 Relay
2026-11-17 19:33 ` [PATCH 02/10] dt-bindings: phy: amlogic: Add Meson HDMI TX PHY binding Ronald Claveau via B4 Relay
2026-11-17 19:33 ` [PATCH 03/10] dt-bindings: soc: amlogic: meson-gx-hhi-sysctrl: Add hdmi-phy child node Ronald Claveau via B4 Relay
2026-11-17 19:39   ` sashiko-bot
2026-11-17 19:33 ` [PATCH 04/10] phy: amlogic: Add Meson HDMI TX PHY driver Ronald Claveau via B4 Relay
2026-11-17 19:58   ` sashiko-bot
2026-11-17 19:33 ` [PATCH 05/10] dt-bindings: display: amlogic,meson-dw-hdmi: Add phys and phy-names Ronald Claveau via B4 Relay
2026-11-17 19:33 ` [PATCH 06/10] drm/meson: dw-hdmi: Drop manual HHI clock and memory PD setup Ronald Claveau via B4 Relay
2026-11-17 20:11   ` sashiko-bot
2026-11-17 19:33 ` [PATCH 07/10] drm/meson: dw-hdmi: Use the generic PHY framework for the HDMI TX PHY Ronald Claveau via B4 Relay
2026-11-17 20:03   ` sashiko-bot [this message]
2026-11-17 19:33 ` [PATCH 08/10] arm64: dts: amlogic: Add HDMI TX PHY node for G12 Ronald Claveau via B4 Relay
2026-11-17 19:33 ` [PATCH 09/10] arm64: dts: amlogic: Add HDMI TX PHY node for GXBB Ronald Claveau via B4 Relay
2026-11-17 19:33 ` [PATCH 10/10] arm64: dts: amlogic: Add HDMI TX PHY node for GXL Ronald Claveau via B4 Relay

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-219549@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=linux-kernel-dev@aliel.fr \
    --cc=linux-phy@lists.infradead.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox