Skip to content

Commit 1609bfe

Browse files
pchaignoKernel Patches Daemon
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]>
1 parent d9865de commit 1609bfe

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
@@ -1004,19 +1004,6 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
10041004
if (size < ETH_HLEN)
10051005
return -EINVAL;
10061006

1007-
data = bpf_test_init(kattr, kattr->test.data_size_in,
1008-
size, NET_SKB_PAD + NET_IP_ALIGN,
1009-
SKB_DATA_ALIGN(sizeof(struct skb_shared_info)));
1010-
if (IS_ERR(data))
1011-
return PTR_ERR(data);
1012-
1013-
ctx = bpf_ctx_init(kattr, sizeof(struct __sk_buff));
1014-
if (IS_ERR(ctx)) {
1015-
ret = PTR_ERR(ctx);
1016-
ctx = NULL;
1017-
goto out;
1018-
}
1019-
10201007
switch (prog->type) {
10211008
case BPF_PROG_TYPE_SCHED_CLS:
10221009
case BPF_PROG_TYPE_SCHED_ACT:
@@ -1032,6 +1019,19 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
10321019
break;
10331020
}
10341021

1022+
ctx = bpf_ctx_init(kattr, sizeof(struct __sk_buff));
1023+
if (IS_ERR(ctx))
1024+
return PTR_ERR(ctx);
1025+
1026+
data = bpf_test_init(kattr, kattr->test.data_size_in,
1027+
size, NET_SKB_PAD + NET_IP_ALIGN,
1028+
SKB_DATA_ALIGN(sizeof(struct skb_shared_info)));
1029+
if (IS_ERR(data)) {
1030+
ret = PTR_ERR(data);
1031+
data = NULL;
1032+
goto out;
1033+
}
1034+
10351035
sk = sk_alloc(net, AF_UNSPEC, GFP_USER, &bpf_dummy_proto, 1);
10361036
if (!sk) {
10371037
ret = -ENOMEM;

0 commit comments

Comments
 (0)