Skip to content

Commit 0384c8e

Browse files
ankitkhushwahaakpm00
authored andcommitted
selftests/mm/uffd: initialize char variable to Null
In "uffd-stress.c" & "uffd-unit-tests.c". address of char variable having garbage value (uninitialized) is passed to 'write' syscall triggers warning. uffd-stress.c:246:39: warning: variable 'c' is uninitialized when passed as a const pointer argument here [-Wuninitialized-const-pointer] uffd-unit-tests.c:581:31: warning: variable 'c' is uninitialized when passed as a const pointer argument here [-Wuninitialized-const-pointer] so the fix is to assign char variable to '\0' to prevent writing of garbage value. Link: https://lkml.kernel.org/r/20251126160830.52124-1-ankitkhushwaha.linux@gmail.com Signed-off-by: Ankit Khushwaha <ankitkhushwaha.linux@gmail.com> Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Cc: Bill Wendling <morbo@google.com> Cc: Justin Stitt <justinstitt@google.com> Cc: Liam Howlett <liam.howlett@oracle.com> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Nathan Chancellor <nathan@kernel.org> Cc: Peter Xu <peterx@redhat.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent f65372c commit 0384c8e

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

tools/testing/selftests/mm/uffd-stress.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ static int stress(struct uffd_args *args)
241241
return 1;
242242

243243
for (cpu = 0; cpu < gopts->nr_parallel; cpu++) {
244-
char c;
244+
char c = '\0';
245245
if (bounces & BOUNCE_POLL) {
246246
if (write(gopts->pipefd[cpu*2+1], &c, 1) != 1)
247247
err("pipefd write error");

tools/testing/selftests/mm/uffd-unit-tests.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ static void uffd_minor_test_common(uffd_global_test_opts_t *gopts, bool test_col
543543
{
544544
unsigned long p;
545545
pthread_t uffd_mon;
546-
char c;
546+
char c = '\0';
547547
struct uffd_args args = { 0 };
548548
args.gopts = gopts;
549549

@@ -759,7 +759,7 @@ static void uffd_sigbus_test_common(uffd_global_test_opts_t *gopts, bool wp)
759759
pthread_t uffd_mon;
760760
pid_t pid;
761761
int err;
762-
char c;
762+
char c = '\0';
763763
struct uffd_args args = { 0 };
764764
args.gopts = gopts;
765765

@@ -819,7 +819,7 @@ static void uffd_events_test_common(uffd_global_test_opts_t *gopts, bool wp)
819819
pthread_t uffd_mon;
820820
pid_t pid;
821821
int err;
822-
char c;
822+
char c = '\0';
823823
struct uffd_args args = { 0 };
824824
args.gopts = gopts;
825825

@@ -1125,7 +1125,7 @@ uffd_move_test_common(uffd_global_test_opts_t *gopts,
11251125
{
11261126
unsigned long nr;
11271127
pthread_t uffd_mon;
1128-
char c;
1128+
char c = '\0';
11291129
unsigned long long count;
11301130
struct uffd_args args = { 0 };
11311131
char *orig_area_src = NULL, *orig_area_dst = NULL;

0 commit comments

Comments
 (0)