drm/dp/mst: Handle invalid link bandwidth from DPCD gracefully
authorChris Wilson <chris@chris-wilson.co.uk>
Wed, 12 Nov 2014 10:13:37 +0000 (10:13 +0000)
committerDave Airlie <airlied@redhat.com>
Fri, 14 Nov 2014 23:31:34 +0000 (09:31 +1000)
Don't BUG out if the link reports an invalid (or plain unknown)
bandwidth value, but report the failure and fail gracefully.

Fixes a trivial compiler warning in case the BUG is ever compiled away.

Link: http://lkml.kernel.org/p/1415785566-12758-1-git-send-email-geert@linux-m68k.org
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Dave Airlie <airlied@redhat.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
drivers/gpu/drm/drm_dp_mst_topology.c

index dc98b8f781680f39f990ae236cac4998e12893f0..5682d7e9f1ec28a825263097d7009fdbf5b5cdd5 100644 (file)
@@ -1799,17 +1799,27 @@ static int drm_dp_send_up_ack_reply(struct drm_dp_mst_topology_mgr *mgr,
        return 0;
 }
 
-static int drm_dp_get_vc_payload_bw(int dp_link_bw, int dp_link_count)
+static bool drm_dp_get_vc_payload_bw(int dp_link_bw,
+                                    int dp_link_count,
+                                    int *out)
 {
        switch (dp_link_bw) {
+       default:
+               DRM_DEBUG_KMS("invalid link bandwidth in DPCD: %x (link count: %d)\n",
+                             dp_link_bw, dp_link_count);
+               return false;
+
        case DP_LINK_BW_1_62:
-               return 3 * dp_link_count;
+               *out = 3 * dp_link_count;
+               break;
        case DP_LINK_BW_2_7:
-               return 5 * dp_link_count;
+               *out = 5 * dp_link_count;
+               break;
        case DP_LINK_BW_5_4:
-               return 10 * dp_link_count;
+               *out = 10 * dp_link_count;
+               break;
        }
-       BUG();
+       return true;
 }
 
 /**
@@ -1841,7 +1851,13 @@ int drm_dp_mst_topology_mgr_set_mst(struct drm_dp_mst_topology_mgr *mgr, bool ms
                        goto out_unlock;
                }
 
-               mgr->pbn_div = drm_dp_get_vc_payload_bw(mgr->dpcd[1], mgr->dpcd[2] & DP_MAX_LANE_COUNT_MASK);
+               if (!drm_dp_get_vc_payload_bw(mgr->dpcd[1],
+                                             mgr->dpcd[2] & DP_MAX_LANE_COUNT_MASK,
+                                             &mgr->pbn_div)) {
+                       ret = -EINVAL;
+                       goto out_unlock;
+               }
+
                mgr->total_pbn = 2560;
                mgr->total_slots = DIV_ROUND_UP(mgr->total_pbn, mgr->pbn_div);
                mgr->avail_slots = mgr->total_slots;