linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests: filelock: Initialize the flock to zero
@ 2025-08-28  8:30 zhouyuhang
  0 siblings, 0 replies; only message in thread
From: zhouyuhang @ 2025-08-28  8:30 UTC (permalink / raw)
  To: shuah; +Cc: linux-kselftest, linux-kernel, Zhou Yuhang

From: Zhou Yuhang <zhouyuhang@kylinos.cn>

Flock fl and fl2 are not initialized after definition.
Due to struct padding, this may cause memcmp() to return
a non-zero value. The output is as follows:

 # [INFO] opened fds 3 4
 # [SUCCESS] set OFD read lock on first fd
 # [SUCCESS] read and write locks conflicted
 # [SUCCESS] F_UNLCK test returns: locked, type 0 pid -1 len 3
 # [FAIL] F_UNLCK test returns: locked, type 0 pid -1 len 3

Initialize them to zero to solve this problem.

Signed-off-by: Zhou Yuhang <zhouyuhang@kylinos.cn>
---
 tools/testing/selftests/filelock/ofdlocks.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/testing/selftests/filelock/ofdlocks.c b/tools/testing/selftests/filelock/ofdlocks.c
index a55b79810ab2..84e25505bebb 100644
--- a/tools/testing/selftests/filelock/ofdlocks.c
+++ b/tools/testing/selftests/filelock/ofdlocks.c
@@ -36,6 +36,8 @@ int main(void)
 {
 	int rc;
 	struct flock fl, fl2;
+	memset(&fl, 0, sizeof(fl));
+	memset(&fl2, 0, sizeof(fl2));
 	int fd = open("/tmp/aa", O_RDWR | O_CREAT | O_EXCL, 0600);
 	int fd2 = open("/tmp/aa", O_RDONLY);
 
-- 
2.33.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2025-08-28  8:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-28  8:30 [PATCH] selftests: filelock: Initialize the flock to zero zhouyuhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).