Browse Source

Merge "ipa-kernel-tests: Pull latest changes"

qctecmdr 3 years ago
parent
commit
95ca49f517

+ 5 - 5
drivers/platform/msm/ipa/ipa_test_module/ipa_test_module_impl.c

@@ -532,14 +532,14 @@ int create_channel_device_by_type(
 	/* Add a pointer from the channel device to the test context info */
 	channel_dev->test = ipa_test;
 
-	channel_dev->class = class_create(THIS_MODULE, name);
+	channel_dev->class = class_create(THIS_MODULE, channel_dev->name);
 	if (IS_ERR(channel_dev->class)) {
 		IPATEST_ERR(":class_create() err.\n");
 		ret = -ENOMEM;
 		goto create_class_failure;
 	}
 
-	ret = alloc_chrdev_region(&channel_dev->dev_num, 0, 1, name);
+	ret = alloc_chrdev_region(&channel_dev->dev_num, 0, 1, channel_dev->name);
 	if (ret) {
 		IPATEST_ERR("alloc_chrdev_region err.\n");
 		ret = -ENOMEM;
@@ -547,7 +547,7 @@ int create_channel_device_by_type(
 	}
 
 	channel_dev->dev = device_create(channel_dev->class, NULL,
-		channel_dev->dev_num, channel_dev, name);
+		channel_dev->dev_num, channel_dev, channel_dev->name);
 	if (IS_ERR(channel_dev->dev)) {
 		IPATEST_ERR("device_create err.\n");
 		ret = -ENODEV;
@@ -576,7 +576,7 @@ int create_channel_device_by_type(
 
 	if (!ret)
 		IPATEST_DBG("Channel device:%d, name:%s created, address:0x%px.\n",
-			index, name, channel_dev);
+			index, channel_dev->name, channel_dev);
 
 	return 0;
 
@@ -593,7 +593,7 @@ create_class_failure:
 create_channel_device_failure:
 	kfree(channel_dev);
 	IPATEST_ERR("Channel device %d, name %s creation FAILED.\n",
-		index, name);
+		index, channel_dev->name);
 
 	return ret;
 }

+ 15 - 28
ipanat/src/ipa_ipv6ct.c

@@ -38,6 +38,8 @@
 #define IPA_IPV6CT_DEBUG_FILE_PATH "/sys/kernel/debug/ipa/ipv6ct"
 #define IPA_UC_ACT_DEBUG_FILE_PATH "/sys/kernel/debug/ipa/uc_act_table"
 #define IPA_IPV6CT_TABLE_NAME "IPA IPv6CT table"
+#define IPA_MAX_DMA_ENTRIES_FOR_ADD 2
+#define IPA_MAX_DMA_ENTRIES_FOR_DEL 2
 
 static int ipa_ipv6ct_create_table(ipa_ipv6ct_table* ipv6ct_table, uint16_t number_of_entries, uint8_t table_index);
 static int ipa_ipv6ct_destroy_table(ipa_ipv6ct_table* ipv6ct_table);
@@ -213,6 +215,9 @@ int ipa_ipv6ct_add_rule(uint32_t table_handle, const ipa_ipv6ct_rule* user_rule,
 	ipa_ipv6ct_table* ipv6ct_table;
 	uint16_t new_entry_index;
 	uint32_t new_entry_handle;
+	uint32_t cmd_sz = sizeof(struct ipa_ioc_nat_dma_cmd) +
+		(IPA_MAX_DMA_ENTRIES_FOR_ADD * sizeof(struct ipa_ioc_nat_dma_one));
+	char cmd_buf[cmd_sz];
 	struct ipa_ioc_nat_dma_cmd* cmd;
 
 	IPADBG("\n");
@@ -252,24 +257,16 @@ int ipa_ipv6ct_add_rule(uint32_t table_handle, const ipa_ipv6ct_rule* user_rule,
 		goto unlock;
 	}
 
-	cmd = (struct ipa_ioc_nat_dma_cmd *)calloc(1,
-		sizeof(struct ipa_ioc_nat_dma_cmd) +
-		(MAX_DMA_ENTRIES_FOR_ADD * sizeof(struct ipa_ioc_nat_dma_one)));
-	if (cmd == NULL)
-	{
-		IPAERR("unable to allocate memory for Talbe DMA command\n");
-		ret = -ENOMEM;
-		goto unlock;
-	}
+	memset(cmd_buf, 0, sizeof(cmd_buf));
+	cmd = (struct ipa_ioc_nat_dma_cmd*) cmd_buf;
 	cmd->entries = 0;
-
 	new_entry_index = ipa_ipv6ct_hash(user_rule, ipv6ct_table->table.table_entries - 1);
 
 	ret = ipa_table_add_entry(&ipv6ct_table->table, (void*)user_rule, &new_entry_index, &new_entry_handle, cmd);
 	if (ret)
 	{
 		IPAERR("failed to add a new IPV6CT entry\n");
-		goto fail_add_entry;
+		goto unlock;
 	}
 
 	ret = ipa_ipv6ct_post_dma_cmd(cmd);
@@ -278,7 +275,6 @@ int ipa_ipv6ct_add_rule(uint32_t table_handle, const ipa_ipv6ct_rule* user_rule,
 		IPAERR("unable to post dma command\n");
 		goto bail;
 	}
-	free(cmd);
 
 	if (pthread_mutex_unlock(&ipv6ct_mutex))
 	{
@@ -293,8 +289,6 @@ int ipa_ipv6ct_add_rule(uint32_t table_handle, const ipa_ipv6ct_rule* user_rule,
 
 bail:
 	ipa_table_erase_entry(&ipv6ct_table->table, new_entry_index);
-fail_add_entry:
-	free(cmd);
 unlock:
 	if (pthread_mutex_unlock(&ipv6ct_mutex))
 		IPAERR("unable to unlock the ipv6ct mutex\n");
@@ -304,9 +298,12 @@ unlock:
 int ipa_ipv6ct_del_rule(uint32_t table_handle, uint32_t rule_handle)
 {
 	ipa_ipv6ct_table* ipv6ct_table;
-	struct ipa_ioc_nat_dma_cmd* cmd;
 	ipa_table_iterator table_iterator;
 	ipa_ipv6ct_hw_entry* entry;
+	uint32_t cmd_sz = sizeof(struct ipa_ioc_nat_dma_cmd) +
+		(IPA_MAX_DMA_ENTRIES_FOR_DEL * sizeof(struct ipa_ioc_nat_dma_one));
+	char cmd_buf[cmd_sz];
+	struct ipa_ioc_nat_dma_cmd* cmd;
 	uint16_t index;
 	int ret;
 
@@ -356,15 +353,8 @@ int ipa_ipv6ct_del_rule(uint32_t table_handle, uint32_t rule_handle)
 		goto unlock;
 	}
 
-	cmd = (struct ipa_ioc_nat_dma_cmd *)calloc(1,
-		sizeof(struct ipa_ioc_nat_dma_cmd) +
-		(MAX_DMA_ENTRIES_FOR_DEL * sizeof(struct ipa_ioc_nat_dma_one)));
-	if (cmd == NULL)
-	{
-		IPAERR("unable to allocate memory for Talbe DMA command\n");
-		ret = -ENOMEM;
-		goto unlock;
-	}
+	memset(cmd_buf, 0, sizeof(cmd_buf));
+	cmd = (struct ipa_ioc_nat_dma_cmd*) cmd_buf;
 	cmd->entries = 0;
 
 	ipa_table_create_delete_command(&ipv6ct_table->table, cmd, &table_iterator);
@@ -373,7 +363,7 @@ int ipa_ipv6ct_del_rule(uint32_t table_handle, uint32_t rule_handle)
 	if (ret)
 	{
 		IPAERR("unable to post dma command\n");
-		goto fail;
+		goto unlock;
 	}
 
 	if (!ipa_table_iterator_is_head_with_tail(&table_iterator))
@@ -384,9 +374,6 @@ int ipa_ipv6ct_del_rule(uint32_t table_handle, uint32_t rule_handle)
 		ipa_table_delete_entry(&ipv6ct_table->table, &table_iterator, is_prev_empty);
 	}
 
-fail:
-	free(cmd);
-
 unlock:
 	if (pthread_mutex_unlock(&ipv6ct_mutex))
 	{

+ 1 - 1
ipanat/src/ipa_mem_descriptor.c

@@ -145,7 +145,7 @@ static int MapMemory(
 	if (ipa_dev_dir_path_len >= IPA_RESOURCE_NAME_MAX)
 	{
 		IPAERR("Unable to copy a string with size %d to buffer with size %d\n",
-			   ipa_dev_dir_path_len, IPA_RESOURCE_NAME_MAX);
+			   (int)ipa_dev_dir_path_len, IPA_RESOURCE_NAME_MAX);
 		ret = -EINVAL;
 		goto bail;
 	}

+ 8 - 2
ipanat/src/ipa_table.c

@@ -203,13 +203,19 @@ uint8_t* ipa_table_calculate_addresses(
 void ipa_table_reset(
 	ipa_table* table)
 {
+	uint32_t i,tot;
+
 	IPADBG("In\n");
 
 	IPADBG("memset %s table to 0, %pK\n", table->name, table->table_addr);
-	memset(table->table_addr, 0, table->entry_size * table->table_entries);
+	tot = table->entry_size * table->table_entries;
+	for (i = 0; i < tot; i++)
+		table->table_addr[i] = '\0';
 
 	IPADBG("memset %s expn table to 0, %pK\n", table->name, table->expn_table_addr);
-	memset(table->expn_table_addr, 0, table->entry_size * table->expn_table_entries);
+	tot = table->entry_size * table->expn_table_entries;
+	for (i = 0; i < tot; i++)
+		table->expn_table_addr[i] = '\0';
 
 	IPADBG("Out\n");
 }

+ 2 - 2
kernel-tests/DataPathTests.cpp

@@ -54,7 +54,7 @@ public:
 		LOG_MSG_DEBUG("Entering %s\n", __func__);
 		int ret;
 		unsigned char *input, *output;
-		char pkt[PACKET_SIZE] = {
+		unsigned char pkt[PACKET_SIZE] = {
 			0x59, 0x61, 0x6e, 0x69,
 			0x76, 0x5f, 0x48 ,0x61,
 			0x73 ,0x62 ,0x61 ,0x6e,
@@ -142,7 +142,7 @@ public:
 		LOG_MSG_DEBUG("Entering %s\n", __func__);
 		int ret;
 		unsigned char *input, *output;
-		char pkt[PACKET_SIZE] = {
+		unsigned char pkt[PACKET_SIZE] = {
 			0x59, 0x61, 0x6e, 0x69,
 			0x76, 0x5f, 0x48 ,0x61,
 			0x73 ,0x62 ,0x61 ,0x6e,

+ 17 - 3
kernel-tests/main.cpp

@@ -91,6 +91,7 @@ const char *ipa_hw_type_name[] = {
 	"4.5",
 	"4.9",
 	"5.0",
+	"5.1",
 	"MAX"
 };
 
@@ -199,10 +200,15 @@ int chooserMode() {
 	const char* res;
 	int result = 0;
 	char input_str[4];
+	char* temp;
 
 	printf("Welcome to the ip_accelerator\nChoose an option:\n");
 	printf("1) Run tests\n2) Run suites\n3) Exit\nChoose an option: ");
-	res = fgets(input_str, sizeof(input_str), stdin);
+	temp = fgets(input_str, sizeof(input_str), stdin);
+	if (!temp) {
+		printf("Error: fgets returned nullptr !!");
+		return -1;
+	}
 	type = atoi(input_str);
 	switch((enum ipa_test_type)type) {
 	case TEST:
@@ -210,7 +216,11 @@ int chooserMode() {
 		showTests();
 		printf("Choose which test you wish to run: \n");
 		fflush(stdin);
-		res = fgets(input_str, sizeof(input_str), stdin);
+		temp = fgets(input_str, sizeof(input_str), stdin);
+		if (!temp) {
+			printf("Error: fgets returned nullptr !!");
+			return -1;
+		}
 		test_num = atoi(input_str);
 		if ( test_num > testmanager->m_testList.size()) {
 			printf("Invalid test number. Try again\n");
@@ -231,7 +241,11 @@ int chooserMode() {
 		showSuits();
 		printf("Choose which suite you wish to run: \n");
 		fflush(stdin);
-		res = fgets(input_str, sizeof(input_str), stdin);
+		temp = fgets(input_str, sizeof(input_str), stdin);
+		if (!temp) {
+			printf("Error: fgets returned nullptr !!");
+			return -1;
+		}
 		suite_num = atoi(input_str);
 		if (suite_num < 0 || suite_num > MAX_SUITES) {
 			printf("Invalid test number. Try again\n");