Commit 0639e022 authored by Mark Brown's avatar Mark Brown Committed by Catalin Marinas

selftests/arm64: Use switch statements in mte_common_util.c

In the MTE tests there are several places where we use chains of if
statements to open code what could be written as switch statements, move
over to switch statements to make the idiom clearer.
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20220510164520.768783-6-broonie@kernel.orgSigned-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
parent 541235de
...@@ -128,13 +128,16 @@ static void *__mte_allocate_memory_range(size_t size, int mem_type, int mapping, ...@@ -128,13 +128,16 @@ static void *__mte_allocate_memory_range(size_t size, int mem_type, int mapping,
int prot_flag, map_flag; int prot_flag, map_flag;
size_t entire_size = size + range_before + range_after; size_t entire_size = size + range_before + range_after;
if (mem_type != USE_MALLOC && mem_type != USE_MMAP && switch (mem_type) {
mem_type != USE_MPROTECT) { case USE_MALLOC:
return malloc(entire_size) + range_before;
case USE_MMAP:
case USE_MPROTECT:
break;
default:
ksft_print_msg("FAIL: Invalid allocate request\n"); ksft_print_msg("FAIL: Invalid allocate request\n");
return NULL; return NULL;
} }
if (mem_type == USE_MALLOC)
return malloc(entire_size) + range_before;
prot_flag = PROT_READ | PROT_WRITE; prot_flag = PROT_READ | PROT_WRITE;
if (mem_type == USE_MMAP) if (mem_type == USE_MMAP)
...@@ -287,13 +290,19 @@ int mte_switch_mode(int mte_option, unsigned long incl_mask) ...@@ -287,13 +290,19 @@ int mte_switch_mode(int mte_option, unsigned long incl_mask)
ksft_print_msg("FAIL: Invalid incl_mask %lx\n", incl_mask); ksft_print_msg("FAIL: Invalid incl_mask %lx\n", incl_mask);
return -EINVAL; return -EINVAL;
} }
en = PR_TAGGED_ADDR_ENABLE; en = PR_TAGGED_ADDR_ENABLE;
if (mte_option == MTE_SYNC_ERR) switch (mte_option) {
case MTE_SYNC_ERR:
en |= PR_MTE_TCF_SYNC; en |= PR_MTE_TCF_SYNC;
else if (mte_option == MTE_ASYNC_ERR) break;
case MTE_ASYNC_ERR:
en |= PR_MTE_TCF_ASYNC; en |= PR_MTE_TCF_ASYNC;
else if (mte_option == MTE_NONE_ERR) break;
case MTE_NONE_ERR:
en |= PR_MTE_TCF_NONE; en |= PR_MTE_TCF_NONE;
break;
}
en |= (incl_mask << PR_MTE_TAG_SHIFT); en |= (incl_mask << PR_MTE_TAG_SHIFT);
/* Enable address tagging ABI, mte error reporting mode and tag inclusion mask. */ /* Enable address tagging ABI, mte error reporting mode and tag inclusion mask. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment