drm/i915/gvt: fix a bounds check in ring_id_to_context_switch_event()
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 13 Apr 2017 19:48:28 +0000 (22:48 +0300)
committerZhenyu Wang <zhenyuw@linux.intel.com>
Tue, 18 Apr 2017 09:50:05 +0000 (17:50 +0800)
There are two bugs here.  The && should be || and the > is off by one so
it should be >= ARRAY_SIZE().

Fixes: 8453d674ae7e ("drm/i915/gvt: vGPU execlist virtualization")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Zhenyu Wang <zhenyuw@linux.intel.com>
drivers/gpu/drm/i915/gvt/execlist.c

index d077ed97970f9ff01a604299c002dd09fa65b1ff..dc9aef3e92d462ca76c010f140302bb388e14844 100644 (file)
@@ -56,8 +56,8 @@ static int context_switch_events[] = {
 
 static int ring_id_to_context_switch_event(int ring_id)
 {
-       if (WARN_ON(ring_id < RCS && ring_id >
-                               ARRAY_SIZE(context_switch_events)))
+       if (WARN_ON(ring_id < RCS ||
+                   ring_id >= ARRAY_SIZE(context_switch_events)))
                return -EINVAL;
 
        return context_switch_events[ring_id];