Skip to contentSkip to conversation

selftests/filesystems: Use return value of the function 'chdir()'

PATCH In review Alessandro Zanni 2 participants 2 messages Jul 10, 2025 – Sep 8, 2025 Kselftest

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/filesystems: Use return value of the function 'chdir()'

Fix to use the return value of the function 'chdir("/")' and check if the return is either 0 (ok) or 1 (not ok, so the test stops).

The patch fies the solves the following errors:
mount-notify_test.c:468:17: warning: ignoring return value of ‘chdir’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
468 | chdir("/");

mount-notify_test_ns.c:489:17: warning: ignoring return value of ‘chdir’ declared with attribute ‘warn_unused_result’ [-Wunused- result]
489 | chdir("/");

To reproduce the issue, use the command:
make kselftest TARGET=filesystems/statmount

---
 .../selftests/filesystems/mount-notify/mount-notify_test.c      | 2 +-
 .../selftests/filesystems/mount-notify/mount-notify_test_ns.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +1 -1
index 5a3b0ace1a88..a7f899599d52 100644
@@ -458,7 +458,7 @@ TEST_F(fanotify, rmdir)
 	ASSERT_GE(ret, 0);
 
 	if (ret == 0) {
-		chdir("/");
+		ASSERT_EQ(0, chdir("/"));
 		unshare(CLONE_NEWNS);
 		mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL);
 		umount2("/a", MNT_DETACH);
tools/testing/selftests/filesystems/mount-notify/mount-notify_test_ns.c +1 -1
index d91946e69591..dc9eb3087a1a 100644
@@ -486,7 +486,7 @@ TEST_F(fanotify, rmdir)
 	ASSERT_GE(ret, 0);
 
 	if (ret == 0) {
-		chdir("/");
+		ASSERT_EQ(0, chdir("/"));
 		unshare(CLONE_NEWNS);
 		mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL);
 		umount2("/a", MNT_DETACH);
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Alessandro Zanni

Fix to use the return value of the function 'chdir("/")' and check if the return is either 0 (ok) or 1 (not ok, so the test stops).

The patch fies the solves the following errors:
mount-notify_test.c:468:17: warning: ignoring return value of ‘chdir’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
468 | chdir("/");

mount-notify_test_ns.c:489:17: warning: ignoring return value of ‘chdir’ declared with attribute ‘warn_unused_result’ [-Wunused- result]
489 | chdir("/");

Quoted 4 lines

To reproduce the issue, use the command:
make kselftest TARGET=filesystems/statmount

Looks good. Feel free to add:

Honza

Quoted 34 lines
---
 .../selftests/filesystems/mount-notify/mount-notify_test.c      | 2 +-
 .../selftests/filesystems/mount-notify/mount-notify_test_ns.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +1 -1
index 5a3b0ace1a88..a7f899599d52 100644
@@ -458,7 +458,7 @@ TEST_F(fanotify, rmdir)
 	ASSERT_GE(ret, 0);
 
 	if (ret == 0) {
-		chdir("/");
+		ASSERT_EQ(0, chdir("/"));
 		unshare(CLONE_NEWNS);
 		mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL);
 		umount2("/a", MNT_DETACH);
tools/testing/selftests/filesystems/mount-notify/mount-notify_test_ns.c +1 -1
index d91946e69591..dc9eb3087a1a 100644
@@ -486,7 +486,7 @@ TEST_F(fanotify, rmdir)
 	ASSERT_GE(ret, 0);
 
 	if (ret == 0) {
-		chdir("/");
+		ASSERT_EQ(0, chdir("/"));
 		unshare(CLONE_NEWNS);
 		mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL);
 		umount2("/a", MNT_DETACH);
Signature · 1 line
2.43.0
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR