Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kselftest: arm64: Add a null pointer check

There is a 'malloc' call, which can be unsuccessful.
This patch will add the malloc failure checking
to avoid possible null dereference and give more information
about test fail reasons.

Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Link: https://lore.kernel.org/r/20240423082102.2018886-1-chentao@kylinos.cn
Signed-off-by: Will Deacon <will@kernel.org>

authored by

Kunwu Chan and committed by
Will Deacon
80164282 b7fab1b6

+4
+4
tools/testing/selftests/arm64/tags/tags_test.c
··· 6 6 #include <stdint.h> 7 7 #include <sys/prctl.h> 8 8 #include <sys/utsname.h> 9 + #include "../../kselftest.h" 9 10 10 11 #define SHIFT_TAG(tag) ((uint64_t)(tag) << 56) 11 12 #define SET_TAG(ptr, tag) (((uint64_t)(ptr) & ~SHIFT_TAG(0xff)) | \ ··· 22 21 if (prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0) == 0) 23 22 tbi_enabled = 1; 24 23 ptr = (struct utsname *)malloc(sizeof(*ptr)); 24 + if (!ptr) 25 + ksft_exit_fail_msg("Failed to allocate utsname buffer\n"); 26 + 25 27 if (tbi_enabled) 26 28 tag = 0x42; 27 29 ptr = (struct utsname *)SET_TAG(ptr, tag);