Re: [PATCH] selftests/vm: silence uninitialized variable warning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux