aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2012-07-15 07:34:23 -0400
committerDaniel Vetter <daniel.vetter@ffwll.ch>2012-07-25 04:39:58 -0400
commitb259b3120607f642daabdaadc99430a306899ffe (patch)
tree4da2ddab5e4470ca1b89f47ff1b2c1fec7806e3e /drivers/gpu
parenteeef9b3874d756405ab8f71b4012a2e7ce31458e (diff)
drm/i915: fix invalid reference handling of the default ctx obj
Otherwise we end up trying to unpin a freed object and BUG. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Reviewed-by: Ben Widawsky <ben@bwidawsk.net> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Diffstat (limited to 'drivers/gpu')
-rw-r--r--drivers/gpu/drm/i915/i915_gem_context.c18
1 files changed, 4 insertions, 14 deletions
diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index 65639ad72808..873119f2436e 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -419,8 +419,11 @@ static int do_switch(struct drm_i915_gem_object *from_obj,
419 from_obj->dirty = 1; 419 from_obj->dirty = 1;
420 BUG_ON(from_obj->ring != to->ring); 420 BUG_ON(from_obj->ring != to->ring);
421 i915_gem_object_unpin(from_obj); 421 i915_gem_object_unpin(from_obj);
422
423 drm_gem_object_unreference(&from_obj->base);
422 } 424 }
423 425
426 drm_gem_object_reference(&to->obj->base);
424 ring->last_context_obj = to->obj; 427 ring->last_context_obj = to->obj;
425 to->is_initialized = true; 428 to->is_initialized = true;
426 429
@@ -470,20 +473,7 @@ int i915_switch_context(struct intel_ring_buffer *ring,
470 if (from_obj == to->obj) 473 if (from_obj == to->obj)
471 return 0; 474 return 0;
472 475
473 ret = do_switch(from_obj, to, i915_gem_next_request_seqno(to->ring)); 476 return do_switch(from_obj, to, i915_gem_next_request_seqno(to->ring));
474 if (ret)
475 return ret;
476
477 /* Just to make the code a little cleaner we take the object reference
478 * after the switch was successful. It would be more intuitive to ref
479 * the 'to' object before the switch but we know the refcount must be >0
480 * if context_get() succeeded, and we hold struct mutex. So it's safe to
481 * do this here/now
482 */
483 drm_gem_object_reference(&to->obj->base);
484 if (from_obj != NULL)
485 drm_gem_object_unreference(&from_obj->base);
486 return ret;
487} 477}
488 478
489int i915_gem_context_create_ioctl(struct drm_device *dev, void *data, 479int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,