Переглянути джерело

qcacld-3.0: Allocate memory for set_offload and program at once

qcacld-2.0 to qcacld-3.0 propagation

Presently, in BPF set_offload structure and the filter program are
allocated separately. In certain error paths the program is not
freed correctly because of which there can be memory leaks.
Have a single allocation for the set_offload and program to avoid any
memory leaks.

Change-Id: I097d3408cc89c26e015fd6aee8668f53e8f64cf7
CRs-Fixed: 1006522
Arun Khandavalli 9 роки тому
батько
коміт
ca198b5eb5
2 змінених файлів з 4 додано та 14 видалено
  1. 4 13
      core/sme/src/common/sme_api.c
  2. 0 1
      core/wma/src/wma_features.c

+ 4 - 13
core/sme/src/common/sme_api.c

@@ -16064,7 +16064,8 @@ QDF_STATUS sme_set_bpf_instructions(tHalHandle hal,
 	cds_msg_t           cds_msg;
 	struct sir_bpf_set_offload *set_offload;
 
-	set_offload = qdf_mem_malloc(sizeof(*set_offload));
+	set_offload = qdf_mem_malloc(sizeof(*set_offload) +
+					req->current_length);
 
 	if (NULL == set_offload) {
 		QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
@@ -16078,14 +16079,8 @@ QDF_STATUS sme_set_bpf_instructions(tHalHandle hal,
 	set_offload->total_length = req->total_length;
 	set_offload->current_length = req->current_length;
 	if (set_offload->total_length) {
-		set_offload->program = qdf_mem_malloc(sizeof(uint8_t) *
-						req->current_length);
-		if (NULL == set_offload->program) {
-			QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
-				FL("Failed to alloc instruction memory"));
-			qdf_mem_free(set_offload);
-			return QDF_STATUS_E_NOMEM;
-		}
+		set_offload->program = ((uint8_t *)set_offload) +
+					sizeof(*set_offload);
 		qdf_mem_copy(set_offload->program, req->program,
 				set_offload->current_length);
 	}
@@ -16100,16 +16095,12 @@ QDF_STATUS sme_set_bpf_instructions(tHalHandle hal,
 			QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
 				FL("Post BPF set offload msg fail"));
 			status = QDF_STATUS_E_FAILURE;
-			if (set_offload->total_length)
-				qdf_mem_free(set_offload->program);
 			qdf_mem_free(set_offload);
 		}
 		sme_release_global_lock(&mac_ctx->sme);
 	} else {
 		QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
 				FL("sme_acquire_global_lock failed"));
-		if (set_offload->total_length)
-			qdf_mem_free(set_offload->program);
 		qdf_mem_free(set_offload);
 	}
 	return status;

+ 0 - 1
core/wma/src/wma_features.c

@@ -7907,7 +7907,6 @@ QDF_STATUS wma_set_bpf_instructions(tp_wma_handle wma,
 		buf_ptr += WMI_TLV_HDR_SIZE;
 		qdf_mem_copy(buf_ptr, bpf_set_offload->program,
 					bpf_set_offload->current_length);
-		qdf_mem_free(bpf_set_offload->program);
 	}
 
 	if (wmi_unified_cmd_send(wma->wmi_handle, wmi_buf, len,