From patchwork Fri Jan 22 15:47:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= X-Patchwork-Id: 12039789 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9FB88C433E6 for ; Fri, 22 Jan 2021 15:49:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 715DB221FF for ; Fri, 22 Jan 2021 15:49:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728957AbhAVPtD (ORCPT ); Fri, 22 Jan 2021 10:49:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729200AbhAVPsN (ORCPT ); Fri, 22 Jan 2021 10:48:13 -0500 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 968FCC061786; Fri, 22 Jan 2021 07:47:32 -0800 (PST) Received: by mail-lf1-x12d.google.com with SMTP id a8so8135613lfi.8; Fri, 22 Jan 2021 07:47:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rR70sbxeH3YICr0K6kn+CgDDebNkK3ZMmmvVHIwEsjU=; b=YRDW0rWUkEPiymncPKtxde6E4jSRmSXRFUT+KCB/jwIWjcmx4Q+DYhMkZCpNKCs5rB oJ7mHxRzgG8Z7Sk6crobEAXqvoudMu7VKNXDqnZbgpIadWtdEFyETOg1tvQkrUGr9whN jkKLX7oQihzYrII6nQ13Tva3C153xBHnbeBf8nvNpGuiVY461Kh5zYl7dJm6aSanVCcb eTxYWVYhFR3wlCOrSqsRxKrpW5qhQ3CwLRIhItCoIAPKxCqPCbt+mwOLEAWZYZfOH3+H dkNZZymrbVLcOQnQAv8WszvWvvIAgEbFjXW+0elYx1K/MpY0t4Kuj1dju+odJsH1VyO1 xhgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rR70sbxeH3YICr0K6kn+CgDDebNkK3ZMmmvVHIwEsjU=; b=nEmJXonqb1ta3pyZ6lhn/pQCiZrfzxvwe3z4xygXBf3FvLk8q6DLvudEDoKE3jCDZT FCYN0I/Fmux1l07qA0uqn4GRmq0Bu4qTMTyTooCVI0SEwConoI+0I4KA4wpumjbvMTyw x6atMO8arNwpOdob9/s4tmiCa53Vsjb1Kp1XZmqGCcBD6v5XHUlD81xYwmw61I92gobs usJfcWMT1zVCh5al3lP63lqzo43v/N58SvltbAmkMcsJU0t+SOgAVnPf8jHDzexqUBnH YgCpURey9n3XwYmoUji7aEPffTmQi//PB2gBlb3tthYr5xym4SSeyxmw6dAsPaBjd4Bt kIVA== X-Gm-Message-State: AOAM533UOpiMl3k4mXdIegsFuoPkOlawDQiCXwm3R+POt7MZDfWBrZXA tYKL/rcabDyTJOgFiq9Wryo= X-Google-Smtp-Source: ABdhPJyDmyIdYZKBBHULa9ROT4yqdAXLVvNIzrXwCF7SPjBe42Rh6PmdwPlBKqWXoiJA4GHWKK+egA== X-Received: by 2002:ac2:4e85:: with SMTP id o5mr161039lfr.149.1611330451118; Fri, 22 Jan 2021 07:47:31 -0800 (PST) Received: from btopel-mobl.ger.intel.com (c213-102-90-208.bredband.comhem.se. [213.102.90.208]) by smtp.gmail.com with ESMTPSA id w17sm928589lft.52.2021.01.22.07.47.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jan 2021 07:47:30 -0800 (PST) From: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= To: ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, bpf@vger.kernel.org Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , magnus.karlsson@intel.com, jonathan.lemon@gmail.com, ciara.loftus@intel.com, weqaar.a.janjua@intel.com Subject: [PATCH bpf-next 01/12] selftests/bpf: remove a lot of ifobject casting Date: Fri, 22 Jan 2021 16:47:14 +0100 Message-Id: <20210122154725.22140-2-bjorn.topel@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210122154725.22140-1-bjorn.topel@gmail.com> References: <20210122154725.22140-1-bjorn.topel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Björn Töpel Instead of passing void * all over the place, let us pass the actual type (ifobject) and remove the void-ptr-to-type-ptr casting. Signed-off-by: Björn Töpel --- tools/testing/selftests/bpf/xdpxceiver.c | 88 ++++++++++++------------ 1 file changed, 43 insertions(+), 45 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index 1e722ee76b1f..cd1dd2b7458f 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -224,14 +224,14 @@ static inline u16 udp_csum(u32 saddr, u32 daddr, u32 len, u8 proto, u16 *udp_pkt return csum_tcpudp_magic(saddr, daddr, len, proto, csum); } -static void gen_eth_hdr(void *data, struct ethhdr *eth_hdr) +static void gen_eth_hdr(struct ifobject *ifobject, struct ethhdr *eth_hdr) { - memcpy(eth_hdr->h_dest, ((struct ifobject *)data)->dst_mac, ETH_ALEN); - memcpy(eth_hdr->h_source, ((struct ifobject *)data)->src_mac, ETH_ALEN); + memcpy(eth_hdr->h_dest, ifobject->dst_mac, ETH_ALEN); + memcpy(eth_hdr->h_source, ifobject->src_mac, ETH_ALEN); eth_hdr->h_proto = htons(ETH_P_IP); } -static void gen_ip_hdr(void *data, struct iphdr *ip_hdr) +static void gen_ip_hdr(struct ifobject *ifobject, struct iphdr *ip_hdr) { ip_hdr->version = IP_PKT_VER; ip_hdr->ihl = 0x5; @@ -241,15 +241,15 @@ static void gen_ip_hdr(void *data, struct iphdr *ip_hdr) ip_hdr->frag_off = 0; ip_hdr->ttl = IPDEFTTL; ip_hdr->protocol = IPPROTO_UDP; - ip_hdr->saddr = ((struct ifobject *)data)->src_ip; - ip_hdr->daddr = ((struct ifobject *)data)->dst_ip; + ip_hdr->saddr = ifobject->src_ip; + ip_hdr->daddr = ifobject->dst_ip; ip_hdr->check = 0; } -static void gen_udp_hdr(void *data, void *arg, struct udphdr *udp_hdr) +static void gen_udp_hdr(void *data, struct ifobject *ifobject, struct udphdr *udp_hdr) { - udp_hdr->source = htons(((struct ifobject *)arg)->src_port); - udp_hdr->dest = htons(((struct ifobject *)arg)->dst_port); + udp_hdr->source = htons(ifobject->src_port); + udp_hdr->dest = htons(ifobject->dst_port); udp_hdr->len = htons(UDP_PKT_SIZE); memset32_htonl(pkt_data + PKT_HDR_SIZE, htonl(((struct generic_data *)data)->seqnum), UDP_PKT_DATA_SIZE); @@ -628,28 +628,27 @@ static inline int get_batch_size(int pkt_cnt) return opt_pkt_count - pkt_cnt; } -static void complete_tx_only_all(void *arg) +static void complete_tx_only_all(struct ifobject *ifobject) { bool pending; do { pending = false; - if (((struct ifobject *)arg)->xsk->outstanding_tx) { - complete_tx_only(((struct ifobject *) - arg)->xsk, BATCH_SIZE); - pending = !!((struct ifobject *)arg)->xsk->outstanding_tx; + if (ifobject->xsk->outstanding_tx) { + complete_tx_only(ifobject->xsk, BATCH_SIZE); + pending = !!ifobject->xsk->outstanding_tx; } } while (pending); } -static void tx_only_all(void *arg) +static void tx_only_all(struct ifobject *ifobject) { struct pollfd fds[MAX_SOCKS] = { }; u32 frame_nb = 0; int pkt_cnt = 0; int ret; - fds[0].fd = xsk_socket__fd(((struct ifobject *)arg)->xsk->xsk); + fds[0].fd = xsk_socket__fd(ifobject->xsk->xsk); fds[0].events = POLLOUT; while ((opt_pkt_count && pkt_cnt < opt_pkt_count) || !opt_pkt_count) { @@ -664,12 +663,12 @@ static void tx_only_all(void *arg) continue; } - tx_only(((struct ifobject *)arg)->xsk, &frame_nb, batch_size); + tx_only(ifobject->xsk, &frame_nb, batch_size); pkt_cnt += batch_size; } if (opt_pkt_count) - complete_tx_only_all(arg); + complete_tx_only_all(ifobject); } static void worker_pkt_dump(void) @@ -780,14 +779,14 @@ static void worker_pkt_validate(void) } } -static void thread_common_ops(void *arg, void *bufs, pthread_mutex_t *mutexptr, +static void thread_common_ops(struct ifobject *ifobject, void *bufs, pthread_mutex_t *mutexptr, atomic_int *spinningptr) { int ctr = 0; int ret; - xsk_configure_umem((struct ifobject *)arg, bufs, num_frames * XSK_UMEM__DEFAULT_FRAME_SIZE); - ret = xsk_configure_socket((struct ifobject *)arg); + xsk_configure_umem(ifobject, bufs, num_frames * XSK_UMEM__DEFAULT_FRAME_SIZE); + ret = xsk_configure_socket(ifobject); /* Retry Create Socket if it fails as xsk_socket__create() * is asynchronous @@ -798,9 +797,8 @@ static void thread_common_ops(void *arg, void *bufs, pthread_mutex_t *mutexptr, pthread_mutex_lock(mutexptr); while (ret && ctr < SOCK_RECONF_CTR) { atomic_store(spinningptr, 1); - xsk_configure_umem((struct ifobject *)arg, - bufs, num_frames * XSK_UMEM__DEFAULT_FRAME_SIZE); - ret = xsk_configure_socket((struct ifobject *)arg); + xsk_configure_umem(ifobject, bufs, num_frames * XSK_UMEM__DEFAULT_FRAME_SIZE); + ret = xsk_configure_socket(ifobject); usleep(USLEEP_MAX); ctr++; } @@ -818,6 +816,7 @@ static void *worker_testapp_validate(void *arg) struct generic_data *data = (struct generic_data *)malloc(sizeof(struct generic_data)); struct iphdr *ip_hdr = (struct iphdr *)(pkt_data + sizeof(struct ethhdr)); struct ethhdr *eth_hdr = (struct ethhdr *)pkt_data; + struct ifobject *ifobject = (struct ifobject *)arg; void *bufs = NULL; pthread_attr_setstacksize(&attr, THREAD_STACK); @@ -828,49 +827,48 @@ static void *worker_testapp_validate(void *arg) if (bufs == MAP_FAILED) exit_with_error(errno); - if (strcmp(((struct ifobject *)arg)->nsname, "")) - switch_namespace(((struct ifobject *)arg)->ifdict_index); + if (strcmp(ifobject->nsname, "")) + switch_namespace(ifobject->ifdict_index); } - if (((struct ifobject *)arg)->fv.vector == tx) { + if (ifobject->fv.vector == tx) { int spinningrxctr = 0; if (!bidi_pass) - thread_common_ops(arg, bufs, &sync_mutex_tx, &spinning_tx); + thread_common_ops(ifobject, bufs, &sync_mutex_tx, &spinning_tx); while (atomic_load(&spinning_rx) && spinningrxctr < SOCK_RECONF_CTR) { spinningrxctr++; usleep(USLEEP_MAX); } - ksft_print_msg("Interface [%s] vector [Tx]\n", ((struct ifobject *)arg)->ifname); + ksft_print_msg("Interface [%s] vector [Tx]\n", ifobject->ifname); for (int i = 0; i < num_frames; i++) { /*send EOT frame */ if (i == (num_frames - 1)) data->seqnum = -1; else data->seqnum = i; - gen_udp_hdr((void *)data, (void *)arg, udp_hdr); - gen_ip_hdr((void *)arg, ip_hdr); + gen_udp_hdr((void *)data, ifobject, udp_hdr); + gen_ip_hdr(ifobject, ip_hdr); gen_udp_csum(udp_hdr, ip_hdr); - gen_eth_hdr((void *)arg, eth_hdr); - gen_eth_frame(((struct ifobject *)arg)->umem, - i * XSK_UMEM__DEFAULT_FRAME_SIZE); + gen_eth_hdr(ifobject, eth_hdr); + gen_eth_frame(ifobject->umem, i * XSK_UMEM__DEFAULT_FRAME_SIZE); } free(data); ksft_print_msg("Sending %d packets on interface %s\n", - (opt_pkt_count - 1), ((struct ifobject *)arg)->ifname); - tx_only_all(arg); - } else if (((struct ifobject *)arg)->fv.vector == rx) { + (opt_pkt_count - 1), ifobject->ifname); + tx_only_all(ifobject); + } else if (ifobject->fv.vector == rx) { struct pollfd fds[MAX_SOCKS] = { }; int ret; if (!bidi_pass) - thread_common_ops(arg, bufs, &sync_mutex_tx, &spinning_rx); + thread_common_ops(ifobject, bufs, &sync_mutex_tx, &spinning_rx); - ksft_print_msg("Interface [%s] vector [Rx]\n", ((struct ifobject *)arg)->ifname); - xsk_populate_fill_ring(((struct ifobject *)arg)->umem); + ksft_print_msg("Interface [%s] vector [Rx]\n", ifobject->ifname); + xsk_populate_fill_ring(ifobject->umem); TAILQ_INIT(&head); if (debug_pkt_dump) { @@ -879,7 +877,7 @@ static void *worker_testapp_validate(void *arg) exit_with_error(errno); } - fds[0].fd = xsk_socket__fd(((struct ifobject *)arg)->xsk->xsk); + fds[0].fd = xsk_socket__fd(ifobject->xsk->xsk); fds[0].events = POLLIN; pthread_mutex_lock(&sync_mutex); @@ -892,7 +890,7 @@ static void *worker_testapp_validate(void *arg) if (ret <= 0) continue; } - rx_pkt(((struct ifobject *)arg)->xsk, fds); + rx_pkt(ifobject->xsk, fds); worker_pkt_validate(); if (sigvar) @@ -900,15 +898,15 @@ static void *worker_testapp_validate(void *arg) } ksft_print_msg("Received %d packets on interface %s\n", - pkt_counter, ((struct ifobject *)arg)->ifname); + pkt_counter, ifobject->ifname); if (opt_teardown) ksft_print_msg("Destroying socket\n"); } if (!opt_bidi || (opt_bidi && bidi_pass)) { - xsk_socket__delete(((struct ifobject *)arg)->xsk->xsk); - (void)xsk_umem__delete(((struct ifobject *)arg)->umem->umem); + xsk_socket__delete(ifobject->xsk->xsk); + (void)xsk_umem__delete(ifobject->umem->umem); } pthread_exit(NULL); } From patchwork Fri Jan 22 15:47:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= X-Patchwork-Id: 12039791 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EA85C433E6 for ; Fri, 22 Jan 2021 15:49:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D432B221FF for ; Fri, 22 Jan 2021 15:49:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729272AbhAVPtM (ORCPT ); Fri, 22 Jan 2021 10:49:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729203AbhAVPsO (ORCPT ); Fri, 22 Jan 2021 10:48:14 -0500 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC76FC061788; Fri, 22 Jan 2021 07:47:33 -0800 (PST) Received: by mail-lj1-x229.google.com with SMTP id i17so7056588ljn.1; Fri, 22 Jan 2021 07:47:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=maHLJw8k83sCOfC+LMzg4m1i0HKxmeUozPV59RTWziI=; b=g2a9nzRdIAt2uoCWlQjEXDzAHRkU3ZryqTSyL52cuVLaXJbmlANv6kF4q00G4oAZZt 2r/1M/R7lBtR0c6BsTrV3ivVsLbAzi+t2vJbgbLWIDwIBOrsVjtamUSKKHwGraZTLgU0 w+3HtliPaMC4mph6rbNkqFzcp9FzePY1w4CwREhCXKtuoEXn2veMRo6hffRCULXAmJuM DUORGN75UlwkVp9POsXQp04kYSTZrAC3xtE65VXcM2GAj8+kL/BfAIfEW5l/Yq21WC/Y OkkP9llIEPHn2IyusU8qz798OKcKyk0j0F6e67sSY1OKeF5R49G2s/eiYC+t2gIVNb7N h6rQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=maHLJw8k83sCOfC+LMzg4m1i0HKxmeUozPV59RTWziI=; b=nGZI3sSj6RoanUzbKHY/N+QYEEmd0IqMgH9BA7xAdcnFlQC/u775PeN3V05yBY2k4G 26lRwIiermwBiUjYtNLmdgxutWUNYDlUCKLaJwDGcsGIlhb6mVNPIkw5LkfB2c/CBbJU J39hr0se199NcHdccskyJbge/gGAfF741uilqNWHwuf9lpQVFgn8fggxIiKuFt/6aqJi 9Aj302Gf1RRtSpJUTuEF9QaK6/rDsEGV/KhG0vnVt0EoEU4zQcn4grMF4fd7so9m6nf3 xqC8zng9Y5Rhv74+oK0lO73bLiZlBJkV/reuCQSPtYJ6hvXUpZ4Loooew4xh/pnvaS5s LMVA== X-Gm-Message-State: AOAM5330fM3xtmHcsDqLXlIp6x2w6XaMFqs+4t1lpa/2uK0dp8b4JP5j Oe/lIzu8xA5e2mHN7/dYhZw= X-Google-Smtp-Source: ABdhPJzDxdWNSG93twA7d2+tUI7e/Cs/mpF0eHiaeLTgO2npLveAk3gl248qC+I/lPRt74fdIpZfEw== X-Received: by 2002:a2e:b52c:: with SMTP id z12mr1105988ljm.250.1611330452562; Fri, 22 Jan 2021 07:47:32 -0800 (PST) Received: from btopel-mobl.ger.intel.com (c213-102-90-208.bredband.comhem.se. [213.102.90.208]) by smtp.gmail.com with ESMTPSA id w17sm928589lft.52.2021.01.22.07.47.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jan 2021 07:47:32 -0800 (PST) From: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= To: ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, bpf@vger.kernel.org Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , magnus.karlsson@intel.com, jonathan.lemon@gmail.com, ciara.loftus@intel.com, weqaar.a.janjua@intel.com Subject: [PATCH bpf-next 02/12] selftests/bpf: remove unused enums Date: Fri, 22 Jan 2021 16:47:15 +0100 Message-Id: <20210122154725.22140-3-bjorn.topel@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210122154725.22140-1-bjorn.topel@gmail.com> References: <20210122154725.22140-1-bjorn.topel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Björn Töpel The enums undef and bidi are not used. Remove them. Signed-off-by: Björn Töpel --- tools/testing/selftests/bpf/xdpxceiver.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index 61f595b6f200..0e9f9b7e61c2 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -92,8 +92,6 @@ struct flow_vector { enum fvector { tx, rx, - bidi, - undef, } vector; }; From patchwork Fri Jan 22 15:47:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= X-Patchwork-Id: 12039793 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DD89C433DB for ; Fri, 22 Jan 2021 15:49:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6943A221FF for ; Fri, 22 Jan 2021 15:49:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729175AbhAVPtV (ORCPT ); Fri, 22 Jan 2021 10:49:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729206AbhAVPsQ (ORCPT ); Fri, 22 Jan 2021 10:48:16 -0500 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9508FC0617A7; Fri, 22 Jan 2021 07:47:35 -0800 (PST) Received: by mail-lj1-x229.google.com with SMTP id 3so7045051ljc.4; Fri, 22 Jan 2021 07:47:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p4oRU7lCPi/l9kAI4UjeoerSjmPOgdl0S170D2ESND4=; b=H6WMac2OnGBQZlpqEinwMRCUlp3iXb5Uid/6kyKPzKkijyjMFnTfJ39HSNTcPq+YP/ iLc8WPjzoy1pvIOnql0AurCwmZXBaIyjVkzyaPvXTOeFP6rvNJSxQgdYxdqvV08RZjkT cd7mf2P0SFrMANsybpg3LkPPP4+7SOOeP/Y4NZ3/Clo2jN1NpbCT1cyvvaSayHZJbWWy JUzu9WcPQ2E/odrLXvBk+eqrGHoNgEiMzTa6Pqk5HQdvEKVWWGQZcbdK9B9Z1UyVE6NS IQpFgp86fSPQBZHObN+VraMTiAo/t+xoa+rYW1I+1kyWdwybAqt989dYFW1dQbmobyYB drcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p4oRU7lCPi/l9kAI4UjeoerSjmPOgdl0S170D2ESND4=; b=nXn3P9oNa3PZVnSu16svVxD3CUg0oZUXeuTyUlzb5gwD2qUI89ivpeOsNI/01ed1BG jlLL/UuyXrqI+CnBawuh+Cd7HUWB2XMg7f0g8gj4YyW3AINfqA2gBRPipI+VzKa5f0VO ei9pb0IuRoEy4SQdZW3enaQQllYSaE3hjBUWpC3ZVVxEuLrLBUdXdPCXh2VFy6fQtpHc j9uih4QrhY/FxGxC5uAMk6KFQlLjy8n8j6jzDgpELebY5pU+H/AHmSPBqffQmsv/WnG4 Q1J1U84BWXJurcrIrBKEdIqZU7HpBMPsKnIGZkETabra+8Jg0+MrnQCNIFKIop7jcjw5 hF8A== X-Gm-Message-State: AOAM533KLOE7i3toP02eNN9UNl+xtzzWF2HhxpWWxfvvSnljBIIwDHAN z77z0ygtDaSgalPSKn7WpFhogH9udTE4+A== X-Google-Smtp-Source: ABdhPJysOtensk2J2AU1GMupgiqXOg8sluKPx/PsDKc0PvNhodjdFNiJQV8WdBjeHUU7ytM3fd0Kfw== X-Received: by 2002:a2e:9b47:: with SMTP id o7mr1693806ljj.99.1611330454159; Fri, 22 Jan 2021 07:47:34 -0800 (PST) Received: from btopel-mobl.ger.intel.com (c213-102-90-208.bredband.comhem.se. [213.102.90.208]) by smtp.gmail.com with ESMTPSA id w17sm928589lft.52.2021.01.22.07.47.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jan 2021 07:47:33 -0800 (PST) From: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= To: ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, bpf@vger.kernel.org Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , magnus.karlsson@intel.com, jonathan.lemon@gmail.com, ciara.loftus@intel.com, weqaar.a.janjua@intel.com Subject: [PATCH bpf-next 03/12] selftests/bpf: fix style warnings Date: Fri, 22 Jan 2021 16:47:16 +0100 Message-Id: <20210122154725.22140-4-bjorn.topel@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210122154725.22140-1-bjorn.topel@gmail.com> References: <20210122154725.22140-1-bjorn.topel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Björn Töpel Silence three checkpatch style warnings. Signed-off-by: Björn Töpel --- tools/testing/selftests/bpf/xdpxceiver.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index cd1dd2b7458f..77d1bda37afa 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -734,10 +734,10 @@ static void worker_pkt_validate(void) break; /*do not increment pktcounter if !(tos=0x9 and ipv4) */ if ((((struct iphdr *)(pkt_node_rx_q->pkt_frame + - sizeof(struct ethhdr)))->version == IP_PKT_VER) - && (((struct iphdr *)(pkt_node_rx_q->pkt_frame + sizeof(struct ethhdr)))->tos == + sizeof(struct ethhdr)))->version == IP_PKT_VER) && + (((struct iphdr *)(pkt_node_rx_q->pkt_frame + sizeof(struct ethhdr)))->tos == IP_PKT_TOS)) { - payloadseqnum = *((uint32_t *) (pkt_node_rx_q->pkt_frame + PKT_HDR_SIZE)); + payloadseqnum = *((uint32_t *)(pkt_node_rx_q->pkt_frame + PKT_HDR_SIZE)); if (debug_pkt_dump && payloadseqnum != EOT) { pkt_obj = (struct pkt_frame *)malloc(sizeof(struct pkt_frame)); pkt_obj->payload = (char *)malloc(PKT_SIZE); @@ -767,10 +767,10 @@ static void worker_pkt_validate(void) } else { ksft_print_msg("Invalid frame received: "); ksft_print_msg("[IP_PKT_VER: %02X], [IP_PKT_TOS: %02X]\n", - ((struct iphdr *)(pkt_node_rx_q->pkt_frame + - sizeof(struct ethhdr)))->version, - ((struct iphdr *)(pkt_node_rx_q->pkt_frame + - sizeof(struct ethhdr)))->tos); + ((struct iphdr *)(pkt_node_rx_q->pkt_frame + + sizeof(struct ethhdr)))->version, + ((struct iphdr *)(pkt_node_rx_q->pkt_frame + + sizeof(struct ethhdr)))->tos); TAILQ_REMOVE(&head, pkt_node_rx_q, pkt_nodes); free(pkt_node_rx_q->pkt_frame); free(pkt_node_rx_q); From patchwork Fri Jan 22 15:47:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= X-Patchwork-Id: 12039795 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5CB43C433DB for ; Fri, 22 Jan 2021 15:49:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2BCF621D81 for ; Fri, 22 Jan 2021 15:49:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729299AbhAVPti (ORCPT ); Fri, 22 Jan 2021 10:49:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729240AbhAVPso (ORCPT ); Fri, 22 Jan 2021 10:48:44 -0500 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B775C0617AA; Fri, 22 Jan 2021 07:47:37 -0800 (PST) Received: by mail-lf1-x12f.google.com with SMTP id a8so8135975lfi.8; Fri, 22 Jan 2021 07:47:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Kgfuj77ygCva6xUycXu58Mip5sGXVnu1WDOsdvd/Pqw=; b=oSHVaptuMd6IcnnNeq3M9M4pLKSGE4eJU8zI/LmTiLP02onRTkKmaK7124Oz3GCUMm QmbT1gaKxzJGHSN0pSBdBzg6M6UhZqAuSk8Ptodv78wku1J8M8ScGnb93M0IbwEpBLu5 z7lWPj4Yrn0Y1X0R1Dqh91hNyTwVCAYdv89wCFiN5md5I1Z4PoZG0M2LRy36K+27ezHu OtMFr8nXpH9IGvrUfatwv+pSi0tUJQbALxtIrcM/ZWY41mPlxK7VvozD7oyAuM4G1cvX cTyLyt4jtb0sdgHybUu3aUXau+96p2ocfg4wS2FG1PF974knuSzzAnYVqouU/KmpH9Ec CmQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Kgfuj77ygCva6xUycXu58Mip5sGXVnu1WDOsdvd/Pqw=; b=nw8oKmYIcpuI1/ndAMa0WdhE2cYW7x1qmSbHWM5c/bqyISP3J2zmlD0+eZEuJcSUED GV3Zguw7QyiPieYjmermGMWB4wfFBe5G7e+DRZrdmXPFq/L4qVTbqhP4GqN9zwBnnVxo +XEKE1Y4Ufd9B4pz+AIh84cqPeca/hV+YLBZDSqBL2/9FBFlgP2OFtaFwcmYznHHplXX 82UehDp76f4gvLSQUNSwrh2bQFLTqRwI2MZWGluNX1LP0bRr2mJVsXHj1ofizOSMyS2g 5wGDDc1s+/+3bH1jIkVIdrpd+q00bBL6DBADGMg6dDY3Zv9zjPM4iuwKql6/Ktxt4DKq OmvQ== X-Gm-Message-State: AOAM530w3jq6ls0unC3ePXsHy/syyS5GKbasdW/r4BpIgOw/LRYoR82R mTiuBWJGjVBm3Gt1gX2o996HwZrRfYxRvg== X-Google-Smtp-Source: ABdhPJxidcUwMf6ZeyoOT4kb/KeSF/nzsxbbNNkK/ewqGCoZQumTPImklJ9fxu/TmMfV5YsAstqYwA== X-Received: by 2002:a05:6512:32ad:: with SMTP id q13mr2405817lfe.83.1611330455589; Fri, 22 Jan 2021 07:47:35 -0800 (PST) Received: from btopel-mobl.ger.intel.com (c213-102-90-208.bredband.comhem.se. [213.102.90.208]) by smtp.gmail.com with ESMTPSA id w17sm928589lft.52.2021.01.22.07.47.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jan 2021 07:47:34 -0800 (PST) From: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= To: ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, bpf@vger.kernel.org Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , magnus.karlsson@intel.com, jonathan.lemon@gmail.com, ciara.loftus@intel.com, weqaar.a.janjua@intel.com Subject: [PATCH bpf-next 04/12] selftests/bpf: remove memory leak Date: Fri, 22 Jan 2021 16:47:17 +0100 Message-Id: <20210122154725.22140-5-bjorn.topel@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210122154725.22140-1-bjorn.topel@gmail.com> References: <20210122154725.22140-1-bjorn.topel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Björn Töpel The allocated entry is immediately overwritten by an assignment. Fix that. Signed-off-by: Björn Töpel --- tools/testing/selftests/bpf/xdpxceiver.c | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index 77d1bda37afa..9f40d310805a 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -728,7 +728,6 @@ static void worker_pkt_validate(void) u32 payloadseqnum = -2; while (1) { - pkt_node_rx_q = malloc(sizeof(struct pkt)); pkt_node_rx_q = TAILQ_LAST(&head, head_s); if (!pkt_node_rx_q) break; From patchwork Fri Jan 22 15:47:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= X-Patchwork-Id: 12039819 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A52E2C433E9 for ; Fri, 22 Jan 2021 15:53:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6C0A323AC8 for ; Fri, 22 Jan 2021 15:53:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729350AbhAVPxW (ORCPT ); Fri, 22 Jan 2021 10:53:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729241AbhAVPso (ORCPT ); Fri, 22 Jan 2021 10:48:44 -0500 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 317AEC0617AB; Fri, 22 Jan 2021 07:47:38 -0800 (PST) Received: by mail-lf1-x130.google.com with SMTP id o10so8101873lfl.13; Fri, 22 Jan 2021 07:47:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GhUpAzrFKl9HvT53tqAGb4Rhe5tD4IBo+hhshfGNg4U=; b=icIYpGj/CuKsO5Vh2vXQJhE8ghPCvw4ei5twvMnmXLbLZOhohk/mUe8cJJV362oexn mtaWYdB06b0Nx0JQNZmlySTUtSAx8vvtcD+17GE1Y73EuRofWUR76MwYZU0u1yO9Oz6u qAM8+s0nsS1NJawY9eSvjZ+pDVZWAlfhXD9ElNeO/Q1zHgvXivxKC/JI+REIHpz/HxdQ Nrv0Ze1wcOwEwJ7Azi2H+HO74bzmVHQBW/rXIJFrouSHasjBrN1+WLBoEWCZ2Kvmr2fi sO+/Kvg5i0/gPRYZoJ1uWHL8TiOYK0bVl+iTa8pRjW8HpqBTQ9/xqF9RcFTrc1DnLgu7 iFkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GhUpAzrFKl9HvT53tqAGb4Rhe5tD4IBo+hhshfGNg4U=; b=kMCWW44zpP96N5hItigPEra46x4o2jzL/9xG6dmFHAEySub1NhlmpTy0Mit69mrNxO OsDIuuV1EDkxP9ulPEBCEBgrCZ5pCY7xPwmaCZPpczmWP8jJTVx1SDpAbf1oSDBXIt+v E3iGhj8TvL5FWSX59TCTr6c/pWtW3RA+II6T3eWYP29gno8Ek5XBntyiTCdjEZPWG+NI YGa4KK1kjquzV+hg/Iidn2ElyqjW3MYHc6c8zoEIZ8yakgrAzPab6LRXeAG2xMa0CkZO kuN59D7atq6+c2/9sgGfqvCY/DsUNytfENU6GRsjUNc3Czpwb55HLiOx/lVoHyx7/Zbt +HoA== X-Gm-Message-State: AOAM531FsbtoXSUPZB90oAnHkrjcNYz6g3fWgnbqE+vMWXuwYj84+13+ zGn8sXR7u+ZJ/xco6hkjhbmDrkCEHMUI6Q== X-Google-Smtp-Source: ABdhPJywc489JSoov+oO84GF1UeqVMeKnPBoPCyCHxrqLxq+0ZqT8vT0ndkpxbOVrkGpnzknESKZfw== X-Received: by 2002:a05:6512:398e:: with SMTP id j14mr29081lfu.9.1611330456742; Fri, 22 Jan 2021 07:47:36 -0800 (PST) Received: from btopel-mobl.ger.intel.com (c213-102-90-208.bredband.comhem.se. [213.102.90.208]) by smtp.gmail.com with ESMTPSA id w17sm928589lft.52.2021.01.22.07.47.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jan 2021 07:47:36 -0800 (PST) From: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= To: ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, bpf@vger.kernel.org Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , magnus.karlsson@intel.com, jonathan.lemon@gmail.com, ciara.loftus@intel.com, weqaar.a.janjua@intel.com Subject: [PATCH bpf-next 05/12] selftests/bpf: improve readability of xdpxceiver/worker_pkt_validate() Date: Fri, 22 Jan 2021 16:47:18 +0100 Message-Id: <20210122154725.22140-6-bjorn.topel@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210122154725.22140-1-bjorn.topel@gmail.com> References: <20210122154725.22140-1-bjorn.topel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Björn Töpel Introduce a local variable to get rid of lot of casting. Move common code outside the if/else-clause. Signed-off-by: Björn Töpel --- tools/testing/selftests/bpf/xdpxceiver.c | 29 ++++++++++-------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index 9f40d310805a..ab2ed7b85f9e 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -726,16 +726,17 @@ static void worker_pkt_dump(void) static void worker_pkt_validate(void) { u32 payloadseqnum = -2; + struct iphdr *iphdr; while (1) { pkt_node_rx_q = TAILQ_LAST(&head, head_s); if (!pkt_node_rx_q) break; + + iphdr = (struct iphdr *)(pkt_node_rx_q->pkt_frame + sizeof(struct ethhdr)); + /*do not increment pktcounter if !(tos=0x9 and ipv4) */ - if ((((struct iphdr *)(pkt_node_rx_q->pkt_frame + - sizeof(struct ethhdr)))->version == IP_PKT_VER) && - (((struct iphdr *)(pkt_node_rx_q->pkt_frame + sizeof(struct ethhdr)))->tos == - IP_PKT_TOS)) { + if (iphdr->version == IP_PKT_VER && iphdr->tos == IP_PKT_TOS) { payloadseqnum = *((uint32_t *)(pkt_node_rx_q->pkt_frame + PKT_HDR_SIZE)); if (debug_pkt_dump && payloadseqnum != EOT) { pkt_obj = (struct pkt_frame *)malloc(sizeof(struct pkt_frame)); @@ -757,24 +758,18 @@ static void worker_pkt_validate(void) ksft_exit_xfail(); } - TAILQ_REMOVE(&head, pkt_node_rx_q, pkt_nodes); - free(pkt_node_rx_q->pkt_frame); - free(pkt_node_rx_q); - pkt_node_rx_q = NULL; prev_pkt = payloadseqnum; pkt_counter++; } else { ksft_print_msg("Invalid frame received: "); - ksft_print_msg("[IP_PKT_VER: %02X], [IP_PKT_TOS: %02X]\n", - ((struct iphdr *)(pkt_node_rx_q->pkt_frame + - sizeof(struct ethhdr)))->version, - ((struct iphdr *)(pkt_node_rx_q->pkt_frame + - sizeof(struct ethhdr)))->tos); - TAILQ_REMOVE(&head, pkt_node_rx_q, pkt_nodes); - free(pkt_node_rx_q->pkt_frame); - free(pkt_node_rx_q); - pkt_node_rx_q = NULL; + ksft_print_msg("[IP_PKT_VER: %02X], [IP_PKT_TOS: %02X]\n", iphdr->version, + iphdr->tos); } + + TAILQ_REMOVE(&head, pkt_node_rx_q, pkt_nodes); + free(pkt_node_rx_q->pkt_frame); + free(pkt_node_rx_q); + pkt_node_rx_q = NULL; } } From patchwork Fri Jan 22 15:47:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= X-Patchwork-Id: 12039815 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB9E6C433E0 for ; Fri, 22 Jan 2021 15:53:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B9F8D221FF for ; Fri, 22 Jan 2021 15:53:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729317AbhAVPxC (ORCPT ); Fri, 22 Jan 2021 10:53:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729214AbhAVPsZ (ORCPT ); Fri, 22 Jan 2021 10:48:25 -0500 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7013C061352; Fri, 22 Jan 2021 07:47:39 -0800 (PST) Received: by mail-lf1-x12a.google.com with SMTP id q12so8114699lfo.12; Fri, 22 Jan 2021 07:47:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6gzMRNx7yyDeNli7agXjpdBucvRsuco8IoAFpUqw3Xw=; b=Cfke9vgCLDD/eJ36xIxqJem3XAQ8gaSFnbsXXDTycg9LS1OVVl15rYGtuvjrHXquKR 5sHlYWSYU7YqzVdos/RIqNobzU/V5F8cB+E468MwF7c3q7VIOqig7wUaei5yom26bCZc tv64+tMoJFmTKlimLown196yl98eKfiIqG7aqdu5XGyfozZMitm8nxYAVmlC00heQijr 5htf5pOzySgxluu03AduhYGewS5hmlMZ0WMtaXWv5bTYLAHeWHbyVUbKGl45LATMFgHF 2UxeR/dxfVeHQrRyUbsd8jj5N4l8RIwpcQwXTL9njD0BRg4W9O+AiIVkwfdwu1pIriis 0zXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6gzMRNx7yyDeNli7agXjpdBucvRsuco8IoAFpUqw3Xw=; b=K4Da2XEfHmdBis3QNATHdiG7c6z1wAC9HZkoEPLX6Kfi+QZj+rty61cKdM7IoytLAM V1glBZL27zBu0suRBMWj0AE1Gp3jLORdfadEUJ0+tvAFdibwlLFGOfRkg3uFHqv3zNHL yAGgsAyiL26FWnR+od5ap7MJgXG5+IJxsW2YaTZ1Cp/xFQkwx75BsGihDlw/aBeKC1WL /gPpnHL4eyL/vg2tT2I+/cZOcWf4GZq0wNWe2nQg8bFJY+t5RBwJY+J+zHiloU5EJUNl eFWmYzCCvC2hALwbuREJDi0Ls4Vegs6eFewr+Po8OSZ7ogPXd2I/3yWJsO+0ekHvHL8R RlKg== X-Gm-Message-State: AOAM533TAvZchfGgE1cmkqQ2EPzDUL8SfL+HnZzBU4NOXtkspShBFr1L tRi01OtLf0wBRLhY67dAeb8= X-Google-Smtp-Source: ABdhPJy2OQ8ke3/QFkMFbBfzUcJ3vLegqgoe9JfY9PgXw188pBrYiK6tlZdjL409PPIBh12l73Dm9Q== X-Received: by 2002:a19:40c7:: with SMTP id n190mr2353133lfa.635.1611330458320; Fri, 22 Jan 2021 07:47:38 -0800 (PST) Received: from btopel-mobl.ger.intel.com (c213-102-90-208.bredband.comhem.se. [213.102.90.208]) by smtp.gmail.com with ESMTPSA id w17sm928589lft.52.2021.01.22.07.47.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jan 2021 07:47:37 -0800 (PST) From: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= To: ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, bpf@vger.kernel.org Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , magnus.karlsson@intel.com, jonathan.lemon@gmail.com, ciara.loftus@intel.com, weqaar.a.janjua@intel.com Subject: [PATCH bpf-next 06/12] selftests/bpf: remove casting by introduce local variable Date: Fri, 22 Jan 2021 16:47:19 +0100 Message-Id: <20210122154725.22140-7-bjorn.topel@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210122154725.22140-1-bjorn.topel@gmail.com> References: <20210122154725.22140-1-bjorn.topel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Björn Töpel Let us use a local variable in nsswitchthread(), so we can remove a lot of casting for better readability. Signed-off-by: Björn Töpel --- tools/testing/selftests/bpf/xdpxceiver.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index ab2ed7b85f9e..bea006ad8e17 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -382,21 +382,19 @@ static bool switch_namespace(int idx) static void *nsswitchthread(void *args) { - if (switch_namespace(((struct targs *)args)->idx)) { - ifdict[((struct targs *)args)->idx]->ifindex = - if_nametoindex(ifdict[((struct targs *)args)->idx]->ifname); - if (!ifdict[((struct targs *)args)->idx]->ifindex) { - ksft_test_result_fail - ("ERROR: [%s] interface \"%s\" does not exist\n", - __func__, ifdict[((struct targs *)args)->idx]->ifname); - ((struct targs *)args)->retptr = false; + struct targs *targs = args; + + targs->retptr = false; + + if (switch_namespace(targs->idx)) { + ifdict[targs->idx]->ifindex = if_nametoindex(ifdict[targs->idx]->ifname); + if (!ifdict[targs->idx]->ifindex) { + ksft_test_result_fail("ERROR: [%s] interface \"%s\" does not exist\n", + __func__, ifdict[targs->idx]->ifname); } else { - ksft_print_msg("Interface found: %s\n", - ifdict[((struct targs *)args)->idx]->ifname); - ((struct targs *)args)->retptr = true; + ksft_print_msg("Interface found: %s\n", ifdict[targs->idx]->ifname); + targs->retptr = true; } - } else { - ((struct targs *)args)->retptr = false; } pthread_exit(NULL); } From patchwork Fri Jan 22 15:47:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= X-Patchwork-Id: 12040135 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45654C433E0 for ; Fri, 22 Jan 2021 17:50:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1276523ABA for ; Fri, 22 Jan 2021 17:50:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729531AbhAVR1a (ORCPT ); Fri, 22 Jan 2021 12:27:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729250AbhAVPsu (ORCPT ); Fri, 22 Jan 2021 10:48:50 -0500 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45722C061353; Fri, 22 Jan 2021 07:47:41 -0800 (PST) Received: by mail-lf1-x136.google.com with SMTP id p21so3046028lfu.11; Fri, 22 Jan 2021 07:47:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jMSB2XCCWwNKG8wfylQfgVp3ITrC3cpaG+GY+0LO0PU=; b=KEEaNXrTQp2zANXAAA8as5TO5XyRPWiakvMFCwTdtB3EFh5rLqR3vEsZ/bh7XpMTko pQ+sr6lVjEhub9SWNrACvgQL1ZvQAwoCcwbw92MeLVUjdCg93rGkwi/F3VH02DJsfSh/ 9urOs06JzAEQgCD6vf9MGWdWk6vo0d+2OnbKtMX7nm51NbTg7vL22FA8oujbj+8YfZXy VlRvGGWvBCE6yp2JhpI72DXxSgBsiCpYp9zyceYfPgFqz1XQktrnFifU8OTGu7NYmgsj hrAiKWXegLDyxt16PK5z0xoe12XHgaIMGW6OezCaHHUCZHoV7tVyr3L92syvhjsCky1F kdXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jMSB2XCCWwNKG8wfylQfgVp3ITrC3cpaG+GY+0LO0PU=; b=nBSQ8EeIKbRQClQIpqma0bP+H8pYrI1sDwwVosL6WEMQ9cRDn10+H11uT0+etxxTKP 5iBThDSJzdwGP7kIFRKu10Y0YBRIgppsHMbuia5lTjXMq7E/hUknab/diDcOh0vYsTJx vp8l93Noh0iC5iTF4TJmYcelj6bY/sn122hDeRsWCE+bQLqS9LuA1LQa8sms67YiMidT g8hOdAL0WPqlnYufowqfVhYmjD3gRjqi169LOfB/XVgka13wXn0kfFfMR95WxUXKrj24 0RXlZxSadBtO+GkWYSdtlff5drlOaa03dsc/uSmuNGY2SKPCX6dAnBnfuYlmcd1WHzkv 25GA== X-Gm-Message-State: AOAM531Bt8trJtzxkkaaOxfQBRDFbfOhw3s9JHfJ/Y0MBtNhIJM5Plhl sRLk2ZyFNBVPI5/hu85sBo4= X-Google-Smtp-Source: ABdhPJykkXUMRdMcuwSrXVRYurNf/zOIdp5azOfvUEFE75s28b6RkfCtSV/qDyZ8YfiUGK6eZ8MeBw== X-Received: by 2002:ac2:5d4f:: with SMTP id w15mr2473867lfd.321.1611330459835; Fri, 22 Jan 2021 07:47:39 -0800 (PST) Received: from btopel-mobl.ger.intel.com (c213-102-90-208.bredband.comhem.se. [213.102.90.208]) by smtp.gmail.com with ESMTPSA id w17sm928589lft.52.2021.01.22.07.47.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jan 2021 07:47:39 -0800 (PST) From: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= To: ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, bpf@vger.kernel.org Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , magnus.karlsson@intel.com, jonathan.lemon@gmail.com, ciara.loftus@intel.com, weqaar.a.janjua@intel.com Subject: [PATCH bpf-next 07/12] selftests/bpf: change type from void * to struct ifaceconfigobj * Date: Fri, 22 Jan 2021 16:47:20 +0100 Message-Id: <20210122154725.22140-8-bjorn.topel@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210122154725.22140-1-bjorn.topel@gmail.com> References: <20210122154725.22140-1-bjorn.topel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Björn Töpel Instead of casting from void *, let us use the actual type in init_iface_config(). Signed-off-by: Björn Töpel --- tools/testing/selftests/bpf/xdpxceiver.c | 28 ++++++++++++------------ 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index bea006ad8e17..c2cfc0b6d19e 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -981,25 +981,25 @@ static void testapp_sockets(void) print_ksft_result(); } -static void init_iface_config(void *ifaceconfig) +static void init_iface_config(struct ifaceconfigobj *ifaceconfig) { /*Init interface0 */ ifdict[0]->fv.vector = tx; - memcpy(ifdict[0]->dst_mac, ((struct ifaceconfigobj *)ifaceconfig)->dst_mac, ETH_ALEN); - memcpy(ifdict[0]->src_mac, ((struct ifaceconfigobj *)ifaceconfig)->src_mac, ETH_ALEN); - ifdict[0]->dst_ip = ((struct ifaceconfigobj *)ifaceconfig)->dst_ip.s_addr; - ifdict[0]->src_ip = ((struct ifaceconfigobj *)ifaceconfig)->src_ip.s_addr; - ifdict[0]->dst_port = ((struct ifaceconfigobj *)ifaceconfig)->dst_port; - ifdict[0]->src_port = ((struct ifaceconfigobj *)ifaceconfig)->src_port; + memcpy(ifdict[0]->dst_mac, ifaceconfig->dst_mac, ETH_ALEN); + memcpy(ifdict[0]->src_mac, ifaceconfig->src_mac, ETH_ALEN); + ifdict[0]->dst_ip = ifaceconfig->dst_ip.s_addr; + ifdict[0]->src_ip = ifaceconfig->src_ip.s_addr; + ifdict[0]->dst_port = ifaceconfig->dst_port; + ifdict[0]->src_port = ifaceconfig->src_port; /*Init interface1 */ ifdict[1]->fv.vector = rx; - memcpy(ifdict[1]->dst_mac, ((struct ifaceconfigobj *)ifaceconfig)->src_mac, ETH_ALEN); - memcpy(ifdict[1]->src_mac, ((struct ifaceconfigobj *)ifaceconfig)->dst_mac, ETH_ALEN); - ifdict[1]->dst_ip = ((struct ifaceconfigobj *)ifaceconfig)->src_ip.s_addr; - ifdict[1]->src_ip = ((struct ifaceconfigobj *)ifaceconfig)->dst_ip.s_addr; - ifdict[1]->dst_port = ((struct ifaceconfigobj *)ifaceconfig)->src_port; - ifdict[1]->src_port = ((struct ifaceconfigobj *)ifaceconfig)->dst_port; + memcpy(ifdict[1]->dst_mac, ifaceconfig->src_mac, ETH_ALEN); + memcpy(ifdict[1]->src_mac, ifaceconfig->dst_mac, ETH_ALEN); + ifdict[1]->dst_ip = ifaceconfig->src_ip.s_addr; + ifdict[1]->src_ip = ifaceconfig->dst_ip.s_addr; + ifdict[1]->dst_port = ifaceconfig->src_port; + ifdict[1]->src_port = ifaceconfig->dst_port; } int main(int argc, char **argv) @@ -1038,7 +1038,7 @@ int main(int argc, char **argv) num_frames = ++opt_pkt_count; - init_iface_config((void *)ifaceconfig); + init_iface_config(ifaceconfig); pthread_init_mutex(); From patchwork Fri Jan 22 15:47:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= X-Patchwork-Id: 12040133 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34770C43381 for ; Fri, 22 Jan 2021 17:50:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ED39423A79 for ; Fri, 22 Jan 2021 17:50:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729363AbhAVR15 (ORCPT ); Fri, 22 Jan 2021 12:27:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729251AbhAVPsv (ORCPT ); Fri, 22 Jan 2021 10:48:51 -0500 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBB85C061356; Fri, 22 Jan 2021 07:47:42 -0800 (PST) Received: by mail-lf1-x135.google.com with SMTP id b26so8119468lff.9; Fri, 22 Jan 2021 07:47:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0kqZW1nBtOtWqAlYCZDluyRBJN4NJNIsym7whQUc+x0=; b=kECSjdtfM3Dy4LH4y2a1JtFnPtu2G1UbOJQNe9CcEK3HurNIYFTqnnkJzlUFdBfayQ lnRYP5PN1X+wJfp8vmAG4C9Zm/Cqpmd/TqZw804JnuXvhTK9/LWHNvYImRt5RQ4GEWB3 sBUEko270upAXZB1b3NyY9YUnxBap9TvRO8DXSWQuwESbXr4XK6C7DZGAZBiuqefQKIY RAtpmrvzh6BoZysvWX8sGmYr7Mg08BggmFb866YZmTp8+yw0OF1cZHZH53LwwHT5Xwqy cfaiCvvY6w30cWfRo6mNxBRs9S4KObmLJueB7RXQZJ35iCeyLdaKdTtqV43qQMbx0Ziq iYcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0kqZW1nBtOtWqAlYCZDluyRBJN4NJNIsym7whQUc+x0=; b=XSS/FzfHDLuypAEG8497+i7Q9+ka7Zoe2kIeBL7Tbmxb1DlpCAzqSOcpNVP3lXZ9Lm +AwRDBdlC7RTpaXDuIDPGP+J8KX54uYNxCLPd0onpVGFxtJl8m467uj3Fcn8gzsQ3SPq cWpnBCPtZXK8oHmDot60Lb4m9rzAERySA9TWBPdiIt0cmusJKWIguOE7N+P1y7z8bRKI OH3uhcJ1ZNfEq758A7+KGjgElPHy4N6I0310++uScPe8IvC6kVOvI5Q7xtEgmmWOiK6E 7qR2XIxDCX7h8QkLXa80yFMSV2Gm6KOcRSAKvh7NbveF9lVR4871t5ksjFMyw8t9H84y ZGQw== X-Gm-Message-State: AOAM531iH7JIn5c2sRqKQCsTDOtPNSoVjn8RWUkhOAwmlr63F47Cvxw/ ApB+3gs35dWKAfjgtvIQCeM= X-Google-Smtp-Source: ABdhPJyfWM7PoI2RHhEZYYHJgkpW3T/0x9IDPm9+SVENAIy/FpQf6xDhBnw4Y8N4xUtzX7HXtDXgHA== X-Received: by 2002:a05:6512:909:: with SMTP id e9mr370121lft.359.1611330461355; Fri, 22 Jan 2021 07:47:41 -0800 (PST) Received: from btopel-mobl.ger.intel.com (c213-102-90-208.bredband.comhem.se. [213.102.90.208]) by smtp.gmail.com with ESMTPSA id w17sm928589lft.52.2021.01.22.07.47.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jan 2021 07:47:40 -0800 (PST) From: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= To: ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, bpf@vger.kernel.org Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , magnus.karlsson@intel.com, jonathan.lemon@gmail.com, ciara.loftus@intel.com, weqaar.a.janjua@intel.com Subject: [PATCH bpf-next 08/12] selftests/bpf: change type from void * to struct generic_data * Date: Fri, 22 Jan 2021 16:47:21 +0100 Message-Id: <20210122154725.22140-9-bjorn.topel@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210122154725.22140-1-bjorn.topel@gmail.com> References: <20210122154725.22140-1-bjorn.topel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Björn Töpel Instead of casting from void *, let us use the actual type in gen_udp_hdr(). Signed-off-by: Björn Töpel --- tools/testing/selftests/bpf/xdpxceiver.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index c2cfc0b6d19e..993ce9b7aa76 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -246,13 +246,13 @@ static void gen_ip_hdr(struct ifobject *ifobject, struct iphdr *ip_hdr) ip_hdr->check = 0; } -static void gen_udp_hdr(void *data, struct ifobject *ifobject, struct udphdr *udp_hdr) +static void gen_udp_hdr(struct generic_data *data, struct ifobject *ifobject, + struct udphdr *udp_hdr) { udp_hdr->source = htons(ifobject->src_port); udp_hdr->dest = htons(ifobject->dst_port); udp_hdr->len = htons(UDP_PKT_SIZE); - memset32_htonl(pkt_data + PKT_HDR_SIZE, - htonl(((struct generic_data *)data)->seqnum), UDP_PKT_DATA_SIZE); + memset32_htonl(pkt_data + PKT_HDR_SIZE, htonl(data->seqnum), UDP_PKT_DATA_SIZE); } static void gen_udp_csum(struct udphdr *udp_hdr, struct iphdr *ip_hdr) @@ -841,7 +841,7 @@ static void *worker_testapp_validate(void *arg) data->seqnum = -1; else data->seqnum = i; - gen_udp_hdr((void *)data, ifobject, udp_hdr); + gen_udp_hdr(data, ifobject, udp_hdr); gen_ip_hdr(ifobject, ip_hdr); gen_udp_csum(udp_hdr, ip_hdr); gen_eth_hdr(ifobject, eth_hdr); From patchwork Fri Jan 22 15:47:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= X-Patchwork-Id: 12040097 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F6A7C4332D for ; Fri, 22 Jan 2021 17:31:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6ADCE22DBF for ; Fri, 22 Jan 2021 17:31:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729651AbhAVR2x (ORCPT ); Fri, 22 Jan 2021 12:28:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729033AbhAVPtD (ORCPT ); Fri, 22 Jan 2021 10:49:03 -0500 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3702BC0612F2; Fri, 22 Jan 2021 07:47:44 -0800 (PST) Received: by mail-lf1-x131.google.com with SMTP id h7so8147512lfc.6; Fri, 22 Jan 2021 07:47:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JlfeYn4HFiJpHf15ex05CldQ0EQy4DxuxZ0ZzVxDhNs=; b=QGkhk7XXtOrVW13j51U8Ff2bD0QJk7+enN2gaT54pqsrIhn+nyjL3WirTTk1f/lpWd +E2qUghgVtRVJYHV2iXYM7ToNpZxzvoJHV+TLeOz2ZAZsHxmUCQVKob0c7k+6pD7wBld 5QDdPrakED1mprib7mkSmCdw+2IxhGD50BKyw6IpyKDLxSBLCIdib4q0Q68epysQBz1J eMfPQEii9Z5VszT3ppFkwU0+qiMvIoKt1CwxHgzyWH+m4EN87FlMNXo02jl3zZS9ts0D ov0Jve/q0s6cP1NZvytjjyvRO5fBH+MEqTsbBvK3IVVfd14HOSUPgnuQb9zMN78uwUTb 6dIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JlfeYn4HFiJpHf15ex05CldQ0EQy4DxuxZ0ZzVxDhNs=; b=dOU21RVDxU1bBk5z68vJHoCA62L1mqh7US6wgM4L2a0IL07t+kj5TebzB/Ue6p3ye9 oBO4xdEcFAR7eL5H/aRsiJlhA5gL5IWl5cWXuJFB+whLQoy60WA9a3/EIxiUbYThqW15 8oZc9AtR9V3p1YvJ7mOfEcnL++2kjbQRLzXJNa/CgMDy4Rfntp4971JI2CA75sUHC+bu 4ev4u3BgEkZQ/Hie+/LMeSbS6no0PaFQzcosMjVRhnuB6Gn7K9VmVotLHk/BG/Ah6c2v Ss2wSZf8G/8MK9PMm7tLd3+HEeEDJY70zP33avzbQ3/Q7CFTmfKLFQHul+ezySj6u/kD gkIg== X-Gm-Message-State: AOAM5314IOutTmJPeS8VjKeiUvgWCX0DpFAuEKSU8mTgVv40UtXLfL5m ntZngaxhpMuUnYFBSQSZuIE= X-Google-Smtp-Source: ABdhPJyXPxnlLv2Nv4R22XP8efR/6zlut0Kju7/TOvNhqbn5Ilzx6hYRZfNdcc23lGt62rQecnhqzQ== X-Received: by 2002:a05:6512:b1b:: with SMTP id w27mr979300lfu.10.1611330462780; Fri, 22 Jan 2021 07:47:42 -0800 (PST) Received: from btopel-mobl.ger.intel.com (c213-102-90-208.bredband.comhem.se. [213.102.90.208]) by smtp.gmail.com with ESMTPSA id w17sm928589lft.52.2021.01.22.07.47.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jan 2021 07:47:42 -0800 (PST) From: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= To: ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, bpf@vger.kernel.org Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , magnus.karlsson@intel.com, jonathan.lemon@gmail.com, ciara.loftus@intel.com, weqaar.a.janjua@intel.com Subject: [PATCH bpf-next 09/12] selftests/bpf: define local variables at the beginning of a block Date: Fri, 22 Jan 2021 16:47:22 +0100 Message-Id: <20210122154725.22140-10-bjorn.topel@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210122154725.22140-1-bjorn.topel@gmail.com> References: <20210122154725.22140-1-bjorn.topel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Björn Töpel Use C89 rules for variable definition. Signed-off-by: Björn Töpel --- tools/testing/selftests/bpf/xdpxceiver.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index 993ce9b7aa76..34bdcae9b908 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -567,9 +567,11 @@ static void rx_pkt(struct xsk_socket_info *xsk, struct pollfd *fds) } for (i = 0; i < rcvd; i++) { - u64 addr = xsk_ring_cons__rx_desc(&xsk->rx, idx_rx)->addr; - (void)xsk_ring_cons__rx_desc(&xsk->rx, idx_rx++)->len; - u64 orig = xsk_umem__extract_addr(addr); + u64 addr, orig; + + addr = xsk_ring_cons__rx_desc(&xsk->rx, idx_rx)->addr; + xsk_ring_cons__rx_desc(&xsk->rx, idx_rx++); + orig = xsk_umem__extract_addr(addr); addr = xsk_umem__add_offset_to_addr(addr); pkt_node_rx = malloc(sizeof(struct pkt) + PKT_SIZE); @@ -905,6 +907,8 @@ static void *worker_testapp_validate(void *arg) static void testapp_validate(void) { + struct timespec max_wait = { 0, 0 }; + pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, THREAD_STACK); @@ -929,8 +933,6 @@ static void testapp_validate(void) exit_with_error(errno); } - struct timespec max_wait = { 0, 0 }; - if (clock_gettime(CLOCK_REALTIME, &max_wait)) exit_with_error(errno); max_wait.tv_sec += TMOUT_SEC; From patchwork Fri Jan 22 15:47:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= X-Patchwork-Id: 12040131 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6AD4C433E6 for ; Fri, 22 Jan 2021 17:50:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AB51E23A79 for ; Fri, 22 Jan 2021 17:50:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729687AbhAVR3D (ORCPT ); Fri, 22 Jan 2021 12:29:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729283AbhAVPt0 (ORCPT ); Fri, 22 Jan 2021 10:49:26 -0500 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9F1AC06121C; Fri, 22 Jan 2021 07:47:45 -0800 (PST) Received: by mail-lf1-x136.google.com with SMTP id b26so8119685lff.9; Fri, 22 Jan 2021 07:47:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UNnUlBe99LdDA4M1w7ZyuRqsbUedR9JBc0FKV+8YSIA=; b=nQnkW7SX3zSxlVPRi+TOB0BjJAOJOtyNtW7KZpQbeM7zzU7BIZTuvr+UaewQbtBSJc SxZGE0ms8uNbidwrc4nn6GlSlcx4UqAY2DIacctD0RWDIOXXAjsZH44cg3e60iBHgtB4 x9y3Yi9PemysBc9WVz344hwjg1zXEeALaJOVV7wk46TDAz9N+7yIiJ+f0M07CmfPzIxl CAHHtiRgXYkyW7t6MmaDo43Ua04mNjx9tNCUUBEcVFrNrSMPVFehy5WVWbOy/dZnOvjN K5vJVdWhASxRU7N5bM6eFnXEZUpl9fiDT2SqN6ak8WECxCXLUwM6IaFjMcdVZHh9RsuM bZSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UNnUlBe99LdDA4M1w7ZyuRqsbUedR9JBc0FKV+8YSIA=; b=N7NzM4oguoA2V2Ee38zp4/ITyJhh5l/cmMcFnBQTWURmrmhJleJyOgV5U8FWC3LalX QOqfCq2e7hUV4xzKQZ1qLXKLqPg803yXTYBh2V9k00gqq/BP4WwJzHx1QVBBPJnoPdeP 1U1nONvJngLPnnREqxHAvwe3BkqQW/uh+U0NdzUeJ8euyWF3xDnlM90+Xm5SYlVq/k06 1sRIbz2b9NAgWBy5toIQzYbZ+MjkyW8WMnyY3n0Mz6I0YPQUH6M+dYkIkrciMpxTOqgL 6B76VLlsYgEO3Sq0xcAuvA61rLUJzbxpleJLYkeY5QLcHpnGAt+Gh618933kvEOo6sB8 Dibg== X-Gm-Message-State: AOAM533bADX+1Sqe+2f37KkkPVO9/N/Xb6iBlp7XT6zBI8frpXqllpfH Ethj8mIvZ8EHEOZf4m1DDrI= X-Google-Smtp-Source: ABdhPJz/48D0xBVgV0J3bWPZAg+5dn+jEzdcUFXrW1ytaOxObNtGn3s7HeQcRsWgZ+b5Ec/EJJpc7w== X-Received: by 2002:a19:4f4f:: with SMTP id a15mr851516lfk.309.1611330464338; Fri, 22 Jan 2021 07:47:44 -0800 (PST) Received: from btopel-mobl.ger.intel.com (c213-102-90-208.bredband.comhem.se. [213.102.90.208]) by smtp.gmail.com with ESMTPSA id w17sm928589lft.52.2021.01.22.07.47.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jan 2021 07:47:43 -0800 (PST) From: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= To: ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, bpf@vger.kernel.org Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , magnus.karlsson@intel.com, jonathan.lemon@gmail.com, ciara.loftus@intel.com, weqaar.a.janjua@intel.com Subject: [PATCH bpf-next 10/12] selftests/bpf: avoid heap allocation Date: Fri, 22 Jan 2021 16:47:23 +0100 Message-Id: <20210122154725.22140-11-bjorn.topel@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210122154725.22140-1-bjorn.topel@gmail.com> References: <20210122154725.22140-1-bjorn.topel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Björn Töpel The data variable is only used locally. Instead of using the heap, stick to using the stack. Signed-off-by: Björn Töpel --- tools/testing/selftests/bpf/xdpxceiver.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index 34bdcae9b908..2da59b142c03 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -807,10 +807,10 @@ static void *worker_testapp_validate(void *arg) { struct udphdr *udp_hdr = (struct udphdr *)(pkt_data + sizeof(struct ethhdr) + sizeof(struct iphdr)); - struct generic_data *data = (struct generic_data *)malloc(sizeof(struct generic_data)); struct iphdr *ip_hdr = (struct iphdr *)(pkt_data + sizeof(struct ethhdr)); struct ethhdr *eth_hdr = (struct ethhdr *)pkt_data; struct ifobject *ifobject = (struct ifobject *)arg; + struct generic_data data; void *bufs = NULL; pthread_attr_setstacksize(&attr, THREAD_STACK); @@ -840,17 +840,16 @@ static void *worker_testapp_validate(void *arg) for (int i = 0; i < num_frames; i++) { /*send EOT frame */ if (i == (num_frames - 1)) - data->seqnum = -1; + data.seqnum = -1; else - data->seqnum = i; - gen_udp_hdr(data, ifobject, udp_hdr); + data.seqnum = i; + gen_udp_hdr(&data, ifobject, udp_hdr); gen_ip_hdr(ifobject, ip_hdr); gen_udp_csum(udp_hdr, ip_hdr); gen_eth_hdr(ifobject, eth_hdr); gen_eth_frame(ifobject->umem, i * XSK_UMEM__DEFAULT_FRAME_SIZE); } - free(data); ksft_print_msg("Sending %d packets on interface %s\n", (opt_pkt_count - 1), ifobject->ifname); tx_only_all(ifobject); From patchwork Fri Jan 22 15:47:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= X-Patchwork-Id: 12040095 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78548C4332B for ; Fri, 22 Jan 2021 17:31:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D6A323A9A for ; Fri, 22 Jan 2021 17:31:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729601AbhAVR2Y (ORCPT ); Fri, 22 Jan 2021 12:28:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729038AbhAVPtD (ORCPT ); Fri, 22 Jan 2021 10:49:03 -0500 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DA09C06121D; Fri, 22 Jan 2021 07:47:47 -0800 (PST) Received: by mail-lj1-x22e.google.com with SMTP id n11so7028386lji.5; Fri, 22 Jan 2021 07:47:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9lypuuFapCkdEuGmqYnc3gh+0SvDvs04apzCvLnPK8w=; b=vAj681rSrtdPDrq2yBjvzEPUOgg2fDUR6XMyOpXO+7qSgD+Lq5yKYteP4AgWedEZG0 T8xjCXrYzI+S6BWHy9r0ObbuwlUrdiDFjXDGSmA9aMQJ1RlzqKMQ96djB+sFu2tPEyn5 b8Qh6EP1FX31rX+/hALxZHl6Hty/z8gbLYJpr6VSCxwkyVZBXAdPQOATOCtdr/Eunz8n MXfedswejUqhfzcl7/hjoSPlDowBy9B+Wli3fNeCO50WoSdai7CyZKZ5OMg23k+fIQEV 9+aNeSf5V7VSHfypmbipaAMSRAIJZdx+KIJfjH9RmdPer/iOW/qBtixb3sepFflZa/zl M1Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9lypuuFapCkdEuGmqYnc3gh+0SvDvs04apzCvLnPK8w=; b=b+bh0Hk0DQ+IcmWIcJvtJ8xu2BDpopmY2tNv8fHU7JE4cz8CvqWvB/NtbaoPvcKGPq H4qVz42KMFA4Sxn9O4tjwVuvPJSAbvUaaKZfygp9j16cdXgyvD+k3O51a0t92mly1sOv UmLq5BOXt2h/AxbaU1z1TJE6cnMZNY6ndVs3xLqUDHFJybGSRTxvs3FQ4pH7Masnmzpw fDECnPvqn4SgzFOTuTokH8fZX3/GTezn8iAremR3lzb+9ELo6OVdEfhBrXKCo3x2L0su FRh5ebm9h/TWcG9D98a610mgZgIUf7r0wBBwlKR4pfXTW8F5FO9fJYh1N8kQn7gPuao0 nrIw== X-Gm-Message-State: AOAM533nVgdNFoXFQLe7ZVFAo5jXkQZXlu723RUZMfrODDh77ieagDDy NEae+F08qmNWIHKPEFtPMWo= X-Google-Smtp-Source: ABdhPJzFf9bpEciMgCRoP5fkXkb6O/kWNbxwfLJI03mUyHkpf+bw6zQaTEVP0gWYGXySbuieLBC2sw== X-Received: by 2002:a05:651c:1395:: with SMTP id k21mr1762545ljb.225.1611330465960; Fri, 22 Jan 2021 07:47:45 -0800 (PST) Received: from btopel-mobl.ger.intel.com (c213-102-90-208.bredband.comhem.se. [213.102.90.208]) by smtp.gmail.com with ESMTPSA id w17sm928589lft.52.2021.01.22.07.47.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jan 2021 07:47:45 -0800 (PST) From: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= To: ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, bpf@vger.kernel.org Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , magnus.karlsson@intel.com, jonathan.lemon@gmail.com, ciara.loftus@intel.com, weqaar.a.janjua@intel.com Subject: [PATCH bpf-next 11/12] selftests/bpf: consistent malloc/calloc usage Date: Fri, 22 Jan 2021 16:47:24 +0100 Message-Id: <20210122154725.22140-12-bjorn.topel@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210122154725.22140-1-bjorn.topel@gmail.com> References: <20210122154725.22140-1-bjorn.topel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Björn Töpel Use calloc instead of malloc where it makes sense, and avoid C++-style void *-cast. Signed-off-by: Björn Töpel --- tools/testing/selftests/bpf/xdpxceiver.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index 2da59b142c03..a64e2a929e70 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -411,7 +411,7 @@ static int validate_interfaces(void) if (strcmp(ifdict[i]->nsname, "")) { struct targs *targs; - targs = (struct targs *)malloc(sizeof(struct targs)); + targs = malloc(sizeof(*targs)); if (!targs) exit_with_error(errno); @@ -578,7 +578,7 @@ static void rx_pkt(struct xsk_socket_info *xsk, struct pollfd *fds) if (!pkt_node_rx) exit_with_error(errno); - pkt_node_rx->pkt_frame = (char *)malloc(PKT_SIZE); + pkt_node_rx->pkt_frame = malloc(PKT_SIZE); if (!pkt_node_rx->pkt_frame) exit_with_error(errno); @@ -739,8 +739,8 @@ static void worker_pkt_validate(void) if (iphdr->version == IP_PKT_VER && iphdr->tos == IP_PKT_TOS) { payloadseqnum = *((uint32_t *)(pkt_node_rx_q->pkt_frame + PKT_HDR_SIZE)); if (debug_pkt_dump && payloadseqnum != EOT) { - pkt_obj = (struct pkt_frame *)malloc(sizeof(struct pkt_frame)); - pkt_obj->payload = (char *)malloc(PKT_SIZE); + pkt_obj = malloc(sizeof(*pkt_obj)); + pkt_obj->payload = malloc(PKT_SIZE); memcpy(pkt_obj->payload, pkt_node_rx_q->pkt_frame, PKT_SIZE); pkt_buf[payloadseqnum] = pkt_obj; } @@ -865,7 +865,7 @@ static void *worker_testapp_validate(void *arg) TAILQ_INIT(&head); if (debug_pkt_dump) { - pkt_buf = malloc(sizeof(struct pkt_frame **) * num_frames); + pkt_buf = calloc(num_frames, sizeof(*pkt_buf)); if (!pkt_buf) exit_with_error(errno); } @@ -1017,7 +1017,7 @@ int main(int argc, char **argv) u16 UDP_DST_PORT = 2020; u16 UDP_SRC_PORT = 2121; - ifaceconfig = (struct ifaceconfigobj *)malloc(sizeof(struct ifaceconfigobj)); + ifaceconfig = malloc(sizeof(struct ifaceconfigobj)); memcpy(ifaceconfig->dst_mac, MAC1, ETH_ALEN); memcpy(ifaceconfig->src_mac, MAC2, ETH_ALEN); inet_aton(IP1, &ifaceconfig->dst_ip); @@ -1026,7 +1026,7 @@ int main(int argc, char **argv) ifaceconfig->src_port = UDP_SRC_PORT; for (int i = 0; i < MAX_INTERFACES; i++) { - ifdict[i] = (struct ifobject *)malloc(sizeof(struct ifobject)); + ifdict[i] = malloc(sizeof(struct ifobject)); if (!ifdict[i]) exit_with_error(errno); From patchwork Fri Jan 22 15:47:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= X-Patchwork-Id: 12040079 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DAA4AC433E0 for ; Fri, 22 Jan 2021 17:27:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 98C2C23A79 for ; Fri, 22 Jan 2021 17:27:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729279AbhAVR03 (ORCPT ); Fri, 22 Jan 2021 12:26:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729285AbhAVPt0 (ORCPT ); Fri, 22 Jan 2021 10:49:26 -0500 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8AD3C06121E; Fri, 22 Jan 2021 07:47:48 -0800 (PST) Received: by mail-lj1-x22e.google.com with SMTP id p13so7050627ljg.2; Fri, 22 Jan 2021 07:47:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ej/vX1nAudOHlcsj/wkk0E6CPzhd1z5jtaipD1+YZts=; b=AkAM03jGtCitne0blJcZVBymlpzWFXoPm31Mzrx2LCCOc5n1MrQHXG6IQFknELgqZM twu9eQUgCZi8VZmUx/Sc5BJQhdFLvYcZtJFI2lTYNY+jM3GyxSgZzI/YrNz4nQ4baypd 3SwjSRZ6l6egctCX1GJBa3xW7JYseHYKqSAPnoNJQNmSWLdRYQtlXm8Y5+tePhTM5wnW Z6RtDo6NK8Dse50BigHXzARqBEdeSZmZY/SWaAKFx4X2LhfRZNJPrigFG6NeDBbqk6dj Bdq55JYx8h6MrjyGlucerPn6yr/rKWAMuGbU1Z9AXMrNdAMa2jADp+uZqroK1Z+fcTDF 8AJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ej/vX1nAudOHlcsj/wkk0E6CPzhd1z5jtaipD1+YZts=; b=TyWfagGXMb5USWZv/7buRAGjIvbpaAkoj+pBeFtnusVLF8X2Q9Ck+R5tI4yvttk7Fk 5GxAhHY6eiVx3wie9skoTzPTHSg/UhJg1dTyTsQg2QYBJo3BlUg6I7Oc2dp1tBPhUBAy Zpe9QDneEHC/Lp2kjQPwyJoF7u6+duW0wwyDtb31PgkWKaBD8T373xCZUuFR7dhiPFbB SS+LMkB0rl2SEcRzcoysBqFFeZbbEv/jGarS86yuzanO6uIq/4QystkCSJKgQ6i2uNT3 IZOvlfWyYTNnomZxnD7nkl74DjXe8r3Ujwt/8mTLcyxGcu2LsBW4gl97hByldxp0x4gr TtEA== X-Gm-Message-State: AOAM533+W9a5H7VVhKiVKvv/ett/ZsaKHpFjEOQWfajJ7gvkP0TWYlV1 Pxbv+xBYGObBiR3Ob+jd9KIFW2NTHO9HeA== X-Google-Smtp-Source: ABdhPJwZNvLfQapELB95eEZieSnJ04GovHOPWXWo1/ZOFCFs+Gp+KvulRs0xlP0jKDHSh1QDyIZ0SQ== X-Received: by 2002:a2e:959a:: with SMTP id w26mr564631ljh.113.1611330467334; Fri, 22 Jan 2021 07:47:47 -0800 (PST) Received: from btopel-mobl.ger.intel.com (c213-102-90-208.bredband.comhem.se. [213.102.90.208]) by smtp.gmail.com with ESMTPSA id w17sm928589lft.52.2021.01.22.07.47.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jan 2021 07:47:46 -0800 (PST) From: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= To: ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, bpf@vger.kernel.org Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , magnus.karlsson@intel.com, jonathan.lemon@gmail.com, ciara.loftus@intel.com, weqaar.a.janjua@intel.com Subject: [PATCH bpf-next 12/12] selftests/bpf: avoid useless void *-casts Date: Fri, 22 Jan 2021 16:47:25 +0100 Message-Id: <20210122154725.22140-13-bjorn.topel@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210122154725.22140-1-bjorn.topel@gmail.com> References: <20210122154725.22140-1-bjorn.topel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Björn Töpel There is no need to cast to void * when the argument is void *. Avoid cluttering of code. Signed-off-by: Björn Töpel --- tools/testing/selftests/bpf/xdpxceiver.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index a64e2a929e70..99ea6cf069e6 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -416,7 +416,7 @@ static int validate_interfaces(void) exit_with_error(errno); targs->idx = i; - if (pthread_create(&ns_thread, NULL, nsswitchthread, (void *)targs)) + if (pthread_create(&ns_thread, NULL, nsswitchthread, targs)) exit_with_error(errno); pthread_join(ns_thread, NULL); @@ -923,12 +923,12 @@ static void testapp_validate(void) /*Spawn RX thread */ if (!opt_bidi || (opt_bidi && !bidi_pass)) { - if (pthread_create(&t0, &attr, worker_testapp_validate, (void *)ifdict[1])) + if (pthread_create(&t0, &attr, worker_testapp_validate, ifdict[1])) exit_with_error(errno); } else if (opt_bidi && bidi_pass) { /*switch Tx/Rx vectors */ ifdict[0]->fv.vector = rx; - if (pthread_create(&t0, &attr, worker_testapp_validate, (void *)ifdict[0])) + if (pthread_create(&t0, &attr, worker_testapp_validate, ifdict[0])) exit_with_error(errno); } @@ -943,12 +943,12 @@ static void testapp_validate(void) /*Spawn TX thread */ if (!opt_bidi || (opt_bidi && !bidi_pass)) { - if (pthread_create(&t1, &attr, worker_testapp_validate, (void *)ifdict[0])) + if (pthread_create(&t1, &attr, worker_testapp_validate, ifdict[0])) exit_with_error(errno); } else if (opt_bidi && bidi_pass) { /*switch Tx/Rx vectors */ ifdict[1]->fv.vector = tx; - if (pthread_create(&t1, &attr, worker_testapp_validate, (void *)ifdict[1])) + if (pthread_create(&t1, &attr, worker_testapp_validate, ifdict[1])) exit_with_error(errno); }