diff mbox series

selftests: filesystems: fix warn_unused_result build warnings

Message ID 20240417184913.74734-1-amer.shanawany@gmail.com
State Accepted
Commit 2049aad5d3a6921f80121029afe6fbcfb2727861
Headers show
Series selftests: filesystems: fix warn_unused_result build warnings | expand

Commit Message

Amer Al Shanawany April 17, 2024, 6:49 p.m. UTC
Fix the following warnings by adding return check and error messages.

statmount_test.c: In function ‘cleanup_namespace’:
statmount_test.c:128:9: warning: ignoring return value of ‘fchdir’
declared with attribute ‘warn_unused_result’ [-Wunused-result]
  128 |         fchdir(orig_root);
      |         ^~~~~~~~~~~~~~~~~
statmount_test.c:129:9: warning: ignoring return value of ‘chroot’
declared with attribute ‘warn_unused_result’ [-Wunused-result]
  129 |         chroot(".");
      |         ^~~~~~~~~~~

Signed-off-by: Amer Al Shanawany <amer.shanawany@gmail.com>
---
 .../selftests/filesystems/statmount/statmount_test.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Comments

Muhammad Usama Anjum April 19, 2024, 4:41 p.m. UTC | #1
On 4/17/24 11:49 PM, Amer Al Shanawany wrote:
> Fix the following warnings by adding return check and error messages.
> 
> statmount_test.c: In function ‘cleanup_namespace’:
> statmount_test.c:128:9: warning: ignoring return value of ‘fchdir’
> declared with attribute ‘warn_unused_result’ [-Wunused-result]
>   128 |         fchdir(orig_root);
>       |         ^~~~~~~~~~~~~~~~~
> statmount_test.c:129:9: warning: ignoring return value of ‘chroot’
> declared with attribute ‘warn_unused_result’ [-Wunused-result]
>   129 |         chroot(".");
>       |         ^~~~~~~~~~~
> 
> Signed-off-by: Amer Al Shanawany <amer.shanawany@gmail.com>
Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>

> ---
>  .../selftests/filesystems/statmount/statmount_test.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/filesystems/statmount/statmount_test.c b/tools/testing/selftests/filesystems/statmount/statmount_test.c
> index e6d7c4f1c85b..e8c019d72cbf 100644
> --- a/tools/testing/selftests/filesystems/statmount/statmount_test.c
> +++ b/tools/testing/selftests/filesystems/statmount/statmount_test.c
> @@ -125,8 +125,16 @@ static uint32_t old_root_id, old_parent_id;
>  
>  static void cleanup_namespace(void)
>  {
> -	fchdir(orig_root);
> -	chroot(".");
> +	int ret;
> +
> +	ret = fchdir(orig_root);
> +	if (ret == -1)
> +		ksft_perror("fchdir to original root");
> +
> +	ret = chroot(".");
> +	if (ret == -1)
> +		ksft_perror("chroot to original root");
> +
>  	umount2(root_mntpoint, MNT_DETACH);
>  	rmdir(root_mntpoint);
>  }
Amer Al Shanawany May 4, 2024, 5:17 p.m. UTC | #2
On 4/19/24 18:41, Muhammad Usama Anjum wrote:
> On 4/17/24 11:49 PM, Amer Al Shanawany wrote:
>> Fix the following warnings by adding return check and error messages.
>>
>> statmount_test.c: In function ‘cleanup_namespace’:
>> statmount_test.c:128:9: warning: ignoring return value of ‘fchdir’
>> declared with attribute ‘warn_unused_result’ [-Wunused-result]
>>   128 |         fchdir(orig_root);
>>       |         ^~~~~~~~~~~~~~~~~
>> statmount_test.c:129:9: warning: ignoring return value of ‘chroot’
>> declared with attribute ‘warn_unused_result’ [-Wunused-result]
>>   129 |         chroot(".");
>>       |         ^~~~~~~~~~~
>>
>> Signed-off-by: Amer Al Shanawany <amer.shanawany@gmail.com>
> Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
>
>> ---
>>  .../selftests/filesystems/statmount/statmount_test.c | 12 ++++++++++--
>>  1 file changed, 10 insertions(+), 2 deletions(-)
>>
>> diff --git a/tools/testing/selftests/filesystems/statmount/statmount_test.c b/tools/testing/selftests/filesystems/statmount/statmount_test.c
>> index e6d7c4f1c85b..e8c019d72cbf 100644
>> --- a/tools/testing/selftests/filesystems/statmount/statmount_test.c
>> +++ b/tools/testing/selftests/filesystems/statmount/statmount_test.c
>> @@ -125,8 +125,16 @@ static uint32_t old_root_id, old_parent_id;
>>  
>>  static void cleanup_namespace(void)
>>  {
>> -	fchdir(orig_root);
>> -	chroot(".");
>> +	int ret;
>> +
>> +	ret = fchdir(orig_root);
>> +	if (ret == -1)
>> +		ksft_perror("fchdir to original root");
>> +
>> +	ret = chroot(".");
>> +	if (ret == -1)
>> +		ksft_perror("chroot to original root");
>> +
>>  	umount2(root_mntpoint, MNT_DETACH);
>>  	rmdir(root_mntpoint);
>>  }
Hi,

Can you please consider this patch?

Thank  you

Amer
Amer Al Shanawany June 3, 2024, 11:17 a.m. UTC | #3
On 5/4/24 19:17, Amer Al Shanawany wrote:
> On 4/19/24 18:41, Muhammad Usama Anjum wrote:
>> On 4/17/24 11:49 PM, Amer Al Shanawany wrote:
>>> Fix the following warnings by adding return check and error messages.
>>>
>>> statmount_test.c: In function ‘cleanup_namespace’:
>>> statmount_test.c:128:9: warning: ignoring return value of ‘fchdir’
>>> declared with attribute ‘warn_unused_result’ [-Wunused-result]
>>>   128 |         fchdir(orig_root);
>>>       |         ^~~~~~~~~~~~~~~~~
>>> statmount_test.c:129:9: warning: ignoring return value of ‘chroot’
>>> declared with attribute ‘warn_unused_result’ [-Wunused-result]
>>>   129 |         chroot(".");
>>>       |         ^~~~~~~~~~~
>>>
>>> Signed-off-by: Amer Al Shanawany <amer.shanawany@gmail.com>
>> Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
>>
>>> ---
>>>  .../selftests/filesystems/statmount/statmount_test.c | 12 ++++++++++--
>>>  1 file changed, 10 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/tools/testing/selftests/filesystems/statmount/statmount_test.c b/tools/testing/selftests/filesystems/statmount/statmount_test.c
>>> index e6d7c4f1c85b..e8c019d72cbf 100644
>>> --- a/tools/testing/selftests/filesystems/statmount/statmount_test.c
>>> +++ b/tools/testing/selftests/filesystems/statmount/statmount_test.c
>>> @@ -125,8 +125,16 @@ static uint32_t old_root_id, old_parent_id;
>>>  
>>>  static void cleanup_namespace(void)
>>>  {
>>> -	fchdir(orig_root);
>>> -	chroot(".");
>>> +	int ret;
>>> +
>>> +	ret = fchdir(orig_root);
>>> +	if (ret == -1)
>>> +		ksft_perror("fchdir to original root");
>>> +
>>> +	ret = chroot(".");
>>> +	if (ret == -1)
>>> +		ksft_perror("chroot to original root");
>>> +
>>>  	umount2(root_mntpoint, MNT_DETACH);
>>>  	rmdir(root_mntpoint);
>>>  }
> Hi,
>
> Can you please consider this patch?
>
> Thank  you
>
> Amer
>
>
>
Hello,

Could you please consider this simple patch for fixing build warnings for kselftest ?

Thank you

Amer
Shuah Khan June 11, 2024, 3:23 p.m. UTC | #4
On 6/3/24 05:17, Amer Al Shanawany wrote:
> On 5/4/24 19:17, Amer Al Shanawany wrote:
>> On 4/19/24 18:41, Muhammad Usama Anjum wrote:
>>> On 4/17/24 11:49 PM, Amer Al Shanawany wrote:
>>>> Fix the following warnings by adding return check and error messages.
>>>>
>>>> statmount_test.c: In function ‘cleanup_namespace’:
>>>> statmount_test.c:128:9: warning: ignoring return value of ‘fchdir’
>>>> declared with attribute ‘warn_unused_result’ [-Wunused-result]
>>>>    128 |         fchdir(orig_root);
>>>>        |         ^~~~~~~~~~~~~~~~~
>>>> statmount_test.c:129:9: warning: ignoring return value of ‘chroot’
>>>> declared with attribute ‘warn_unused_result’ [-Wunused-result]
>>>>    129 |         chroot(".");
>>>>        |         ^~~~~~~~~~~
>>>>
>>>> Signed-off-by: Amer Al Shanawany <amer.shanawany@gmail.com>
>>> Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
>>>
>>>> ---
>>>>   .../selftests/filesystems/statmount/statmount_test.c | 12 ++++++++++--
>>>>   1 file changed, 10 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/tools/testing/selftests/filesystems/statmount/statmount_test.c b/tools/testing/selftests/filesystems/statmount/statmount_test.c
>>>> index e6d7c4f1c85b..e8c019d72cbf 100644
>>>> --- a/tools/testing/selftests/filesystems/statmount/statmount_test.c
>>>> +++ b/tools/testing/selftests/filesystems/statmount/statmount_test.c
>>>> @@ -125,8 +125,16 @@ static uint32_t old_root_id, old_parent_id;
>>>>   
>>>>   static void cleanup_namespace(void)
>>>>   {
>>>> -	fchdir(orig_root);
>>>> -	chroot(".");
>>>> +	int ret;
>>>> +
>>>> +	ret = fchdir(orig_root);
>>>> +	if (ret == -1)
>>>> +		ksft_perror("fchdir to original root");
>>>> +
>>>> +	ret = chroot(".");
>>>> +	if (ret == -1)
>>>> +		ksft_perror("chroot to original root");
>>>> +
>>>>   	umount2(root_mntpoint, MNT_DETACH);
>>>>   	rmdir(root_mntpoint);
>>>>   }
>> Hi,
>>
>> Can you please consider this patch?
>>
>> Thank  you
>>
>> Amer
>>
>>
>>
> Hello,
> 
> Could you please consider this simple patch for fixing build warnings for kselftest ?
> 
> Thank you
> 
> Amer

Applied to linux-kselftest fixes branch for the next rc.

thanks,
-- Shuah
diff mbox series

Patch

diff --git a/tools/testing/selftests/filesystems/statmount/statmount_test.c b/tools/testing/selftests/filesystems/statmount/statmount_test.c
index e6d7c4f1c85b..e8c019d72cbf 100644
--- a/tools/testing/selftests/filesystems/statmount/statmount_test.c
+++ b/tools/testing/selftests/filesystems/statmount/statmount_test.c
@@ -125,8 +125,16 @@  static uint32_t old_root_id, old_parent_id;
 
 static void cleanup_namespace(void)
 {
-	fchdir(orig_root);
-	chroot(".");
+	int ret;
+
+	ret = fchdir(orig_root);
+	if (ret == -1)
+		ksft_perror("fchdir to original root");
+
+	ret = chroot(".");
+	if (ret == -1)
+		ksft_perror("chroot to original root");
+
 	umount2(root_mntpoint, MNT_DETACH);
 	rmdir(root_mntpoint);
 }