linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: ipv4: tcp.c: fix an assignment in an if condition
@ 2022-03-12 16:27 Alexander Vorwerk
  2022-03-12 17:19 ` Al Viro
  2022-03-12 17:19 ` Stephen Hemminger
  0 siblings, 2 replies; 3+ messages in thread
From: Alexander Vorwerk @ 2022-03-12 16:27 UTC (permalink / raw)
  To: edumazet, davem, yoshfuji, dsahern, kuba
  Cc: netdev, linux-kernel, Alexander Vorwerk

reported by checkpatch.pl

Signed-off-by: Alexander Vorwerk <alexander.vorwerk@stud.uni-goettingen.de>
---
 net/ipv4/tcp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 28ff2a820f7c..7fa6e7e6ea80 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -959,10 +959,10 @@ static struct sk_buff *tcp_build_frag(struct sock *sk, int size_goal, int flags,
 	struct sk_buff *skb = tcp_write_queue_tail(sk);
 	struct tcp_sock *tp = tcp_sk(sk);
 	bool can_coalesce;
-	int copy, i;
+	int copy = size_goal - skb->len;
+	int i;
 
-	if (!skb || (copy = size_goal - skb->len) <= 0 ||
-	    !tcp_skb_can_collapse_to(skb)) {
+	if (!skb || copy <= 0 || !tcp_skb_can_collapse_to(skb)) {
 new_segment:
 		if (!sk_stream_memory_free(sk))
 			return NULL;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: ipv4: tcp.c: fix an assignment in an if condition
  2022-03-12 16:27 [PATCH] net: ipv4: tcp.c: fix an assignment in an if condition Alexander Vorwerk
@ 2022-03-12 17:19 ` Al Viro
  2022-03-12 17:19 ` Stephen Hemminger
  1 sibling, 0 replies; 3+ messages in thread
From: Al Viro @ 2022-03-12 17:19 UTC (permalink / raw)
  To: Alexander Vorwerk
  Cc: edumazet, davem, yoshfuji, dsahern, kuba, netdev, linux-kernel

On Sat, Mar 12, 2022 at 05:27:44PM +0100, Alexander Vorwerk wrote:
> reported by checkpatch.pl

... nicely demonstrating why checkpatch.pl is a menace.

> Signed-off-by: Alexander Vorwerk <alexander.vorwerk@stud.uni-goettingen.de>
> ---
>  net/ipv4/tcp.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index 28ff2a820f7c..7fa6e7e6ea80 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -959,10 +959,10 @@ static struct sk_buff *tcp_build_frag(struct sock *sk, int size_goal, int flags,
>  	struct sk_buff *skb = tcp_write_queue_tail(sk);
>  	struct tcp_sock *tp = tcp_sk(sk);
>  	bool can_coalesce;
> -	int copy, i;
> +	int copy = size_goal - skb->len;
> +	int i;
>  
> -	if (!skb || (copy = size_goal - skb->len) <= 0 ||
> -	    !tcp_skb_can_collapse_to(skb)) {
> +	if (!skb || copy <= 0 || !tcp_skb_can_collapse_to(skb)) {

	What is going to happen when you variant runs into
skb == NULL?  And if for some reason that cannot happen, where
is the explanation of that reason?

	IOW, this patch ends up quietly introducing a bug, with
no better rationale than "checkpatch.pl pointed me to that line".

NAKed-by: Al Viro <viro@zeniv.linux.org.uk>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: ipv4: tcp.c: fix an assignment in an if condition
  2022-03-12 16:27 [PATCH] net: ipv4: tcp.c: fix an assignment in an if condition Alexander Vorwerk
  2022-03-12 17:19 ` Al Viro
@ 2022-03-12 17:19 ` Stephen Hemminger
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2022-03-12 17:19 UTC (permalink / raw)
  To: Alexander Vorwerk
  Cc: edumazet, davem, yoshfuji, dsahern, kuba, netdev, linux-kernel

On Sat, 12 Mar 2022 17:27:44 +0100
Alexander Vorwerk <alexander.vorwerk@stud.uni-goettingen.de> wrote:

> reported by checkpatch.pl
> 
> Signed-off-by: Alexander Vorwerk <alexander.vorwerk@stud.uni-goettingen.de>
> ---
>  net/ipv4/tcp.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index 28ff2a820f7c..7fa6e7e6ea80 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -959,10 +959,10 @@ static struct sk_buff *tcp_build_frag(struct sock *sk, int size_goal, int flags,
>  	struct sk_buff *skb = tcp_write_queue_tail(sk);
>  	struct tcp_sock *tp = tcp_sk(sk);
>  	bool can_coalesce;
> -	int copy, i;
> +	int copy = size_goal - skb->len;
> +	int i;
>  
> -	if (!skb || (copy = size_goal - skb->len) <= 0 ||
> -	    !tcp_skb_can_collapse_to(skb)) {
> +	if (!skb || copy <= 0 || !tcp_skb_can_collapse_to(skb)) {
>  new_segment:
>  		if (!sk_stream_memory_free(sk))
>  			return NULL;

Your new code will crash if skb is NULL.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-03-12 17:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-12 16:27 [PATCH] net: ipv4: tcp.c: fix an assignment in an if condition Alexander Vorwerk
2022-03-12 17:19 ` Al Viro
2022-03-12 17:19 ` Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).