Browse Source

Merge "smcinvoke: SHM create/delete handling in memory objects"

qctecmdr 2 years ago
parent
commit
56d39957f0
1 changed files with 10 additions and 9 deletions
  1. 10 9
      smcinvoke/smcinvoke.c

+ 10 - 9
smcinvoke/smcinvoke.c

@@ -264,7 +264,7 @@ struct smcinvoke_mem_obj {
 	uint64_t p_addr;
 	size_t p_addr_len;
 	struct list_head list;
-	bool bridge_created_by_others;
+	bool is_smcinvoke_created_shmbridge;
 	uint64_t shmbridge_handle;
 };
 
@@ -373,7 +373,7 @@ static uint32_t next_mem_map_obj_id_locked(void)
 static inline void free_mem_obj_locked(struct smcinvoke_mem_obj *mem_obj)
 {
 	int ret = 0;
-	bool is_bridge_created_by_others = mem_obj->bridge_created_by_others;
+	bool is_bridge_created = mem_obj->is_smcinvoke_created_shmbridge;
 	struct dma_buf *dmabuf_to_free = mem_obj->dma_buf;
 	uint64_t shmbridge_handle = mem_obj->shmbridge_handle;
 
@@ -382,7 +382,7 @@ static inline void free_mem_obj_locked(struct smcinvoke_mem_obj *mem_obj)
 	mem_obj = NULL;
 	mutex_unlock(&g_smcinvoke_lock);
 
-	if (!is_bridge_created_by_others)
+	if (is_bridge_created)
 		ret = qtee_shmbridge_deregister(shmbridge_handle);
 	if (ret)
 		pr_err("Error:%d delete bridge failed leaking memory 0x%x\n",
@@ -848,17 +848,18 @@ static int smcinvoke_create_bridge(struct smcinvoke_mem_obj *mem_obj)
 	ret = qtee_shmbridge_register(phys, size, vmid_list, perms_list, nelems,
 			tz_perm, &mem_obj->shmbridge_handle);
 
-	if (ret && ret != -EEXIST) {
+	if (ret == 0) {
+		/* In case of ret=0/success handle has to be freed in memobj release */
+		mem_obj->is_smcinvoke_created_shmbridge = true;
+	} else if (ret == -EEXIST) {
+		ret = 0;
+		goto exit;
+	} else {
 		pr_err("creation of shm bridge for mem_region_id %d failed ret %d\n",
 				mem_obj->mem_region_id, ret);
 		goto exit;
 	}
 
-	if (ret == -EEXIST) {
-		mem_obj->bridge_created_by_others = true;
-		ret = 0;
-	}
-
 	trace_smcinvoke_create_bridge(mem_obj->shmbridge_handle, mem_obj->mem_region_id);
 exit:
 	kfree(perms_list);