linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [akpm-mm:mm-unstable 36/78] test_memcontrol.c:201:6: warning: variable 'fd4_closed' is used uninitialized whenever 'if' condition is true
@ 2024-07-28  3:58 kernel test robot
  2024-07-28 20:18 ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: kernel test robot @ 2024-07-28  3:58 UTC (permalink / raw)
  To: David Finkel; +Cc: oe-kbuild-all, Andrew Morton, Linux Memory Management List

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@intel.com/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@intel.com>
| Closes: https://lore.kernel.org/r/202407272301.bBC2CidR-lkp@intel.com/

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]
     201 |         if (peak_fd == -1)
         |             ^~~~~~~~~~~~~
   test_memcontrol.c:283:7: note: uninitialized use occurs here
     283 |         if (!fd4_closed)
         |              ^~~~~~~~~~
   test_memcontrol.c:201:2: note: remove the 'if' if its condition is always false
     201 |         if (peak_fd == -1)
         |         ^~~~~~~~~~~~~~~~~~
     202 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:191:6: warning: variable 'fd4_closed' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     191 |         if (peak < MB(50))
         |             ^~~~~~~~~~~~~
   test_memcontrol.c:283:7: note: uninitialized use occurs here
     283 |         if (!fd4_closed)
         |              ^~~~~~~~~~
   test_memcontrol.c:191:2: note: remove the 'if' if its condition is always false
     191 |         if (peak < MB(50))
         |         ^~~~~~~~~~~~~~~~~~
     192 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:187:6: warning: variable 'fd4_closed' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     187 |         if (cg_run(memcg, alloc_anon_50M_check, NULL))
         |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   test_memcontrol.c:283:7: note: uninitialized use occurs here
     283 |         if (!fd4_closed)
         |              ^~~~~~~~~~
   test_memcontrol.c:187:2: note: remove the 'if' if its condition is always false
     187 |         if (cg_run(memcg, alloc_anon_50M_check, NULL))
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     188 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:184:6: warning: variable 'fd4_closed' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     184 |         if (peak != 0)
         |             ^~~~~~~~~
   test_memcontrol.c:283:7: note: uninitialized use occurs here
     283 |         if (!fd4_closed)
         |              ^~~~~~~~~~
   test_memcontrol.c:184:2: note: remove the 'if' if its condition is always false
     184 |         if (peak != 0)
         |         ^~~~~~~~~~~~~~
     185 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:180:6: warning: variable 'fd4_closed' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     180 |         if (current != 0)
         |             ^~~~~~~~~~~~
   test_memcontrol.c:283:7: note: uninitialized use occurs here
     283 |         if (!fd4_closed)
         |              ^~~~~~~~~~
   test_memcontrol.c:180:2: note: remove the 'if' if its condition is always false
     180 |         if (current != 0)
         |         ^~~~~~~~~~~~~~~~~
     181 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:176:6: warning: variable 'fd4_closed' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     176 |         if (cg_create(memcg))
         |             ^~~~~~~~~~~~~~~~
   test_memcontrol.c:283:7: note: uninitialized use occurs here
     283 |         if (!fd4_closed)
         |              ^~~~~~~~~~
   test_memcontrol.c:176:2: note: remove the 'if' if its condition is always false
     176 |         if (cg_create(memcg))
         |         ^~~~~~~~~~~~~~~~~~~~~
     177 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:173:6: warning: variable 'fd4_closed' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     173 |         if (!memcg)
         |             ^~~~~~
   test_memcontrol.c:283:7: note: uninitialized use occurs here
     283 |         if (!fd4_closed)
         |              ^~~~~~~~~~
   test_memcontrol.c:173:2: note: remove the 'if' if its condition is always false
     173 |         if (!memcg)
         |         ^~~~~~~~~~~
     174 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:204:2: note: variable 'fd4_closed' is declared here
     204 |         bool fd2_closed = false, fd3_closed = false, fd4_closed = false;
         |         ^
   /opt/cross/clang-617a15a9ea/lib/clang/18/include/stdbool.h:20:14: note: expanded from macro 'bool'
      20 | #define bool _Bool
         |              ^
>> test_memcontrol.c:201:6: warning: variable 'fd3_closed' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     201 |         if (peak_fd == -1)
         |             ^~~~~~~~~~~~~
   test_memcontrol.c:281:7: note: uninitialized use occurs here
     281 |         if (!fd3_closed)
         |              ^~~~~~~~~~
   test_memcontrol.c:201:2: note: remove the 'if' if its condition is always false
     201 |         if (peak_fd == -1)
         |         ^~~~~~~~~~~~~~~~~~
     202 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:191:6: warning: variable 'fd3_closed' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     191 |         if (peak < MB(50))
         |             ^~~~~~~~~~~~~
   test_memcontrol.c:281:7: note: uninitialized use occurs here
     281 |         if (!fd3_closed)
         |              ^~~~~~~~~~
   test_memcontrol.c:191:2: note: remove the 'if' if its condition is always false
     191 |         if (peak < MB(50))
         |         ^~~~~~~~~~~~~~~~~~
     192 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:187:6: warning: variable 'fd3_closed' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     187 |         if (cg_run(memcg, alloc_anon_50M_check, NULL))
         |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   test_memcontrol.c:281:7: note: uninitialized use occurs here
     281 |         if (!fd3_closed)
         |              ^~~~~~~~~~
   test_memcontrol.c:187:2: note: remove the 'if' if its condition is always false
     187 |         if (cg_run(memcg, alloc_anon_50M_check, NULL))
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     188 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:184:6: warning: variable 'fd3_closed' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     184 |         if (peak != 0)
         |             ^~~~~~~~~
   test_memcontrol.c:281:7: note: uninitialized use occurs here
     281 |         if (!fd3_closed)
         |              ^~~~~~~~~~
   test_memcontrol.c:184:2: note: remove the 'if' if its condition is always false
     184 |         if (peak != 0)
         |         ^~~~~~~~~~~~~~
     185 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:180:6: warning: variable 'fd3_closed' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     180 |         if (current != 0)
         |             ^~~~~~~~~~~~
   test_memcontrol.c:281:7: note: uninitialized use occurs here
     281 |         if (!fd3_closed)
         |              ^~~~~~~~~~
   test_memcontrol.c:180:2: note: remove the 'if' if its condition is always false
     180 |         if (current != 0)
         |         ^~~~~~~~~~~~~~~~~
     181 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:176:6: warning: variable 'fd3_closed' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     176 |         if (cg_create(memcg))
         |             ^~~~~~~~~~~~~~~~
   test_memcontrol.c:281:7: note: uninitialized use occurs here
     281 |         if (!fd3_closed)
         |              ^~~~~~~~~~
   test_memcontrol.c:176:2: note: remove the 'if' if its condition is always false
     176 |         if (cg_create(memcg))
         |         ^~~~~~~~~~~~~~~~~~~~~
     177 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:173:6: warning: variable 'fd3_closed' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     173 |         if (!memcg)
         |             ^~~~~~
   test_memcontrol.c:281:7: note: uninitialized use occurs here
     281 |         if (!fd3_closed)
         |              ^~~~~~~~~~
   test_memcontrol.c:173:2: note: remove the 'if' if its condition is always false
     173 |         if (!memcg)
         |         ^~~~~~~~~~~
     174 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:204:2: note: variable 'fd3_closed' is declared here
     204 |         bool fd2_closed = false, fd3_closed = false, fd4_closed = false;
         |         ^
   /opt/cross/clang-617a15a9ea/lib/clang/18/include/stdbool.h:20:14: note: expanded from macro 'bool'
      20 | #define bool _Bool
         |              ^
>> test_memcontrol.c:191:6: warning: variable 'peak_fd' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     191 |         if (peak < MB(50))
         |             ^~~~~~~~~~~~~
   test_memcontrol.c:278:8: note: uninitialized use occurs here
     278 |         close(peak_fd);
         |               ^~~~~~~
   test_memcontrol.c:191:2: note: remove the 'if' if its condition is always false
     191 |         if (peak < MB(50))
         |         ^~~~~~~~~~~~~~~~~~
     192 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:187:6: warning: variable 'peak_fd' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     187 |         if (cg_run(memcg, alloc_anon_50M_check, NULL))
         |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   test_memcontrol.c:278:8: note: uninitialized use occurs here
     278 |         close(peak_fd);
         |               ^~~~~~~
   test_memcontrol.c:187:2: note: remove the 'if' if its condition is always false
     187 |         if (cg_run(memcg, alloc_anon_50M_check, NULL))
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     188 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:184:6: warning: variable 'peak_fd' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     184 |         if (peak != 0)
         |             ^~~~~~~~~
   test_memcontrol.c:278:8: note: uninitialized use occurs here
     278 |         close(peak_fd);
         |               ^~~~~~~
   test_memcontrol.c:184:2: note: remove the 'if' if its condition is always false
     184 |         if (peak != 0)
         |         ^~~~~~~~~~~~~~
     185 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:180:6: warning: variable 'peak_fd' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     180 |         if (current != 0)
         |             ^~~~~~~~~~~~
   test_memcontrol.c:278:8: note: uninitialized use occurs here
     278 |         close(peak_fd);
         |               ^~~~~~~
   test_memcontrol.c:180:2: note: remove the 'if' if its condition is always false
     180 |         if (current != 0)
         |         ^~~~~~~~~~~~~~~~~
     181 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:176:6: warning: variable 'peak_fd' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     176 |         if (cg_create(memcg))
         |             ^~~~~~~~~~~~~~~~
   test_memcontrol.c:278:8: note: uninitialized use occurs here
     278 |         close(peak_fd);
         |               ^~~~~~~
   test_memcontrol.c:176:2: note: remove the 'if' if its condition is always false
     176 |         if (cg_create(memcg))
         |         ^~~~~~~~~~~~~~~~~~~~~
     177 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:173:6: warning: variable 'peak_fd' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     173 |         if (!memcg)
         |             ^~~~~~
   test_memcontrol.c:278:8: note: uninitialized use occurs here
     278 |         close(peak_fd);
         |               ^~~~~~~
   test_memcontrol.c:173:2: note: remove the 'if' if its condition is always false
     173 |         if (!memcg)
         |         ^~~~~~~~~~~
     174 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:199:2: note: variable 'peak_fd' is declared here
     199 |         int peak_fd = cg_open(memcg, "memory.peak", O_RDWR | O_APPEND | O_CLOEXEC);
         |         ^
>> test_memcontrol.c:201:6: warning: variable 'fd2_closed' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     201 |         if (peak_fd == -1)
         |             ^~~~~~~~~~~~~
   test_memcontrol.c:279:7: note: uninitialized use occurs here
     279 |         if (!fd2_closed)
         |              ^~~~~~~~~~
   test_memcontrol.c:201:2: note: remove the 'if' if its condition is always false
     201 |         if (peak_fd == -1)
         |         ^~~~~~~~~~~~~~~~~~
     202 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:191:6: warning: variable 'fd2_closed' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     191 |         if (peak < MB(50))
         |             ^~~~~~~~~~~~~
   test_memcontrol.c:279:7: note: uninitialized use occurs here
     279 |         if (!fd2_closed)
         |              ^~~~~~~~~~
   test_memcontrol.c:191:2: note: remove the 'if' if its condition is always false
     191 |         if (peak < MB(50))
         |         ^~~~~~~~~~~~~~~~~~
     192 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:187:6: warning: variable 'fd2_closed' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     187 |         if (cg_run(memcg, alloc_anon_50M_check, NULL))
         |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   test_memcontrol.c:279:7: note: uninitialized use occurs here
     279 |         if (!fd2_closed)
         |              ^~~~~~~~~~
   test_memcontrol.c:187:2: note: remove the 'if' if its condition is always false
     187 |         if (cg_run(memcg, alloc_anon_50M_check, NULL))
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     188 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:184:6: warning: variable 'fd2_closed' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     184 |         if (peak != 0)
         |             ^~~~~~~~~
   test_memcontrol.c:279:7: note: uninitialized use occurs here
     279 |         if (!fd2_closed)
         |              ^~~~~~~~~~
   test_memcontrol.c:184:2: note: remove the 'if' if its condition is always false
     184 |         if (peak != 0)
         |         ^~~~~~~~~~~~~~
     185 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:180:6: warning: variable 'fd2_closed' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     180 |         if (current != 0)
         |             ^~~~~~~~~~~~
   test_memcontrol.c:279:7: note: uninitialized use occurs here
     279 |         if (!fd2_closed)
         |              ^~~~~~~~~~
   test_memcontrol.c:180:2: note: remove the 'if' if its condition is always false
     180 |         if (current != 0)
         |         ^~~~~~~~~~~~~~~~~
     181 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:176:6: warning: variable 'fd2_closed' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     176 |         if (cg_create(memcg))
         |             ^~~~~~~~~~~~~~~~
   test_memcontrol.c:279:7: note: uninitialized use occurs here
     279 |         if (!fd2_closed)
         |              ^~~~~~~~~~
   test_memcontrol.c:176:2: note: remove the 'if' if its condition is always false
     176 |         if (cg_create(memcg))
         |         ^~~~~~~~~~~~~~~~~~~~~
     177 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:173:6: warning: variable 'fd2_closed' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     173 |         if (!memcg)
         |             ^~~~~~
   test_memcontrol.c:279:7: note: uninitialized use occurs here
     279 |         if (!fd2_closed)
         |              ^~~~~~~~~~
   test_memcontrol.c:173:2: note: remove the 'if' if its condition is always false
     173 |         if (!memcg)
         |         ^~~~~~~~~~~
     174 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:204:2: note: variable 'fd2_closed' is declared here
     204 |         bool fd2_closed = false, fd3_closed = false, fd4_closed = false;
         |         ^
   /opt/cross/clang-617a15a9ea/lib/clang/18/include/stdbool.h:20:14: note: expanded from macro 'bool'
      20 | #define bool _Bool
         |              ^
>> test_memcontrol.c:934:6: warning: variable 'swap_peak_fd' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     934 |         if (cg_read_long(memcg, "memory.swap.current")) {
         |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   test_memcontrol.c:1083:12: note: uninitialized use occurs here
    1083 |         if (close(swap_peak_fd))
         |                   ^~~~~~~~~~~~
   test_memcontrol.c:934:2: note: remove the 'if' if its condition is always false
     934 |         if (cg_read_long(memcg, "memory.swap.current")) {
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     935 |                 ret = KSFT_SKIP;
         |                 ~~~~~~~~~~~~~~~~
     936 |                 goto cleanup;
         |                 ~~~~~~~~~~~~~
     937 |         }
         |         ~
   test_memcontrol.c:931:6: warning: variable 'swap_peak_fd' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     931 |         if (cg_create(memcg))
         |             ^~~~~~~~~~~~~~~~
   test_memcontrol.c:1083:12: note: uninitialized use occurs here
    1083 |         if (close(swap_peak_fd))
         |                   ^~~~~~~~~~~~
   test_memcontrol.c:931:2: note: remove the 'if' if its condition is always false
     931 |         if (cg_create(memcg))
         |         ^~~~~~~~~~~~~~~~~~~~~
     932 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:928:6: warning: variable 'swap_peak_fd' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     928 |         if (!memcg)
         |             ^~~~~~
   test_memcontrol.c:1083:12: note: uninitialized use occurs here
    1083 |         if (close(swap_peak_fd))
         |                   ^~~~~~~~~~~~
   test_memcontrol.c:928:2: note: remove the 'if' if its condition is always false
     928 |         if (!memcg)
         |         ^~~~~~~~~~~
     929 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:939:2: note: variable 'swap_peak_fd' is declared here
     939 |         int swap_peak_fd = cg_open(memcg, "memory.swap.peak",
         |         ^
>> test_memcontrol.c:942:6: warning: variable 'mem_peak_fd' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     942 |         if (swap_peak_fd == -1)
         |             ^~~~~~~~~~~~~~~~~~
   test_memcontrol.c:1081:12: note: uninitialized use occurs here
    1081 |         if (close(mem_peak_fd))
         |                   ^~~~~~~~~~~
   test_memcontrol.c:942:2: note: remove the 'if' if its condition is always false
     942 |         if (swap_peak_fd == -1)
         |         ^~~~~~~~~~~~~~~~~~~~~~~
     943 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:934:6: warning: variable 'mem_peak_fd' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     934 |         if (cg_read_long(memcg, "memory.swap.current")) {
         |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   test_memcontrol.c:1081:12: note: uninitialized use occurs here
    1081 |         if (close(mem_peak_fd))
         |                   ^~~~~~~~~~~
   test_memcontrol.c:934:2: note: remove the 'if' if its condition is always false
     934 |         if (cg_read_long(memcg, "memory.swap.current")) {
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     935 |                 ret = KSFT_SKIP;
         |                 ~~~~~~~~~~~~~~~~
     936 |                 goto cleanup;
         |                 ~~~~~~~~~~~~~
     937 |         }
         |         ~
   test_memcontrol.c:931:6: warning: variable 'mem_peak_fd' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     931 |         if (cg_create(memcg))
         |             ^~~~~~~~~~~~~~~~
   test_memcontrol.c:1081:12: note: uninitialized use occurs here
    1081 |         if (close(mem_peak_fd))
         |                   ^~~~~~~~~~~
   test_memcontrol.c:931:2: note: remove the 'if' if its condition is always false
     931 |         if (cg_create(memcg))
         |         ^~~~~~~~~~~~~~~~~~~~~
     932 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:928:6: warning: variable 'mem_peak_fd' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     928 |         if (!memcg)
         |             ^~~~~~
   test_memcontrol.c:1081:12: note: uninitialized use occurs here
    1081 |         if (close(mem_peak_fd))
         |                   ^~~~~~~~~~~
   test_memcontrol.c:928:2: note: remove the 'if' if its condition is always false
     928 |         if (!memcg)
         |         ^~~~~~~~~~~
     929 |                 goto cleanup;
         |                 ~~~~~~~~~~~~
   test_memcontrol.c:945:2: note: variable 'mem_peak_fd' is declared here
     945 |         int mem_peak_fd = cg_open(memcg, "memory.peak", O_RDWR | O_APPEND | O_CLOEXEC);
         |         ^
   34 warnings generated.


vim +201 tools/testing/selftests/cgroup/test_memcontrol.c

84092dbcf90176 Roman Gushchin 2018-05-11  160  
84092dbcf90176 Roman Gushchin 2018-05-11  161  /*
84092dbcf90176 Roman Gushchin 2018-05-11  162   * This test create a memory cgroup, allocates
84092dbcf90176 Roman Gushchin 2018-05-11  163   * some anonymous memory and some pagecache
f2db5cca818233 David Finkel   2024-07-24  164   * and checks memory.current, memory.peak, and some memory.stat values.
84092dbcf90176 Roman Gushchin 2018-05-11  165   */
f2db5cca818233 David Finkel   2024-07-24  166  static int test_memcg_current_peak(const char *root)
84092dbcf90176 Roman Gushchin 2018-05-11  167  {
84092dbcf90176 Roman Gushchin 2018-05-11  168  	int ret = KSFT_FAIL;
f2db5cca818233 David Finkel   2024-07-24  169  	long current, peak, peak_reset;
84092dbcf90176 Roman Gushchin 2018-05-11  170  	char *memcg;
84092dbcf90176 Roman Gushchin 2018-05-11  171  
84092dbcf90176 Roman Gushchin 2018-05-11  172  	memcg = cg_name(root, "memcg_test");
84092dbcf90176 Roman Gushchin 2018-05-11  173  	if (!memcg)
84092dbcf90176 Roman Gushchin 2018-05-11  174  		goto cleanup;
84092dbcf90176 Roman Gushchin 2018-05-11  175  
84092dbcf90176 Roman Gushchin 2018-05-11  176  	if (cg_create(memcg))
84092dbcf90176 Roman Gushchin 2018-05-11  177  		goto cleanup;
84092dbcf90176 Roman Gushchin 2018-05-11  178  
84092dbcf90176 Roman Gushchin 2018-05-11  179  	current = cg_read_long(memcg, "memory.current");
84092dbcf90176 Roman Gushchin 2018-05-11  180  	if (current != 0)
84092dbcf90176 Roman Gushchin 2018-05-11  181  		goto cleanup;
84092dbcf90176 Roman Gushchin 2018-05-11  182  
f2db5cca818233 David Finkel   2024-07-24  183  	peak = cg_read_long(memcg, "memory.peak");
f2db5cca818233 David Finkel   2024-07-24  184  	if (peak != 0)
f2db5cca818233 David Finkel   2024-07-24  185  		goto cleanup;
f2db5cca818233 David Finkel   2024-07-24  186  
84092dbcf90176 Roman Gushchin 2018-05-11  187  	if (cg_run(memcg, alloc_anon_50M_check, NULL))
84092dbcf90176 Roman Gushchin 2018-05-11  188  		goto cleanup;
84092dbcf90176 Roman Gushchin 2018-05-11  189  
f2db5cca818233 David Finkel   2024-07-24  190  	peak = cg_read_long(memcg, "memory.peak");
f2db5cca818233 David Finkel   2024-07-24  191  	if (peak < MB(50))
f2db5cca818233 David Finkel   2024-07-24  192  		goto cleanup;
f2db5cca818233 David Finkel   2024-07-24  193  
f2db5cca818233 David Finkel   2024-07-24  194  	/*
f2db5cca818233 David Finkel   2024-07-24  195  	 * We'll open a few FDs for the same memory.peak file to exercise the free-path
f2db5cca818233 David Finkel   2024-07-24  196  	 * We need at least three to be closed in a different order than writes occurred to test
f2db5cca818233 David Finkel   2024-07-24  197  	 * the linked-list handling.
f2db5cca818233 David Finkel   2024-07-24  198  	 */
f2db5cca818233 David Finkel   2024-07-24  199  	int peak_fd = cg_open(memcg, "memory.peak", O_RDWR | O_APPEND | O_CLOEXEC);
f2db5cca818233 David Finkel   2024-07-24  200  
f2db5cca818233 David Finkel   2024-07-24 @201  	if (peak_fd == -1)
f2db5cca818233 David Finkel   2024-07-24  202  		goto cleanup;
f2db5cca818233 David Finkel   2024-07-24  203  
f2db5cca818233 David Finkel   2024-07-24  204  	bool fd2_closed = false, fd3_closed = false, fd4_closed = false;
f2db5cca818233 David Finkel   2024-07-24  205  	int peak_fd2 = cg_open(memcg, "memory.peak", O_RDWR | O_APPEND | O_CLOEXEC);
f2db5cca818233 David Finkel   2024-07-24  206  
f2db5cca818233 David Finkel   2024-07-24  207  	if (peak_fd2 == -1)
f2db5cca818233 David Finkel   2024-07-24  208  		goto cleanup;
f2db5cca818233 David Finkel   2024-07-24  209  
f2db5cca818233 David Finkel   2024-07-24  210  	int peak_fd3 = cg_open(memcg, "memory.peak", O_RDWR | O_APPEND | O_CLOEXEC);
f2db5cca818233 David Finkel   2024-07-24  211  
f2db5cca818233 David Finkel   2024-07-24  212  	if (peak_fd3 == -1)
f2db5cca818233 David Finkel   2024-07-24  213  		goto cleanup;
f2db5cca818233 David Finkel   2024-07-24  214  
f2db5cca818233 David Finkel   2024-07-24  215  	static const char reset_string[] = "reset\n";
f2db5cca818233 David Finkel   2024-07-24  216  
f2db5cca818233 David Finkel   2024-07-24  217  	peak_reset = write(peak_fd, reset_string, sizeof(reset_string));
f2db5cca818233 David Finkel   2024-07-24  218  	if (peak_reset != sizeof(reset_string))
f2db5cca818233 David Finkel   2024-07-24  219  		goto cleanup;
f2db5cca818233 David Finkel   2024-07-24  220  
f2db5cca818233 David Finkel   2024-07-24  221  	peak_reset = write(peak_fd2, reset_string, sizeof(reset_string));
f2db5cca818233 David Finkel   2024-07-24  222  	if (peak_reset != sizeof(reset_string))
f2db5cca818233 David Finkel   2024-07-24  223  		goto cleanup;
f2db5cca818233 David Finkel   2024-07-24  224  
f2db5cca818233 David Finkel   2024-07-24  225  	peak_reset = write(peak_fd3, reset_string, sizeof(reset_string));
f2db5cca818233 David Finkel   2024-07-24  226  	if (peak_reset != sizeof(reset_string))
f2db5cca818233 David Finkel   2024-07-24  227  		goto cleanup;
f2db5cca818233 David Finkel   2024-07-24  228  
f2db5cca818233 David Finkel   2024-07-24  229  	/* Make sure a completely independent read isn't affected by our  FD-local reset above*/
f2db5cca818233 David Finkel   2024-07-24  230  	peak = cg_read_long(memcg, "memory.peak");
f2db5cca818233 David Finkel   2024-07-24  231  	if (peak < MB(50))
f2db5cca818233 David Finkel   2024-07-24  232  		goto cleanup;
f2db5cca818233 David Finkel   2024-07-24  233  
f2db5cca818233 David Finkel   2024-07-24  234  	fd2_closed = true;
f2db5cca818233 David Finkel   2024-07-24  235  	if (close(peak_fd2))
f2db5cca818233 David Finkel   2024-07-24  236  		goto cleanup;
f2db5cca818233 David Finkel   2024-07-24  237  
f2db5cca818233 David Finkel   2024-07-24  238  	int peak_fd4 = cg_open(memcg, "memory.peak", O_RDWR | O_APPEND | O_CLOEXEC);
f2db5cca818233 David Finkel   2024-07-24  239  
f2db5cca818233 David Finkel   2024-07-24  240  	if (peak_fd4 == -1)
f2db5cca818233 David Finkel   2024-07-24  241  		goto cleanup;
f2db5cca818233 David Finkel   2024-07-24  242  
f2db5cca818233 David Finkel   2024-07-24  243  	peak_reset = write(peak_fd4, reset_string, sizeof(reset_string));
f2db5cca818233 David Finkel   2024-07-24  244  	if (peak_reset != sizeof(reset_string))
f2db5cca818233 David Finkel   2024-07-24  245  		goto cleanup;
f2db5cca818233 David Finkel   2024-07-24  246  
f2db5cca818233 David Finkel   2024-07-24  247  	peak = cg_read_long_fd(peak_fd);
f2db5cca818233 David Finkel   2024-07-24  248  	if (peak > MB(30) || peak < 0)
f2db5cca818233 David Finkel   2024-07-24  249  		goto cleanup;
f2db5cca818233 David Finkel   2024-07-24  250  
84092dbcf90176 Roman Gushchin 2018-05-11  251  	if (cg_run(memcg, alloc_pagecache_50M_check, NULL))
84092dbcf90176 Roman Gushchin 2018-05-11  252  		goto cleanup;
84092dbcf90176 Roman Gushchin 2018-05-11  253  
f2db5cca818233 David Finkel   2024-07-24  254  	peak = cg_read_long(memcg, "memory.peak");
f2db5cca818233 David Finkel   2024-07-24  255  	if (peak < MB(50))
f2db5cca818233 David Finkel   2024-07-24  256  		goto cleanup;
f2db5cca818233 David Finkel   2024-07-24  257  
f2db5cca818233 David Finkel   2024-07-24  258  	/* Make sure everything is back to normal */
f2db5cca818233 David Finkel   2024-07-24  259  	peak = cg_read_long_fd(peak_fd);
f2db5cca818233 David Finkel   2024-07-24  260  	if (peak < MB(50))
f2db5cca818233 David Finkel   2024-07-24  261  		goto cleanup;
f2db5cca818233 David Finkel   2024-07-24  262  
f2db5cca818233 David Finkel   2024-07-24  263  	peak = cg_read_long_fd(peak_fd4);
f2db5cca818233 David Finkel   2024-07-24  264  	if (peak < MB(50))
f2db5cca818233 David Finkel   2024-07-24  265  		goto cleanup;
f2db5cca818233 David Finkel   2024-07-24  266  
f2db5cca818233 David Finkel   2024-07-24  267  	fd3_closed = true;
f2db5cca818233 David Finkel   2024-07-24  268  	if (close(peak_fd3))
f2db5cca818233 David Finkel   2024-07-24  269  		goto cleanup;
f2db5cca818233 David Finkel   2024-07-24  270  
f2db5cca818233 David Finkel   2024-07-24  271  	fd4_closed = true;
f2db5cca818233 David Finkel   2024-07-24  272  	if (close(peak_fd4))
f2db5cca818233 David Finkel   2024-07-24  273  		goto cleanup;
f2db5cca818233 David Finkel   2024-07-24  274  
84092dbcf90176 Roman Gushchin 2018-05-11  275  	ret = KSFT_PASS;
84092dbcf90176 Roman Gushchin 2018-05-11  276  
84092dbcf90176 Roman Gushchin 2018-05-11  277  cleanup:
f2db5cca818233 David Finkel   2024-07-24  278  	close(peak_fd);
f2db5cca818233 David Finkel   2024-07-24  279  	if (!fd2_closed)
f2db5cca818233 David Finkel   2024-07-24  280  		close(peak_fd2);
f2db5cca818233 David Finkel   2024-07-24  281  	if (!fd3_closed)
f2db5cca818233 David Finkel   2024-07-24  282  		close(peak_fd3);
f2db5cca818233 David Finkel   2024-07-24  283  	if (!fd4_closed)
f2db5cca818233 David Finkel   2024-07-24  284  		close(peak_fd4);
84092dbcf90176 Roman Gushchin 2018-05-11  285  	cg_destroy(memcg);
84092dbcf90176 Roman Gushchin 2018-05-11  286  	free(memcg);
84092dbcf90176 Roman Gushchin 2018-05-11  287  
84092dbcf90176 Roman Gushchin 2018-05-11  288  	return ret;
84092dbcf90176 Roman Gushchin 2018-05-11  289  }
84092dbcf90176 Roman Gushchin 2018-05-11  290  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [akpm-mm:mm-unstable 36/78] test_memcontrol.c:201:6: warning: variable 'fd4_closed' is used uninitialized whenever 'if' condition is true
  2024-07-28  3:58 [akpm-mm:mm-unstable 36/78] test_memcontrol.c:201:6: warning: variable 'fd4_closed' is used uninitialized whenever 'if' condition is true kernel test robot
@ 2024-07-28 20:18 ` Andrew Morton
  2024-07-29  2:20   ` Philip Li
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2024-07-28 20:18 UTC (permalink / raw)
  To: kernel test robot
  Cc: David Finkel, oe-kbuild-all, Linux Memory Management List

On Sun, 28 Jul 2024 11:58:47 +0800 kernel test robot <lkp@intel.com> 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@intel.com/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@intel.com>
> | Closes: https://lore.kernel.org/r/202407272301.bBC2CidR-lkp@intel.com/
> 
> 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?


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [akpm-mm:mm-unstable 36/78] test_memcontrol.c:201:6: warning: variable 'fd4_closed' is used uninitialized whenever 'if' condition is true
  2024-07-28 20:18 ` Andrew Morton
@ 2024-07-29  2:20   ` Philip Li
  2024-07-29 13:45     ` David Finkel
  0 siblings, 1 reply; 4+ messages in thread
From: Philip Li @ 2024-07-29  2:20 UTC (permalink / raw)
  To: Andrew Morton
  Cc: kernel test robot, David Finkel, oe-kbuild-all,
	Linux Memory Management List

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@intel.com> 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@intel.com/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@intel.com>
> > | Closes: https://lore.kernel.org/r/202407272301.bBC2CidR-lkp@intel.com/
> > 
> > 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.

+       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);

> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [akpm-mm:mm-unstable 36/78] test_memcontrol.c:201:6: warning: variable 'fd4_closed' is used uninitialized whenever 'if' condition is true
  2024-07-29  2:20   ` Philip Li
@ 2024-07-29 13:45     ` David Finkel
  0 siblings, 0 replies; 4+ messages in thread
From: David Finkel @ 2024-07-29 13:45 UTC (permalink / raw)
  To: Philip Li
  Cc: Andrew Morton, kernel test robot, oe-kbuild-all,
	Linux Memory Management List

On Sun, Jul 28, 2024 at 10:21 PM Philip Li <philip.li@intel.com> 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@intel.com> 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@intel.com/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@intel.com>
> > > | Closes: https://lore.kernel.org/r/202407272301.bBC2CidR-lkp@intel.com/
> > >
> > > 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-07-29 13:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-28  3:58 [akpm-mm:mm-unstable 36/78] test_memcontrol.c:201:6: warning: variable 'fd4_closed' is used uninitialized whenever 'if' condition is true kernel test robot
2024-07-28 20:18 ` Andrew Morton
2024-07-29  2:20   ` Philip Li
2024-07-29 13:45     ` David Finkel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox