Selaa lähdekoodia

msm: camera: icp: Memory leak and unused variables fixes

This change fixes some VA_UNUSED.GEN and MLK.MIGHT issues reported
by KW analysis tool. In addition to a functional fix related to
handle_type not being assigned properly.

CRs-Fixed: 3394193
Change-Id: Id28a06f3a65c639c0968dd1858d16a547f4d4959
Signed-off-by: Atiya Kailany <[email protected]>
Atiya Kailany 2 vuotta sitten
vanhempi
sitoutus
fb42ce28bc
2 muutettua tiedostoa jossa 17 lisäystä ja 23 poistoa
  1. 0 5
      drivers/cam_icp/hfi.c
  2. 17 18
      drivers/cam_icp/icp_hw/icp_hw_mgr/cam_icp_hw_mgr.c

+ 0 - 5
drivers/cam_icp/hfi.c

@@ -123,8 +123,6 @@ void cam_hfi_mini_dump(int client_handle, struct hfi_mini_dump_info *dst)
 {
 	struct hfi_info *hfi;
 	struct hfi_mem_info *hfi_mem;
-	struct hfi_qtbl *qtbl;
-	struct hfi_q_hdr *q_hdr;
 	uint32_t *dwords;
 	int rc;
 
@@ -142,12 +140,9 @@ void cam_hfi_mini_dump(int client_handle, struct hfi_mini_dump_info *dst)
 		return;
 	}
 
-	qtbl = (struct hfi_qtbl *)hfi_mem->qtbl.kva;
-	q_hdr = &qtbl->q_hdr[Q_CMD];
 	dwords = (uint32_t *)hfi_mem->cmd_q.kva;
 	memcpy(dst->cmd_q, dwords, ICP_CMD_Q_SIZE_IN_BYTES);
 
-	q_hdr = &qtbl->q_hdr[Q_MSG];
 	dwords = (uint32_t *)hfi_mem->msg_q.kva;
 	memcpy(dst->msg_q, dwords, ICP_CMD_Q_SIZE_IN_BYTES);
 	dst->msg_q_state = hfi->msg_q_state;

+ 17 - 18
drivers/cam_icp/icp_hw/icp_hw_mgr/cam_icp_hw_mgr.c

@@ -1803,7 +1803,8 @@ static int cam_icp_mgr_device_resume(struct cam_icp_hw_mgr *hw_mgr,
 	if (!dbg_prop) {
 		CAM_ERR(CAM_ICP, "%s Allocate command prop failed",
 			ctx_data->ctx_id_string);
-		return -ENOMEM;
+		rc = -ENOMEM;
+		goto end;
 	}
 
 	dbg_prop->size = size;
@@ -1822,7 +1823,8 @@ static int cam_icp_mgr_device_resume(struct cam_icp_hw_mgr *hw_mgr,
 	default:
 		CAM_ERR(CAM_ICP, "%s Invalid hw dev type: %u",
 			ctx_data->ctx_id_string, hw_dev_type);
-		return -EINVAL;
+		rc = -EINVAL;
+		goto free_dbg_prop;
 	}
 
 	dbg_prop->prop_data[1] = hw_mgr->dev_pc_flag;
@@ -1830,6 +1832,7 @@ static int cam_icp_mgr_device_resume(struct cam_icp_hw_mgr *hw_mgr,
 
 	hfi_write_cmd(hw_mgr->hfi_handle, dbg_prop);
 
+free_dbg_prop:
 	kfree(dbg_prop);
 
 end:
@@ -4528,7 +4531,6 @@ static unsigned long cam_icp_hw_mgr_mini_dump_cb(void *dst, unsigned long len,
 
 		dumped_len += icp_dump_args.offset;
 		md->fw_img = (void *)icp_dump_args.cpu_addr;
-		remain_len = len - dumped_len;
 	}
 end:
 	return dumped_len;
@@ -4948,7 +4950,6 @@ static int cam_icp_mgr_enqueue_config(struct cam_icp_hw_mgr *hw_mgr,
 	uint64_t request_id = 0;
 	struct crm_workq_task *task;
 	struct hfi_cmd_work_data *task_data;
-	struct hfi_cmd_dev_async *hfi_cmd;
 	struct cam_hw_update_entry *hw_update_entries;
 	struct icp_frame_info *frame_info = NULL;
 
@@ -4966,7 +4967,6 @@ static int cam_icp_mgr_enqueue_config(struct cam_icp_hw_mgr *hw_mgr,
 
 	task_data = (struct hfi_cmd_work_data *)task->payload;
 	task_data->data = (void *)hw_update_entries->addr;
-	hfi_cmd = (struct hfi_cmd_dev_async *)hw_update_entries->addr;
 	task_data->request_id = request_id;
 	task_data->type = ICP_WORKQ_TASK_CMD_TYPE;
 	task->process_cb = cam_icp_mgr_process_cmd;
@@ -5339,7 +5339,6 @@ static int cam_icp_mgr_process_cmd_desc(struct cam_icp_hw_mgr *hw_mgr,
 {
 	int rc = 0;
 	int i;
-	int num_cmd_buf = 0;
 	dma_addr_t addr;
 	size_t len;
 	struct cam_cmd_buf_desc *cmd_desc = NULL;
@@ -5352,16 +5351,13 @@ static int cam_icp_mgr_process_cmd_desc(struct cam_icp_hw_mgr *hw_mgr,
 		return rc;
 
 	*fw_cmd_buf_iova_addr = 0;
-	for (i = 0; i < packet->num_cmd_buf; i++, num_cmd_buf++) {
+	for (i = 0; i < packet->num_cmd_buf; i++) {
 		if (cmd_desc[i].type == CAM_CMD_BUF_FW) {
 			rc = cam_mem_get_io_buf(cmd_desc[i].mem_handle,
 				hw_mgr->iommu_hdl, &addr, &len, NULL);
 			if (rc) {
 				CAM_ERR(CAM_ICP, "%s: get cmd buf failed %x",
 					ctx_data->ctx_id_string, hw_mgr->iommu_hdl);
-
-				if (num_cmd_buf > 0)
-					num_cmd_buf--;
 				return rc;
 			}
 			/* FW buffers are expected to be within 32-bit address range */
@@ -5385,9 +5381,6 @@ static int cam_icp_mgr_process_cmd_desc(struct cam_icp_hw_mgr *hw_mgr,
 				CAM_ERR(CAM_ICP, "%s: get cmd buf failed %x",
 					ctx_data->ctx_id_string, hw_mgr->iommu_hdl);
 				*fw_cmd_buf_iova_addr = 0;
-
-				if (num_cmd_buf > 0)
-					num_cmd_buf--;
 				return rc;
 			}
 			if ((len <= cmd_desc[i].offset) ||
@@ -6630,10 +6623,6 @@ static int cam_icp_mgr_create_handle(struct cam_icp_hw_mgr *hw_mgr,
 	int rc = 0;
 	uint32_t handle_type;
 
-	task = cam_req_mgr_workq_get_task(hw_mgr->cmd_work);
-	if (!task)
-		return -ENOMEM;
-
 	if (ctx_data->hw_dev_type == CAM_ICP_DEV_OFE) {
 		create_handle.pkt_type = HFI_CMD_OFE_CREATE_HANDLE;
 		switch (dev_type) {
@@ -6646,6 +6635,9 @@ static int cam_icp_mgr_create_handle(struct cam_icp_hw_mgr *hw_mgr,
 		case CAM_ICP_RES_TYPE_OFE_SEMI_RT:
 			handle_type = HFI_OFE_HANDLE_TYPE_OFE_SEMI_RT;
 			break;
+		default:
+			CAM_ERR(CAM_ICP, "Invalid OFE stream type: %u", dev_type);
+			return -EINVAL;
 		}
 	} else {
 		create_handle.pkt_type = HFI_CMD_IPEBPS_CREATE_HANDLE;
@@ -6668,10 +6660,17 @@ static int cam_icp_mgr_create_handle(struct cam_icp_hw_mgr *hw_mgr,
 		case CAM_ICP_RES_TYPE_BPS_SEMI_RT:
 			handle_type = HFI_IPEBPS_HANDLE_TYPE_BPS_SEMI_RT;
 			break;
+		default:
+			CAM_ERR(CAM_ICP, "Invalid IPE/BPS stream type: %u", dev_type);
+			return -EINVAL;
 		}
 	}
+	task = cam_req_mgr_workq_get_task(hw_mgr->cmd_work);
+	if (!task)
+		return -ENOMEM;
+
 	create_handle.size = sizeof(struct hfi_cmd_create_handle);
-	create_handle.handle_type = dev_type;
+	create_handle.handle_type = handle_type;
 	create_handle.user_data1 = PTR_TO_U64(ctx_data);
 	reinit_completion(&ctx_data->wait_complete);
 	task_data = (struct hfi_cmd_work_data *)task->payload;