Browse Source

msm: ipa3: Prevent addition of duplicate headers

Print a failure if IPA tries to add a header with the same name
as a header that is already present in the header list and
return that original header.

Change-Id: I3e3b91da216b9a0c383c8653ea5cd2587804329f
Signed-off-by: Michael Adisumarta <[email protected]>
Michael Adisumarta 3 years ago
parent
commit
56b691cb52
1 changed files with 22 additions and 1 deletions
  1. 22 1
      drivers/platform/msm/ipa/ipa_v3/ipa_hdr.c

+ 22 - 1
drivers/platform/msm/ipa/ipa_v3/ipa_hdr.c

@@ -543,12 +543,13 @@ bad_len:
 static int __ipa_add_hdr(struct ipa_hdr_add *hdr, bool user,
 	struct ipa3_hdr_entry **entry_out)
 {
-	struct ipa3_hdr_entry *entry;
+	struct ipa3_hdr_entry *entry, *entry_t, *next;
 	struct ipa_hdr_offset_entry *offset = NULL;
 	u32 bin;
 	struct ipa3_hdr_tbl *htbl;
 	int id;
 	int mem_size;
+	enum hdr_tbl_storage hdr_tbl_loc;
 
 	if (hdr->hdr_len > IPA_HDR_MAX_SIZE) {
 		IPAERR_RL("bad param\n");
@@ -579,6 +580,26 @@ static int __ipa_add_hdr(struct ipa_hdr_add *hdr, bool user,
 			 (entry->is_partial || (hdr->status == IPA_HDR_TO_DDR_PATTERN))) ||
 			 !IPA_MEM_PART(apps_hdr_size)) ? false : true;
 
+	/* check to see if adding header entry with duplicate name */
+	for (hdr_tbl_loc = HDR_TBL_LCL; hdr_tbl_loc < HDR_TBLS_TOTAL; hdr_tbl_loc++) {
+		list_for_each_entry_safe(entry_t, next,
+			&ipa3_ctx->hdr_tbl[hdr_tbl_loc].head_hdr_entry_list, link) {
+
+			/* return if adding the same name */
+			if (!strcmp(entry_t->name, entry->name) && (user == true)) {
+				IPAERR("IPACM Trying to add hdr %s len=%d, duplicate entry, return old one\n",
+					entry->name, entry->hdr_len);
+
+				/* return the original entry */
+				if (entry_out)
+					*entry_out = entry_t;
+
+				kmem_cache_free(ipa3_ctx->hdr_cache, entry);
+				return 0;
+			}
+		}
+	}
+
 	if (hdr->hdr_len <= ipa_hdr_bin_sz[IPA_HDR_BIN0])
 		bin = IPA_HDR_BIN0;
 	else if (hdr->hdr_len <= ipa_hdr_bin_sz[IPA_HDR_BIN1])