Skip to contentSkip to conversation

selftests/filesystems/mount-notify: fix unused unused result warning

PATCH Superseded Chen Linxuan 2 participants 5 messages Jun 20, 2025 – Jun 23, 2025 Kselftest

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 selftests/filesystems/mount-notify: fix unused unused result warning

When running make kselftest, the following compilation warning was encountered:

mount-notify_test.c: In function ‘fanotify_rmdir’:
mount-notify_test.c:490:17: warning: ignoring return value of ‘chdir’ declared with attribute ‘warn_unused_result’ [-Wunused-result]

  490 |                 chdir("/");
      |                 ^~~~~~~~~~

---
Changes in v2:
- Apply changes suggested by Shuah Khan
- Link to v1: https://lore.kernel.org/all/[email protected]/

---
 .../filesystems/mount-notify/mount-notify_test.c  | 15 ++++++++++-----
 .../mount-notify/mount-notify_test_ns.c           | 15 ++++++++++-----
 2 files changed, 20 insertions(+), 10 deletions(-)
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +10 -5
index 5a3b0ace1a88c..f8e0c6b06e2d9 100644
@@ -458,12 +458,17 @@ TEST_F(fanotify, rmdir)
 	ASSERT_GE(ret, 0);
 
 	if (ret == 0) {
-		chdir("/");
-		unshare(CLONE_NEWNS);
-		mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL);
-		umount2("/a", MNT_DETACH);
+		if (chdir("/"))
+			exit(-1);
+		if (unshare(CLONE_NEWNS))
+			exit(-1);
+		if (mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL))
+			exit(-1);
+		if (umount2("/a", MNT_DETACH))
+			exit(-1);
 		// This triggers a detach in the other namespace
-		rmdir("/a");
+		if (rmdir("/a"))
+			exit(-1);
 		exit(0);
 	}
 	wait(NULL);
tools/testing/selftests/filesystems/mount-notify/mount-notify_test_ns.c +10 -5
index d91946e69591a..d6a6a7ee87028 100644
@@ -486,12 +486,17 @@ TEST_F(fanotify, rmdir)
 	ASSERT_GE(ret, 0);
 
 	if (ret == 0) {
-		chdir("/");
-		unshare(CLONE_NEWNS);
-		mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL);
-		umount2("/a", MNT_DETACH);
+		if (chdir("/"))
+			exit(-1);
+		if (unshare(CLONE_NEWNS))
+			exit(-1);
+		if (mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL))
+			exit(-1);
+		if (umount2("/a", MNT_DETACH))
+			exit(-1);
 		// This triggers a detach in the other namespace
-		rmdir("/a");
+		if (rmdir("/a"))
+			exit(-1);
 		exit(0);
 	}
 	wait(NULL);
Signature · 1 line
2.43.0
#1 lore raw
Quoted 22 lines · Chen Linxuan

When running make kselftest, the following compilation warning was encountered:

mount-notify_test.c: In function ‘fanotify_rmdir’:
mount-notify_test.c:490:17: warning: ignoring return value of ‘chdir’ declared with attribute ‘warn_unused_result’ [-Wunused-result]

  490 |                 chdir("/");
      |                 ^~~~~~~~~~

---
Changes in v2:
- Apply changes suggested by Shuah Khan
- Link to v1: https://lore.kernel.org/all/[email protected]/

---
 .../filesystems/mount-notify/mount-notify_test.c  | 15 ++++++++++-----
 .../mount-notify/mount-notify_test_ns.c           | 15 ++++++++++-----
 2 files changed, 20 insertions(+), 10 deletions(-)
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +0 -0
index 5a3b0ace1a88c..f8e0c6b06e2d9 100644

tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c TEST_F(fanotify, rmdir) · line 461

Quoted 8 lines
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +1 -4
@@ -458,12 +458,17 @@ TEST_F(fanotify, rmdir)
 	ASSERT_GE(ret, 0);
 
 	if (ret == 0) {
-		chdir("/");
-		unshare(CLONE_NEWNS);
-		mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL);
-		umount2("/a", MNT_DETACH);
+		if (chdir("/"))

Please use the APIs provided by the kselftest_harness.h instead of checking return types manually. For example:
use ASSERT_EQ(chdir("/", 0)).

Quoted 41 lines
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +9 -1
+			exit(-1);
+		if (unshare(CLONE_NEWNS))
+			exit(-1);
+		if (mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL))
+			exit(-1);
+		if (umount2("/a", MNT_DETACH))
+			exit(-1);
 		// This triggers a detach in the other namespace
-		rmdir("/a");
+		if (rmdir("/a"))
+			exit(-1);
 		exit(0);
 	}
 	wait(NULL);
tools/testing/selftests/filesystems/mount-notify/mount-notify_test_ns.c +10 -5
index d91946e69591a..d6a6a7ee87028 100644
@@ -486,12 +486,17 @@ TEST_F(fanotify, rmdir)
 	ASSERT_GE(ret, 0);
 
 	if (ret == 0) {
-		chdir("/");
-		unshare(CLONE_NEWNS);
-		mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL);
-		umount2("/a", MNT_DETACH);
+		if (chdir("/"))
+			exit(-1);
+		if (unshare(CLONE_NEWNS))
+			exit(-1);
+		if (mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL))
+			exit(-1);
+		if (umount2("/a", MNT_DETACH))
+			exit(-1);
 		// This triggers a detach in the other namespace
-		rmdir("/a");
+		if (rmdir("/a"))
+			exit(-1);
 		exit(0);
 	}
 	wait(NULL);
#2 lore raw
Quoted 26 lines · Muhammad Usama Anjum
Quoted 24 lines · Chen Linxuan

When running make kselftest, the following compilation warning was encountered:

mount-notify_test.c: In function ‘fanotify_rmdir’:
mount-notify_test.c:490:17: warning: ignoring return value of ‘chdir’ declared with attribute ‘warn_unused_result’ [-Wunused-result]

  490 |                 chdir("/");
      |                 ^~~~~~~~~~

---
Changes in v2:
- Apply changes suggested by Shuah Khan
- Link to v1: https://lore.kernel.org/all/[email protected]/

---
 .../filesystems/mount-notify/mount-notify_test.c  | 15 ++++++++++-----
 .../mount-notify/mount-notify_test_ns.c           | 15 ++++++++++-----
 2 files changed, 20 insertions(+), 10 deletions(-)
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +0 -0
index 5a3b0ace1a88c..f8e0c6b06e2d9 100644
@@ -458,12 +458,17 @@ TEST_F(fanotify, rmdir)
      ASSERT_GE(ret, 0);
 
Quoted 9 lines

tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c TEST_F(fanotify, rmdir) · line 461

Quoted 6 lines
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +1 -4
      if (ret == 0) {
-             chdir("/");
-             unshare(CLONE_NEWNS);
-             mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL);
-             umount2("/a", MNT_DETACH);
+             if (chdir("/"))

Please use the APIs provided by the kselftest_harness.h instead of checking return types manually. For example:
use ASSERT_EQ(chdir("/", 0)).

Are you sure?We're in a forked sub process here.

Quoted 45 lines
Quoted 42 lines
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +9 -1
+                     exit(-1);
+             if (unshare(CLONE_NEWNS))
+                     exit(-1);
+             if (mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL))
+                     exit(-1);
+             if (umount2("/a", MNT_DETACH))
+                     exit(-1);
              // This triggers a detach in the other namespace
-             rmdir("/a");
+             if (rmdir("/a"))
+                     exit(-1);
              exit(0);
      }
      wait(NULL);
tools/testing/selftests/filesystems/mount-notify/mount-notify_test_ns.c +10 -5
index d91946e69591a..d6a6a7ee87028 100644
@@ -486,12 +486,17 @@ TEST_F(fanotify, rmdir)
      ASSERT_GE(ret, 0);
 
      if (ret == 0) {
-             chdir("/");
-             unshare(CLONE_NEWNS);
-             mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL);
-             umount2("/a", MNT_DETACH);
+             if (chdir("/"))
+                     exit(-1);
+             if (unshare(CLONE_NEWNS))
+                     exit(-1);
+             if (mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL))
+                     exit(-1);
+             if (umount2("/a", MNT_DETACH))
+                     exit(-1);
              // This triggers a detach in the other namespace
-             rmdir("/a");
+             if (rmdir("/a"))
+                     exit(-1);
              exit(0);
      }
      wait(NULL);
#3 lore raw
Quoted 38 lines · Chen Linxuan
Quoted 26 lines · Muhammad Usama Anjum
Quoted 24 lines · Chen Linxuan

When running make kselftest, the following compilation warning was encountered:

mount-notify_test.c: In function ‘fanotify_rmdir’:
mount-notify_test.c:490:17: warning: ignoring return value of ‘chdir’ declared with attribute ‘warn_unused_result’ [-Wunused-result]

  490 |                 chdir("/");
      |                 ^~~~~~~~~~

---
Changes in v2:
- Apply changes suggested by Shuah Khan
- Link to v1: https://lore.kernel.org/all/[email protected]/

---
 .../filesystems/mount-notify/mount-notify_test.c  | 15 ++++++++++-----
 .../mount-notify/mount-notify_test_ns.c           | 15 ++++++++++-----
 2 files changed, 20 insertions(+), 10 deletions(-)
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +0 -0
index 5a3b0ace1a88c..f8e0c6b06e2d9 100644
@@ -458,12 +458,17 @@ TEST_F(fanotify, rmdir)
      ASSERT_GE(ret, 0);
 
Quoted 9 lines

tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c TEST_F(fanotify, rmdir) · line 461

Quoted 6 lines
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +1 -4
      if (ret == 0) {
-             chdir("/");
-             unshare(CLONE_NEWNS);
-             mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL);
-             umount2("/a", MNT_DETACH);
+             if (chdir("/"))

Please use the APIs provided by the kselftest_harness.h instead of checking return types manually. For example:
use ASSERT_EQ(chdir("/", 0)).

Quoted 1 line

Are you sure?We're in a forked sub process here.

ASSERT_* are macros. They can be used anywhere. Please give it a try.

Quoted 46 lines
Quoted 46 lines
Quoted 43 lines
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +9 -1
+                     exit(-1);
+             if (unshare(CLONE_NEWNS))
+                     exit(-1);
+             if (mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL))
+                     exit(-1);
+             if (umount2("/a", MNT_DETACH))
+                     exit(-1);
              // This triggers a detach in the other namespace
-             rmdir("/a");
+             if (rmdir("/a"))
+                     exit(-1);
              exit(0);
      }
      wait(NULL);
tools/testing/selftests/filesystems/mount-notify/mount-notify_test_ns.c +10 -5
index d91946e69591a..d6a6a7ee87028 100644
@@ -486,12 +486,17 @@ TEST_F(fanotify, rmdir)
      ASSERT_GE(ret, 0);
 
      if (ret == 0) {
-             chdir("/");
-             unshare(CLONE_NEWNS);
-             mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL);
-             umount2("/a", MNT_DETACH);
+             if (chdir("/"))
+                     exit(-1);
+             if (unshare(CLONE_NEWNS))
+                     exit(-1);
+             if (mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL))
+                     exit(-1);
+             if (umount2("/a", MNT_DETACH))
+                     exit(-1);
              // This triggers a detach in the other namespace
-             rmdir("/a");
+             if (rmdir("/a"))
+                     exit(-1);
              exit(0);
      }
      wait(NULL);
#4 lore raw
Quoted 40 lines · Muhammad Usama Anjum
Quoted 38 lines · Chen Linxuan
Quoted 35 lines · Muhammad Usama Anjum
Quoted 22 lines · Chen Linxuan

When running make kselftest, the following compilation warning was encountered:

mount-notify_test.c: In function ‘fanotify_rmdir’:
mount-notify_test.c:490:17: warning: ignoring return value of ‘chdir’ declared with attribute ‘warn_unused_result’ [-Wunused-result]

  490 |                 chdir("/");
      |                 ^~~~~~~~~~

---
Changes in v2:
- Apply changes suggested by Shuah Khan
- Link to v1: https://lore.kernel.org/all/[email protected]/

---
 .../filesystems/mount-notify/mount-notify_test.c  | 15 ++++++++++-----
 .../mount-notify/mount-notify_test_ns.c           | 15 ++++++++++-----
 2 files changed, 20 insertions(+), 10 deletions(-)
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +0 -0
index 5a3b0ace1a88c..f8e0c6b06e2d9 100644

tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c TEST_F(fanotify, rmdir) · line 461

Quoted 8 lines
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +1 -4
@@ -458,12 +458,17 @@ TEST_F(fanotify, rmdir)
      ASSERT_GE(ret, 0);
 
      if (ret == 0) {
-             chdir("/");
-             unshare(CLONE_NEWNS);
-             mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL);
-             umount2("/a", MNT_DETACH);
+             if (chdir("/"))

Please use the APIs provided by the kselftest_harness.h instead of checking return types manually. For example:
use ASSERT_EQ(chdir("/", 0)).

Quoted 2 lines
Quoted 1 line

Are you sure?We're in a forked sub process here.

ASSERT_* are macros. They can be used anywhere. Please give it a try.

V3: https://lore.kernel.org/all/[email protected]/

Quoted 50 lines
Quoted 47 lines
Quoted 47 lines
Quoted 44 lines
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +9 -1
+                     exit(-1);
+             if (unshare(CLONE_NEWNS))
+                     exit(-1);
+             if (mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL))
+                     exit(-1);
+             if (umount2("/a", MNT_DETACH))
+                     exit(-1);
              // This triggers a detach in the other namespace
-             rmdir("/a");
+             if (rmdir("/a"))
+                     exit(-1);
              exit(0);
      }
      wait(NULL);
tools/testing/selftests/filesystems/mount-notify/mount-notify_test_ns.c +10 -5
index d91946e69591a..d6a6a7ee87028 100644
@@ -486,12 +486,17 @@ TEST_F(fanotify, rmdir)
      ASSERT_GE(ret, 0);
 
      if (ret == 0) {
-             chdir("/");
-             unshare(CLONE_NEWNS);
-             mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL);
-             umount2("/a", MNT_DETACH);
+             if (chdir("/"))
+                     exit(-1);
+             if (unshare(CLONE_NEWNS))
+                     exit(-1);
+             if (mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL))
+                     exit(-1);
+             if (umount2("/a", MNT_DETACH))
+                     exit(-1);
              // This triggers a detach in the other namespace
-             rmdir("/a");
+             if (rmdir("/a"))
+                     exit(-1);
              exit(0);
      }
      wait(NULL);