All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Björn Töpel" <bjorn.topel@gmail.com>
To: ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org,
	bpf@vger.kernel.org
Cc: "Björn Töpel" <bjorn.topel@intel.com>,
	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	[thread overview]
Message-ID: <20210122154725.22140-11-bjorn.topel@gmail.com> (raw)
In-Reply-To: <20210122154725.22140-1-bjorn.topel@gmail.com>

From: Björn Töpel <bjorn.topel@intel.com>

The data variable is only used locally. Instead of using the heap,
stick to using the stack.

Signed-off-by: Björn Töpel <bjorn.topel@intel.com>
---
 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);
-- 
2.27.0


  parent reply	other threads:[~2021-01-22 18:10 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-22 15:47 [PATCH bpf-next 00/12] Various cleanups/fixes for AF_XDP selftests Björn Töpel
2021-01-22 15:47 ` [PATCH bpf-next 01/12] selftests/bpf: remove a lot of ifobject casting Björn Töpel
2021-01-22 15:47 ` [PATCH bpf-next 02/12] selftests/bpf: remove unused enums Björn Töpel
2021-01-22 15:47 ` [PATCH bpf-next 03/12] selftests/bpf: fix style warnings Björn Töpel
2021-01-22 15:47 ` [PATCH bpf-next 04/12] selftests/bpf: remove memory leak Björn Töpel
2021-01-22 15:47 ` [PATCH bpf-next 05/12] selftests/bpf: improve readability of xdpxceiver/worker_pkt_validate() Björn Töpel
2021-01-22 15:47 ` [PATCH bpf-next 06/12] selftests/bpf: remove casting by introduce local variable Björn Töpel
2021-01-22 15:47 ` [PATCH bpf-next 07/12] selftests/bpf: change type from void * to struct ifaceconfigobj * Björn Töpel
2021-01-22 15:47 ` [PATCH bpf-next 08/12] selftests/bpf: change type from void * to struct generic_data * Björn Töpel
2021-01-22 15:47 ` [PATCH bpf-next 09/12] selftests/bpf: define local variables at the beginning of a block Björn Töpel
2021-01-22 15:47 ` Björn Töpel [this message]
2021-01-22 15:47 ` [PATCH bpf-next 11/12] selftests/bpf: consistent malloc/calloc usage Björn Töpel
2021-01-22 15:47 ` [PATCH bpf-next 12/12] selftests/bpf: avoid useless void *-casts Björn Töpel
2021-01-25 23:10 ` [PATCH bpf-next 00/12] Various cleanups/fixes for AF_XDP selftests patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210122154725.22140-11-bjorn.topel@gmail.com \
    --to=bjorn.topel@gmail.com \
    --cc=ast@kernel.org \
    --cc=bjorn.topel@intel.com \
    --cc=bpf@vger.kernel.org \
    --cc=ciara.loftus@intel.com \
    --cc=daniel@iogearbox.net \
    --cc=jonathan.lemon@gmail.com \
    --cc=magnus.karlsson@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=weqaar.a.janjua@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.