]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/mm/uffd: initialize char variable to Null
authorAnkit Khushwaha <ankitkhushwaha.linux@gmail.com>
Wed, 26 Nov 2025 16:08:30 +0000 (21:38 +0530)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 29 Nov 2025 18:41:09 +0000 (10:41 -0800)
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>
tools/testing/selftests/mm/uffd-stress.c
tools/testing/selftests/mm/uffd-unit-tests.c

index b51c89e1cd1ae4ffb3781688dc1b0bb8558c8b89..700fbaa18d44b87c83c211db4482206d16dacfa6 100644 (file)
@@ -241,7 +241,7 @@ static int stress(struct uffd_args *args)
                        return 1;
 
        for (cpu = 0; cpu < gopts->nr_parallel; cpu++) {
-               char c;
+               char c = '\0';
                if (bounces & BOUNCE_POLL) {
                        if (write(gopts->pipefd[cpu*2+1], &c, 1) != 1)
                                err("pipefd write error");
index f917b4c4c9436915ea21226066da7a68eb8f8aa5..f4807242c5b2b4cb78fa99be493c71306c6d1285 100644 (file)
@@ -543,7 +543,7 @@ static void uffd_minor_test_common(uffd_global_test_opts_t *gopts, bool test_col
 {
        unsigned long p;
        pthread_t uffd_mon;
-       char c;
+       char c = '\0';
        struct uffd_args args = { 0 };
        args.gopts = gopts;
 
@@ -759,7 +759,7 @@ static void uffd_sigbus_test_common(uffd_global_test_opts_t *gopts, bool wp)
        pthread_t uffd_mon;
        pid_t pid;
        int err;
-       char c;
+       char c = '\0';
        struct uffd_args args = { 0 };
        args.gopts = gopts;
 
@@ -819,7 +819,7 @@ static void uffd_events_test_common(uffd_global_test_opts_t *gopts, bool wp)
        pthread_t uffd_mon;
        pid_t pid;
        int err;
-       char c;
+       char c = '\0';
        struct uffd_args args = { 0 };
        args.gopts = gopts;
 
@@ -1125,7 +1125,7 @@ uffd_move_test_common(uffd_global_test_opts_t *gopts,
 {
        unsigned long nr;
        pthread_t uffd_mon;
-       char c;
+       char c = '\0';
        unsigned long long count;
        struct uffd_args args = { 0 };
        char *orig_area_src = NULL, *orig_area_dst = NULL;