[Intel-gfx] [PATCH] drm/i915/overlay: Fix unpinning along init error paths

Ben Widawsky ben at bwidawsk.net
Tue Jun 28 17:57:14 CEST 2011


On Tue, Jun 28, 2011 at 11:27:47AM +0100, Chris Wilson wrote:
> As pointed out by Dan Carpenter, it was seemingly possible to hit an error
> whilst mapping the buffer for the regs (except the only likely error
> returns should not happen during init) and so leak a pin count on the
> bo. To handle this we would need to reacquire the struct mutex, so for
> simplicity rearrange for the lock to be held for the entire function.
> For extra pedagogy, test that we only call init once.
> 
> Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
Reviewed-by: Ben Widawsky <ben at bwidawsk.net>

> diff --git a/drivers/gpu/drm/i915/intel_overlay.c b/drivers/gpu/drm/i915/intel_overlay.c
> index cffd3ed..d360380 100644
> --- a/drivers/gpu/drm/i915/intel_overlay.c
> +++ b/drivers/gpu/drm/i915/intel_overlay.c
> @@ -1405,6 +1405,11 @@ void intel_setup_overlay(struct drm_device *dev)
>  	overlay = kzalloc(sizeof(struct intel_overlay), GFP_KERNEL);
>  	if (!overlay)
>  		return;
> +
> +	mutex_lock(&dev->struct_mutex);
> +	if (WARN_ON(dev_priv->overlay))
> +		goto out_free;
> +
>  	overlay->dev = dev;
>  
>  	reg_bo = i915_gem_alloc_object(dev, PAGE_SIZE);

For my curiosity, was there a reason you chose to acquire the lock after
the kzalloc?





More information about the Intel-gfx mailing list