]> git.ipfire.org Git - thirdparty/linux.git/commit
selftests/memfd: fix -Wmaybe-uninitialized warning in memfd_test
authorKonstantin Khorenko <khorenko@virtuozzo.com>
Sun, 24 May 2026 19:35:56 +0000 (22:35 +0300)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 4 Jun 2026 21:45:06 +0000 (14:45 -0700)
commit528db7d37e08dc7eae70d046cda5a2ee30208448
tree93c7ea9fb8b4766739eabe3a1222a752ad39085e
parentbf7033eb7c2f892580f060554ae4ea92bd52b9fb
selftests/memfd: fix -Wmaybe-uninitialized warning in memfd_test

Patch series "selftests/memfd: fix compilation warnings".

This patchset fixes warnings about unused but initialized variables, and
unused dummy buffer passed to pwrite() syscall in the tests.

This patch (of 2):

  memfd_test.c: In function 'mfd_fail_grow_write.part.0':
  memfd_test.c:685:13: warning: '<unknown>' may be used uninitialized
  [-Wmaybe-uninitialized]
    685 |         l = pwrite(fd, buf, mfd_def_size * 8, 0);
        |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

pwrite() is declared with attribute 'access (read_only, 2, 3)', so GCC
knows it reads from the buffer.  malloc() returns uninitialized memory,
hence the warning.  Use calloc() to zero-initialize the buffer.  The
actual contents don't matter here since the test verifies that pwrite()
fails on a sealed memfd.

Link: https://lore.kernel.org/20260524193732.48853-1-eva.kurchatova@virtuozzo.com
Link: https://lore.kernel.org/20260524193732.48853-2-eva.kurchatova@virtuozzo.com
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
Cc: Aristeu Rozanski <aris@redhat.com>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
tools/testing/selftests/memfd/memfd_test.c