drm: free core gem object from driver callbacks
authorDaniel Vetter <daniel.vetter@ffwll.ch>
Fri, 9 Apr 2010 19:05:05 +0000 (19:05 +0000)
committerDave Airlie <airlied@redhat.com>
Tue, 20 Apr 2010 03:19:33 +0000 (13:19 +1000)
When drivers embed the core gem object into their own structures,
they'll have to do this. Temporarily this results in an ugly

kfree(gem_obj);

in every gem driver.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Acked-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Dave Airlie <airlied@redhat.com>
drivers/gpu/drm/drm_gem.c
drivers/gpu/drm/i915/i915_gem.c
drivers/gpu/drm/nouveau/nouveau_gem.c
drivers/gpu/drm/radeon/radeon_gem.c
include/drm/drmP.h

index 3b64d0ef1998d0918d63672b70d7753e01a7af35..33dad3fa60439e0b39daca428f8b062ddfca8276 100644 (file)
@@ -422,15 +422,15 @@ drm_gem_release(struct drm_device *dev, struct drm_file *file_private)
        idr_destroy(&file_private->object_idr);
 }
 
-static void
-drm_gem_object_free_common(struct drm_gem_object *obj)
+void
+drm_gem_object_release(struct drm_gem_object *obj)
 {
        struct drm_device *dev = obj->dev;
        fput(obj->filp);
        atomic_dec(&dev->object_count);
        atomic_sub(obj->size, &dev->object_memory);
-       kfree(obj);
 }
+EXPORT_SYMBOL(drm_gem_object_release);
 
 /**
  * Called after the last reference to the object has been lost.
@@ -448,8 +448,6 @@ drm_gem_object_free(struct kref *kref)
 
        if (dev->driver->gem_free_object != NULL)
                dev->driver->gem_free_object(obj);
-
-       drm_gem_object_free_common(obj);
 }
 EXPORT_SYMBOL(drm_gem_object_free);
 
@@ -472,8 +470,6 @@ drm_gem_object_free_unlocked(struct kref *kref)
                dev->driver->gem_free_object(obj);
                mutex_unlock(&dev->struct_mutex);
        }
-
-       drm_gem_object_free_common(obj);
 }
 EXPORT_SYMBOL(drm_gem_object_free_unlocked);
 
index 80871c62a57102770867ad273cee16cafc27ff5c..d4ea90999f675b93c22a4559d4e73dbc1569c78e 100644 (file)
@@ -4474,6 +4474,9 @@ void i915_gem_free_object(struct drm_gem_object *obj)
        kfree(obj_priv->page_cpu_valid);
        kfree(obj_priv->bit_17);
        kfree(obj->driver_private);
+
+       drm_gem_object_release(obj);
+       kfree(obj);
 }
 
 /** Unbinds all inactive objects. */
index 1bc0b38a5167d49f6c2a2a6a23fe385e07135c06..6d1aa89ec870b4c9a2b0955e1868fc4f0e3d927a 100644 (file)
@@ -57,6 +57,9 @@ nouveau_gem_object_del(struct drm_gem_object *gem)
        }
 
        ttm_bo_unref(&bo);
+
+       drm_gem_object_release(gem);
+       kfree(gem);
 }
 
 int
index 28dd3e1b9c3a671b7e259d643aeb7cfc832c4096..a72a3ee5d69b332242f48ce7cc5304aa59d4e619 100644 (file)
@@ -44,6 +44,9 @@ void radeon_gem_object_free(struct drm_gem_object *gobj)
        if (robj) {
                radeon_bo_unref(&robj);
        }
+
+       drm_gem_object_release(gobj);
+       kfree(gobj);
 }
 
 int radeon_gem_object_create(struct radeon_device *rdev, int size,
index b3b57b561b920d0505bbb4754ef0e4d058e6e878..c1b987158dfa20c19285e59533c40b2aa5ebb0b2 100644 (file)
@@ -1428,6 +1428,7 @@ extern void drm_sysfs_connector_remove(struct drm_connector *connector);
 /* Graphics Execution Manager library functions (drm_gem.c) */
 int drm_gem_init(struct drm_device *dev);
 void drm_gem_destroy(struct drm_device *dev);
+void drm_gem_object_release(struct drm_gem_object *obj);
 void drm_gem_object_free(struct kref *kref);
 void drm_gem_object_free_unlocked(struct kref *kref);
 struct drm_gem_object *drm_gem_object_alloc(struct drm_device *dev,