drm/ttm: Don't leak a resource on eviction error
authorjsg <jsg@openbsd.org>
Fri, 4 Aug 2023 08:57:11 +0000 (08:57 +0000)
committerjsg <jsg@openbsd.org>
Fri, 4 Aug 2023 08:57:11 +0000 (08:57 +0000)
From Thomas Hellstrom
e9c44738cb1f537b177cc1beabcf6913690460cd in linux-6.1.y/6.1.43
e8188c461ee015ba0b9ab2fc82dbd5ebca5a5532 in mainline linux

sys/dev/pci/drm/ttm/ttm_bo.c

index a7f5071..48476da 100644 (file)
@@ -499,18 +499,18 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo,
                goto out;
        }
 
-bounce:
-       ret = ttm_bo_handle_move_mem(bo, evict_mem, true, ctx, &hop);
-       if (ret == -EMULTIHOP) {
+       do {
+               ret = ttm_bo_handle_move_mem(bo, evict_mem, true, ctx, &hop);
+               if (ret != -EMULTIHOP)
+                       break;
+
                ret = ttm_bo_bounce_temp_buffer(bo, &evict_mem, ctx, &hop);
-               if (ret) {
-                       if (ret != -ERESTARTSYS && ret != -EINTR)
-                               pr_err("Buffer eviction failed\n");
-                       ttm_resource_free(bo, &evict_mem);
-                       goto out;
-               }
-               /* try and move to final place now. */
-               goto bounce;
+       } while (!ret);
+
+       if (ret) {
+               ttm_resource_free(bo, &evict_mem);
+               if (ret != -ERESTARTSYS && ret != -EINTR)
+                       pr_err("Buffer eviction failed\n");
        }
 out:
        return ret;