Skip to content

Commit 93dd4a0

Browse files
Björn Töpelborkmann
authored andcommitted
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: Björn Töpel <bjorn.topel@intel.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/bpf/20210122154725.22140-11-bjorn.topel@gmail.com
1 parent 829725e commit 93dd4a0

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

tools/testing/selftests/bpf/xdpxceiver.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -807,10 +807,10 @@ static void *worker_testapp_validate(void *arg)
807807
{
808808
struct udphdr *udp_hdr =
809809
(struct udphdr *)(pkt_data + sizeof(struct ethhdr) + sizeof(struct iphdr));
810-
struct generic_data *data = (struct generic_data *)malloc(sizeof(struct generic_data));
811810
struct iphdr *ip_hdr = (struct iphdr *)(pkt_data + sizeof(struct ethhdr));
812811
struct ethhdr *eth_hdr = (struct ethhdr *)pkt_data;
813812
struct ifobject *ifobject = (struct ifobject *)arg;
813+
struct generic_data data;
814814
void *bufs = NULL;
815815

816816
pthread_attr_setstacksize(&attr, THREAD_STACK);
@@ -840,17 +840,16 @@ static void *worker_testapp_validate(void *arg)
840840
for (int i = 0; i < num_frames; i++) {
841841
/*send EOT frame */
842842
if (i == (num_frames - 1))
843-
data->seqnum = -1;
843+
data.seqnum = -1;
844844
else
845-
data->seqnum = i;
846-
gen_udp_hdr(data, ifobject, udp_hdr);
845+
data.seqnum = i;
846+
gen_udp_hdr(&data, ifobject, udp_hdr);
847847
gen_ip_hdr(ifobject, ip_hdr);
848848
gen_udp_csum(udp_hdr, ip_hdr);
849849
gen_eth_hdr(ifobject, eth_hdr);
850850
gen_eth_frame(ifobject->umem, i * XSK_UMEM__DEFAULT_FRAME_SIZE);
851851
}
852852

853-
free(data);
854853
ksft_print_msg("Sending %d packets on interface %s\n",
855854
(opt_pkt_count - 1), ifobject->ifname);
856855
tx_only_all(ifobject);

0 commit comments

Comments
 (0)