All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Mike Kravetz <mike.kravetz@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: Fri, 22 Jul 2022 08:50:35 +0300	[thread overview]
Message-ID: <20220722055035.GM2338@kadam> (raw)
In-Reply-To: <YtmSdjr4oMW+mVax@monkey>

On Thu, Jul 21, 2022 at 10:52:54AM -0700, Mike Kravetz wrote:
> > 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.

These days compilers don't like when you read something and then don't
use it.  It's possible they might just start optimizing parts of that
away?  I think we've now tricked the compiler into doing what we want.

regards,
dan carpenter


      reply	other threads:[~2022-07-22  5:51 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
2022-07-22  5:50   ` Dan Carpenter [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=20220722055035.GM2338@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mike.kravetz@oracle.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.