Skip to content

Commit 72c935c

Browse files
pchaignoKernel Patches Daemon
authored andcommitted
bpf: Refactor cleanup of bpf_prog_test_run_skb
This bit of refactoring aims to simplify the next patch in this series, in which freeing 'data' is a bit less straightforward. Signed-off-by: Paul Chaignon <[email protected]>
1 parent 0e26bd3 commit 72c935c

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

net/bpf/test_run.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,8 +1009,8 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
10091009

10101010
ctx = bpf_ctx_init(kattr, sizeof(struct __sk_buff));
10111011
if (IS_ERR(ctx)) {
1012-
kfree(data);
1013-
return PTR_ERR(ctx);
1012+
ret = PTR_ERR(ctx);
1013+
goto out;
10141014
}
10151015

10161016
switch (prog->type) {
@@ -1030,24 +1030,23 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
10301030

10311031
sk = sk_alloc(net, AF_UNSPEC, GFP_USER, &bpf_dummy_proto, 1);
10321032
if (!sk) {
1033-
kfree(data);
1034-
kfree(ctx);
1035-
return -ENOMEM;
1033+
ret = -ENOMEM;
1034+
goto out;
10361035
}
10371036
sock_init_data(NULL, sk);
10381037

10391038
skb = slab_build_skb(data);
10401039
if (!skb) {
1041-
kfree(data);
1042-
kfree(ctx);
1043-
sk_free(sk);
1044-
return -ENOMEM;
1040+
ret = -ENOMEM;
1041+
goto out;
10451042
}
10461043
skb->sk = sk;
10471044

10481045
skb_reserve(skb, NET_SKB_PAD + NET_IP_ALIGN);
10491046
__skb_put(skb, size);
10501047

1048+
data = NULL; /* data released via kfree_skb */
1049+
10511050
if (ctx && ctx->ifindex > 1) {
10521051
dev = dev_get_by_index(net, ctx->ifindex);
10531052
if (!dev) {
@@ -1139,7 +1138,9 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
11391138
if (dev && dev != net->loopback_dev)
11401139
dev_put(dev);
11411140
kfree_skb(skb);
1142-
sk_free(sk);
1141+
kfree(data);
1142+
if (sk)
1143+
sk_free(sk);
11431144
kfree(ctx);
11441145
return ret;
11451146
}

0 commit comments

Comments
 (0)