diff mbox

[net-next,2/4] ipv4: Correct two conditions checking when buildig nskb

Message ID 1425978986-8512-3-git-send-email-fan.du@intel.com
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Fan Du March 10, 2015, 9:16 a.m. UTC
When traversing write queue to build 'nskb', the size of 'copy'
could only be equal or smaller than skb->len.

And as we need exactly 'probe_size' bytes data for 'nskb', thus
break condition could only be len == probe_size.

Signed-off-by: Fan Du <fan.du@intel.com>
---
 net/ipv4/tcp_output.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

Comments

John Heffner March 18, 2015, 12:44 p.m. UTC | #1
On Tue, Mar 10, 2015 at 5:16 AM, Fan Du <fan.du@intel.com> wrote:
> When traversing write queue to build 'nskb', the size of 'copy'
> could only be equal or smaller than skb->len.
>
> And as we need exactly 'probe_size' bytes data for 'nskb', thus
> break condition could only be len == probe_size.
>
> Signed-off-by: Fan Du <fan.du@intel.com>
> ---
>  net/ipv4/tcp_output.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
> index 5a73ad5..79977d1 100644
> --- a/net/ipv4/tcp_output.c
> +++ b/net/ipv4/tcp_output.c
> @@ -1954,7 +1954,7 @@ static int tcp_mtu_probe(struct sock *sk)
>                                                             skb_put(nskb, copy),
>                                                             copy, nskb->csum);
>
> -               if (skb->len <= copy) {
> +               if (skb->len == copy) {
>                         /* We've eaten all the data from this skb.
>                          * Throw it away. */
>                         TCP_SKB_CB(nskb)->tcp_flags |= TCP_SKB_CB(skb)->tcp_flags;
> @@ -1977,7 +1977,7 @@ static int tcp_mtu_probe(struct sock *sk)
>
>                 len += copy;
>
> -               if (len >= probe_size)
> +               if (len == probe_size)
>                         break;
>         }
>         tcp_init_tso_segs(sk, nskb, nskb->len);
> --
> 1.7.1
>

This is called "defensive programming." ;-)
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 5a73ad5..79977d1 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -1954,7 +1954,7 @@  static int tcp_mtu_probe(struct sock *sk)
 							    skb_put(nskb, copy),
 							    copy, nskb->csum);
 
-		if (skb->len <= copy) {
+		if (skb->len == copy) {
 			/* We've eaten all the data from this skb.
 			 * Throw it away. */
 			TCP_SKB_CB(nskb)->tcp_flags |= TCP_SKB_CB(skb)->tcp_flags;
@@ -1977,7 +1977,7 @@  static int tcp_mtu_probe(struct sock *sk)
 
 		len += copy;
 
-		if (len >= probe_size)
+		if (len == probe_size)
 			break;
 	}
 	tcp_init_tso_segs(sk, nskb, nskb->len);