Commit 93dd4a06 authored by Björn Töpel's avatar Björn Töpel Committed by Daniel Borkmann

selftests/bpf: Avoid heap allocation

The data variable is only used locally. Instead of using the heap,
stick to using the stack.
Signed-off-by: default avatarBjörn Töpel <bjorn.topel@intel.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20210122154725.22140-11-bjorn.topel@gmail.com
parent 829725ec
...@@ -807,10 +807,10 @@ static void *worker_testapp_validate(void *arg) ...@@ -807,10 +807,10 @@ static void *worker_testapp_validate(void *arg)
{ {
struct udphdr *udp_hdr = struct udphdr *udp_hdr =
(struct udphdr *)(pkt_data + sizeof(struct ethhdr) + sizeof(struct iphdr)); (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 iphdr *ip_hdr = (struct iphdr *)(pkt_data + sizeof(struct ethhdr));
struct ethhdr *eth_hdr = (struct ethhdr *)pkt_data; struct ethhdr *eth_hdr = (struct ethhdr *)pkt_data;
struct ifobject *ifobject = (struct ifobject *)arg; struct ifobject *ifobject = (struct ifobject *)arg;
struct generic_data data;
void *bufs = NULL; void *bufs = NULL;
pthread_attr_setstacksize(&attr, THREAD_STACK); pthread_attr_setstacksize(&attr, THREAD_STACK);
...@@ -840,17 +840,16 @@ static void *worker_testapp_validate(void *arg) ...@@ -840,17 +840,16 @@ static void *worker_testapp_validate(void *arg)
for (int i = 0; i < num_frames; i++) { for (int i = 0; i < num_frames; i++) {
/*send EOT frame */ /*send EOT frame */
if (i == (num_frames - 1)) if (i == (num_frames - 1))
data->seqnum = -1; data.seqnum = -1;
else else
data->seqnum = i; data.seqnum = i;
gen_udp_hdr(data, ifobject, udp_hdr); gen_udp_hdr(&data, ifobject, udp_hdr);
gen_ip_hdr(ifobject, ip_hdr); gen_ip_hdr(ifobject, ip_hdr);
gen_udp_csum(udp_hdr, ip_hdr); gen_udp_csum(udp_hdr, ip_hdr);
gen_eth_hdr(ifobject, eth_hdr); gen_eth_hdr(ifobject, eth_hdr);
gen_eth_frame(ifobject->umem, i * XSK_UMEM__DEFAULT_FRAME_SIZE); gen_eth_frame(ifobject->umem, i * XSK_UMEM__DEFAULT_FRAME_SIZE);
} }
free(data);
ksft_print_msg("Sending %d packets on interface %s\n", ksft_print_msg("Sending %d packets on interface %s\n",
(opt_pkt_count - 1), ifobject->ifname); (opt_pkt_count - 1), ifobject->ifname);
tx_only_all(ifobject); tx_only_all(ifobject);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment