[PATCH v2 3/3] drm/i915/gem: Remove some unnecessary code

Niranjana Vishwanathapura niranjana.vishwanathapura at intel.com
Wed Mar 2 20:29:23 UTC 2022


On Wed, Mar 02, 2022 at 11:22:00AM +0100, Thomas Hellström wrote:
>The test for vma should always return true, and when assigning -EBUSY
>to ret, the variable should already have that value.
>
>Signed-off-by: Thomas Hellström <thomas.hellstrom at linux.intel.com>
>---
> drivers/gpu/drm/i915/i915_gem.c | 32 ++++++++++++++------------------
> 1 file changed, 14 insertions(+), 18 deletions(-)
>
>diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
>index c26110abcc0b..9747924cc57b 100644
>--- a/drivers/gpu/drm/i915/i915_gem.c
>+++ b/drivers/gpu/drm/i915/i915_gem.c
>@@ -118,6 +118,7 @@ int i915_gem_object_unbind(struct drm_i915_gem_object *obj,
> 			   unsigned long flags)
> {
> 	struct intel_runtime_pm *rpm = &to_i915(obj->base.dev)->runtime_pm;
>+	bool vm_trylock = !!(flags & I915_GEM_OBJECT_UNBIND_VM_TRYLOCK);
> 	LIST_HEAD(still_in_list);
> 	intel_wakeref_t wakeref;
> 	struct i915_vma *vma;
>@@ -170,26 +171,21 @@ int i915_gem_object_unbind(struct drm_i915_gem_object *obj,
> 		 * and destroy the vma from under us.
> 		 */
>
>-		if (vma) {
>-			bool vm_trylock = !!(flags & I915_GEM_OBJECT_UNBIND_VM_TRYLOCK);
>-			ret = -EBUSY;
>-			if (flags & I915_GEM_OBJECT_UNBIND_ASYNC) {
>-				assert_object_held(vma->obj);
>-				ret = i915_vma_unbind_async(vma, vm_trylock);
>-			}
>+		ret = -EBUSY;
>+		if (flags & I915_GEM_OBJECT_UNBIND_ASYNC) {
>+			assert_object_held(vma->obj);
>+			ret = i915_vma_unbind_async(vma, vm_trylock);
>+		}
>
>-			if (ret == -EBUSY && (flags & I915_GEM_OBJECT_UNBIND_ACTIVE ||
>-					      !i915_vma_is_active(vma))) {
>-				if (vm_trylock) {
>-					if (mutex_trylock(&vma->vm->mutex)) {
>-						ret = __i915_vma_unbind(vma);
>-						mutex_unlock(&vma->vm->mutex);
>-					} else {
>-						ret = -EBUSY;
>-					}
>-				} else {
>-					ret = i915_vma_unbind(vma);
>+		if (ret == -EBUSY && (flags & I915_GEM_OBJECT_UNBIND_ACTIVE ||
>+				      !i915_vma_is_active(vma))) {
>+			if (vm_trylock) {
>+				if (mutex_trylock(&vma->vm->mutex)) {
>+					ret = __i915_vma_unbind(vma);
>+					mutex_unlock(&vma->vm->mutex);
> 				}
>+			} else {
>+				ret = i915_vma_unbind(vma);
> 			}
> 		}

Looks good to me.
Reviewed-by: Niranjana Vishwanathapura <niranjana.vishwanathapura at intel.com>

>
>-- 
>2.34.1
>


More information about the dri-devel mailing list