Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/msm/dp: early return in msm_dp_hpd_plug_handle() skips
  branch sink init
- [Medium] drm/msm/dp: stale sink_count in
  msm_dp_display_is_dongle_plugged() on unplug
--

commit f7be63be5e39d6eb47128f66765be92b0a077052
Author: Gianfranco Mariotti <[email protected]>

drm/msm/dp: fix HPD plugged, AUX gate, and runtime PM tracking

This commit updates hotplug, connector detection, and link preparation in the
MSM DP driver to balance dp->plugged state, AUX transfer enablement, and
runtime PM reference counting.

> diff --git a/drivers/gpu/drm/msm/dp/dp_display.c 
> b/drivers/gpu/drm/msm/dp/dp_display.c
> index 7831dd13b0674..a48f42a173657 100644
> --- a/drivers/gpu/drm/msm/dp/dp_display.c
> +++ b/drivers/gpu/drm/msm/dp/dp_display.c
> @@ -408,8 +408,9 @@ static int msm_dp_display_handle_irq_hpd(struct 
> msm_dp_display_private *dp)
>  
>  static int msm_dp_hpd_plug_handle(struct msm_dp_display_private *dp)
>  {
> -     int ret;
>       struct platform_device *pdev = dp->msm_dp_display.pdev;
> +     bool phy_deinit;
> +     int ret;
>  
>       drm_dbg_dp(dp->drm_dev, "Before, type=%d sink_count=%d\n",
>                       dp->msm_dp_display.connector_type,
> @@ -417,6 +418,9 @@ static int msm_dp_hpd_plug_handle(struct 
> msm_dp_display_private *dp)
>  
>       guard(mutex)(&dp->plugged_lock);
>  
> +     if (dp->plugged)
> +             return 0;
> +
>       ret = pm_runtime_resume_and_get(&pdev->dev);
>       if (ret) {
>               DRM_ERROR("failed to pm_runtime_resume\n");
> @@ -425,9 +429,16 @@ static int msm_dp_hpd_plug_handle(struct 
> msm_dp_display_private *dp)
>  
>       msm_dp_aux_enable_xfers(dp->aux, true);
>  
> -     msm_dp_display_host_phy_init(dp);
> +     phy_deinit = msm_dp_display_host_phy_init(dp);
>  
>       ret = msm_dp_display_process_hpd_high(dp);
> +     if (ret && ret != -ENOTCONN) {
> +             msm_dp_aux_enable_xfers(dp->aux, false);
> +             if (phy_deinit)
> +                     msm_dp_display_host_phy_exit(dp);
> +             pm_runtime_put(&pdev->dev);
> +             return ret;
> +     }
>  
>       drm_dbg_dp(dp->drm_dev, "After, type=%d sink_count=%d\n",
>                       dp->msm_dp_display.connector_type,
> @@ -435,8 +446,8 @@ static int msm_dp_hpd_plug_handle(struct 
> msm_dp_display_private *dp)
>  
>       dp->plugged = true;
>  
> -     return ret;
> -};
> +     return 0;
> +}

[Severity: High]
Does the early return when dp->plugged is true skip downstream sink
initialization when a monitor is later plugged into an already-attached empty
branch device?

When an empty branch dongle is connected first, msm_dp_panel_read_link_caps()
sets dp->link->sink_count = 0 and returns -ENOTCONN before reading EDID, and
msm_dp_hpd_plug_handle() sets dp->plugged = true.  When a downstream monitor
is connected afterward and msm_dp_bridge_hpd_notify() calls
msm_dp_hpd_plug_handle() (for example on external Type-C HPD where
hpd_link_status is ISR_DISCONNECTED, or via drm_bridge_connector_detect()),
msm_dp_hpd_plug_handle() returns early without running
msm_dp_display_process_hpd_high().  Because msm_dp_bridge_detect() only reads
DP_SINK_COUNT into a local variable, dp->link->sink_count stays 0, EDID is
never read, and msm_dp_display_prepare_link() fails with -ENOTCONN.

[ ... ]

> @@ -1598,6 +1603,22 @@ void msm_dp_bridge_hpd_disable(struct drm_bridge 
> *bridge)
>       pm_runtime_put_sync(&msm_dp_display->pdev->dev);
>  }
>  
> +static bool msm_dp_display_is_dongle_plugged(struct msm_dp_display_private 
> *dp,
> +                                          u32 hpd_link_status)
> +{
> +     u8 rev;
> +
> +     guard(mutex)(&dp->plugged_lock);
> +
> +     if (!dp->plugged || !dp->link->has_sink_count || dp->link->sink_count)
> +             return false;
> +
> +     if (hpd_link_status != ISR_DISCONNECTED)
> +             return true;
> +
> +     return !drm_dp_dpcd_read_byte(dp->aux, DP_DPCD_REV, &rev);
> +}
> +
>  void msm_dp_bridge_hpd_notify(struct drm_bridge *bridge,
>                             struct drm_connector *connector,
>                             enum drm_connector_status status)
> @@ -1626,7 +1647,7 @@ void msm_dp_bridge_hpd_notify(struct drm_bridge *bridge,
>               } else {
>                       msm_dp_hpd_plug_handle(dp);
>               }
> -     } else {
> +     } else if (!msm_dp_display_is_dongle_plugged(dp, hpd_link_status)) {
>               msm_dp_hpd_unplug_handle(dp);
>       }

[Severity: Medium]
Can msm_dp_display_is_dongle_plugged() see a stale non-zero
dp->link->sink_count when a downstream monitor is unplugged from an attached
branch dongle?

When a downstream monitor is disconnected and detection runs through
drm_bridge_connector_detect() -> msm_dp_bridge_detect() without a prior
native IRQ_HPD pulse updating dp->link->sink_count, msm_dp_bridge_detect()
reads DP_SINK_COUNT == 0 into a local variable and returns
connector_status_disconnected while dp->link->sink_count remains >= 1.
msm_dp_display_is_dongle_plugged() then returns false and
msm_dp_bridge_hpd_notify() calls msm_dp_hpd_unplug_handle(), tearing down
dp->plugged, AUX transfers, and runtime PM for the still-attached dongle.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=7

Reply via email to