linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests: memfd_test.c: fix compilation warning.
@ 2017-11-05 10:56 Lei Yang
  2017-11-06 23:46 ` Shuah Khan
  2017-11-09 20:14 ` Shuah Khan
  0 siblings, 2 replies; 5+ messages in thread
From: Lei Yang @ 2017-11-05 10:56 UTC (permalink / raw)
  To: lei.yang, shuahkh, linux-kselftest, linux-kernel

Replace '%d' by '%zu' to fix the following compilation warning.

memfd_test.c:517:3: warning: format ‘%d’ expects argument of
type ‘int’,but argument 2 has type ‘size_t’ [-Wformat=]
   printf("malloc(%d) failed: %m\n", mfd_def_size * 8);
   ^
memfd_test.c: In function ‘mfd_fail_grow_write’:
memfd_test.c:537:3: warning: format ‘%d’ expects argument
of type ‘int’,but argument 2 has type ‘size_t’ [-Wformat=]
   printf("malloc(%d) failed: %m\n", mfd_def_size * 8);

Signed-off-by: Lei Yang <Lei.Yang@windriver.com>
---
 tools/testing/selftests/memfd/memfd_test.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/memfd/memfd_test.c b/tools/testing/selftests/memfd/memfd_test.c
index f94c6d1..95df9e6 100644
--- a/tools/testing/selftests/memfd/memfd_test.c
+++ b/tools/testing/selftests/memfd/memfd_test.c
@@ -514,7 +514,7 @@ static void mfd_assert_grow_write(int fd)
 
 	buf = malloc(mfd_def_size * 8);
 	if (!buf) {
-		printf("malloc(%d) failed: %m\n", mfd_def_size * 8);
+		printf("malloc(%zu) failed: %m\n", mfd_def_size * 8);
 		abort();
 	}
 
@@ -534,7 +534,7 @@ static void mfd_fail_grow_write(int fd)
 
 	buf = malloc(mfd_def_size * 8);
 	if (!buf) {
-		printf("malloc(%d) failed: %m\n", mfd_def_size * 8);
+		printf("malloc(%zu) failed: %m\n", mfd_def_size * 8);
 		abort();
 	}
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] selftests: memfd_test.c: fix compilation warning.
  2017-11-05 10:56 [PATCH] selftests: memfd_test.c: fix compilation warning Lei Yang
@ 2017-11-06 23:46 ` Shuah Khan
  2017-11-07  1:11   ` lei yang
  2017-11-08  3:22   ` lei yang
  2017-11-09 20:14 ` Shuah Khan
  1 sibling, 2 replies; 5+ messages in thread
From: Shuah Khan @ 2017-11-06 23:46 UTC (permalink / raw)
  To: Lei Yang; +Cc: linux-kselftest, linux-kernel, Shuah Khan, Shuah Khan

On 11/05/2017 03:56 AM, Lei Yang wrote:
> Replace '%d' by '%zu' to fix the following compilation warning.
> 
> memfd_test.c:517:3: warning: format ‘%d’ expects argument of
> type ‘int’,but argument 2 has type ‘size_t’ [-Wformat=]
>    printf("malloc(%d) failed: %m\n", mfd_def_size * 8);
>    ^
> memfd_test.c: In function ‘mfd_fail_grow_write’:
> memfd_test.c:537:3: warning: format ‘%d’ expects argument
> of type ‘int’,but argument 2 has type ‘size_t’ [-Wformat=]
>    printf("malloc(%d) failed: %m\n", mfd_def_size * 8);
> 
> Signed-off-by: Lei Yang <Lei.Yang@windriver.com>
> ---
>  tools/testing/selftests/memfd/memfd_test.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/memfd/memfd_test.c b/tools/testing/selftests/memfd/memfd_test.c
> index f94c6d1..95df9e6 100644
> --- a/tools/testing/selftests/memfd/memfd_test.c
> +++ b/tools/testing/selftests/memfd/memfd_test.c
> @@ -514,7 +514,7 @@ static void mfd_assert_grow_write(int fd)
>  
>  	buf = malloc(mfd_def_size * 8);
>  	if (!buf) {
> -		printf("malloc(%d) failed: %m\n", mfd_def_size * 8);
> +		printf("malloc(%zu) failed: %m\n", mfd_def_size * 8);
>  		abort();
>  	}
>  
> @@ -534,7 +534,7 @@ static void mfd_fail_grow_write(int fd)
>  
>  	buf = malloc(mfd_def_size * 8);
>  	if (!buf) {
> -		printf("malloc(%d) failed: %m\n", mfd_def_size * 8);
> +		printf("malloc(%zu) failed: %m\n", mfd_def_size * 8);
>  		abort();
>  	}
>  
> 

Relates to gcc version perhaps. What's your gcc version?

thanks,
-- Shuah

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] selftests: memfd_test.c: fix compilation warning.
  2017-11-06 23:46 ` Shuah Khan
@ 2017-11-07  1:11   ` lei yang
  2017-11-08  3:22   ` lei yang
  1 sibling, 0 replies; 5+ messages in thread
From: lei yang @ 2017-11-07  1:11 UTC (permalink / raw)
  To: Shuah Khan; +Cc: linux-kselftest, linux-kernel, Shuah Khan



On 2017年11月07日 07:46, Shuah Khan wrote:
> On 11/05/2017 03:56 AM, Lei Yang wrote:
>> Replace '%d' by '%zu' to fix the following compilation warning.
>>
>> memfd_test.c:517:3: warning: format ‘%d’ expects argument of
>> type ‘int’,but argument 2 has type ‘size_t’ [-Wformat=]
>>     printf("malloc(%d) failed: %m\n", mfd_def_size * 8);
>>     ^
>> memfd_test.c: In function ‘mfd_fail_grow_write’:
>> memfd_test.c:537:3: warning: format ‘%d’ expects argument
>> of type ‘int’,but argument 2 has type ‘size_t’ [-Wformat=]
>>     printf("malloc(%d) failed: %m\n", mfd_def_size * 8);
>>
>> Signed-off-by: Lei Yang <Lei.Yang@windriver.com>
>> ---
>>   tools/testing/selftests/memfd/memfd_test.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/tools/testing/selftests/memfd/memfd_test.c b/tools/testing/selftests/memfd/memfd_test.c
>> index f94c6d1..95df9e6 100644
>> --- a/tools/testing/selftests/memfd/memfd_test.c
>> +++ b/tools/testing/selftests/memfd/memfd_test.c
>> @@ -514,7 +514,7 @@ static void mfd_assert_grow_write(int fd)
>>   
>>   	buf = malloc(mfd_def_size * 8);
>>   	if (!buf) {
>> -		printf("malloc(%d) failed: %m\n", mfd_def_size * 8);
>> +		printf("malloc(%zu) failed: %m\n", mfd_def_size * 8);
>>   		abort();
>>   	}
>>   
>> @@ -534,7 +534,7 @@ static void mfd_fail_grow_write(int fd)
>>   
>>   	buf = malloc(mfd_def_size * 8);
>>   	if (!buf) {
>> -		printf("malloc(%d) failed: %m\n", mfd_def_size * 8);
>> +		printf("malloc(%zu) failed: %m\n", mfd_def_size * 8);
>>   		abort();
>>   	}
>>   
>>
> Relates to gcc version perhaps. What's your gcc version?

$ cat /proc/version
Linux version 3.16.0-30-generic (buildd@kissel) (gcc version 4.8.2 
(Ubuntu 4.8.2-19ubuntu1) ) #40~14.04.1-Ubuntu SMP Thu Jan 15 17:43:14 
UTC 2015


Lei



> thanks,
> -- Shuah

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] selftests: memfd_test.c: fix compilation warning.
  2017-11-06 23:46 ` Shuah Khan
  2017-11-07  1:11   ` lei yang
@ 2017-11-08  3:22   ` lei yang
  1 sibling, 0 replies; 5+ messages in thread
From: lei yang @ 2017-11-08  3:22 UTC (permalink / raw)
  To: Shuah Khan; +Cc: linux-kselftest, linux-kernel, Shuah Khan

I got the same warning even with ubuntu new distro, this patch fixed 
this issue.

$ gcc --version
gcc (Ubuntu 6.3.0-12ubuntu2) 6.3.0 20170406
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ make -v
GNU Make 4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
<http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ uname -a
Linux pek-lyang0-u17 4.10.0-38-generic #42-Ubuntu SMP Tue Oct 10 
13:24:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux


---------------------

memfd_test.c: In function mfd_assert_grow_write:
memfd_test.c:517:19: warning: format %d expects argument of type int, 
but argument 2 has type size_t {aka long unsigned int} [-Wformat=]
    printf("malloc(%d) failed: %m\n", mfd_def_size * 8);
                    ^
memfd_test.c: In function mfd_fail_grow_write:
memfd_test.c:537:19: warning: format %d expects argument of type int, 
but argument 2 has type size_t {aka long unsigned int} [-Wformat=]
    printf("malloc(%d) failed: %m\n", mfd_def_size * 8);



Lei


On 2017年11月07日 07:46, Shuah Khan wrote:
> On 11/05/2017 03:56 AM, Lei Yang wrote:
>> Replace '%d' by '%zu' to fix the following compilation warning.
>>
>> memfd_test.c:517:3: warning: format ‘%d’ expects argument of
>> type ‘int’,but argument 2 has type ‘size_t’ [-Wformat=]
>>     printf("malloc(%d) failed: %m\n", mfd_def_size * 8);
>>     ^
>> memfd_test.c: In function ‘mfd_fail_grow_write’:
>> memfd_test.c:537:3: warning: format ‘%d’ expects argument
>> of type ‘int’,but argument 2 has type ‘size_t’ [-Wformat=]
>>     printf("malloc(%d) failed: %m\n", mfd_def_size * 8);
>>
>> Signed-off-by: Lei Yang <Lei.Yang@windriver.com>
>> ---
>>   tools/testing/selftests/memfd/memfd_test.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/tools/testing/selftests/memfd/memfd_test.c b/tools/testing/selftests/memfd/memfd_test.c
>> index f94c6d1..95df9e6 100644
>> --- a/tools/testing/selftests/memfd/memfd_test.c
>> +++ b/tools/testing/selftests/memfd/memfd_test.c
>> @@ -514,7 +514,7 @@ static void mfd_assert_grow_write(int fd)
>>   
>>   	buf = malloc(mfd_def_size * 8);
>>   	if (!buf) {
>> -		printf("malloc(%d) failed: %m\n", mfd_def_size * 8);
>> +		printf("malloc(%zu) failed: %m\n", mfd_def_size * 8);
>>   		abort();
>>   	}
>>   
>> @@ -534,7 +534,7 @@ static void mfd_fail_grow_write(int fd)
>>   
>>   	buf = malloc(mfd_def_size * 8);
>>   	if (!buf) {
>> -		printf("malloc(%d) failed: %m\n", mfd_def_size * 8);
>> +		printf("malloc(%zu) failed: %m\n", mfd_def_size * 8);
>>   		abort();
>>   	}
>>   
>>
> Relates to gcc version perhaps. What's your gcc version?
>
> thanks,
> -- Shuah

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] selftests: memfd_test.c: fix compilation warning.
  2017-11-05 10:56 [PATCH] selftests: memfd_test.c: fix compilation warning Lei Yang
  2017-11-06 23:46 ` Shuah Khan
@ 2017-11-09 20:14 ` Shuah Khan
  1 sibling, 0 replies; 5+ messages in thread
From: Shuah Khan @ 2017-11-09 20:14 UTC (permalink / raw)
  To: Lei Yang, linux-kselftest, linux-kernel, Shuah Khan, Shuah Khan

On 11/05/2017 03:56 AM, Lei Yang wrote:
> Replace '%d' by '%zu' to fix the following compilation warning.
> 
> memfd_test.c:517:3: warning: format ‘%d’ expects argument of
> type ‘int’,but argument 2 has type ‘size_t’ [-Wformat=]
>    printf("malloc(%d) failed: %m\n", mfd_def_size * 8);
>    ^
> memfd_test.c: In function ‘mfd_fail_grow_write’:
> memfd_test.c:537:3: warning: format ‘%d’ expects argument
> of type ‘int’,but argument 2 has type ‘size_t’ [-Wformat=]
>    printf("malloc(%d) failed: %m\n", mfd_def_size * 8);
> 
> Signed-off-by: Lei Yang <Lei.Yang@windriver.com>

Thanks for the patch. Applied to linux-kselftest next for 4.15-rc1

-- Shuah

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-11-09 20:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-05 10:56 [PATCH] selftests: memfd_test.c: fix compilation warning Lei Yang
2017-11-06 23:46 ` Shuah Khan
2017-11-07  1:11   ` lei yang
2017-11-08  3:22   ` lei yang
2017-11-09 20:14 ` Shuah Khan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).