diff mbox series

[net] vsock_diag_test: remove free_sock_stat() call in test_no_sockets

Message ID 20211014152045.173872-1-sgarzare@redhat.com (mailing list archive)
State Accepted
Commit ba95a6225b02c24d99f39fd930b6a388e5fd7b48
Delegated to: Netdev Maintainers
Headers show
Series [net] vsock_diag_test: remove free_sock_stat() call in test_no_sockets | expand

Checks

Context Check Description
netdev/cover_letter success Single patches do not need cover letters
netdev/fixes_present fail Series targets non-next tree, but doesn't contain any Fixes tags
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net
netdev/subject_prefix success Link
netdev/cc_maintainers success CCed 3 of 3 maintainers
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 35 this patch: 35
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success No Fixes tag
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 28 this patch: 28
netdev/header_inline success No static functions without inline keyword in header files

Commit Message

Stefano Garzarella Oct. 14, 2021, 3:20 p.m. UTC
In `test_no_sockets` we don't expect any sockets, indeed
check_no_sockets() prints an error and exits if `sockets` list is
not empty, so free_sock_stat() call is unnecessary since it would
only be called when the `sockets` list is empty.

This was discovered by a strange warning printed by gcc v11.2.1:
  In file included from ../../include/linux/list.h:7,
                   from vsock_diag_test.c:18:
  vsock_diag_test.c: In function ‘test_no_sockets’:
  ../../include/linux/kernel.h:35:45: error: array subscript ‘struct vsock_stat[0]’ is partly outside array bound
  s of ‘struct list_head[1]’ [-Werror=array-bounds]
     35 |         const typeof(((type *)0)->member) * __mptr = (ptr);     \
        |                                             ^~~~~~
  ../../include/linux/list.h:352:9: note: in expansion of macro ‘container_of’
    352 |         container_of(ptr, type, member)
        |         ^~~~~~~~~~~~
  ../../include/linux/list.h:393:9: note: in expansion of macro ‘list_entry’
    393 |         list_entry((pos)->member.next, typeof(*(pos)), member)
        |         ^~~~~~~~~~
  ../../include/linux/list.h:522:21: note: in expansion of macro ‘list_next_entry’
    522 |                 n = list_next_entry(pos, member);                       \
        |                     ^~~~~~~~~~~~~~~
  vsock_diag_test.c:325:9: note: in expansion of macro ‘list_for_each_entry_safe’
    325 |         list_for_each_entry_safe(st, next, sockets, list) {
        |         ^~~~~~~~~~~~~~~~~~~~~~~~
  In file included from vsock_diag_test.c:18:
  vsock_diag_test.c:333:19: note: while referencing ‘sockets’
    333 |         LIST_HEAD(sockets);
        |                   ^~~~~~~
  ../../include/linux/list.h:23:26: note: in definition of macro ‘LIST_HEAD’
     23 |         struct list_head name = LIST_HEAD_INIT(name)

It seems related to some compiler optimization and assumption
about the empty `sockets` list, since this warning is printed
only with -02 or -O3. Also removing `exit(1)` from
check_no_sockets() makes the warning disappear since in that
case free_sock_stat() can be reached also when the list is
not empty.

Reported-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---
 tools/testing/vsock/vsock_diag_test.c | 2 --
 1 file changed, 2 deletions(-)

Comments

patchwork-bot+netdevbpf@kernel.org Oct. 16, 2021, 12:50 a.m. UTC | #1
Hello:

This patch was applied to netdev/net.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Thu, 14 Oct 2021 17:20:45 +0200 you wrote:
> In `test_no_sockets` we don't expect any sockets, indeed
> check_no_sockets() prints an error and exits if `sockets` list is
> not empty, so free_sock_stat() call is unnecessary since it would
> only be called when the `sockets` list is empty.
> 
> This was discovered by a strange warning printed by gcc v11.2.1:
>   In file included from ../../include/linux/list.h:7,
>                    from vsock_diag_test.c:18:
>   vsock_diag_test.c: In function ‘test_no_sockets’:
>   ../../include/linux/kernel.h:35:45: error: array subscript ‘struct vsock_stat[0]’ is partly outside array bound
>   s of ‘struct list_head[1]’ [-Werror=array-bounds]
>      35 |         const typeof(((type *)0)->member) * __mptr = (ptr);     \
>         |                                             ^~~~~~
>   ../../include/linux/list.h:352:9: note: in expansion of macro ‘container_of’
>     352 |         container_of(ptr, type, member)
>         |         ^~~~~~~~~~~~
>   ../../include/linux/list.h:393:9: note: in expansion of macro ‘list_entry’
>     393 |         list_entry((pos)->member.next, typeof(*(pos)), member)
>         |         ^~~~~~~~~~
>   ../../include/linux/list.h:522:21: note: in expansion of macro ‘list_next_entry’
>     522 |                 n = list_next_entry(pos, member);                       \
>         |                     ^~~~~~~~~~~~~~~
>   vsock_diag_test.c:325:9: note: in expansion of macro ‘list_for_each_entry_safe’
>     325 |         list_for_each_entry_safe(st, next, sockets, list) {
>         |         ^~~~~~~~~~~~~~~~~~~~~~~~
>   In file included from vsock_diag_test.c:18:
>   vsock_diag_test.c:333:19: note: while referencing ‘sockets’
>     333 |         LIST_HEAD(sockets);
>         |                   ^~~~~~~
>   ../../include/linux/list.h:23:26: note: in definition of macro ‘LIST_HEAD’
>      23 |         struct list_head name = LIST_HEAD_INIT(name)
> 
> [...]

Here is the summary with links:
  - [net] vsock_diag_test: remove free_sock_stat() call in test_no_sockets
    https://git.kernel.org/netdev/net/c/ba95a6225b02

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
diff mbox series

Patch

diff --git a/tools/testing/vsock/vsock_diag_test.c b/tools/testing/vsock/vsock_diag_test.c
index cec6f5a738e1..fa927ad16f8a 100644
--- a/tools/testing/vsock/vsock_diag_test.c
+++ b/tools/testing/vsock/vsock_diag_test.c
@@ -332,8 +332,6 @@  static void test_no_sockets(const struct test_opts *opts)
 	read_vsock_stat(&sockets);
 
 	check_no_sockets(&sockets);
-
-	free_sock_stat(&sockets);
 }
 
 static void test_listen_socket_server(const struct test_opts *opts)