linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Dev Jain <dev.jain@arm.com>
To: Yang Ruibin <11162571@vivo.com>,
	Andy Whitcroft <apw@canonical.com>, Joe Perches <joe@perches.com>,
	Dwaipayan Ray <dwaipayanray1@gmail.com>,
	Lukas Bulwahn <lukas.bulwahn@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Shuah Khan <shuah@kernel.org>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	linux-kselftest@vger.kernel.org
Cc: opensource.kernel@vivo.com
Subject: Re: [PATCH v2] selftests:mm: Fix mmap() error paths to check for MAP_FAILED
Date: Thu, 22 Aug 2024 17:59:21 +0530	[thread overview]
Message-ID: <ddbd0cdd-5e13-4904-b6b7-af09dab29586@arm.com> (raw)
In-Reply-To: <20240822120022.2095848-1-11162571@vivo.com>


On 8/22/24 17:30, Yang Ruibin wrote:
> To correctly detect whether mmap is successful, must use if
> (map_ptr == MAP_FAILED)to avoid incorrectly handling a valid
> mapping.Fix mmap() error paths to check for MAP_FAILED.


Shouldn't you have written "avoid processing the return value
from a failed mmap" instead of "avoid incorrectly handling a
valid mapping", because !addr won't be a valid mapping? Also,
I guess it would be better to use ksft_exit_fail_perror(), but
I won't insist.

>
> Signed-off-by: Yang Ruibin <11162571@vivo.com>
> ---
>   tools/testing/selftests/mm/ksm_tests.c     | 2 +-
>   tools/testing/selftests/mm/madv_populate.c | 2 +-
>   tools/testing/selftests/mm/soft-dirty.c    | 2 +-
>   3 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/tools/testing/selftests/mm/ksm_tests.c b/tools/testing/selftests/mm/ksm_tests.c
> index b748c4890..dad54840f 100644
> --- a/tools/testing/selftests/mm/ksm_tests.c
> +++ b/tools/testing/selftests/mm/ksm_tests.c
> @@ -201,7 +201,7 @@ static void  *allocate_memory(void *ptr, int prot, int mapping, char data, size_
>   {
>   	void *map_ptr = mmap(ptr, map_size, PROT_WRITE, mapping, -1, 0);
>   
> -	if (!map_ptr) {
> +	if (map_ptr == MAP_FAILED) {
>   		perror("mmap");
>   		return NULL;
>   	}
> diff --git a/tools/testing/selftests/mm/madv_populate.c b/tools/testing/selftests/mm/madv_populate.c
> index ef7d911da..b89cb83ca 100644
> --- a/tools/testing/selftests/mm/madv_populate.c
> +++ b/tools/testing/selftests/mm/madv_populate.c
> @@ -34,7 +34,7 @@ static void sense_support(void)
>   
>   	addr = mmap(0, pagesize, PROT_READ | PROT_WRITE,
>   		    MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
> -	if (!addr)
> +	if (addr == MAP_FAILED)
>   		ksft_exit_fail_msg("mmap failed\n");
>   
>   	ret = madvise(addr, pagesize, MADV_POPULATE_READ);
> diff --git a/tools/testing/selftests/mm/soft-dirty.c b/tools/testing/selftests/mm/soft-dirty.c
> index bdfa5d085..4ccbc053b 100644
> --- a/tools/testing/selftests/mm/soft-dirty.c
> +++ b/tools/testing/selftests/mm/soft-dirty.c
> @@ -134,7 +134,7 @@ static void test_mprotect(int pagemap_fd, int pagesize, bool anon)
>   	if (anon) {
>   		map = mmap(NULL, pagesize, PROT_READ|PROT_WRITE,
>   			   MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
> -		if (!map)
> +		if (map == MAP_FAILED)
>   			ksft_exit_fail_msg("anon mmap failed\n");
>   	} else {
>   		test_fd = open(fname, O_RDWR | O_CREAT, 0664);


      reply	other threads:[~2024-08-22 12:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-22 12:00 Yang Ruibin
2024-08-22 12:29 ` Dev Jain [this message]

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=ddbd0cdd-5e13-4904-b6b7-af09dab29586@arm.com \
    --to=dev.jain@arm.com \
    --cc=11162571@vivo.com \
    --cc=akpm@linux-foundation.org \
    --cc=apw@canonical.com \
    --cc=dwaipayanray1@gmail.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lukas.bulwahn@gmail.com \
    --cc=opensource.kernel@vivo.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