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 06:38:59AM +0530, Souptick Joarder wrote:
> On Tue, Jul 19, 2022 at 3:13 PM Dan Carpenter <dan.carpenter@xxxxxxxxxx> wrote:
> >
> > This code just reads from memory without caring about the data itself.
> 
> The caller has put an attempt to at least validate the address read
> from mmap() before
> passing it to read_fault_pages() which looks correct. I think this
> line is not needed.

What I mean is, the value of "tmp" was always nonsense but it doesn't
matter because we don't care.  In other words, we're just reading but we
don't care about the actual data.

regards,
dan carpenter

> 
> > 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@xxxxxxxxxx>
> 
> Acked-by: Souptick Joarder (HPE) <jrdr.linux@xxxxxxxxx>
> 
> > ---
> >  tools/testing/selftests/vm/hugetlb-madvise.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > 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)));
> > +               dummy += *((unsigned long *)(addr + (i * huge_page_size)));
> >  }
> >
> >  int main(int argc, char **argv)
> > --
> > 2.35.1
> >
> >



[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