On 6/19/25 01:46, Chen Linxuan wrote:
On Thu, Jun 19, 2025 at 5:23 AM Shuah Khan <sk...@linuxfoundation.org> wrote:

On 6/9/25 20:07, Chen Linxuan wrote:
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("/");
        |                 ^~~~~~~~~~

This patch addresses the warning by
explicitly suppressing the unused result of the `chdir` function.

Signed-off-by: Chen Linxuan <chenlinx...@uniontech.com>
---
   .../selftests/filesystems/mount-notify/mount-notify_test.c    | 4 +++-
   1 file changed, 3 insertions(+), 1 deletion(-)

diff --git 
a/tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c 
b/tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c
index 63ce708d93ed0..34afe27b7978f 100644
--- a/tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c
+++ b/tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c
@@ -465,7 +465,9 @@ TEST_F(fanotify, rmdir)
       ASSERT_GE(ret, 0);

       if (ret == 0) {
-             chdir("/");
+             // Suppress -Wunused-result
+             // Ref: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425#c34
+             (void) !chdir("/");
Why not fix the problem the right way by checking the return value.
Suppressing the error isn't useful.

The code is already handling cleanup in error cases,
and I don't think checking the result of chdir would be useful here.

We check for chdir() in several tools in the kernel. Add a check for
it instead of suppressing the [-Wunused-result] - suppressing doesn't
do any good.

thanks,
-- Shuah



Reply via email to