On 11/21/26 20:37, [email protected] wrote:
> Thank you for your contribution! Sashiko AI review found 3 potential
> issues to consider:
> - [High] drm/meson: dw-hdmi: invalid phy_destroy() in
>   meson_dw_hdmi_bind() error path
> - [Medium] drm/meson: dw-hdmi: stateless device link leaked in
>   meson_dw_hdmi_unbind()
> - [Medium] drm/meson: dw-hdmi: meson_venc_init() clobbers PHY CNTL0 on
>   system resume
> --
> 
> commit 60b745dc55898638b05c8fcafed9d3683b30dff0
> Author: Ronald Claveau <[email protected]>
> 
> drm/meson: dw-hdmi: Use the generic PHY framework for the HDMI TX PHY
> 
> This commit converts the Meson DW-HDMI glue driver to manage the HDMI TX
> PHY through the generic PHY framework, with a legacy fallback when the
> device tree lacks a "phys" property, and adds a stateless device link
> between the VPU master and HDMI-TX device.
> 
>> diff --git a/drivers/gpu/drm/meson/meson_dw_hdmi.c 
>> b/drivers/gpu/drm/meson/meson_dw_hdmi.c
>> index 20a821936b3af..8fdb997c28b40 100644
>> --- a/drivers/gpu/drm/meson/meson_dw_hdmi.c
>> +++ b/drivers/gpu/drm/meson/meson_dw_hdmi.c
> 
> [ ... ]
> 
>> @@ -746,7 +663,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, NULL);
>> +    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 */
>>  
>> @@ -767,14 +703,26 @@ static int meson_dw_hdmi_bind(struct device *dev, 
>> struct device *master,
>>      platform_set_drvdata(pdev, meson_dw_hdmi);
>>  
>>      meson_dw_hdmi->hdmi = dw_hdmi_probe(pdev, &meson_dw_hdmi->dw_plat_data);
>> -    if (IS_ERR(meson_dw_hdmi->hdmi))
>> -            return PTR_ERR(meson_dw_hdmi->hdmi);
>> +    if (IS_ERR(meson_dw_hdmi->hdmi)) {
>> +            ret = PTR_ERR(meson_dw_hdmi->hdmi);
>> +            goto err_hdmi_probe;
>> +    }
>>  
>>      meson_dw_hdmi->bridge = of_drm_find_and_get_bridge(pdev->dev.of_node);
>>  
>> +    link = device_link_add(master, dev, DL_FLAG_STATELESS);
>> +    if (!link)
>> +            dev_warn(dev, "failed to link HDMI (supplier) to DRM master 
>> (consumer)\n");
>> +
>>      DRM_DEBUG_DRIVER("HDMI controller initialized\n");
>>  
>>      return 0;
>> +
>> +err_hdmi_probe:
>> +    phy_exit(meson_dw_hdmi->phy);
>> +    phy_destroy(meson_dw_hdmi->phy);
>> +
>> +    return ret;
>>  }
> 
> [Severity: High]
> Does calling phy_destroy(meson_dw_hdmi->phy) in err_hdmi_probe cause a
> double free or destroy the external provider's PHY when dw_hdmi_probe()
> fails (for example with -EPROBE_DEFER)?
> 
> Both devm_phy_optional_get() and meson_hdmi_phy_create_legacy() (which
> uses devm_phy_create()) are devres-managed in the component devres group
> that component_bind() releases on bind failure.  When legacy_phy is
> false, meson_dw_hdmi is only a consumer, so phy_destroy() unregisters
> the external PHY provider's device while the provider remains bound.
> When legacy_phy is true, component_bind() immediately runs
> devm_phy_consume() -> phy_destroy() a second time on the already-freed
> phy.
> 
> Dropping phy_destroy() from err_hdmi_probe and leaving the cleanup to
> component_bind()'s devres release avoids both issues.
> 

I will drop it.

>>  
>>  static void meson_dw_hdmi_unbind(struct device *dev, struct device *master,
>> @@ -786,6 +734,10 @@ static void meson_dw_hdmi_unbind(struct device *dev, 
>> struct device *master,
>>  
>>      devm_free_irq(dev, irq, meson_dw_hdmi);
>>      dw_hdmi_unbind(meson_dw_hdmi->hdmi);
>> +
>> +    phy_exit(meson_dw_hdmi->phy);
>> +    if (meson_dw_hdmi->legacy_phy)
>> +            devm_phy_destroy(dev, meson_dw_hdmi->phy);
>>      drm_bridge_put(meson_dw_hdmi->bridge);
>>  }
> 
> [Severity: Medium]
> Does meson_dw_hdmi_unbind() leak the DL_FLAG_STATELESS device link
> created in meson_dw_hdmi_bind()?  Stateless device links are not removed
> automatically by the driver core on unbind and require an explicit
> device_link_remove(master, dev) or device_link_del().
> 

I forgot it, thanks for the reminder, I will add the device_link_remove().

>> @@ -801,6 +753,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 +765,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: Medium]
> With the new device link ordering dev (supplier) to resume before master
> (consumer), will meson_drv_pm_resume() -> meson_venc_init() clobber
> HHI_HDMI_PHY_CNTL0 after meson_dw_hdmi_pm_resume() has initialized the
> PHY?
> 
> drivers/gpu/drm/meson/meson_venc.c:meson_venc_init() {
>       ...
>       /* Disable HDMI PHY */
>       regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL0, 0);
>       ...
> }
> 
> meson_dw_hdmi_init() calls phy_init(), which programs HHI_HDMI_PHY_CNTL0
> to cntl0_init (0x000b4242 on G12A for the bandgap).  When the consumer
> meson_drv_pm_resume() runs next, meson_venc_init() overwrites
> HHI_HDMI_PHY_CNTL0 with 0, leaving the G12A bandgap disabled whenever no
> HDMI mode is active across suspend and resume.
> 

I will change the link order to the oposite, and use prepare/complete
for the drm_mode_config_helper suspend/resume.

-- 
Best regards,
Ronald

Reply via email to