]> git.baikalelectronics.ru Git - kernel.git/commitdiff
habanalabs: remove dead code from free_device_memory()
authorTomer Tayar <ttayar@habana.ai>
Fri, 24 Jun 2022 10:05:23 +0000 (13:05 +0300)
committerOded Gabbay <ogabbay@kernel.org>
Tue, 12 Jul 2022 06:09:26 +0000 (09:09 +0300)
free_device_memory() ends with if and else, each has a return statement,
followed by another return statement that can never be reached.
Restructure the function and remove this dead code.

Signed-off-by: Tomer Tayar <ttayar@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
drivers/misc/habanalabs/common/memory.c

index 4f35a5668fcbc658ada1afb9ed9ba0f822b90a88..bc921f32716a3855bb3e2a7f8b38dc6af93b7806 100644 (file)
@@ -359,41 +359,35 @@ static int free_device_memory(struct hl_ctx *ctx, struct hl_mem_in *args)
 
        spin_lock(&vm->idr_lock);
        phys_pg_pack = idr_find(&vm->phys_pg_pack_handles, handle);
-       if (phys_pg_pack) {
-               if (atomic_read(&phys_pg_pack->mapping_cnt) > 0) {
-                       dev_err(hdev->dev, "handle %u is mapped, cannot free\n",
-                               handle);
-                       spin_unlock(&vm->idr_lock);
-                       return -EINVAL;
-               }
-
-               if (phys_pg_pack->exporting_cnt) {
-                       dev_dbg(hdev->dev, "handle %u is exported, cannot free\n", handle);
-                       spin_unlock(&vm->idr_lock);
-                       return -EINVAL;
-               }
-
-               /*
-                * must remove from idr before the freeing of the physical
-                * pages as the refcount of the pool is also the trigger of the
-                * idr destroy
-                */
-               idr_remove(&vm->phys_pg_pack_handles, handle);
+       if (!phys_pg_pack) {
                spin_unlock(&vm->idr_lock);
+               dev_err(hdev->dev, "free device memory failed, no match for handle %u\n", handle);
+               return -EINVAL;
+       }
 
-               atomic64_sub(phys_pg_pack->total_size, &ctx->dram_phys_mem);
-               atomic64_sub(phys_pg_pack->total_size, &hdev->dram_used_mem);
+       if (atomic_read(&phys_pg_pack->mapping_cnt) > 0) {
+               spin_unlock(&vm->idr_lock);
+               dev_err(hdev->dev, "handle %u is mapped, cannot free\n", handle);
+               return -EINVAL;
+       }
 
-               free_phys_pg_pack(hdev, phys_pg_pack);
-               return 0;
-       } else {
+       if (phys_pg_pack->exporting_cnt) {
                spin_unlock(&vm->idr_lock);
-               dev_err(hdev->dev,
-                       "free device memory failed, no match for handle %u\n",
-                       handle);
+               dev_dbg(hdev->dev, "handle %u is exported, cannot free\n", handle);
                return -EINVAL;
        }
 
+       /* must remove from idr before the freeing of the physical pages as the refcount of the pool
+        * is also the trigger of the idr destroy
+        */
+       idr_remove(&vm->phys_pg_pack_handles, handle);
+       spin_unlock(&vm->idr_lock);
+
+       atomic64_sub(phys_pg_pack->total_size, &ctx->dram_phys_mem);
+       atomic64_sub(phys_pg_pack->total_size, &hdev->dram_used_mem);
+
+       free_phys_pg_pack(hdev, phys_pg_pack);
+
        return 0;
 }