diff mbox series

[v1,1/1] selftests: net: af_unix: cast void* to char* in call to macro TH_LOG()

Message ID 20240812002257.23447-2-mtodorovac69@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [v1,1/1] selftests: net: af_unix: cast void* to char* in call to macro TH_LOG() | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 7 this patch: 7
netdev/build_tools success Errors and warnings before: 9 this patch: 9
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 7 this patch: 7
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 7
netdev/checkpatch warning WARNING: 'beeing' may be misspelled - perhaps 'being'? WARNING: Please use correct Fixes: style 'Fixes: <12 chars of sha1> ("<title line>")' - ie: 'Fixes: d098d77232c3 ("selftest: af_unix: Add msg_oob.c.")' WARNING: line length of 104 exceeds 80 columns WARNING: line length of 112 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-08-13--12-00 (tests: 706)

Commit Message

Mirsad Todorovac Aug. 12, 2024, 12:22 a.m. UTC
GCC 13.2.0 reported warning about (void *) beeing used as a param where (char *) is expected:

In file included from msg_oob.c:14:
msg_oob.c: In function ‘__recvpair’:
../../kselftest_harness.h:106:40: warning: format ‘%s’ expects argument of type ‘char *’,
							but argument 6 has type ‘const void *’ [-Wformat=]
  106 |                 fprintf(TH_LOG_STREAM, "# %s:%d:%s:" fmt "\n", \
      |                                        ^~~~~~~~~~~~~
../../kselftest_harness.h:101:17: note: in expansion of macro ‘__TH_LOG’
  101 |                 __TH_LOG(fmt, ##__VA_ARGS__); \
      |                 ^~~~~~~~
msg_oob.c:235:17: note: in expansion of macro ‘TH_LOG’
  235 |                 TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : expected_buf);
      |                 ^~~~~~
../../kselftest_harness.h:106:40: warning: format ‘%s’ expects argument of type ‘char *’,
							but argument 6 has type ‘const void *’ [-Wformat=]
  106 |                 fprintf(TH_LOG_STREAM, "# %s:%d:%s:" fmt "\n", \
      |                                        ^~~~~~~~~~~~~
../../kselftest_harness.h:101:17: note: in expansion of macro ‘__TH_LOG’
  101 |                 __TH_LOG(fmt, ##__VA_ARGS__); \
      |                 ^~~~~~~~
msg_oob.c:259:25: note: in expansion of macro ‘TH_LOG’
  259 |                 TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : expected_buf);
      |                 ^~~~~~

Casting param to (char *) silences the warning.

Fixes: d098d77232c37 ("selftest: af_unix: Add msg_oob.c.")
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Kuniyuki Iwashima <kuniyu@amazon.com>
Cc: netdev@vger.kernel.org
Cc: linux-kselftest@vger.kernel.org
Signed-off-by: Mirsad Todorovac <mtodorovac69@gmail.com>
---
v1:
 initial version to fix the compiler warning.

 tools/testing/selftests/net/af_unix/msg_oob.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Simon Horman Aug. 12, 2024, 3:17 p.m. UTC | #1
On Mon, Aug 12, 2024 at 02:22:58AM +0200, Mirsad Todorovac wrote:
> GCC 13.2.0 reported warning about (void *) beeing used as a param where (char *) is expected:

nit: being

> 
> In file included from msg_oob.c:14:
> msg_oob.c: In function ‘__recvpair’:
> ../../kselftest_harness.h:106:40: warning: format ‘%s’ expects argument of type ‘char *’,
> 							but argument 6 has type ‘const void *’ [-Wformat=]
>   106 |                 fprintf(TH_LOG_STREAM, "# %s:%d:%s:" fmt "\n", \
>       |                                        ^~~~~~~~~~~~~
> ../../kselftest_harness.h:101:17: note: in expansion of macro ‘__TH_LOG’
>   101 |                 __TH_LOG(fmt, ##__VA_ARGS__); \
>       |                 ^~~~~~~~
> msg_oob.c:235:17: note: in expansion of macro ‘TH_LOG’
>   235 |                 TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : expected_buf);
>       |                 ^~~~~~
> ../../kselftest_harness.h:106:40: warning: format ‘%s’ expects argument of type ‘char *’,
> 							but argument 6 has type ‘const void *’ [-Wformat=]
>   106 |                 fprintf(TH_LOG_STREAM, "# %s:%d:%s:" fmt "\n", \
>       |                                        ^~~~~~~~~~~~~
> ../../kselftest_harness.h:101:17: note: in expansion of macro ‘__TH_LOG’
>   101 |                 __TH_LOG(fmt, ##__VA_ARGS__); \
>       |                 ^~~~~~~~
> msg_oob.c:259:25: note: in expansion of macro ‘TH_LOG’
>   259 |                 TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : expected_buf);
>       |                 ^~~~~~

Thanks, I see this too.

> Casting param to (char *) silences the warning.

It seems that all callers pass a string as the expected_errno argument.
Perhaps it's type could be updated to char *, if that is what it is.
I think this would avoid the need to cast.

> Fixes: d098d77232c37 ("selftest: af_unix: Add msg_oob.c.")
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: Shuah Khan <shuah@kernel.org>
> Cc: Kuniyuki Iwashima <kuniyu@amazon.com>
> Cc: netdev@vger.kernel.org
> Cc: linux-kselftest@vger.kernel.org
> Signed-off-by: Mirsad Todorovac <mtodorovac69@gmail.com>

...
Kuniyuki Iwashima Aug. 12, 2024, 6:45 p.m. UTC | #2
From: Mirsad Todorovac <mtodorovac69@gmail.com>
Date: Mon, 12 Aug 2024 02:22:58 +0200
> GCC 13.2.0 reported warning about (void *) beeing used as a param where (char *) is expected:
> 
> In file included from msg_oob.c:14:
> msg_oob.c: In function ‘__recvpair’:
> ../../kselftest_harness.h:106:40: warning: format ‘%s’ expects argument of type ‘char *’,
> 							but argument 6 has type ‘const void *’ [-Wformat=]
>   106 |                 fprintf(TH_LOG_STREAM, "# %s:%d:%s:" fmt "\n", \
>       |                                        ^~~~~~~~~~~~~
> ../../kselftest_harness.h:101:17: note: in expansion of macro ‘__TH_LOG’
>   101 |                 __TH_LOG(fmt, ##__VA_ARGS__); \
>       |                 ^~~~~~~~
> msg_oob.c:235:17: note: in expansion of macro ‘TH_LOG’
>   235 |                 TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : expected_buf);
>       |                 ^~~~~~
> ../../kselftest_harness.h:106:40: warning: format ‘%s’ expects argument of type ‘char *’,
> 							but argument 6 has type ‘const void *’ [-Wformat=]
>   106 |                 fprintf(TH_LOG_STREAM, "# %s:%d:%s:" fmt "\n", \
>       |                                        ^~~~~~~~~~~~~
> ../../kselftest_harness.h:101:17: note: in expansion of macro ‘__TH_LOG’
>   101 |                 __TH_LOG(fmt, ##__VA_ARGS__); \
>       |                 ^~~~~~~~
> msg_oob.c:259:25: note: in expansion of macro ‘TH_LOG’
>   259 |                 TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : expected_buf);
>       |                 ^~~~~~
> 
> Casting param to (char *) silences the warning.
> 
> Fixes: d098d77232c37 ("selftest: af_unix: Add msg_oob.c.")
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: Shuah Khan <shuah@kernel.org>
> Cc: Kuniyuki Iwashima <kuniyu@amazon.com>
> Cc: netdev@vger.kernel.org
> Cc: linux-kselftest@vger.kernel.org
> Signed-off-by: Mirsad Todorovac <mtodorovac69@gmail.com>

Thanks for the patch!

but I found the same patch posted a bit earlier here,
and Abhinav will post v2.

https://lore.kernel.org/netdev/20240810134037.669765-1-jain.abhinav177@gmail.com/
Mirsad Todorovac Aug. 13, 2024, 3:36 p.m. UTC | #3
Hi, Simon,

On 8/12/24 17:17, Simon Horman wrote:
> On Mon, Aug 12, 2024 at 02:22:58AM +0200, Mirsad Todorovac wrote:
>> GCC 13.2.0 reported warning about (void *) beeing used as a param where (char *) is expected:
> 
> nit: being

Ouch! No patch is small enough that one should take its correctness for granted. :-O

>> In file included from msg_oob.c:14:
>> msg_oob.c: In function ‘__recvpair’:
>> ../../kselftest_harness.h:106:40: warning: format ‘%s’ expects argument of type ‘char *’,
>> 							but argument 6 has type ‘const void *’ [-Wformat=]
>>   106 |                 fprintf(TH_LOG_STREAM, "# %s:%d:%s:" fmt "\n", \
>>       |                                        ^~~~~~~~~~~~~
>> ../../kselftest_harness.h:101:17: note: in expansion of macro ‘__TH_LOG’
>>   101 |                 __TH_LOG(fmt, ##__VA_ARGS__); \
>>       |                 ^~~~~~~~
>> msg_oob.c:235:17: note: in expansion of macro ‘TH_LOG’
>>   235 |                 TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : expected_buf);
>>       |                 ^~~~~~
>> ../../kselftest_harness.h:106:40: warning: format ‘%s’ expects argument of type ‘char *’,
>> 							but argument 6 has type ‘const void *’ [-Wformat=]
>>   106 |                 fprintf(TH_LOG_STREAM, "# %s:%d:%s:" fmt "\n", \
>>       |                                        ^~~~~~~~~~~~~
>> ../../kselftest_harness.h:101:17: note: in expansion of macro ‘__TH_LOG’
>>   101 |                 __TH_LOG(fmt, ##__VA_ARGS__); \
>>       |                 ^~~~~~~~
>> msg_oob.c:259:25: note: in expansion of macro ‘TH_LOG’
>>   259 |                 TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : expected_buf);
>>       |                 ^~~~~~
> 
> Thanks, I see this too.
> 
>> Casting param to (char *) silences the warning.
> 
> It seems that all callers pass a string as the expected_errno argument.
> Perhaps it's type could be updated to char *, if that is what it is.
> I think this would avoid the need to cast.

Agreed and verified. If it is OK with you, I might post a v2.

Best regards,
Mirsad Todorovac

>> Fixes: d098d77232c37 ("selftest: af_unix: Add msg_oob.c.")
>> Cc: "David S. Miller" <davem@davemloft.net>
>> Cc: Eric Dumazet <edumazet@google.com>
>> Cc: Jakub Kicinski <kuba@kernel.org>
>> Cc: Paolo Abeni <pabeni@redhat.com>
>> Cc: Shuah Khan <shuah@kernel.org>
>> Cc: Kuniyuki Iwashima <kuniyu@amazon.com>
>> Cc: netdev@vger.kernel.org
>> Cc: linux-kselftest@vger.kernel.org
>> Signed-off-by: Mirsad Todorovac <mtodorovac69@gmail.com>
> 
> ...
diff mbox series

Patch

diff --git a/tools/testing/selftests/net/af_unix/msg_oob.c b/tools/testing/selftests/net/af_unix/msg_oob.c
index 16d0c172eaeb..ae2623eea8ae 100644
--- a/tools/testing/selftests/net/af_unix/msg_oob.c
+++ b/tools/testing/selftests/net/af_unix/msg_oob.c
@@ -232,7 +232,7 @@  static void __recvpair(struct __test_metadata *_metadata,
 
 	if (ret[0] != expected_len || recv_errno[0] != expected_errno) {
 		TH_LOG("AF_UNIX :%s", ret[0] < 0 ? strerror(recv_errno[0]) : recv_buf[0]);
-		TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : expected_buf);
+		TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : (char *)expected_buf);
 
 		ASSERT_EQ(ret[0], expected_len);
 		ASSERT_EQ(recv_errno[0], expected_errno);
@@ -256,7 +256,7 @@  static void __recvpair(struct __test_metadata *_metadata,
 		cmp = strncmp(expected_buf, recv_buf[0], expected_len);
 		if (cmp) {
 			TH_LOG("AF_UNIX :%s", ret[0] < 0 ? strerror(recv_errno[0]) : recv_buf[0]);
-			TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : expected_buf);
+			TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : (char *)expected_buf);
 
 			ASSERT_EQ(cmp, 0);
 		}