All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: tap: remove redundant assignments
@ 2021-02-22 14:57 Tang Bin
  2021-02-23  0:53 ` Jakub Kicinski
  0 siblings, 1 reply; 2+ messages in thread
From: Tang Bin @ 2021-02-22 14:57 UTC (permalink / raw)
  To: davem, kuba; +Cc: netdev, linux-kernel, Tang Bin

In the function tap_get_user, the assignment of 'err' at both places
is redundant, so remove one.

Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com>
---
 drivers/net/tap.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/net/tap.c b/drivers/net/tap.c
index 1f4bdd944..3e9c72738 100644
--- a/drivers/net/tap.c
+++ b/drivers/net/tap.c
@@ -625,7 +625,7 @@ static ssize_t tap_get_user(struct tap_queue *q, void *msg_control,
 	struct tap_dev *tap;
 	unsigned long total_len = iov_iter_count(from);
 	unsigned long len = total_len;
-	int err;
+	int err = -EINVAL;
 	struct virtio_net_hdr vnet_hdr = { 0 };
 	int vnet_hdr_len = 0;
 	int copylen = 0;
@@ -636,7 +636,6 @@ static ssize_t tap_get_user(struct tap_queue *q, void *msg_control,
 	if (q->flags & IFF_VNET_HDR) {
 		vnet_hdr_len = READ_ONCE(q->vnet_hdr_sz);
 
-		err = -EINVAL;
 		if (len < vnet_hdr_len)
 			goto err;
 		len -= vnet_hdr_len;
@@ -657,7 +656,6 @@ static ssize_t tap_get_user(struct tap_queue *q, void *msg_control,
 			goto err;
 	}
 
-	err = -EINVAL;
 	if (unlikely(len < ETH_HLEN))
 		goto err;
 
-- 
2.20.1.windows.1




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

* Re: [PATCH] net: tap: remove redundant assignments
  2021-02-22 14:57 [PATCH] net: tap: remove redundant assignments Tang Bin
@ 2021-02-23  0:53 ` Jakub Kicinski
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2021-02-23  0:53 UTC (permalink / raw)
  To: Tang Bin; +Cc: davem, netdev, linux-kernel

On Mon, 22 Feb 2021 22:57:48 +0800 Tang Bin wrote:
> In the function tap_get_user, the assignment of 'err' at both places
> is redundant, so remove one.
> 
> Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com>
> ---
>  drivers/net/tap.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/net/tap.c b/drivers/net/tap.c
> index 1f4bdd944..3e9c72738 100644
> --- a/drivers/net/tap.c
> +++ b/drivers/net/tap.c
> @@ -625,7 +625,7 @@ static ssize_t tap_get_user(struct tap_queue *q, void *msg_control,
>  	struct tap_dev *tap;
>  	unsigned long total_len = iov_iter_count(from);
>  	unsigned long len = total_len;
> -	int err;
> +	int err = -EINVAL;
>  	struct virtio_net_hdr vnet_hdr = { 0 };
>  	int vnet_hdr_len = 0;
>  	int copylen = 0;
> @@ -636,7 +636,6 @@ static ssize_t tap_get_user(struct tap_queue *q, void *msg_control,
>  	if (q->flags & IFF_VNET_HDR) {
>  		vnet_hdr_len = READ_ONCE(q->vnet_hdr_sz);
>  
> -		err = -EINVAL;
>  		if (len < vnet_hdr_len)
>  			goto err;
>  		len -= vnet_hdr_len;
> @@ -657,7 +656,6 @@ static ssize_t tap_get_user(struct tap_queue *q, void *msg_control,
>  			goto err;
>  	}
>  
> -	err = -EINVAL;
>  	if (unlikely(len < ETH_HLEN))
>  		goto err;
>  

Assigning err close to the gotos makes the code more robust and easier
to read. No applying this, sorry.

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

end of thread, other threads:[~2021-02-23  0:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-22 14:57 [PATCH] net: tap: remove redundant assignments Tang Bin
2021-02-23  0:53 ` Jakub Kicinski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.