selftests/net: replace manual array size calc with ARRAYSIZE macro.
authorMahmoud Maatuq <mahmoudmatook.mm@gmail.com>
Sun, 16 Jul 2023 18:43:49 +0000 (22:43 +0400)
committerJakub Kicinski <kuba@kernel.org>
Wed, 19 Jul 2023 00:43:51 +0000 (17:43 -0700)
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>
tools/testing/selftests/net/Makefile
tools/testing/selftests/net/csum.c
tools/testing/selftests/net/hwtstamp_config.c
tools/testing/selftests/net/psock_lib.h

index 2f69f7274e3d8058fe3e6bfccf7986a9f93e7084..fbf579f469927d674af47d9e0682e217cf623bf7 100644 (file)
@@ -3,6 +3,8 @@
 
 CFLAGS =  -Wall -Wl,--no-as-needed -O2 -g
 CFLAGS += -I../../../../usr/include/ $(KHDR_INCLUDES)
+# Additional include paths needed by kselftest.h
+CFLAGS += -I../
 
 TEST_PROGS := run_netsocktests run_afpackettests test_bpf.sh netdevice.sh \
              rtnetlink.sh xfrm_policy.sh test_blackhole_dev.sh
index 82a1c1839da68ebd3de6aa2b22604fe7133097e8..90eb06fefa59ec4af8534ca1b7e05baf83a2d935 100644 (file)
@@ -91,6 +91,8 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#include "kselftest.h"
+
 static bool cfg_bad_csum;
 static int cfg_family = PF_INET6;
 static int cfg_num_pkt = 4;
@@ -450,7 +452,7 @@ static void send_packet(int fd, const char *buf, int len)
        iov[2].iov_len = len;
 
        msg.msg_iov = iov;
-       msg.msg_iovlen = sizeof(iov) / sizeof(iov[0]);
+       msg.msg_iovlen = ARRAY_SIZE(iov);
 
        msg.msg_name = &addr;
        msg.msg_namelen = sizeof(addr);
@@ -505,7 +507,7 @@ static void __recv_prepare_packet_filter(int fd, int off_nexthdr, int off_dport)
        struct sock_fprog prog = {};
 
        prog.filter = filter;
-       prog.len = sizeof(filter) / sizeof(struct sock_filter);
+       prog.len = ARRAY_SIZE(filter);
        if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &prog, sizeof(prog)))
                error(1, errno, "setsockopt filter");
 }
index e1fdee84102119175390a727f80039802d6d9b16..170728c96c4648943288bb47ab0762e76e8502fc 100644 (file)
@@ -16,6 +16,8 @@
 #include <linux/net_tstamp.h>
 #include <linux/sockios.h>
 
+#include "kselftest.h"
+
 static int
 lookup_value(const char **names, int size, const char *name)
 {
@@ -50,7 +52,7 @@ static const char *tx_types[] = {
        TX_TYPE(ONESTEP_SYNC)
 #undef TX_TYPE
 };
-#define N_TX_TYPES ((int)(sizeof(tx_types) / sizeof(tx_types[0])))
+#define N_TX_TYPES ((int)(ARRAY_SIZE(tx_types)))
 
 static const char *rx_filters[] = {
 #define RX_FILTER(name) [HWTSTAMP_FILTER_ ## name] = #name
@@ -71,7 +73,7 @@ static const char *rx_filters[] = {
        RX_FILTER(PTP_V2_DELAY_REQ),
 #undef RX_FILTER
 };
-#define N_RX_FILTERS ((int)(sizeof(rx_filters) / sizeof(rx_filters[0])))
+#define N_RX_FILTERS ((int)(ARRAY_SIZE(rx_filters)))
 
 static void usage(void)
 {
index faa884385c45cdb3f01624d49abd6a0da9172b04..6e4fef560873be09978b0da1f0a30bff13791c16 100644 (file)
@@ -14,6 +14,8 @@
 #include <arpa/inet.h>
 #include <unistd.h>
 
+#include "kselftest.h"
+
 #define DATA_LEN                       100
 #define DATA_CHAR                      'a'
 #define DATA_CHAR_1                    'b'
@@ -63,7 +65,7 @@ static __maybe_unused void pair_udp_setfilter(int fd)
        struct sock_fprog bpf_prog;
 
        bpf_prog.filter = bpf_filter;
-       bpf_prog.len = sizeof(bpf_filter) / sizeof(struct sock_filter);
+       bpf_prog.len = ARRAY_SIZE(bpf_filter);
 
        if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &bpf_prog,
                       sizeof(bpf_prog))) {