linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Mike Kravetz <mike.kravetz@oracle.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Shuah Khan <shuah@kernel.org>,
	linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] selftests/vm: silence uninitialized variable warning
Date: Thu, 21 Jul 2022 10:52:54 -0700	[thread overview]
Message-ID: <YtmSdjr4oMW+mVax@monkey> (raw)
In-Reply-To: <YtZ8mKJmktA2GaHB@kili>

On 07/19/22 12:42, Dan Carpenter wrote:
> This code just reads from memory without caring about the data itself.
> However static checkers complain that "tmp" is never properly
> initialized.  Initialize it to zero and change the name to "dummy" to
> show that we don't care about the value stored in it.
> 
> Fixes: c4b6cb884011 ("selftests/vm: add hugetlb madvise MADV_DONTNEED MADV_REMOVE test")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  tools/testing/selftests/vm/hugetlb-madvise.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

Thanks Dan!

Your analysis is correct.  We do not care about the value returned, and
just want to trigger a read fault.

Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>

> 
> diff --git a/tools/testing/selftests/vm/hugetlb-madvise.c b/tools/testing/selftests/vm/hugetlb-madvise.c
> index 6c6af40f5747..3c9943131881 100644
> --- a/tools/testing/selftests/vm/hugetlb-madvise.c
> +++ b/tools/testing/selftests/vm/hugetlb-madvise.c
> @@ -89,10 +89,11 @@ void write_fault_pages(void *addr, unsigned long nr_pages)
>  
>  void read_fault_pages(void *addr, unsigned long nr_pages)
>  {
> -	unsigned long i, tmp;
> +	unsigned long dummy = 0;
> +	unsigned long i;
>  
>  	for (i = 0; i < nr_pages; i++)
> -		tmp += *((unsigned long *)(addr + (i * huge_page_size)));

When I originally wrote this, something must have complained if written as:

	tmp = *((unsigned long *)(addr + (i * huge_page_size)));

changing to += eliminated that complaint, but caused this one.  Happy
with your changes, but if there is an even better way to write this, I am
happy to change it.

-- 
Mike Kravetz

> +		dummy += *((unsigned long *)(addr + (i * huge_page_size)));
>  }
>  
>  int main(int argc, char **argv)
> -- 
> 2.35.1
> 


  parent reply	other threads:[~2022-07-21 17:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-19  9:42 [PATCH] selftests/vm: silence uninitialized variable warning Dan Carpenter
2022-07-21  1:08 ` Souptick Joarder
2022-07-21  6:30   ` Dan Carpenter
2022-07-21 17:52 ` Mike Kravetz [this message]
2022-07-22  5:50   ` Dan Carpenter

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=YtmSdjr4oMW+mVax@monkey \
    --to=mike.kravetz@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=dan.carpenter@oracle.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --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;
as well as URLs for NNTP newsgroup(s).