* [PATCH] selftests/mm: mlock2-tests: fix fclose(NULL) in is_vmflag_set()
@ 2026-11-04 8:49 Hongfu Li
2026-11-11 19:49 ` Liam R. Howlett
0 siblings, 1 reply; 3+ messages in thread
From: Hongfu Li @ 2026-11-04 8:49 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Shuah Khan
Cc: hongfu.li, linux-mm, linux-kselftest, linux-kernel, Hongfu Li
From: Hongfu Li <lihongfu@kylinos.cn>
is_vmflag_set() jumps to the shared 'out' label when
seek_to_smaps_entry() fails. smaps is NULL on that path, and the
code at the 'out' label calls fclose(smaps) unconditionally.
fclose(NULL) is undefined behaviour, so the test crashes before
it can report a test result.
Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>
---
tools/testing/selftests/mm/mlock2-tests.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/mm/mlock2-tests.c b/tools/testing/selftests/mm/mlock2-tests.c
index 144b550813a6..85e6cd24515a 100644
--- a/tools/testing/selftests/mm/mlock2-tests.c
+++ b/tools/testing/selftests/mm/mlock2-tests.c
@@ -66,7 +66,7 @@ static bool is_vmflag_set(unsigned long addr, const char *vmflag)
smaps = seek_to_smaps_entry(addr);
if (!smaps) {
ksft_print_msg("Unable to parse /proc/self/smaps\n");
- goto out;
+ return false;
}
while (getline(&line, &size, smaps) > 0) {
---
base-commit: 74d73ffcffe03804f97e9fb82301dadf75671282
change-id: 20261104-for-mlock2-a67f86dad498
Best regards,
--
Hongfu Li <lihongfu@kylinos.cn>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] selftests/mm: mlock2-tests: fix fclose(NULL) in is_vmflag_set()
2026-11-04 8:49 [PATCH] selftests/mm: mlock2-tests: fix fclose(NULL) in is_vmflag_set() Hongfu Li
@ 2026-11-11 19:49 ` Liam R. Howlett
2026-11-12 4:09 ` Hongfu Li
0 siblings, 1 reply; 3+ messages in thread
From: Liam R. Howlett @ 2026-11-11 19:49 UTC (permalink / raw)
To: Hongfu Li
Cc: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Shuah Khan, linux-mm, linux-kselftest, linux-kernel, Hongfu Li
On 26/11/04 04:49PM, Hongfu Li wrote:
> From: Hongfu Li <lihongfu@kylinos.cn>
>
> is_vmflag_set() jumps to the shared 'out' label when
> seek_to_smaps_entry() fails. smaps is NULL on that path, and the
> code at the 'out' label calls fclose(smaps) unconditionally.
> fclose(NULL) is undefined behaviour, so the test crashes before
> it can report a test result.
>
> Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>
The sending address should match the sign off.
> ---
> tools/testing/selftests/mm/mlock2-tests.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/mm/mlock2-tests.c b/tools/testing/selftests/mm/mlock2-tests.c
> index 144b550813a6..85e6cd24515a 100644
> --- a/tools/testing/selftests/mm/mlock2-tests.c
> +++ b/tools/testing/selftests/mm/mlock2-tests.c
> @@ -66,7 +66,7 @@ static bool is_vmflag_set(unsigned long addr, const char *vmflag)
> smaps = seek_to_smaps_entry(addr);
> if (!smaps) {
> ksft_print_msg("Unable to parse /proc/self/smaps\n");
> - goto out;
> + return false;
> }
This looks better.
The next function is also messy with the goto usage/ordering of
unrolling and should probably be changed in the same way.
>
> while (getline(&line, &size, smaps) > 0) {
>
> ---
> base-commit: 74d73ffcffe03804f97e9fb82301dadf75671282
> change-id: 20261104-for-mlock2-a67f86dad498
>
> Best regards,
> --
> Hongfu Li <lihongfu@kylinos.cn>
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] selftests/mm: mlock2-tests: fix fclose(NULL) in is_vmflag_set()
2026-11-11 19:49 ` Liam R. Howlett
@ 2026-11-12 4:09 ` Hongfu Li
0 siblings, 0 replies; 3+ messages in thread
From: Hongfu Li @ 2026-11-12 4:09 UTC (permalink / raw)
To: Liam R. Howlett
Cc: hongfu.li, Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Shuah Khan, linux-mm, linux-kselftest, linux-kernel, Hongfu Li
在 11/12/26 03:49, Liam R. Howlett 写道:
> On 26/11/04 04:49PM, Hongfu Li wrote:
>> From: Hongfu Li <lihongfu@kylinos.cn>
>>
>> is_vmflag_set() jumps to the shared 'out' label when
>> seek_to_smaps_entry() fails. smaps is NULL on that path, and the
>> code at the 'out' label calls fclose(smaps) unconditionally.
>> fclose(NULL) is undefined behaviour, so the test crashes before
>> it can report a test result.
>>
>> Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>
> The sending address should match the sign off.
Sure, I'll send a follow-up from the same address.
>> ---
>> tools/testing/selftests/mm/mlock2-tests.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/tools/testing/selftests/mm/mlock2-tests.c b/tools/testing/selftests/mm/mlock2-tests.c
>> index 144b550813a6..85e6cd24515a 100644
>> --- a/tools/testing/selftests/mm/mlock2-tests.c
>> +++ b/tools/testing/selftests/mm/mlock2-tests.c
>> @@ -66,7 +66,7 @@ static bool is_vmflag_set(unsigned long addr, const char *vmflag)
>> smaps = seek_to_smaps_entry(addr);
>> if (!smaps) {
>> ksft_print_msg("Unable to parse /proc/self/smaps\n");
>> - goto out;
>> + return false;
>> }
> This looks better.
>
> The next function is also messy with the goto usage/ordering of
> unrolling and should probably be changed in the same way.
Thanks for the review.
Agreed, get_value_for_name() has the same pattern. I'll handle it in
the same way in v2.
>>
>> while (getline(&line, &size, smaps) > 0) {
>>
>> ---
>> base-commit: 74d73ffcffe03804f97e9fb82301dadf75671282
>> change-id: 20261104-for-mlock2-a67f86dad498
>>
>> Best regards,
>> --
>> Hongfu Li <lihongfu@kylinos.cn>
>>
--
Best regards,
Hongfu
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-12 4:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-04 8:49 [PATCH] selftests/mm: mlock2-tests: fix fclose(NULL) in is_vmflag_set() Hongfu Li
2026-11-11 19:49 ` Liam R. Howlett
2026-11-12 4:09 ` Hongfu Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®