Skip to content

Commit 0639e02

Browse files
brooniectmarinas
authored andcommitted
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: Mark Brown <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 541235d commit 0639e02

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

tools/testing/selftests/arm64/mte/mte_common_util.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,16 @@ static void *__mte_allocate_memory_range(size_t size, int mem_type, int mapping,
128128
int prot_flag, map_flag;
129129
size_t entire_size = size + range_before + range_after;
130130

131-
if (mem_type != USE_MALLOC && mem_type != USE_MMAP &&
132-
mem_type != USE_MPROTECT) {
131+
switch (mem_type) {
132+
case USE_MALLOC:
133+
return malloc(entire_size) + range_before;
134+
case USE_MMAP:
135+
case USE_MPROTECT:
136+
break;
137+
default:
133138
ksft_print_msg("FAIL: Invalid allocate request\n");
134139
return NULL;
135140
}
136-
if (mem_type == USE_MALLOC)
137-
return malloc(entire_size) + range_before;
138141

139142
prot_flag = PROT_READ | PROT_WRITE;
140143
if (mem_type == USE_MMAP)
@@ -287,13 +290,19 @@ int mte_switch_mode(int mte_option, unsigned long incl_mask)
287290
ksft_print_msg("FAIL: Invalid incl_mask %lx\n", incl_mask);
288291
return -EINVAL;
289292
}
293+
290294
en = PR_TAGGED_ADDR_ENABLE;
291-
if (mte_option == MTE_SYNC_ERR)
295+
switch (mte_option) {
296+
case MTE_SYNC_ERR:
292297
en |= PR_MTE_TCF_SYNC;
293-
else if (mte_option == MTE_ASYNC_ERR)
298+
break;
299+
case MTE_ASYNC_ERR:
294300
en |= PR_MTE_TCF_ASYNC;
295-
else if (mte_option == MTE_NONE_ERR)
301+
break;
302+
case MTE_NONE_ERR:
296303
en |= PR_MTE_TCF_NONE;
304+
break;
305+
}
297306

298307
en |= (incl_mask << PR_MTE_TAG_SHIFT);
299308
/* Enable address tagging ABI, mte error reporting mode and tag inclusion mask. */

0 commit comments

Comments
 (0)