* [PATCH] selftests/mm: Fix compiler -Wmaybe-uninitialized warning
@ 2025-04-09 9:50 Anshuman Khandual
2025-04-09 9:57 ` David Hildenbrand
0 siblings, 1 reply; 7+ messages in thread
From: Anshuman Khandual @ 2025-04-09 9:50 UTC (permalink / raw)
To: linux-mm
Cc: Anshuman Khandual, Andrew Morton, Shuah Khan, linux-kselftest,
linux-kernel
Following build warning comes up for cow test as 'transferred' variable has
not been initialized. Fix the warning via zero init for the variable.
CC cow
cow.c: In function ‘do_test_vmsplice_in_parent’:
cow.c:365:61: warning: ‘transferred’ may be used uninitialized [-Wmaybe-uninitialized]
365 | cur = read(fds[0], new + total, transferred - total);
| ~~~~~~~~~~~~^~~~~~~
cow.c:296:29: note: ‘transferred’ was declared here
296 | ssize_t cur, total, transferred;
| ^~~~~~~~~~~
CC compaction_test
CC gup_longterm
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: linux-mm@kvack.org
Cc: linux-kselftest@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
tools/testing/selftests/mm/cow.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c
index f0cb14ea8608..b6cfe0a4b7df 100644
--- a/tools/testing/selftests/mm/cow.c
+++ b/tools/testing/selftests/mm/cow.c
@@ -293,7 +293,7 @@ static void do_test_vmsplice_in_parent(char *mem, size_t size,
.iov_base = mem,
.iov_len = size,
};
- ssize_t cur, total, transferred;
+ ssize_t cur, total, transferred = 0;
struct comm_pipes comm_pipes;
char *old, *new;
int ret, fds[2];
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] selftests/mm: Fix compiler -Wmaybe-uninitialized warning 2025-04-09 9:50 [PATCH] selftests/mm: Fix compiler -Wmaybe-uninitialized warning Anshuman Khandual @ 2025-04-09 9:57 ` David Hildenbrand 2025-04-09 10:09 ` Anshuman Khandual 0 siblings, 1 reply; 7+ messages in thread From: David Hildenbrand @ 2025-04-09 9:57 UTC (permalink / raw) To: Anshuman Khandual, linux-mm Cc: Andrew Morton, Shuah Khan, linux-kselftest, linux-kernel On 09.04.25 11:50, Anshuman Khandual wrote: > Following build warning comes up for cow test as 'transferred' variable has > not been initialized. Fix the warning via zero init for the variable. > > CC cow > cow.c: In function ‘do_test_vmsplice_in_parent’: > cow.c:365:61: warning: ‘transferred’ may be used uninitialized [-Wmaybe-uninitialized] > 365 | cur = read(fds[0], new + total, transferred - total); > | ~~~~~~~~~~~~^~~~~~~ > cow.c:296:29: note: ‘transferred’ was declared here > 296 | ssize_t cur, total, transferred; > | ^~~~~~~~~~~ > CC compaction_test > CC gup_longterm > > Cc: Andrew Morton <akpm@linux-foundation.org> > Cc: Shuah Khan <shuah@kernel.org> > Cc: linux-mm@kvack.org > Cc: linux-kselftest@vger.kernel.org > Cc: linux-kernel@vger.kernel.org > Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com> > --- > tools/testing/selftests/mm/cow.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c > index f0cb14ea8608..b6cfe0a4b7df 100644 > --- a/tools/testing/selftests/mm/cow.c > +++ b/tools/testing/selftests/mm/cow.c > @@ -293,7 +293,7 @@ static void do_test_vmsplice_in_parent(char *mem, size_t size, > .iov_base = mem, > .iov_len = size, > }; > - ssize_t cur, total, transferred; > + ssize_t cur, total, transferred = 0; > struct comm_pipes comm_pipes; > char *old, *new; > int ret, fds[2]; if (before_fork) { transferred = vmsplice(fds[1], &iov, 1, 0); ... if (!before_fork) { transferred = vmsplice(fds[1], &iov, 1, 0); ... for (total = 0; total < transferred; total += cur) { ... And I don't see any jump label that could jump to code that would ve using transferred. What am I missing? -- Cheers, David / dhildenb ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] selftests/mm: Fix compiler -Wmaybe-uninitialized warning 2025-04-09 9:57 ` David Hildenbrand @ 2025-04-09 10:09 ` Anshuman Khandual 2025-04-09 10:21 ` David Hildenbrand 0 siblings, 1 reply; 7+ messages in thread From: Anshuman Khandual @ 2025-04-09 10:09 UTC (permalink / raw) To: David Hildenbrand, linux-mm Cc: Andrew Morton, Shuah Khan, linux-kselftest, linux-kernel On 4/9/25 15:27, David Hildenbrand wrote: > On 09.04.25 11:50, Anshuman Khandual wrote: >> Following build warning comes up for cow test as 'transferred' variable has >> not been initialized. Fix the warning via zero init for the variable. >> >> CC cow >> cow.c: In function ‘do_test_vmsplice_in_parent’: >> cow.c:365:61: warning: ‘transferred’ may be used uninitialized [-Wmaybe-uninitialized] >> 365 | cur = read(fds[0], new + total, transferred - total); >> | ~~~~~~~~~~~~^~~~~~~ >> cow.c:296:29: note: ‘transferred’ was declared here >> 296 | ssize_t cur, total, transferred; >> | ^~~~~~~~~~~ >> CC compaction_test >> CC gup_longterm >> >> Cc: Andrew Morton <akpm@linux-foundation.org> >> Cc: Shuah Khan <shuah@kernel.org> >> Cc: linux-mm@kvack.org >> Cc: linux-kselftest@vger.kernel.org >> Cc: linux-kernel@vger.kernel.org >> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com> >> --- >> tools/testing/selftests/mm/cow.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c >> index f0cb14ea8608..b6cfe0a4b7df 100644 >> --- a/tools/testing/selftests/mm/cow.c >> +++ b/tools/testing/selftests/mm/cow.c >> @@ -293,7 +293,7 @@ static void do_test_vmsplice_in_parent(char *mem, size_t size, >> .iov_base = mem, >> .iov_len = size, >> }; >> - ssize_t cur, total, transferred; >> + ssize_t cur, total, transferred = 0; >> struct comm_pipes comm_pipes; >> char *old, *new; >> int ret, fds[2]; > > > if (before_fork) { > transferred = vmsplice(fds[1], &iov, 1, 0); > ... > > if (!before_fork) { > transferred = vmsplice(fds[1], &iov, 1, 0); > ... > > for (total = 0; total < transferred; total += cur) { > ... > > > And I don't see any jump label that could jump to code that would ve using transferred. > > What am I missing? Probably because both those conditional statements are not mutually exclusive above with an if-else construct. Hence compiler flags it rather as a false positive ? Initializing with 0 just works around that false positive. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] selftests/mm: Fix compiler -Wmaybe-uninitialized warning 2025-04-09 10:09 ` Anshuman Khandual @ 2025-04-09 10:21 ` David Hildenbrand 2025-04-09 10:25 ` Anshuman Khandual 0 siblings, 1 reply; 7+ messages in thread From: David Hildenbrand @ 2025-04-09 10:21 UTC (permalink / raw) To: Anshuman Khandual, linux-mm Cc: Andrew Morton, Shuah Khan, linux-kselftest, linux-kernel On 09.04.25 12:09, Anshuman Khandual wrote: > > > On 4/9/25 15:27, David Hildenbrand wrote: >> On 09.04.25 11:50, Anshuman Khandual wrote: >>> Following build warning comes up for cow test as 'transferred' variable has >>> not been initialized. Fix the warning via zero init for the variable. >>> >>> CC cow >>> cow.c: In function ‘do_test_vmsplice_in_parent’: >>> cow.c:365:61: warning: ‘transferred’ may be used uninitialized [-Wmaybe-uninitialized] >>> 365 | cur = read(fds[0], new + total, transferred - total); >>> | ~~~~~~~~~~~~^~~~~~~ >>> cow.c:296:29: note: ‘transferred’ was declared here >>> 296 | ssize_t cur, total, transferred; >>> | ^~~~~~~~~~~ >>> CC compaction_test >>> CC gup_longterm >>> >>> Cc: Andrew Morton <akpm@linux-foundation.org> >>> Cc: Shuah Khan <shuah@kernel.org> >>> Cc: linux-mm@kvack.org >>> Cc: linux-kselftest@vger.kernel.org >>> Cc: linux-kernel@vger.kernel.org >>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com> >>> --- >>> tools/testing/selftests/mm/cow.c | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c >>> index f0cb14ea8608..b6cfe0a4b7df 100644 >>> --- a/tools/testing/selftests/mm/cow.c >>> +++ b/tools/testing/selftests/mm/cow.c >>> @@ -293,7 +293,7 @@ static void do_test_vmsplice_in_parent(char *mem, size_t size, >>> .iov_base = mem, >>> .iov_len = size, >>> }; >>> - ssize_t cur, total, transferred; >>> + ssize_t cur, total, transferred = 0; >>> struct comm_pipes comm_pipes; >>> char *old, *new; >>> int ret, fds[2]; >> >> >> if (before_fork) { >> transferred = vmsplice(fds[1], &iov, 1, 0); >> ... >> >> if (!before_fork) { >> transferred = vmsplice(fds[1], &iov, 1, 0); >> ... >> >> for (total = 0; total < transferred; total += cur) { >> ... >> >> >> And I don't see any jump label that could jump to code that would ve using transferred. >> >> What am I missing? > > Probably because both those conditional statements are not mutually > exclusive above with an if-else construct. Hence compiler flags it > rather as a false positive ? Initializing with 0 just works around > that false positive. This is something the compiler should clearly be able to verify. before_fork is never changed in that function. We should not work around wrong compilers. Which compiler are you using such that you run into this issue? -- Cheers, David / dhildenb ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] selftests/mm: Fix compiler -Wmaybe-uninitialized warning 2025-04-09 10:21 ` David Hildenbrand @ 2025-04-09 10:25 ` Anshuman Khandual 2025-04-09 10:31 ` David Hildenbrand 0 siblings, 1 reply; 7+ messages in thread From: Anshuman Khandual @ 2025-04-09 10:25 UTC (permalink / raw) To: David Hildenbrand, linux-mm Cc: Andrew Morton, Shuah Khan, linux-kselftest, linux-kernel On 4/9/25 15:51, David Hildenbrand wrote: > On 09.04.25 12:09, Anshuman Khandual wrote: >> >> >> On 4/9/25 15:27, David Hildenbrand wrote: >>> On 09.04.25 11:50, Anshuman Khandual wrote: >>>> Following build warning comes up for cow test as 'transferred' variable has >>>> not been initialized. Fix the warning via zero init for the variable. >>>> >>>> CC cow >>>> cow.c: In function ‘do_test_vmsplice_in_parent’: >>>> cow.c:365:61: warning: ‘transferred’ may be used uninitialized [-Wmaybe-uninitialized] >>>> 365 | cur = read(fds[0], new + total, transferred - total); >>>> | ~~~~~~~~~~~~^~~~~~~ >>>> cow.c:296:29: note: ‘transferred’ was declared here >>>> 296 | ssize_t cur, total, transferred; >>>> | ^~~~~~~~~~~ >>>> CC compaction_test >>>> CC gup_longterm >>>> >>>> Cc: Andrew Morton <akpm@linux-foundation.org> >>>> Cc: Shuah Khan <shuah@kernel.org> >>>> Cc: linux-mm@kvack.org >>>> Cc: linux-kselftest@vger.kernel.org >>>> Cc: linux-kernel@vger.kernel.org >>>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com> >>>> --- >>>> tools/testing/selftests/mm/cow.c | 2 +- >>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>> >>>> diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c >>>> index f0cb14ea8608..b6cfe0a4b7df 100644 >>>> --- a/tools/testing/selftests/mm/cow.c >>>> +++ b/tools/testing/selftests/mm/cow.c >>>> @@ -293,7 +293,7 @@ static void do_test_vmsplice_in_parent(char *mem, size_t size, >>>> .iov_base = mem, >>>> .iov_len = size, >>>> }; >>>> - ssize_t cur, total, transferred; >>>> + ssize_t cur, total, transferred = 0; >>>> struct comm_pipes comm_pipes; >>>> char *old, *new; >>>> int ret, fds[2]; >>> >>> >>> if (before_fork) { >>> transferred = vmsplice(fds[1], &iov, 1, 0); >>> ... >>> >>> if (!before_fork) { >>> transferred = vmsplice(fds[1], &iov, 1, 0); >>> ... >>> >>> for (total = 0; total < transferred; total += cur) { >>> ... >>> >>> >>> And I don't see any jump label that could jump to code that would ve using transferred. >>> >>> What am I missing? >> >> Probably because both those conditional statements are not mutually >> exclusive above with an if-else construct. Hence compiler flags it >> rather as a false positive ? Initializing with 0 just works around >> that false positive. > > This is something the compiler should clearly be able to verify. before_fork is never changed in that function. > > We should not work around wrong compilers. > > Which compiler are you using such that you run into this issue? gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] selftests/mm: Fix compiler -Wmaybe-uninitialized warning 2025-04-09 10:25 ` Anshuman Khandual @ 2025-04-09 10:31 ` David Hildenbrand 2025-04-09 10:36 ` David Hildenbrand 0 siblings, 1 reply; 7+ messages in thread From: David Hildenbrand @ 2025-04-09 10:31 UTC (permalink / raw) To: Anshuman Khandual, linux-mm Cc: Andrew Morton, Shuah Khan, linux-kselftest, linux-kernel On 09.04.25 12:25, Anshuman Khandual wrote: > > > On 4/9/25 15:51, David Hildenbrand wrote: >> On 09.04.25 12:09, Anshuman Khandual wrote: >>> >>> >>> On 4/9/25 15:27, David Hildenbrand wrote: >>>> On 09.04.25 11:50, Anshuman Khandual wrote: >>>>> Following build warning comes up for cow test as 'transferred' variable has >>>>> not been initialized. Fix the warning via zero init for the variable. >>>>> >>>>> CC cow >>>>> cow.c: In function ‘do_test_vmsplice_in_parent’: >>>>> cow.c:365:61: warning: ‘transferred’ may be used uninitialized [-Wmaybe-uninitialized] >>>>> 365 | cur = read(fds[0], new + total, transferred - total); >>>>> | ~~~~~~~~~~~~^~~~~~~ >>>>> cow.c:296:29: note: ‘transferred’ was declared here >>>>> 296 | ssize_t cur, total, transferred; >>>>> | ^~~~~~~~~~~ >>>>> CC compaction_test >>>>> CC gup_longterm >>>>> >>>>> Cc: Andrew Morton <akpm@linux-foundation.org> >>>>> Cc: Shuah Khan <shuah@kernel.org> >>>>> Cc: linux-mm@kvack.org >>>>> Cc: linux-kselftest@vger.kernel.org >>>>> Cc: linux-kernel@vger.kernel.org >>>>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com> >>>>> --- >>>>> tools/testing/selftests/mm/cow.c | 2 +- >>>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>>> >>>>> diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c >>>>> index f0cb14ea8608..b6cfe0a4b7df 100644 >>>>> --- a/tools/testing/selftests/mm/cow.c >>>>> +++ b/tools/testing/selftests/mm/cow.c >>>>> @@ -293,7 +293,7 @@ static void do_test_vmsplice_in_parent(char *mem, size_t size, >>>>> .iov_base = mem, >>>>> .iov_len = size, >>>>> }; >>>>> - ssize_t cur, total, transferred; >>>>> + ssize_t cur, total, transferred = 0; >>>>> struct comm_pipes comm_pipes; >>>>> char *old, *new; >>>>> int ret, fds[2]; >>>> >>>> >>>> if (before_fork) { >>>> transferred = vmsplice(fds[1], &iov, 1, 0); >>>> ... >>>> >>>> if (!before_fork) { >>>> transferred = vmsplice(fds[1], &iov, 1, 0); >>>> ... >>>> >>>> for (total = 0; total < transferred; total += cur) { >>>> ... >>>> >>>> >>>> And I don't see any jump label that could jump to code that would ve using transferred. >>>> >>>> What am I missing? >>> >>> Probably because both those conditional statements are not mutually >>> exclusive above with an if-else construct. Hence compiler flags it >>> rather as a false positive ? Initializing with 0 just works around >>> that false positive. >> >> This is something the compiler should clearly be able to verify. before_fork is never changed in that function. >> >> We should not work around wrong compilers. >> >> Which compiler are you using such that you run into this issue? > > gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 > gcc (GCC) 14.2.1 20250110 (Red Hat 14.2.1-7) Seems to be fine, just like all other compilers people used with this over the years. Maybe something about that compiler is shaky that was fixed in the meantime? -- Cheers, David / dhildenb ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] selftests/mm: Fix compiler -Wmaybe-uninitialized warning 2025-04-09 10:31 ` David Hildenbrand @ 2025-04-09 10:36 ` David Hildenbrand 0 siblings, 0 replies; 7+ messages in thread From: David Hildenbrand @ 2025-04-09 10:36 UTC (permalink / raw) To: Anshuman Khandual, linux-mm Cc: Andrew Morton, Shuah Khan, linux-kselftest, linux-kernel On 09.04.25 12:31, David Hildenbrand wrote: > On 09.04.25 12:25, Anshuman Khandual wrote: >> >> >> On 4/9/25 15:51, David Hildenbrand wrote: >>> On 09.04.25 12:09, Anshuman Khandual wrote: >>>> >>>> >>>> On 4/9/25 15:27, David Hildenbrand wrote: >>>>> On 09.04.25 11:50, Anshuman Khandual wrote: >>>>>> Following build warning comes up for cow test as 'transferred' variable has >>>>>> not been initialized. Fix the warning via zero init for the variable. >>>>>> >>>>>> CC cow >>>>>> cow.c: In function ‘do_test_vmsplice_in_parent’: >>>>>> cow.c:365:61: warning: ‘transferred’ may be used uninitialized [-Wmaybe-uninitialized] >>>>>> 365 | cur = read(fds[0], new + total, transferred - total); >>>>>> | ~~~~~~~~~~~~^~~~~~~ >>>>>> cow.c:296:29: note: ‘transferred’ was declared here >>>>>> 296 | ssize_t cur, total, transferred; >>>>>> | ^~~~~~~~~~~ >>>>>> CC compaction_test >>>>>> CC gup_longterm >>>>>> >>>>>> Cc: Andrew Morton <akpm@linux-foundation.org> >>>>>> Cc: Shuah Khan <shuah@kernel.org> >>>>>> Cc: linux-mm@kvack.org >>>>>> Cc: linux-kselftest@vger.kernel.org >>>>>> Cc: linux-kernel@vger.kernel.org >>>>>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com> >>>>>> --- >>>>>> tools/testing/selftests/mm/cow.c | 2 +- >>>>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>>>> >>>>>> diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c >>>>>> index f0cb14ea8608..b6cfe0a4b7df 100644 >>>>>> --- a/tools/testing/selftests/mm/cow.c >>>>>> +++ b/tools/testing/selftests/mm/cow.c >>>>>> @@ -293,7 +293,7 @@ static void do_test_vmsplice_in_parent(char *mem, size_t size, >>>>>> .iov_base = mem, >>>>>> .iov_len = size, >>>>>> }; >>>>>> - ssize_t cur, total, transferred; >>>>>> + ssize_t cur, total, transferred = 0; >>>>>> struct comm_pipes comm_pipes; >>>>>> char *old, *new; >>>>>> int ret, fds[2]; >>>>> >>>>> >>>>> if (before_fork) { >>>>> transferred = vmsplice(fds[1], &iov, 1, 0); >>>>> ... >>>>> >>>>> if (!before_fork) { >>>>> transferred = vmsplice(fds[1], &iov, 1, 0); >>>>> ... >>>>> >>>>> for (total = 0; total < transferred; total += cur) { >>>>> ... >>>>> >>>>> >>>>> And I don't see any jump label that could jump to code that would ve using transferred. >>>>> >>>>> What am I missing? >>>> >>>> Probably because both those conditional statements are not mutually >>>> exclusive above with an if-else construct. Hence compiler flags it >>>> rather as a false positive ? Initializing with 0 just works around >>>> that false positive. >>> >>> This is something the compiler should clearly be able to verify. before_fork is never changed in that function. >>> >>> We should not work around wrong compilers. >>> >>> Which compiler are you using such that you run into this issue? >> >> gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 >> > > gcc (GCC) 14.2.1 20250110 (Red Hat 14.2.1-7) > > Seems to be fine, just like all other compilers people used with this > over the years. > > Maybe something about that compiler is shaky that was fixed in the meantime? > Reading https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105562#c29 "Note that sanitizers tend to increase the rate of false positive warnings, most notably those around -Wmaybe-uninitialized. We recommend against combining -Werror and [the use of] sanitizers." Is this maybe related to the use of sanitizers? -- Cheers, David / dhildenb ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-04-09 10:36 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2025-04-09 9:50 [PATCH] selftests/mm: Fix compiler -Wmaybe-uninitialized warning Anshuman Khandual 2025-04-09 9:57 ` David Hildenbrand 2025-04-09 10:09 ` Anshuman Khandual 2025-04-09 10:21 ` David Hildenbrand 2025-04-09 10:25 ` Anshuman Khandual 2025-04-09 10:31 ` David Hildenbrand 2025-04-09 10:36 ` David Hildenbrand
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox