2018-09-20 10:01:00

by zhong jiang

[permalink] [raw]
Subject: [PATCH] bpf: remove redundant null pointer check before consume_skb

consume_skb has taken the null pointer into account. hence it is safe
to remove the redundant null pointer check before consume_skb.

Signed-off-by: zhong jiang <[email protected]>
---
kernel/bpf/sockmap.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/kernel/bpf/sockmap.c b/kernel/bpf/sockmap.c
index 488ef96..a9359cb 100644
--- a/kernel/bpf/sockmap.c
+++ b/kernel/bpf/sockmap.c
@@ -590,8 +590,7 @@ static int free_sg(struct sock *sk, int start,
if (i == MAX_SKB_FRAGS)
i = 0;
}
- if (md->skb)
- consume_skb(md->skb);
+ consume_skb(md->skb);

return free;
}
@@ -973,8 +972,7 @@ static int bpf_tcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,

if (!sg->length && md->sg_start == md->sg_end) {
list_del(&md->list);
- if (md->skb)
- consume_skb(md->skb);
+ consume_skb(md->skb);
kfree(md);
}
}
--
1.7.12.4



2018-09-20 17:54:34

by Song Liu

[permalink] [raw]
Subject: Re: [PATCH] bpf: remove redundant null pointer check before consume_skb

On Thu, Sep 20, 2018 at 3:00 AM zhong jiang <[email protected]> wrote:
>
> consume_skb has taken the null pointer into account. hence it is safe
> to remove the redundant null pointer check before consume_skb.
>
> Signed-off-by: zhong jiang <[email protected]>

Acked-by: Song Liu <[email protected]>

> ---
> kernel/bpf/sockmap.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/bpf/sockmap.c b/kernel/bpf/sockmap.c
> index 488ef96..a9359cb 100644
> --- a/kernel/bpf/sockmap.c
> +++ b/kernel/bpf/sockmap.c
> @@ -590,8 +590,7 @@ static int free_sg(struct sock *sk, int start,
> if (i == MAX_SKB_FRAGS)
> i = 0;
> }
> - if (md->skb)
> - consume_skb(md->skb);
> + consume_skb(md->skb);
>
> return free;
> }
> @@ -973,8 +972,7 @@ static int bpf_tcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
>
> if (!sg->length && md->sg_start == md->sg_end) {
> list_del(&md->list);
> - if (md->skb)
> - consume_skb(md->skb);
> + consume_skb(md->skb);
> kfree(md);
> }
> }
> --
> 1.7.12.4
>

2018-09-22 01:09:12

by Daniel Borkmann

[permalink] [raw]
Subject: Re: [PATCH] bpf: remove redundant null pointer check before consume_skb

On 09/20/2018 11:46 AM, zhong jiang wrote:
> consume_skb has taken the null pointer into account. hence it is safe
> to remove the redundant null pointer check before consume_skb.
>
> Signed-off-by: zhong jiang <[email protected]>

Applied to bpf-next, thanks Zhong!