Re: [akpm-mm:mm-unstable 36/78] test_memcontrol.c:201:6: warning: variable 'fd4_closed' is used uninitialized whenever 'if' condition is true

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

 



On Sun, Jul 28, 2024 at 10:21 PM Philip Li <philip.li@xxxxxxxxx> wrote:
>
> On Sun, Jul 28, 2024 at 01:18:24PM -0700, Andrew Morton wrote:
> > On Sun, 28 Jul 2024 11:58:47 +0800 kernel test robot <lkp@xxxxxxxxx> wrote:
> >
> > > tree:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-unstable
> > > head:   b39b3892d20a337489c55806f91af581474f3943
> > > commit: f2db5cca8182337f4ad485ebfd532b1a2d1c223a [36/78] mm, memcg: cg2 memory{.swap,}.peak write tests
> > > :::::: branch date: 2 days ago
> > > :::::: commit date: 3 days ago
> > > compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
> > > reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240727/202407272301.bBC2CidR-lkp@xxxxxxxxx/reproduce)
> > >
> > > If you fix the issue in a separate patch/commit (i.e. not just a new version of
> > > the same patch/commit), kindly add following tags
> > > | Reported-by: kernel test robot <lkp@xxxxxxxxx>
> > > | Closes: https://lore.kernel.org/r/202407272301.bBC2CidR-lkp@xxxxxxxxx/
> > >
> > > All warnings (new ones prefixed by >>):
> > >
> > > >> test_memcontrol.c:201:6: warning: variable 'fd4_closed' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
> >
> > um,
> >
> >       bool fd2_closed = false, fd3_closed = false, fd4_closed = false;
> >
> > fd4_closed cannot possibly be used uninitialized?
>
> One possible flow is early peak_fd fails to open and go to cleanup, then
> in cleanup side, the variable like fd4_closed is directly used.

Thanks for pointing that out!

My next patchset will move that line to the top of the function.
(Looks like the same issue is present for f2_closed and fd_3_closed)

>
> +       if (peak_fd == -1)
> +               goto cleanup;
> +
> +       bool fd2_closed = false, fd3_closed = false, fd4_closed = false;
> +       int peak_fd2 = cg_open(memcg, "memory.peak", O_RDWR | O_APPEND | O_CLOEXEC);
> +
>  ...
>
>  cleanup:
> +       close(peak_fd);
> +       if (!fd2_closed)
> +               close(peak_fd2);
> +       if (!fd3_closed)
> +               close(peak_fd3);
> +       if (!fd4_closed)
> +               close(peak_fd4);
>
> >



-- 
David Finkel
Senior Principal Software Engineer, Core Services





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux