Skip to contentSkip to conversation

selftests/mm/uffd: initialize char variable to Null

PATCH Applied Ankit Khushwaha 2 participants 2 messages Nov 26, 2025 – Nov 27, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
this warning is raised with clang version 21.1.5 (Fedora 21.1.5-1.fc43).

---
 tools/testing/selftests/mm/uffd-stress.c     | 2 +-
 tools/testing/selftests/mm/uffd-unit-tests.c | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)
tools/testing/selftests/mm/uffd-stress.c +1 -1
index b51c89e1cd1a..700fbaa18d44 100644
@@ -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");
tools/testing/selftests/mm/uffd-unit-tests.c +4 -4
index f917b4c4c943..f4807242c5b2 100644
@@ -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;

--
2.52.0

maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Ankit Khushwaha

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]

Quoted 8 lines

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.

Quoted 63 lines

---
this warning is raised with clang version 21.1.5 (Fedora 21.1.5-1.fc43).

---
 tools/testing/selftests/mm/uffd-stress.c     | 2 +-
 tools/testing/selftests/mm/uffd-unit-tests.c | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)
tools/testing/selftests/mm/uffd-stress.c +1 -1
index b51c89e1cd1a..700fbaa18d44 100644
@@ -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");
tools/testing/selftests/mm/uffd-unit-tests.c +4 -5
index f917b4c4c943..f4807242c5b2 100644
@@ -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;
--

2.52.0

Signature · 2 lines
Sincerely yours,
Mike.