drm/i915: Fix null pointer dereference in ring cleanup code
authorJohn Harrison <John.C.Harrison@Intel.com>
Fri, 31 Oct 2014 12:00:26 +0000 (12:00 +0000)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Tue, 4 Nov 2014 22:22:14 +0000 (23:22 +0100)
If a ring failed to initialise for any reason then the error path would try to
clean up all rings including those that had not yet been allocated. The ring
clean up code did a check that the ring was valid before starting its work.
Unfortunately, that was after it had already dereferenced the ring to obtain a
dev_private pointer.

Signed-off-by: John Harrison <John.C.Harrison@Intel.com>
Reviewed-by: Damien Lespiau <damien.lespiau@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
drivers/gpu/drm/i915/intel_lrc.c
drivers/gpu/drm/i915/intel_ringbuffer.c

index 803fc38664c4f3eec8ad56de6bccc598ab960306..d7525bd6d81058227aad5d038e6cefab569873fd 100644 (file)
@@ -1214,11 +1214,13 @@ static int gen8_emit_request(struct intel_ringbuffer *ringbuf)
  */
 void intel_logical_ring_cleanup(struct intel_engine_cs *ring)
 {
-       struct drm_i915_private *dev_priv = ring->dev->dev_private;
+       struct drm_i915_private *dev_priv;
 
        if (!intel_ring_initialized(ring))
                return;
 
+       dev_priv = ring->dev->dev_private;
+
        intel_logical_ring_stop(ring);
        WARN_ON((I915_READ_MODE(ring) & MODE_IDLE) == 0);
        ring->preallocated_lazy_request = NULL;
index a8f72e8d64e3a690ff37aab62845ec83f0a36ab8..f457146ff6a46cca11169bb1358fd99c822fb403 100644 (file)
@@ -1845,12 +1845,15 @@ error:
 
 void intel_cleanup_ring_buffer(struct intel_engine_cs *ring)
 {
-       struct drm_i915_private *dev_priv = to_i915(ring->dev);
-       struct intel_ringbuffer *ringbuf = ring->buffer;
+       struct drm_i915_private *dev_priv;
+       struct intel_ringbuffer *ringbuf;
 
        if (!intel_ring_initialized(ring))
                return;
 
+       dev_priv = to_i915(ring->dev);
+       ringbuf = ring->buffer;
+
        intel_stop_ring_buffer(ring);
        WARN_ON(!IS_GEN2(ring->dev) && (I915_READ_MODE(ring) & MODE_IDLE) == 0);