Commit a74cf4a8 authored by Tomer Tayar's avatar Tomer Tayar Committed by Oded Gabbay

habanalabs: remove dead code from free_device_memory()

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: default avatarTomer Tayar <ttayar@habana.ai>
Reviewed-by: default avatarOded Gabbay <ogabbay@kernel.org>
Signed-off-by: default avatarOded Gabbay <ogabbay@kernel.org>
parent be882e53
...@@ -359,24 +359,26 @@ static int free_device_memory(struct hl_ctx *ctx, struct hl_mem_in *args) ...@@ -359,24 +359,26 @@ static int free_device_memory(struct hl_ctx *ctx, struct hl_mem_in *args)
spin_lock(&vm->idr_lock); spin_lock(&vm->idr_lock);
phys_pg_pack = idr_find(&vm->phys_pg_pack_handles, handle); phys_pg_pack = idr_find(&vm->phys_pg_pack_handles, handle);
if (phys_pg_pack) { 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;
}
if (atomic_read(&phys_pg_pack->mapping_cnt) > 0) { 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); spin_unlock(&vm->idr_lock);
dev_err(hdev->dev, "handle %u is mapped, cannot free\n", handle);
return -EINVAL; return -EINVAL;
} }
if (phys_pg_pack->exporting_cnt) { if (phys_pg_pack->exporting_cnt) {
dev_dbg(hdev->dev, "handle %u is exported, cannot free\n", handle);
spin_unlock(&vm->idr_lock); spin_unlock(&vm->idr_lock);
dev_dbg(hdev->dev, "handle %u is exported, cannot free\n", handle);
return -EINVAL; return -EINVAL;
} }
/* /* must remove from idr before the freeing of the physical pages as the refcount of the pool
* must remove from idr before the freeing of the physical * is also the trigger of the idr destroy
* pages as the refcount of the pool is also the trigger of the
* idr destroy
*/ */
idr_remove(&vm->phys_pg_pack_handles, handle); idr_remove(&vm->phys_pg_pack_handles, handle);
spin_unlock(&vm->idr_lock); spin_unlock(&vm->idr_lock);
...@@ -385,14 +387,6 @@ static int free_device_memory(struct hl_ctx *ctx, struct hl_mem_in *args) ...@@ -385,14 +387,6 @@ static int free_device_memory(struct hl_ctx *ctx, struct hl_mem_in *args)
atomic64_sub(phys_pg_pack->total_size, &hdev->dram_used_mem); atomic64_sub(phys_pg_pack->total_size, &hdev->dram_used_mem);
free_phys_pg_pack(hdev, phys_pg_pack); free_phys_pg_pack(hdev, phys_pg_pack);
return 0;
} else {
spin_unlock(&vm->idr_lock);
dev_err(hdev->dev,
"free device memory failed, no match for handle %u\n",
handle);
return -EINVAL;
}
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment