[Intel-gfx] [PATCH] fix off by one in phys object cleanup

Jesse Barnes jbarnes at virtuousgeek.org
Mon Jan 19 23:57:27 CET 2009


On Monday, January 19, 2009 12:58 pm Jesse Barnes wrote:
> Fix an off by one in the phys object cleanup code (the cleanup code was
> going from 0-max_objs-1, but it looks like the free_phys_obj code was
> expecting 1-max_objs?), and fix up a related warning while we're at it.
>
> Signed-off-by: Jesse Barnes <jbarnes at virtuousgeek.org>
>
> diff --git a/drivers/gpu/drm/i915/i915_gem.c
> b/drivers/gpu/drm/i915/i915_gem.c index 96316fd..cfb19b8 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -3344,10 +3344,10 @@ void i915_gem_free_phys_object(struct drm_device
> *dev, int id) drm_i915_private_t *dev_priv = dev->dev_private;
>  	struct drm_i915_gem_phys_object *phys_obj;
>
> -	if (!dev_priv->mm.phys_objs[id - 1])
> +	if (!dev_priv->mm.phys_objs[id])
>  		return;
>
> -	phys_obj = dev_priv->mm.phys_objs[id - 1];
> +	phys_obj = dev_priv->mm.phys_objs[id];
>  	if (phys_obj->cur_obj) {
>  		i915_gem_detach_phys_object(dev, phys_obj->cur_obj);
>  	}
> @@ -3357,7 +3357,7 @@ void i915_gem_free_phys_object(struct drm_device
> *dev, int id) #endif
>  	drm_pci_free(dev, phys_obj->handle);
>  	kfree(phys_obj);
> -	dev_priv->mm.phys_objs[id - 1] = NULL;
> +	dev_priv->mm.phys_objs[id] = NULL;
>  }
>
>  void i915_gem_free_all_phys_object(struct drm_device *dev)
> @@ -3427,7 +3427,7 @@ i915_gem_attach_phys_object(struct drm_device *dev,
>  		ret = i915_gem_init_phys_object(dev, id,
>  						obj->size);
>  		if (ret) {
> -			DRM_ERROR("failed to init phys object %d size: %d\n", id, obj->size);
> +			DRM_ERROR("failed to init phys object %d size: %d\n", id,
> (int)obj->size); goto out;
>  		}
>  	}

Ah I see now, the loop in free_all_phys_obj should probably be this instead:

	for (i = I915_GEM_PHYS_CURSOR_0; i < I915_MAX_PHYS_OBJECT; i++)
		i915_gem_free_phys_object(dev, i);

since all the real objects start at ID 1 (index 0).


-- 
Jesse Barnes, Intel Open Source Technology Center



More information about the Intel-gfx mailing list