diff mbox series

[v1,1/1] selftests: mm: uufd-unit-tests: remove a format warning in printf

Message ID 20230610235016.438460-1-mirsad.todorovac@alu.unizg.hr (mailing list archive)
State New
Headers show
Series [v1,1/1] selftests: mm: uufd-unit-tests: remove a format warning in printf | expand

Commit Message

Mirsad Todorovac June 10, 2023, 11:50 p.m. UTC
GCC 11.3.0 issued warnings about macros and types of arguments [edited]:

gcc -Wall -I ../tools/testing/selftests/../../.. \
	-I ../tools/testing/selftests/../../../tools/include/uapi \
	-isystem ../usr/include -no-pie uffd-unit-tests.c vm_util.c \
	uffd-common.c -lrt -lpthread -o \
	../tools/testing/selftests/mm/uffd-unit-tests
uffd-unit-tests.c: In function ‘main’:
uffd-unit-tests.c:1198:41: warning: format not a string literal and no \
	format arguments [-Wformat-security]
 1198 |                         uffd_test_start(test_name);
      |                                         ^~~~~~~~~
uffd-unit-tests.c:100:24: note: in definition of macro ‘uffd_test_start’
  100 |                 printf(__VA_ARGS__);            \
      |                        ^~~~~~~~~~~
uffd-unit-tests.c:1205:33: warning: format not a string literal and no \
	format arguments [-Wformat-security]
 1205 |                                 uffd_test_skip(errmsg);
      |                                 ^~~~~~~~~~~~~~

The macros are defined as:

 #define  uffd_test_start(...)  do {             \
                printf("Testing ");             \
                printf(__VA_ARGS__);            \
                printf("... ");                 \
                fflush(stdout);                 \
        } while (0)

 #define  uffd_test_skip(...)  do {              \
                printf("skipped [reason: ");    \
                printf(__VA_ARGS__);            \
                printf("]\n");                  \
                ksft_inc_xskip_cnt();           \
        } while (0)

Minor workaround, adding "%s" first argument to macro expansion calls seems
to be the easiest way to eliminate the warnings.

Cc: Peter Xu <peterx@redhat.com>
Cc: linux-mm@kvack.org
Cc: linux-kselftest@vger.kernel.org
Fixes: 43759d44dc34 ("selftests/mm: add uffdio register ioctls test")
Fixes: 16a45b57cbf2 ("selftests/mm: add framework for uffd-unit-test")
Signed-off-by: Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>
---
 tools/testing/selftests/mm/uffd-unit-tests.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Muhammad Usama Anjum June 11, 2023, 12:30 p.m. UTC | #1
The fix has already been picked up by Andew in mm unstable:

https://lore.kernel.org/all/20230607023727.0E011C433D2@smtp.kernel.org

On 6/11/23 4:50 AM, Mirsad Todorovac wrote:
> GCC 11.3.0 issued warnings about macros and types of arguments [edited]:
> 
> gcc -Wall -I ../tools/testing/selftests/../../.. \
> 	-I ../tools/testing/selftests/../../../tools/include/uapi \
> 	-isystem ../usr/include -no-pie uffd-unit-tests.c vm_util.c \
> 	uffd-common.c -lrt -lpthread -o \
> 	../tools/testing/selftests/mm/uffd-unit-tests
> uffd-unit-tests.c: In function ‘main’:
> uffd-unit-tests.c:1198:41: warning: format not a string literal and no \
> 	format arguments [-Wformat-security]
>  1198 |                         uffd_test_start(test_name);
>       |                                         ^~~~~~~~~
> uffd-unit-tests.c:100:24: note: in definition of macro ‘uffd_test_start’
>   100 |                 printf(__VA_ARGS__);            \
>       |                        ^~~~~~~~~~~
> uffd-unit-tests.c:1205:33: warning: format not a string literal and no \
> 	format arguments [-Wformat-security]
>  1205 |                                 uffd_test_skip(errmsg);
>       |                                 ^~~~~~~~~~~~~~
> 
> The macros are defined as:
> 
>  #define  uffd_test_start(...)  do {             \
>                 printf("Testing ");             \
>                 printf(__VA_ARGS__);            \
>                 printf("... ");                 \
>                 fflush(stdout);                 \
>         } while (0)
> 
>  #define  uffd_test_skip(...)  do {              \
>                 printf("skipped [reason: ");    \
>                 printf(__VA_ARGS__);            \
>                 printf("]\n");                  \
>                 ksft_inc_xskip_cnt();           \
>         } while (0)
> 
> Minor workaround, adding "%s" first argument to macro expansion calls seems
> to be the easiest way to eliminate the warnings.
> 
> Cc: Peter Xu <peterx@redhat.com>
> Cc: linux-mm@kvack.org
> Cc: linux-kselftest@vger.kernel.org
> Fixes: 43759d44dc34 ("selftests/mm: add uffdio register ioctls test")
> Fixes: 16a45b57cbf2 ("selftests/mm: add framework for uffd-unit-test")
> Signed-off-by: Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>
> ---
>  tools/testing/selftests/mm/uffd-unit-tests.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c
> index 269c86768a02..d356dd271c84 100644
> --- a/tools/testing/selftests/mm/uffd-unit-tests.c
> +++ b/tools/testing/selftests/mm/uffd-unit-tests.c
> @@ -1195,14 +1195,14 @@ int main(int argc, char *argv[])
>  			snprintf(test_name, sizeof(test_name),
>  				 "%s on %s", test->name, mem_type->name);
>  
> -			uffd_test_start(test_name);
> +			uffd_test_start("%s", test_name);
>  			if (!uffd_feature_supported(test)) {
>  				uffd_test_skip("feature missing");
>  				continue;
>  			}
>  			if (uffd_setup_environment(&args, test, mem_type,
>  						   &errmsg)) {
> -				uffd_test_skip(errmsg);
> +				uffd_test_skip("%s", errmsg);
>  				continue;
>  			}
>  			test->uffd_fn(&args);
Mirsad Todorovac June 12, 2023, 12:11 a.m. UTC | #2
Apologies Muhammad then, didn't follow that branch.

Regards,
Mirsad

On 6/11/23 14:30, Muhammad Usama Anjum wrote:
> The fix has already been picked up by Andew in mm unstable:
> 
> https://lore.kernel.org/all/20230607023727.0E011C433D2@smtp.kernel.org
> 
> On 6/11/23 4:50 AM, Mirsad Todorovac wrote:
>> GCC 11.3.0 issued warnings about macros and types of arguments [edited]:
>>
>> gcc -Wall -I ../tools/testing/selftests/../../.. \
>> 	-I ../tools/testing/selftests/../../../tools/include/uapi \
>> 	-isystem ../usr/include -no-pie uffd-unit-tests.c vm_util.c \
>> 	uffd-common.c -lrt -lpthread -o \
>> 	../tools/testing/selftests/mm/uffd-unit-tests
>> uffd-unit-tests.c: In function ‘main’:
>> uffd-unit-tests.c:1198:41: warning: format not a string literal and no \
>> 	format arguments [-Wformat-security]
>>   1198 |                         uffd_test_start(test_name);
>>        |                                         ^~~~~~~~~
>> uffd-unit-tests.c:100:24: note: in definition of macro ‘uffd_test_start’
>>    100 |                 printf(__VA_ARGS__);            \
>>        |                        ^~~~~~~~~~~
>> uffd-unit-tests.c:1205:33: warning: format not a string literal and no \
>> 	format arguments [-Wformat-security]
>>   1205 |                                 uffd_test_skip(errmsg);
>>        |                                 ^~~~~~~~~~~~~~
>>
>> The macros are defined as:
>>
>>   #define  uffd_test_start(...)  do {             \
>>                  printf("Testing ");             \
>>                  printf(__VA_ARGS__);            \
>>                  printf("... ");                 \
>>                  fflush(stdout);                 \
>>          } while (0)
>>
>>   #define  uffd_test_skip(...)  do {              \
>>                  printf("skipped [reason: ");    \
>>                  printf(__VA_ARGS__);            \
>>                  printf("]\n");                  \
>>                  ksft_inc_xskip_cnt();           \
>>          } while (0)
>>
>> Minor workaround, adding "%s" first argument to macro expansion calls seems
>> to be the easiest way to eliminate the warnings.
>>
>> Cc: Peter Xu <peterx@redhat.com>
>> Cc: linux-mm@kvack.org
>> Cc: linux-kselftest@vger.kernel.org
>> Fixes: 43759d44dc34 ("selftests/mm: add uffdio register ioctls test")
>> Fixes: 16a45b57cbf2 ("selftests/mm: add framework for uffd-unit-test")
>> Signed-off-by: Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>
>> ---
>>   tools/testing/selftests/mm/uffd-unit-tests.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c
>> index 269c86768a02..d356dd271c84 100644
>> --- a/tools/testing/selftests/mm/uffd-unit-tests.c
>> +++ b/tools/testing/selftests/mm/uffd-unit-tests.c
>> @@ -1195,14 +1195,14 @@ int main(int argc, char *argv[])
>>   			snprintf(test_name, sizeof(test_name),
>>   				 "%s on %s", test->name, mem_type->name);
>>   
>> -			uffd_test_start(test_name);
>> +			uffd_test_start("%s", test_name);
>>   			if (!uffd_feature_supported(test)) {
>>   				uffd_test_skip("feature missing");
>>   				continue;
>>   			}
>>   			if (uffd_setup_environment(&args, test, mem_type,
>>   						   &errmsg)) {
>> -				uffd_test_skip(errmsg);
>> +				uffd_test_skip("%s", errmsg);
>>   				continue;
>>   			}
>>   			test->uffd_fn(&args);
>
Muhammad Usama Anjum June 12, 2023, 7:42 a.m. UTC | #3
On 6/12/23 5:11 AM, Mirsad Goran Todorovac wrote:
> Apologies Muhammad then, didn't follow that branch.
No problem.

> 
> Regards,
> Mirsad
> 
> On 6/11/23 14:30, Muhammad Usama Anjum wrote:
>> The fix has already been picked up by Andew in mm unstable:
>>
>> https://lore.kernel.org/all/20230607023727.0E011C433D2@smtp.kernel.org
>>
>> On 6/11/23 4:50 AM, Mirsad Todorovac wrote:
>>> GCC 11.3.0 issued warnings about macros and types of arguments [edited]:
>>>
>>> gcc -Wall -I ../tools/testing/selftests/../../.. \
>>>     -I ../tools/testing/selftests/../../../tools/include/uapi \
>>>     -isystem ../usr/include -no-pie uffd-unit-tests.c vm_util.c \
>>>     uffd-common.c -lrt -lpthread -o \
>>>     ../tools/testing/selftests/mm/uffd-unit-tests
>>> uffd-unit-tests.c: In function ‘main’:
>>> uffd-unit-tests.c:1198:41: warning: format not a string literal and no \
>>>     format arguments [-Wformat-security]
>>>   1198 |                         uffd_test_start(test_name);
>>>        |                                         ^~~~~~~~~
>>> uffd-unit-tests.c:100:24: note: in definition of macro ‘uffd_test_start’
>>>    100 |                 printf(__VA_ARGS__);            \
>>>        |                        ^~~~~~~~~~~
>>> uffd-unit-tests.c:1205:33: warning: format not a string literal and no \
>>>     format arguments [-Wformat-security]
>>>   1205 |                                 uffd_test_skip(errmsg);
>>>        |                                 ^~~~~~~~~~~~~~
>>>
>>> The macros are defined as:
>>>
>>>   #define  uffd_test_start(...)  do {             \
>>>                  printf("Testing ");             \
>>>                  printf(__VA_ARGS__);            \
>>>                  printf("... ");                 \
>>>                  fflush(stdout);                 \
>>>          } while (0)
>>>
>>>   #define  uffd_test_skip(...)  do {              \
>>>                  printf("skipped [reason: ");    \
>>>                  printf(__VA_ARGS__);            \
>>>                  printf("]\n");                  \
>>>                  ksft_inc_xskip_cnt();           \
>>>          } while (0)
>>>
>>> Minor workaround, adding "%s" first argument to macro expansion calls seems
>>> to be the easiest way to eliminate the warnings.
>>>
>>> Cc: Peter Xu <peterx@redhat.com>
>>> Cc: linux-mm@kvack.org
>>> Cc: linux-kselftest@vger.kernel.org
>>> Fixes: 43759d44dc34 ("selftests/mm: add uffdio register ioctls test")
>>> Fixes: 16a45b57cbf2 ("selftests/mm: add framework for uffd-unit-test")
>>> Signed-off-by: Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>
>>> ---
>>>   tools/testing/selftests/mm/uffd-unit-tests.c | 4 ++--
>>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c
>>> b/tools/testing/selftests/mm/uffd-unit-tests.c
>>> index 269c86768a02..d356dd271c84 100644
>>> --- a/tools/testing/selftests/mm/uffd-unit-tests.c
>>> +++ b/tools/testing/selftests/mm/uffd-unit-tests.c
>>> @@ -1195,14 +1195,14 @@ int main(int argc, char *argv[])
>>>               snprintf(test_name, sizeof(test_name),
>>>                    "%s on %s", test->name, mem_type->name);
>>>   -            uffd_test_start(test_name);
>>> +            uffd_test_start("%s", test_name);
>>>               if (!uffd_feature_supported(test)) {
>>>                   uffd_test_skip("feature missing");
>>>                   continue;
>>>               }
>>>               if (uffd_setup_environment(&args, test, mem_type,
>>>                              &errmsg)) {
>>> -                uffd_test_skip(errmsg);
>>> +                uffd_test_skip("%s", errmsg);
>>>                   continue;
>>>               }
>>>               test->uffd_fn(&args);
>>
diff mbox series

Patch

diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c
index 269c86768a02..d356dd271c84 100644
--- a/tools/testing/selftests/mm/uffd-unit-tests.c
+++ b/tools/testing/selftests/mm/uffd-unit-tests.c
@@ -1195,14 +1195,14 @@  int main(int argc, char *argv[])
 			snprintf(test_name, sizeof(test_name),
 				 "%s on %s", test->name, mem_type->name);
 
-			uffd_test_start(test_name);
+			uffd_test_start("%s", test_name);
 			if (!uffd_feature_supported(test)) {
 				uffd_test_skip("feature missing");
 				continue;
 			}
 			if (uffd_setup_environment(&args, test, mem_type,
 						   &errmsg)) {
-				uffd_test_skip(errmsg);
+				uffd_test_skip("%s", errmsg);
 				continue;
 			}
 			test->uffd_fn(&args);