Skip to content

Commit 95ff6ed

Browse files
pchaignoguidosarducci
authored andcommitted
bpf: Reorder bpf_prog_test_run_skb initialization
This patch reorders the initialization of bpf_prog_test_run_skb to simplify the subsequent patch. Program types are checked first, followed by the ctx init, and finally the data init. With the subsequent patch, program types and the ctx init provide information that is used in the data init. Thus, we need the data init to happen last. Signed-off-by: Paul Chaignon <[email protected]> Signed-off-by: Martin KaFai Lau <[email protected]> Link: https://patch.msgid.link/063475176f15828a882c07846017394baf72f682.1760037899.git.paul.chaignon@gmail.com
1 parent 031b421 commit 95ff6ed

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

net/bpf/test_run.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -993,19 +993,6 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
993993
if (size < ETH_HLEN)
994994
return -EINVAL;
995995

996-
data = bpf_test_init(kattr, kattr->test.data_size_in,
997-
size, NET_SKB_PAD + NET_IP_ALIGN,
998-
SKB_DATA_ALIGN(sizeof(struct skb_shared_info)));
999-
if (IS_ERR(data))
1000-
return PTR_ERR(data);
1001-
1002-
ctx = bpf_ctx_init(kattr, sizeof(struct __sk_buff));
1003-
if (IS_ERR(ctx)) {
1004-
ret = PTR_ERR(ctx);
1005-
ctx = NULL;
1006-
goto out;
1007-
}
1008-
1009996
switch (prog->type) {
1010997
case BPF_PROG_TYPE_SCHED_CLS:
1011998
case BPF_PROG_TYPE_SCHED_ACT:
@@ -1021,6 +1008,19 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
10211008
break;
10221009
}
10231010

1011+
ctx = bpf_ctx_init(kattr, sizeof(struct __sk_buff));
1012+
if (IS_ERR(ctx))
1013+
return PTR_ERR(ctx);
1014+
1015+
data = bpf_test_init(kattr, kattr->test.data_size_in,
1016+
size, NET_SKB_PAD + NET_IP_ALIGN,
1017+
SKB_DATA_ALIGN(sizeof(struct skb_shared_info)));
1018+
if (IS_ERR(data)) {
1019+
ret = PTR_ERR(data);
1020+
data = NULL;
1021+
goto out;
1022+
}
1023+
10241024
sk = sk_alloc(net, AF_UNSPEC, GFP_USER, &bpf_dummy_proto, 1);
10251025
if (!sk) {
10261026
ret = -ENOMEM;

0 commit comments

Comments
 (0)