2019-04-04 14:48:22

by Colin King

[permalink] [raw]
Subject: [PATCH] tcp: remove redundant check on tskb

From: Colin Ian King <[email protected]>

The non-null check on tskb is always false because it is in an else
path of a check on tskb and hence tskb is null in this code block.
This is check is therefore redundant and can be removed as well
as the label coalesc.

if (tsbk) {
...
} else {
...
if (unlikely(!skb)) {
if (tskb) /* can never be true, redundant code */
goto coalesc;
return;
}
}

Addresses-Coverity: ("Logically dead code")
Signed-off-by: Colin Ian King <[email protected]>
---
net/ipv4/tcp_output.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index e265d1aeeb66..32061928b054 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -3088,7 +3088,6 @@ void tcp_send_fin(struct sock *sk)
tskb = skb_rb_last(&sk->tcp_rtx_queue);

if (tskb) {
-coalesce:
TCP_SKB_CB(tskb)->tcp_flags |= TCPHDR_FIN;
TCP_SKB_CB(tskb)->end_seq++;
tp->write_seq++;
@@ -3104,11 +3103,9 @@ void tcp_send_fin(struct sock *sk)
}
} else {
skb = alloc_skb_fclone(MAX_TCP_HEADER, sk->sk_allocation);
- if (unlikely(!skb)) {
- if (tskb)
- goto coalesce;
+ if (unlikely(!skb))
return;
- }
+
INIT_LIST_HEAD(&skb->tcp_tsorted_anchor);
skb_reserve(skb, MAX_TCP_HEADER);
sk_forced_mem_schedule(sk, skb->truesize);
--
2.20.1


2019-04-04 15:07:39

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH] tcp: remove redundant check on tskb

On Thu, Apr 04, 2019 at 03:46:03PM +0100, Colin King wrote:
> From: Colin Ian King <[email protected]>
>
> The non-null check on tskb is always false because it is in an else
> path of a check on tskb and hence tskb is null in this code block.
> This is check is therefore redundant and can be removed as well
> as the label coalesc.
>
> if (tsbk) {
> ...
> } else {
> ...
> if (unlikely(!skb)) {
> if (tskb) /* can never be true, redundant code */
> goto coalesc;
> return;
> }
> }
>
> Addresses-Coverity: ("Logically dead code")
> Signed-off-by: Colin Ian King <[email protected]>

This was fallout from commit 75c119afe14f ("tcp: implement rb-tree based
retransmit queue").

regards,
dan carpenter

2019-04-05 06:48:36

by Mukesh Ojha

[permalink] [raw]
Subject: Re: [PATCH] tcp: remove redundant check on tskb


On 4/4/2019 8:16 PM, Colin King wrote:
> From: Colin Ian King <[email protected]>
>
> The non-null check on tskb is always false because it is in an else
> path of a check on tskb and hence tskb is null in this code block.
> This is check is therefore redundant and can be removed as well
> as the label coalesc.
>
> if (tsbk) {
> ...
> } else {
> ...
> if (unlikely(!skb)) {
> if (tskb) /* can never be true, redundant code */
> goto coalesc;
> return;
> }
> }
>
> Addresses-Coverity: ("Logically dead code")
> Signed-off-by: Colin Ian King <[email protected]>
Reviewed-by: Mukesh Ojha <[email protected]>

Cheers,
-Mukesh
> ---
> net/ipv4/tcp_output.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
> index e265d1aeeb66..32061928b054 100644
> --- a/net/ipv4/tcp_output.c
> +++ b/net/ipv4/tcp_output.c
> @@ -3088,7 +3088,6 @@ void tcp_send_fin(struct sock *sk)
> tskb = skb_rb_last(&sk->tcp_rtx_queue);
>
> if (tskb) {
> -coalesce:
> TCP_SKB_CB(tskb)->tcp_flags |= TCPHDR_FIN;
> TCP_SKB_CB(tskb)->end_seq++;
> tp->write_seq++;
> @@ -3104,11 +3103,9 @@ void tcp_send_fin(struct sock *sk)
> }
> } else {
> skb = alloc_skb_fclone(MAX_TCP_HEADER, sk->sk_allocation);
> - if (unlikely(!skb)) {
> - if (tskb)
> - goto coalesce;
> + if (unlikely(!skb))
> return;
> - }
> +
> INIT_LIST_HEAD(&skb->tcp_tsorted_anchor);
> skb_reserve(skb, MAX_TCP_HEADER);
> sk_forced_mem_schedule(sk, skb->truesize);

2019-04-05 07:47:41

by Eric Dumazet

[permalink] [raw]
Subject: Re: [PATCH] tcp: remove redundant check on tskb

On Thu, Apr 4, 2019 at 7:46 AM Colin King <[email protected]> wrote:
>
> From: Colin Ian King <[email protected]>
>
> The non-null check on tskb is always false because it is in an else
> path of a check on tskb and hence tskb is null in this code block.
> This is check is therefore redundant and can be removed as well
> as the label coalesc.
>...

> Addresses-Coverity: ("Logically dead code")
> Signed-off-by: Colin Ian King <[email protected]>

SGTM, thanks.

Signed-off-by: Eric Dumazet <[email protected]>

2019-04-07 01:19:38

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] tcp: remove redundant check on tskb

From: Colin King <[email protected]>
Date: Thu, 4 Apr 2019 15:46:03 +0100

> From: Colin Ian King <[email protected]>
>
> The non-null check on tskb is always false because it is in an else
> path of a check on tskb and hence tskb is null in this code block.
> This is check is therefore redundant and can be removed as well
> as the label coalesc.
>
> if (tsbk) {
> ...
> } else {
> ...
> if (unlikely(!skb)) {
> if (tskb) /* can never be true, redundant code */
> goto coalesc;
> return;
> }
> }
>
> Addresses-Coverity: ("Logically dead code")
> Signed-off-by: Colin Ian King <[email protected]>

Applied to net-next.