drm/vmwgfx: Remove the duplicate bo_free function
authorZack Rusin <zackr@vmware.com>
Tue, 31 Jan 2023 03:35:36 +0000 (22:35 -0500)
committerZack Rusin <zackr@vmware.com>
Tue, 14 Feb 2023 02:34:13 +0000 (21:34 -0500)
Remove the explicit bo_free parameter which was switching between
vmw_bo_bo_free and vmw_gem_destroy which had exactly the same
implementation.

It makes no sense to keep parameter which is always the same, remove it
and all code referencing it. Instead use the vmw_bo_bo_free directly.

Signed-off-by: Zack Rusin <zackr@vmware.com>
Reviewed-by: Martin Krastev <krastevm@vmware.com>
Reviewed-by: Maaz Mombasawala <mombasawalam@vmware.com>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20230131033542.953249-3-zack@kde.org
drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
drivers/gpu/drm/vmwgfx/vmwgfx_gem.c
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c
drivers/gpu/drm/vmwgfx/vmwgfx_shader.c

index 9bf1f9d2f9b6e3aeddd2430d0ff211f67c2b5007..0859c72b52eaad7da2ac011d81e6d6a65bd5e7f0 100644 (file)
@@ -46,6 +46,22 @@ vmw_buffer_object(struct ttm_buffer_object *bo)
        return container_of(bo, struct vmw_buffer_object, base);
 }
 
+/**
+ * vmw_bo_bo_free - vmw buffer object destructor
+ *
+ * @bo: Pointer to the embedded struct ttm_buffer_object
+ */
+static void vmw_bo_bo_free(struct ttm_buffer_object *bo)
+{
+       struct vmw_buffer_object *vmw_bo = vmw_buffer_object(bo);
+
+       WARN_ON(vmw_bo->dirty);
+       WARN_ON(!RB_EMPTY_ROOT(&vmw_bo->res_tree));
+       vmw_bo_unmap(vmw_bo);
+       drm_gem_object_release(&bo->base);
+       kfree(vmw_bo);
+}
+
 /**
  * bo_is_vmw - check if the buffer object is a &vmw_buffer_object
  * @bo: ttm buffer object to be checked
@@ -58,8 +74,7 @@ vmw_buffer_object(struct ttm_buffer_object *bo)
  */
 static bool bo_is_vmw(struct ttm_buffer_object *bo)
 {
-       return bo->destroy == &vmw_bo_bo_free ||
-              bo->destroy == &vmw_gem_destroy;
+       return bo->destroy == &vmw_bo_bo_free;
 }
 
 /**
@@ -361,23 +376,6 @@ void vmw_bo_unmap(struct vmw_buffer_object *vbo)
        ttm_bo_kunmap(&vbo->map);
 }
 
-
-/**
- * vmw_bo_bo_free - vmw buffer object destructor
- *
- * @bo: Pointer to the embedded struct ttm_buffer_object
- */
-void vmw_bo_bo_free(struct ttm_buffer_object *bo)
-{
-       struct vmw_buffer_object *vmw_bo = vmw_buffer_object(bo);
-
-       WARN_ON(vmw_bo->dirty);
-       WARN_ON(!RB_EMPTY_ROOT(&vmw_bo->res_tree));
-       vmw_bo_unmap(vmw_bo);
-       drm_gem_object_release(&bo->base);
-       kfree(vmw_bo);
-}
-
 /* default destructor */
 static void vmw_bo_default_destroy(struct ttm_buffer_object *bo)
 {
@@ -434,13 +432,10 @@ error_free:
 int vmw_bo_create(struct vmw_private *vmw,
                  size_t size, struct ttm_placement *placement,
                  bool interruptible, bool pin,
-                 void (*bo_free)(struct ttm_buffer_object *bo),
                  struct vmw_buffer_object **p_bo)
 {
        int ret;
 
-       BUG_ON(!bo_free);
-
        *p_bo = kmalloc(sizeof(**p_bo), GFP_KERNEL);
        if (unlikely(!*p_bo)) {
                DRM_ERROR("Failed to allocate a buffer.\n");
@@ -448,8 +443,7 @@ int vmw_bo_create(struct vmw_private *vmw,
        }
 
        ret = vmw_bo_init(vmw, *p_bo, size,
-                         placement, interruptible, pin,
-                         bo_free);
+                         placement, interruptible, pin);
        if (unlikely(ret != 0))
                goto out_error;
 
@@ -469,7 +463,6 @@ out_error:
  * @placement: Initial placement.
  * @interruptible: Whether waits should be performed interruptible.
  * @pin: If the BO should be created pinned at a fixed location.
- * @bo_free: The buffer object destructor.
  * Returns: Zero on success, negative error code on error.
  *
  * Note that on error, the code will free the buffer object.
@@ -477,8 +470,7 @@ out_error:
 int vmw_bo_init(struct vmw_private *dev_priv,
                struct vmw_buffer_object *vmw_bo,
                size_t size, struct ttm_placement *placement,
-               bool interruptible, bool pin,
-               void (*bo_free)(struct ttm_buffer_object *bo))
+               bool interruptible, bool pin)
 {
        struct ttm_operation_ctx ctx = {
                .interruptible = interruptible,
@@ -488,7 +480,6 @@ int vmw_bo_init(struct vmw_private *dev_priv,
        struct drm_device *vdev = &dev_priv->drm;
        int ret;
 
-       WARN_ON_ONCE(!bo_free);
        memset(vmw_bo, 0, sizeof(*vmw_bo));
        BUILD_BUG_ON(TTM_MAX_BO_PRIORITY <= 3);
        vmw_bo->base.priority = 3;
@@ -498,7 +489,7 @@ int vmw_bo_init(struct vmw_private *dev_priv,
        drm_gem_private_object_init(vdev, &vmw_bo->base.base, size);
 
        ret = ttm_bo_init_reserved(bdev, &vmw_bo->base, ttm_bo_type_device,
-                                  placement, 0, &ctx, NULL, NULL, bo_free);
+                                  placement, 0, &ctx, NULL, NULL, vmw_bo_bo_free);
        if (unlikely(ret)) {
                return ret;
        }
index b78a10312fad2e4bb081c5d2439ac05e8b861770..87455446a6f995ca765da2aee321661ed50c6a4f 100644 (file)
@@ -424,7 +424,7 @@ static int vmw_cotable_resize(struct vmw_resource *res, size_t new_size)
         * we can use tryreserve without failure.
         */
        ret = vmw_bo_create(dev_priv, new_size, &vmw_mob_placement,
-                           true, true, vmw_bo_bo_free, &buf);
+                           true, true, &buf);
        if (ret) {
                DRM_ERROR("Failed initializing new cotable MOB.\n");
                goto out_done;
index afd20811c73c54241b09fa5c53130da1ee3db56f..d1734d9422a758f11afe6e3cd782382e579a8a60 100644 (file)
@@ -397,8 +397,7 @@ static int vmw_dummy_query_bo_create(struct vmw_private *dev_priv)
         * user of the bo currently.
         */
        ret = vmw_bo_create(dev_priv, PAGE_SIZE,
-                           &vmw_sys_placement, false, true,
-                           &vmw_bo_bo_free, &vbo);
+                           &vmw_sys_placement, false, true, &vbo);
        if (unlikely(ret != 0))
                return ret;
 
index 58e1e7c5e5319583bbe2ba9814b3491f20c861c7..e19f630c085170dce9c2701b3e4fe6fd851e79eb 100644 (file)
@@ -893,7 +893,6 @@ extern int vmw_bo_unpin(struct vmw_private *vmw_priv,
 extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf,
                                 SVGAGuestPtr *ptr);
 extern void vmw_bo_pin_reserved(struct vmw_buffer_object *bo, bool pin);
-extern void vmw_bo_bo_free(struct ttm_buffer_object *bo);
 extern int vmw_bo_create_kernel(struct vmw_private *dev_priv,
                                unsigned long size,
                                struct ttm_placement *placement,
@@ -901,13 +900,11 @@ extern int vmw_bo_create_kernel(struct vmw_private *dev_priv,
 extern int vmw_bo_create(struct vmw_private *dev_priv,
                         size_t size, struct ttm_placement *placement,
                         bool interruptible, bool pin,
-                        void (*bo_free)(struct ttm_buffer_object *bo),
                         struct vmw_buffer_object **p_bo);
 extern int vmw_bo_init(struct vmw_private *dev_priv,
                       struct vmw_buffer_object *vmw_bo,
                       size_t size, struct ttm_placement *placement,
-                      bool interruptible, bool pin,
-                      void (*bo_free)(struct ttm_buffer_object *bo));
+                      bool interruptible, bool pin);
 extern int vmw_bo_unref_ioctl(struct drm_device *dev, void *data,
                              struct drm_file *file_priv);
 extern int vmw_user_bo_synccpu_ioctl(struct drm_device *dev, void *data,
@@ -982,7 +979,6 @@ extern int vmw_gem_object_create_with_handle(struct vmw_private *dev_priv,
                                             struct vmw_buffer_object **p_vbo);
 extern int vmw_gem_object_create_ioctl(struct drm_device *dev, void *data,
                                       struct drm_file *filp);
-extern void vmw_gem_destroy(struct ttm_buffer_object *bo);
 extern void vmw_debugfs_gem_init(struct vmw_private *vdev);
 
 /**
index ba4ddd9f7a7e16af109052302dc22aa52f533e5b..ae39029fec4aaed65fad4e15b9c17b4969e1d2b5 100644 (file)
@@ -125,22 +125,6 @@ static const struct drm_gem_object_funcs vmw_gem_object_funcs = {
        .vm_ops = &vmw_vm_ops,
 };
 
-/**
- * vmw_gem_destroy - vmw buffer object destructor
- *
- * @bo: Pointer to the embedded struct ttm_buffer_object
- */
-void vmw_gem_destroy(struct ttm_buffer_object *bo)
-{
-       struct vmw_buffer_object *vbo = vmw_buffer_object(bo);
-
-       WARN_ON(vbo->dirty);
-       WARN_ON(!RB_EMPTY_ROOT(&vbo->res_tree));
-       vmw_bo_unmap(vbo);
-       drm_gem_object_release(&vbo->base.base);
-       kfree(vbo);
-}
-
 int vmw_gem_object_create_with_handle(struct vmw_private *dev_priv,
                                      struct drm_file *filp,
                                      uint32_t size,
@@ -153,7 +137,7 @@ int vmw_gem_object_create_with_handle(struct vmw_private *dev_priv,
                            (dev_priv->has_mob) ?
                                    &vmw_sys_placement :
                                    &vmw_vram_sys_placement,
-                           true, false, &vmw_gem_destroy, p_vbo);
+                           true, false, p_vbo);
 
        (*p_vbo)->base.base.funcs = &vmw_gem_object_funcs;
        if (ret != 0)
index c7d645e5ec7bf84e04172d55577fbef7f767498b..5879e8b9950a533f7ce39679ed3b89afb703f944 100644 (file)
@@ -332,8 +332,7 @@ static int vmw_resource_buf_alloc(struct vmw_resource *res,
 
        ret = vmw_bo_create(res->dev_priv, res->backup_size,
                            res->func->backup_placement,
-                           interruptible, false,
-                           &vmw_bo_bo_free, &backup);
+                           interruptible, false, &backup);
        if (unlikely(ret != 0))
                goto out_no_bo;
 
index e1f36a09c59c192a1fa1f4bc11b11df6138ac7f5..e51a63c05943586111e0cfbfdd6f155e06e0a756 100644 (file)
@@ -445,7 +445,7 @@ vmw_sou_primary_plane_prepare_fb(struct drm_plane *plane,
        vmw_overlay_pause_all(dev_priv);
        ret = vmw_bo_create(dev_priv, size,
                            &vmw_vram_placement,
-                           false, true, &vmw_bo_bo_free, &vps->bo);
+                           false, true, &vps->bo);
        vmw_overlay_resume_all(dev_priv);
        if (ret) {
                vps->bo = NULL; /* vmw_bo_init frees on error */
index 108a496b5d1895ad4df21726d5e5222d56a7eb15..93b1400aed4aa4b95db7e8e573ccf047ab803a70 100644 (file)
@@ -893,7 +893,7 @@ int vmw_compat_shader_add(struct vmw_private *dev_priv,
                return -EINVAL;
 
        ret = vmw_bo_create(dev_priv, size, &vmw_sys_placement,
-                           true, true, vmw_bo_bo_free, &buf);
+                           true, true, &buf);
        if (unlikely(ret != 0))
                goto out;