linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Deming Wang <wangdeming@inspur.com>,
	akpm@linux-foundation.org, shuah@kernel.org
Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] selftests/mm: Replace obsolete memalign() with posix_memalign()
Date: Wed, 12 Apr 2023 10:25:19 +0200	[thread overview]
Message-ID: <d2746727-b0a1-d4ed-cb09-56ae8d3e363a@redhat.com> (raw)
In-Reply-To: <20230412072741.2116-1-wangdeming@inspur.com>

On 12.04.23 09:27, Deming Wang wrote:
> memalign() is obsolete according to its manpage.
> 
> Replace memalign() with posix_memalign() and remove malloc.h include
> that was there for memalign().
> 
> As a pointer is passed into posix_memalign(), initialize *p to NULL
> to silence a warning about the function's return value being used as
> uninitialized (which is not valid anyway because the error is properly
> checked before p is returned).

I don't follow how that comment here applies to the patch. What is p? 
Where is it initialized to NULL?

> 
> Signed-off-by: Deming Wang <wangdeming@inspur.com>
> ---
>   tools/testing/selftests/mm/soft-dirty.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/soft-dirty.c b/tools/testing/selftests/mm/soft-dirty.c
> index 21d8830c5f24..4bb7421141a2 100644
> --- a/tools/testing/selftests/mm/soft-dirty.c
> +++ b/tools/testing/selftests/mm/soft-dirty.c
> @@ -80,8 +80,8 @@ static void test_hugepage(int pagemap_fd, int pagesize)
>   	int i, ret;
>   	size_t hpage_len = read_pmd_pagesize();
>   
> -	map = memalign(hpage_len, hpage_len);
> -	if (!map)
> +	ret = posix_memalign((void *)(&map), hpage_len, hpage_len);

posix_memalign expects an "void **memptr", casting to "void *" looks 
weird. Further, you can drop the parentheses around &map.

ret = posix_memalign((void **)&map, hpage_len, hpage_len);


> +	if (ret < 0)
>   		ksft_exit_fail_msg("memalign failed\n");

Better adjust the comment to "posix_memalign() failed\n"

-- 
Thanks,

David / dhildenb



  reply	other threads:[~2023-04-12  8:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-12  7:27 [PATCH] selftests/mm: Replace obsolete memalign() with posix_memalign() Deming Wang
2023-04-12  8:25 ` David Hildenbrand [this message]
  -- strict thread matches above, loose matches on Subject: below --
2023-04-13  1:27 Deming Wang
2023-04-13 22:11 ` Andrew Morton
2023-04-12  9:35 Deming Wang
2023-04-12  6:58 Deming Wang

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=d2746727-b0a1-d4ed-cb09-56ae8d3e363a@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=shuah@kernel.org \
    --cc=wangdeming@inspur.com \
    /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;
as well as URLs for NNTP newsgroup(s).