drm: Manage drm_gem_init with drmm_
authorDaniel Vetter <daniel.vetter@ffwll.ch>
Mon, 23 Mar 2020 14:49:22 +0000 (15:49 +0100)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Thu, 26 Mar 2020 14:38:09 +0000 (15:38 +0100)
We might want to look into pushing this down into drm_mm_init, but
that would mean rolling out return codes to a pile of functions
unfortunately. So let's leave that for now.

Acked-by: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200323144950.3018436-24-daniel.vetter@ffwll.ch
drivers/gpu/drm/drm_drv.c
drivers/gpu/drm/drm_gem.c
drivers/gpu/drm/drm_internal.h

index 60a17de75ad07f3e861bae24d3ecf6425a2ef5a8..c6123849b721f8e0763b8743d9372f273f30567d 100644 (file)
@@ -687,13 +687,10 @@ int drm_dev_init(struct drm_device *dev,
 
        ret = drm_dev_set_unique(dev, dev_name(parent));
        if (ret)
-               goto err_setunique;
+               goto err;
 
        return 0;
 
-err_setunique:
-       if (drm_core_check_feature(dev, DRIVER_GEM))
-               drm_gem_destroy(dev);
 err:
        drm_managed_release(dev);
 
@@ -755,9 +752,6 @@ EXPORT_SYMBOL(devm_drm_dev_init);
 void drm_dev_fini(struct drm_device *dev)
 {
        drm_vblank_cleanup(dev);
-
-       if (drm_core_check_feature(dev, DRIVER_GEM))
-               drm_gem_destroy(dev);
 }
 EXPORT_SYMBOL(drm_dev_fini);
 
index 7aa133400d128e7b249c604c3d64daf502b2abac..7bf628e130232e69a2ba0674ea2843f4e17ebd6a 100644 (file)
@@ -44,6 +44,7 @@
 #include <drm/drm_drv.h>
 #include <drm/drm_file.h>
 #include <drm/drm_gem.h>
+#include <drm/drm_managed.h>
 #include <drm/drm_print.h>
 #include <drm/drm_vma_manager.h>
 
  * up at a later date, and as our interface with shmfs for memory allocation.
  */
 
+static void
+drm_gem_init_release(struct drm_device *dev, void *ptr)
+{
+       drm_vma_offset_manager_destroy(dev->vma_offset_manager);
+}
+
 /**
  * drm_gem_init - Initialize the GEM device fields
  * @dev: drm_devic structure to initialize
@@ -89,7 +96,8 @@ drm_gem_init(struct drm_device *dev)
        mutex_init(&dev->object_name_lock);
        idr_init_base(&dev->object_name_idr, 1);
 
-       vma_offset_manager = kzalloc(sizeof(*vma_offset_manager), GFP_KERNEL);
+       vma_offset_manager = drmm_kzalloc(dev, sizeof(*vma_offset_manager),
+                                         GFP_KERNEL);
        if (!vma_offset_manager) {
                DRM_ERROR("out of memory\n");
                return -ENOMEM;
@@ -100,16 +108,7 @@ drm_gem_init(struct drm_device *dev)
                                    DRM_FILE_PAGE_OFFSET_START,
                                    DRM_FILE_PAGE_OFFSET_SIZE);
 
-       return 0;
-}
-
-void
-drm_gem_destroy(struct drm_device *dev)
-{
-
-       drm_vma_offset_manager_destroy(dev->vma_offset_manager);
-       kfree(dev->vma_offset_manager);
-       dev->vma_offset_manager = NULL;
+       return drmm_add_action(dev, drm_gem_init_release, NULL);
 }
 
 /**
index 23ba1577309755da8c4956cbd283917ed1250326..a40a0222419ecdba425ee8f024f8713946567fe9 100644 (file)
@@ -144,7 +144,6 @@ void drm_sysfs_lease_event(struct drm_device *dev);
 /* drm_gem.c */
 struct drm_gem_object;
 int drm_gem_init(struct drm_device *dev);
-void drm_gem_destroy(struct drm_device *dev);
 int drm_gem_handle_create_tail(struct drm_file *file_priv,
                               struct drm_gem_object *obj,
                               u32 *handlep);