Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/net: replace manual array size calc with ARRAYSIZE macro.

fixes coccinelle WARNING: Use ARRAY_SIZE

Signed-off-by: Mahmoud Maatuq <mahmoudmatook.mm@gmail.com>
Link: https://lore.kernel.org/r/20230716184349.2124858-1-mahmoudmatook.mm@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Mahmoud Maatuq and committed by
Jakub Kicinski
3645c71b 4a59cdfd

+13 -5
+2
tools/testing/selftests/net/Makefile
··· 3 3 4 4 CFLAGS = -Wall -Wl,--no-as-needed -O2 -g 5 5 CFLAGS += -I../../../../usr/include/ $(KHDR_INCLUDES) 6 + # Additional include paths needed by kselftest.h 7 + CFLAGS += -I../ 6 8 7 9 TEST_PROGS := run_netsocktests run_afpackettests test_bpf.sh netdevice.sh \ 8 10 rtnetlink.sh xfrm_policy.sh test_blackhole_dev.sh
+4 -2
tools/testing/selftests/net/csum.c
··· 91 91 #include <sys/types.h> 92 92 #include <unistd.h> 93 93 94 + #include "kselftest.h" 95 + 94 96 static bool cfg_bad_csum; 95 97 static int cfg_family = PF_INET6; 96 98 static int cfg_num_pkt = 4; ··· 452 450 iov[2].iov_len = len; 453 451 454 452 msg.msg_iov = iov; 455 - msg.msg_iovlen = sizeof(iov) / sizeof(iov[0]); 453 + msg.msg_iovlen = ARRAY_SIZE(iov); 456 454 457 455 msg.msg_name = &addr; 458 456 msg.msg_namelen = sizeof(addr); ··· 507 505 struct sock_fprog prog = {}; 508 506 509 507 prog.filter = filter; 510 - prog.len = sizeof(filter) / sizeof(struct sock_filter); 508 + prog.len = ARRAY_SIZE(filter); 511 509 if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &prog, sizeof(prog))) 512 510 error(1, errno, "setsockopt filter"); 513 511 }
+4 -2
tools/testing/selftests/net/hwtstamp_config.c
··· 16 16 #include <linux/net_tstamp.h> 17 17 #include <linux/sockios.h> 18 18 19 + #include "kselftest.h" 20 + 19 21 static int 20 22 lookup_value(const char **names, int size, const char *name) 21 23 { ··· 52 50 TX_TYPE(ONESTEP_SYNC) 53 51 #undef TX_TYPE 54 52 }; 55 - #define N_TX_TYPES ((int)(sizeof(tx_types) / sizeof(tx_types[0]))) 53 + #define N_TX_TYPES ((int)(ARRAY_SIZE(tx_types))) 56 54 57 55 static const char *rx_filters[] = { 58 56 #define RX_FILTER(name) [HWTSTAMP_FILTER_ ## name] = #name ··· 73 71 RX_FILTER(PTP_V2_DELAY_REQ), 74 72 #undef RX_FILTER 75 73 }; 76 - #define N_RX_FILTERS ((int)(sizeof(rx_filters) / sizeof(rx_filters[0]))) 74 + #define N_RX_FILTERS ((int)(ARRAY_SIZE(rx_filters))) 77 75 78 76 static void usage(void) 79 77 {
+3 -1
tools/testing/selftests/net/psock_lib.h
··· 14 14 #include <arpa/inet.h> 15 15 #include <unistd.h> 16 16 17 + #include "kselftest.h" 18 + 17 19 #define DATA_LEN 100 18 20 #define DATA_CHAR 'a' 19 21 #define DATA_CHAR_1 'b' ··· 65 63 struct sock_fprog bpf_prog; 66 64 67 65 bpf_prog.filter = bpf_filter; 68 - bpf_prog.len = sizeof(bpf_filter) / sizeof(struct sock_filter); 66 + bpf_prog.len = ARRAY_SIZE(bpf_filter); 69 67 70 68 if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &bpf_prog, 71 69 sizeof(bpf_prog))) {