[PATCH v2 12/13] selftests/fs/mount-notify-ns: Fix build warning

Guenter Roeck posted 13 patches 1 week, 6 days ago
[PATCH v2 12/13] selftests/fs/mount-notify-ns: Fix build warning
Posted by Guenter Roeck 1 week, 6 days ago
Fix

mount-notify_test_ns.c: In function ‘fanotify_rmdir’:
mount-notify_test_ns.c:494:17: warning:
	ignoring return value of ‘chdir’ declared with attribute ‘warn_unused_result’

by checking the return value of chdir() and displaying an error message
if it returns an error.

Fixes: 781091f3f5945 ("selftests/fs/mount-notify: add a test variant running inside userns")
Cc: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
v2: Update subject and description to reflect that the patch fixes a build
    warning.
    Use perror() to display an error message if chdir() returns an error.

 .../selftests/filesystems/mount-notify/mount-notify_test_ns.c  | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/filesystems/mount-notify/mount-notify_test_ns.c b/tools/testing/selftests/filesystems/mount-notify/mount-notify_test_ns.c
index 9f57ca46e3af..90bec6faf64e 100644
--- a/tools/testing/selftests/filesystems/mount-notify/mount-notify_test_ns.c
+++ b/tools/testing/selftests/filesystems/mount-notify/mount-notify_test_ns.c
@@ -491,7 +491,8 @@ TEST_F(fanotify, rmdir)
 	ASSERT_GE(ret, 0);
 
 	if (ret == 0) {
-		chdir("/");
+		if (chdir("/"))
+			perror("chdir()");
 		unshare(CLONE_NEWNS);
 		mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL);
 		umount2("/a", MNT_DETACH);
-- 
2.45.2

Re: [PATCH v2 12/13] selftests/fs/mount-notify-ns: Fix build warning
Posted by Amir Goldstein 1 week, 6 days ago
On Fri, Dec 5, 2025 at 6:12 PM Guenter Roeck <linux@roeck-us.net> wrote:
>
> Fix
>
> mount-notify_test_ns.c: In function ‘fanotify_rmdir’:
> mount-notify_test_ns.c:494:17: warning:
>         ignoring return value of ‘chdir’ declared with attribute ‘warn_unused_result’
>
> by checking the return value of chdir() and displaying an error message
> if it returns an error.
>
> Fixes: 781091f3f5945 ("selftests/fs/mount-notify: add a test variant running inside userns")
> Cc: Amir Goldstein <amir73il@gmail.com>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
> v2: Update subject and description to reflect that the patch fixes a build
>     warning.
>     Use perror() to display an error message if chdir() returns an error.
>
>  .../selftests/filesystems/mount-notify/mount-notify_test_ns.c  | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/filesystems/mount-notify/mount-notify_test_ns.c b/tools/testing/selftests/filesystems/mount-notify/mount-notify_test_ns.c
> index 9f57ca46e3af..90bec6faf64e 100644
> --- a/tools/testing/selftests/filesystems/mount-notify/mount-notify_test_ns.c
> +++ b/tools/testing/selftests/filesystems/mount-notify/mount-notify_test_ns.c
> @@ -491,7 +491,8 @@ TEST_F(fanotify, rmdir)
>         ASSERT_GE(ret, 0);
>
>         if (ret == 0) {
> -               chdir("/");
> +               if (chdir("/"))
> +                       perror("chdir()");

ASSERT_EQ(0, chdir("/"));

and there is another one like this in mount-notify_test.c

Thanks,
Amir.
Re: [PATCH v2 12/13] selftests/fs/mount-notify-ns: Fix build warning
Posted by Guenter Roeck 1 week, 6 days ago
On 12/5/25 09:31, Amir Goldstein wrote:
> On Fri, Dec 5, 2025 at 6:12 PM Guenter Roeck <linux@roeck-us.net> wrote:
>>
>> Fix
>>
>> mount-notify_test_ns.c: In function ‘fanotify_rmdir’:
>> mount-notify_test_ns.c:494:17: warning:
>>          ignoring return value of ‘chdir’ declared with attribute ‘warn_unused_result’
>>
>> by checking the return value of chdir() and displaying an error message
>> if it returns an error.
>>
>> Fixes: 781091f3f5945 ("selftests/fs/mount-notify: add a test variant running inside userns")
>> Cc: Amir Goldstein <amir73il@gmail.com>
>> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
>> ---
>> v2: Update subject and description to reflect that the patch fixes a build
>>      warning.
>>      Use perror() to display an error message if chdir() returns an error.
>>
>>   .../selftests/filesystems/mount-notify/mount-notify_test_ns.c  | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/tools/testing/selftests/filesystems/mount-notify/mount-notify_test_ns.c b/tools/testing/selftests/filesystems/mount-notify/mount-notify_test_ns.c
>> index 9f57ca46e3af..90bec6faf64e 100644
>> --- a/tools/testing/selftests/filesystems/mount-notify/mount-notify_test_ns.c
>> +++ b/tools/testing/selftests/filesystems/mount-notify/mount-notify_test_ns.c
>> @@ -491,7 +491,8 @@ TEST_F(fanotify, rmdir)
>>          ASSERT_GE(ret, 0);
>>
>>          if (ret == 0) {
>> -               chdir("/");
>> +               if (chdir("/"))
>> +                       perror("chdir()");
> 
> ASSERT_EQ(0, chdir("/"));
> 
> and there is another one like this in mount-notify_test.c
> 

Done.

Thanks,
Guenter