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

selftests: cgroup: Add 'malloc' failures checks in test_memcontrol

There are several 'malloc' calls in test_memcontrol, which can be
unsuccessful. This patch will add 'malloc' failures checking to
give more details about test's fail reasons and avoid possible
undefined behavior during the future null dereference (like the
one in alloc_anon_50M_check_swap function).

Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
Reviewed-by: Muchun Song <songmuchun@bytedance.com>
Acked-by: Shakeel Butt <shakeelb@google.com>
Acked-by: Roman Gushchin <roman.gushchin@linux.dev>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Ivan Orlov and committed by
Shuah Khan
c83f320e 350d216d

+15
+15
tools/testing/selftests/cgroup/test_memcontrol.c
··· 98 98 int ret = -1; 99 99 100 100 buf = malloc(size); 101 + if (buf == NULL) { 102 + fprintf(stderr, "malloc() failed\n"); 103 + return -1; 104 + } 105 + 101 106 for (ptr = buf; ptr < buf + size; ptr += PAGE_SIZE) 102 107 *ptr = 0; 103 108 ··· 216 211 char *buf, *ptr; 217 212 218 213 buf = malloc(size); 214 + if (buf == NULL) { 215 + fprintf(stderr, "malloc() failed\n"); 216 + return -1; 217 + } 218 + 219 219 for (ptr = buf; ptr < buf + size; ptr += PAGE_SIZE) 220 220 *ptr = 0; 221 221 ··· 788 778 int ret = -1; 789 779 790 780 buf = malloc(size); 781 + if (buf == NULL) { 782 + fprintf(stderr, "malloc() failed\n"); 783 + return -1; 784 + } 785 + 791 786 for (ptr = buf; ptr < buf + size; ptr += PAGE_SIZE) 792 787 *ptr = 0; 793 788