[PATCH 07/10] drm/meson: dw-hdmi: Use the generic PHY framework for the HDMI TX PHY
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Tue Nov 17 12:03:27 PST 2026
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 at 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
More information about the linux-phy
mailing list