drm/dp: Handle zeroed port counts in drm_dp_read_downstream_info()
authorLyude Paul <lyude@redhat.com>
Fri, 30 Apr 2021 22:34:27 +0000 (18:34 -0400)
committerLyude Paul <lyude@redhat.com>
Fri, 7 May 2021 21:32:22 +0000 (17:32 -0400)
While the DP specification isn't entirely clear on if this should be
allowed or not, some branch devices report having downstream ports present
while also reporting a downstream port count of 0. So to avoid breaking
those devices, we need to handle this in drm_dp_read_downstream_info().

So, to do this we assume there's no downstream port info when the
downstream port count is 0.

Signed-off-by: Lyude Paul <lyude@redhat.com>
Tested-by: Jérôme de Bretagne <jerome.debretagne@gmail.com>
Bugzilla: https://gitlab.freedesktop.org/drm/intel/-/issues/3416
Fixes: 3d3721ccb18a ("drm/i915/dp: Extract drm_dp_read_downstream_info()")
Cc: <stable@vger.kernel.org> # v5.10+
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210430223428.10514-1-lyude@redhat.com
drivers/gpu/drm/drm_dp_helper.c

index cb56d74e9d38d6c523403b132ecd581e8231eece..27c8c5bdf7d96627cff66fe85a05b777b207db10 100644 (file)
@@ -682,7 +682,14 @@ int drm_dp_read_downstream_info(struct drm_dp_aux *aux,
            !(dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT))
                return 0;
 
+       /* Some branches advertise having 0 downstream ports, despite also advertising they have a
+        * downstream port present. The DP spec isn't clear on if this is allowed or not, but since
+        * some branches do it we need to handle it regardless.
+        */
        len = drm_dp_downstream_port_count(dpcd);
+       if (!len)
+               return 0;
+
        if (dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DETAILED_CAP_INFO_AVAILABLE)
                len *= 4;