From: John Hubbard <jhubbard@nvidia.com>
To: Peter Xu <peterx@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@redhat.com>,
Shuah Khan <shuah@kernel.org>,
Nathan Chancellor <nathan@kernel.org>, <linux-mm@kvack.org>,
<linux-kselftest@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 03/11] selftests/mm: fix "warning: expression which evaluates to zero..." in mlock2-tests.c
Date: Mon, 5 Jun 2023 12:23:36 -0700 [thread overview]
Message-ID: <f036d110-f43e-0787-fe77-86fa5d062b17@nvidia.com> (raw)
In-Reply-To: <ZH4CvMFgu7IFFMwk@x1n>
On 6/5/23 08:43, Peter Xu wrote:
> On Fri, Jun 02, 2023 at 07:15:50PM -0700, John Hubbard wrote:
>> The stop variable is a char*, and the code was assigning a char value to
>> it. This was generating a warning when compiling with clang.
>>
>> However, as both David and Peter pointed out, stop is not even used
>> after the problematic assignment to a char type. So just delete that
>> line entirely.
>>
>> Cc: David Hildenbrand <david@redhat.com>
>> Cc: Peter Xu <peterx@redhat.com>
>> Signed-off-by: John Hubbard <jhubbard@nvidia.com>
>> ---
>> tools/testing/selftests/mm/mlock2-tests.c | 1 -
>> 1 file changed, 1 deletion(-)
>>
>> diff --git a/tools/testing/selftests/mm/mlock2-tests.c b/tools/testing/selftests/mm/mlock2-tests.c
>> index 11b2301f3aa3..80cddc0de206 100644
>> --- a/tools/testing/selftests/mm/mlock2-tests.c
>> +++ b/tools/testing/selftests/mm/mlock2-tests.c
>> @@ -50,7 +50,6 @@ static int get_vm_area(unsigned long addr, struct vm_boundaries *area)
>> printf("cannot parse /proc/self/maps\n");
>> goto out;
>> }
>> - stop = '\0';
>>
>> sscanf(line, "%lx", &start);
>> sscanf(end_addr, "%lx", &end);
>
> I'd rather simply make it "*stop = '\0'", or as David suggested dropping
> stop completely when we're it (assumes that scanf() will always work with
> number ending with space ' ').
Actually it does not assume that. Rather, it follows the documented behavior
of strchr(3), which is:
The strchr() and strrchr() functions return a pointer to the matched
character or NULL if the character is not found. The terminating
null byte is considered part of the string, so that if c is
specified as '\0', these functions return a pointer to the
terminator.
And we have this code now:
stop = strchr(end_addr, ' ');
if (!stop) {
printf("cannot parse /proc/self/maps\n");
goto out;
}
So, either stop has a valid char* in it, or we goto out. There are no
fragile assumptions in there, as far as I can see anyway.
>
> No strong opinion here, though.
>
OK, I think it's kind of a flip of the coin whether to write this:
stop = strchr(end_addr, ' ');
if (!stop) {
or this:
if (!strchr(end_addr, ' ')) {
So I'll just leave it as the first one, which (depending on the
day of the week) might read slightly clearer. :)
thanks,
--
John Hubbard
NVIDIA
next prev parent reply other threads:[~2023-06-05 19:23 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-03 2:15 [PATCH v2 00/11] A minor flurry of selftest/mm fixes John Hubbard
2023-06-03 2:15 ` [PATCH v2 01/11] selftests/mm: fix uffd-stress unused function warning John Hubbard
2023-06-03 2:15 ` [PATCH v2 02/11] selftests/mm: fix unused variable warnings in hugetlb-madvise.c, migration.c John Hubbard
2023-06-05 11:35 ` David Hildenbrand
2023-06-05 15:41 ` Peter Xu
2023-06-03 2:15 ` [PATCH v2 03/11] selftests/mm: fix "warning: expression which evaluates to zero..." in mlock2-tests.c John Hubbard
2023-06-05 11:36 ` David Hildenbrand
2023-06-05 15:43 ` Peter Xu
2023-06-05 19:23 ` John Hubbard [this message]
2023-06-03 2:15 ` [PATCH v2 04/11] selftests/mm: fix invocation of tests that are run via shell scripts John Hubbard
2023-06-03 2:15 ` [PATCH v2 05/11] selftests/mm: .gitignore: add mkdirty, va_high_addr_switch John Hubbard
2023-06-05 15:53 ` Peter Xu
2023-06-05 19:13 ` John Hubbard
2023-06-03 2:15 ` [PATCH v2 06/11] selftests/mm: fix two -Wformat-security warnings in uffd builds John Hubbard
2023-06-05 11:37 ` David Hildenbrand
2023-06-05 15:55 ` Peter Xu
2023-06-03 2:15 ` [PATCH v2 07/11] selftests/mm: fix a "possibly uninitialized" warning in pkey-x86.h John Hubbard
2023-06-03 2:15 ` [PATCH v2 08/11] selftests/mm: fix uffd-unit-tests.c build failure due to missing MADV_COLLAPSE John Hubbard
2023-06-04 4:27 ` John Hubbard
2023-06-03 2:15 ` [PATCH v2 09/11] selftests/mm: move psize(), pshift() into vm_utils.c John Hubbard
2023-06-03 2:15 ` [PATCH v2 10/11] selftests/mm: move uffd* routines from vm_util.c to uffd-common.c John Hubbard
2023-06-05 11:38 ` David Hildenbrand
2023-06-05 15:59 ` Peter Xu
2023-06-05 19:09 ` John Hubbard
2023-06-05 19:24 ` Peter Xu
2023-06-05 19:28 ` John Hubbard
2023-06-03 2:15 ` [PATCH v2 11/11] Documentation: kselftest: "make headers" is a prerequisite John Hubbard
2023-06-05 11:38 ` David Hildenbrand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f036d110-f43e-0787-fe77-86fa5d062b17@nvidia.com \
--to=jhubbard@nvidia.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nathan@kernel.org \
--cc=peterx@redhat.com \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox