Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1300003 > unrolled thread

[PATCH] net: hns: avoid uninitialized variable warning:

Started byArnd Bergmann <arnd@arndb.de>
First post2016-01-01 23:30 +0100
Last post2016-01-06 06:10 +0100
Articles 5 — 4 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] net: hns: avoid uninitialized variable warning: Arnd Bergmann <arnd@arndb.de> - 2016-01-01 23:30 +0100
    Re: [PATCH] net: hns: avoid uninitialized variable warning: David Miller <davem@davemloft.net> - 2016-01-05 22:50 +0100
      Re: [PATCH] net: hns: avoid uninitialized variable warning: Salil Mehta <salil.mehta@huawei.com> - 2016-01-06 16:40 +0100
    Re: [PATCH] net: hns: avoid uninitialized variable warning: Yisen Zhuang <Yisen.zhuang@huawei.com> - 2016-01-06 02:00 +0100
    Re: [PATCH] net: hns: avoid uninitialized variable warning: David Miller <davem@davemloft.net> - 2016-01-06 06:10 +0100

#1300003 — [PATCH] net: hns: avoid uninitialized variable warning:

FromArnd Bergmann <arnd@arndb.de>
Date2016-01-01 23:30 +0100
Subject[PATCH] net: hns: avoid uninitialized variable warning:
Message-ID<qMgmT-8i1-17@gated-at.bofh.it>
gcc fails to see that the use of the 'last_offset' variable
in hns_nic_reuse_page() is used correctly and issues a bogus
warning:

drivers/net/ethernet/hisilicon/hns/hns_enet.c: In function 'hns_nic_reuse_page':
drivers/net/ethernet/hisilicon/hns/hns_enet.c:541:6: warning: 'last_offset' may be used uninitialized in this function [-Wmaybe-uninitialized]

This simplifies the function to make it more obvious what is
going on to both readers and compilers, which makes the warning
go away.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
Compile-tested only, and complex enough that this requires a proper
review and testing before it gets apply. Please have a look at this.

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index 5a81dafd725e..0e30846a24f8 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -499,50 +499,47 @@ static void hns_nic_reuse_page(struct sk_buff *skb, int i,
 	struct hnae_desc *desc;
 	int truesize, size;
 	int last_offset;
+	bool twobufs;
+
+	twobufs = ((PAGE_SIZE < 8192) && hnae_buf_size(ring) == HNS_BUFFER_SIZE_2048);
 
 	desc = &ring->desc[ring->next_to_clean];
 	size = le16_to_cpu(desc->rx.size);
 
-#if (PAGE_SIZE < 8192)
-	if (hnae_buf_size(ring) == HNS_BUFFER_SIZE_2048) {
+	if (twobufs) {
 		truesize = hnae_buf_size(ring);
 	} else {
 		truesize = ALIGN(size, L1_CACHE_BYTES);
 		last_offset = hnae_page_size(ring) - hnae_buf_size(ring);
 	}
 
-#else
-	truesize = ALIGN(size, L1_CACHE_BYTES);
-	last_offset = hnae_page_size(ring) - hnae_buf_size(ring);
-#endif
-
 	skb_add_rx_frag(skb, i, desc_cb->priv, desc_cb->page_offset + pull_len,
 			size - pull_len, truesize - pull_len);
 
 	 /* avoid re-using remote pages,flag default unreuse */
-	if (likely(page_to_nid(desc_cb->priv) == numa_node_id())) {
-#if (PAGE_SIZE < 8192)
-		if (hnae_buf_size(ring) == HNS_BUFFER_SIZE_2048) {
-			/* if we are only owner of page we can reuse it */
-			if (likely(page_count(desc_cb->priv) == 1)) {
-				/* flip page offset to other buffer */
-				desc_cb->page_offset ^= truesize;
-
-				desc_cb->reuse_flag = 1;
-				/* bump ref count on page before it is given*/
-				get_page(desc_cb->priv);
-			}
-			return;
-		}
-#endif
-		/* move offset up to the next cache line */
-		desc_cb->page_offset += truesize;
+	if (unlikely(page_to_nid(desc_cb->priv) != numa_node_id()))
+		return;
+
+	if (twobufs) {
+		/* if we are only owner of page we can reuse it */
+		if (likely(page_count(desc_cb->priv) == 1)) {
+			/* flip page offset to other buffer */
+			desc_cb->page_offset ^= truesize;
 
-		if (desc_cb->page_offset <= last_offset) {
 			desc_cb->reuse_flag = 1;
 			/* bump ref count on page before it is given*/
 			get_page(desc_cb->priv);
 		}
+		return;
+	}
+
+	/* move offset up to the next cache line */
+	desc_cb->page_offset += truesize;
+
+	if (desc_cb->page_offset <= last_offset) {
+		desc_cb->reuse_flag = 1;
+		/* bump ref count on page before it is given*/
+		get_page(desc_cb->priv);
 	}
 }
 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1302232

FromDavid Miller <davem@davemloft.net>
Date2016-01-05 22:50 +0100
Message-ID<qNHEm-cI-11@gated-at.bofh.it>
In reply to#1300003
From: Arnd Bergmann <arnd@arndb.de>
Date: Fri, 01 Jan 2016 23:27:57 +0100

> gcc fails to see that the use of the 'last_offset' variable
> in hns_nic_reuse_page() is used correctly and issues a bogus
> warning:
> 
> drivers/net/ethernet/hisilicon/hns/hns_enet.c: In function 'hns_nic_reuse_page':
> drivers/net/ethernet/hisilicon/hns/hns_enet.c:541:6: warning: 'last_offset' may be used uninitialized in this function [-Wmaybe-uninitialized]
> 
> This simplifies the function to make it more obvious what is
> going on to both readers and compilers, which makes the warning
> go away.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> Compile-tested only, and complex enough that this requires a proper
> review and testing before it gets apply. Please have a look at this.

If this goes yet another day without being reviewed, I'm just applying
it.

You hisilicon folks can't just let patches rot, you must review them
in a timely manner or else I'm applying them without waiting for you
to look at them.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1302851

FromSalil Mehta <salil.mehta@huawei.com>
Date2016-01-06 16:40 +0100
Message-ID<qNYlP-326-1@gated-at.bofh.it>
In reply to#1302232
On 1/5/2016 9:43 PM, David Miller wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> Date: Fri, 01 Jan 2016 23:27:57 +0100
>
>> gcc fails to see that the use of the 'last_offset' variable
>> in hns_nic_reuse_page() is used correctly and issues a bogus
>> warning:
>>
>> drivers/net/ethernet/hisilicon/hns/hns_enet.c: In function 'hns_nic_reuse_page':
>> drivers/net/ethernet/hisilicon/hns/hns_enet.c:541:6: warning: 'last_offset' may be used uninitialized in this function [-Wmaybe-uninitialized]
>>
>> This simplifies the function to make it more obvious what is
>> going on to both readers and compilers, which makes the warning
>> go away.
>>
>> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>> ---
>> Compile-tested only, and complex enough that this requires a proper
>> review and testing before it gets apply. Please have a look at this.
> If this goes yet another day without being reviewed, I'm just applying
> it.
>
> You hisilicon folks can't just let patches rot, you must review them
> in a timely manner or else I'm applying them without waiting for you
> to look at them.
Hi David and Arnd,
Apologies for the delay in response and the review. Most of us were on 
the Annual Holidays and have just returned back.

Change looks good to me!

Best Regards
Salil


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1302298

FromYisen Zhuang <Yisen.zhuang@huawei.com>
Date2016-01-06 02:00 +0100
Message-ID<qNKCe-299-13@gated-at.bofh.it>
In reply to#1300003

在 2016/1/2 6:27, Arnd Bergmann 写道:
> gcc fails to see that the use of the 'last_offset' variable
> in hns_nic_reuse_page() is used correctly and issues a bogus
> warning:
> 
> drivers/net/ethernet/hisilicon/hns/hns_enet.c: In function 'hns_nic_reuse_page':
> drivers/net/ethernet/hisilicon/hns/hns_enet.c:541:6: warning: 'last_offset' may be used uninitialized in this function [-Wmaybe-uninitialized]
> 
> This simplifies the function to make it more obvious what is
> going on to both readers and compilers, which makes the warning
> go away.
> 


Hi Arnd,

This patch is fine to me.

Many thanks,
Yisen

> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> Compile-tested only, and complex enough that this requires a proper
> review and testing before it gets apply. Please have a look at this.
> 
> diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
> index 5a81dafd725e..0e30846a24f8 100644
> --- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
> +++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
> @@ -499,50 +499,47 @@ static void hns_nic_reuse_page(struct sk_buff *skb, int i,
>  	struct hnae_desc *desc;
>  	int truesize, size;
>  	int last_offset;
> +	bool twobufs;
> +
> +	twobufs = ((PAGE_SIZE < 8192) && hnae_buf_size(ring) == HNS_BUFFER_SIZE_2048);
>  
>  	desc = &ring->desc[ring->next_to_clean];
>  	size = le16_to_cpu(desc->rx.size);
>  
> -#if (PAGE_SIZE < 8192)
> -	if (hnae_buf_size(ring) == HNS_BUFFER_SIZE_2048) {
> +	if (twobufs) {
>  		truesize = hnae_buf_size(ring);
>  	} else {
>  		truesize = ALIGN(size, L1_CACHE_BYTES);
>  		last_offset = hnae_page_size(ring) - hnae_buf_size(ring);
>  	}
>  
> -#else
> -	truesize = ALIGN(size, L1_CACHE_BYTES);
> -	last_offset = hnae_page_size(ring) - hnae_buf_size(ring);
> -#endif
> -
>  	skb_add_rx_frag(skb, i, desc_cb->priv, desc_cb->page_offset + pull_len,
>  			size - pull_len, truesize - pull_len);
>  
>  	 /* avoid re-using remote pages,flag default unreuse */
> -	if (likely(page_to_nid(desc_cb->priv) == numa_node_id())) {
> -#if (PAGE_SIZE < 8192)
> -		if (hnae_buf_size(ring) == HNS_BUFFER_SIZE_2048) {
> -			/* if we are only owner of page we can reuse it */
> -			if (likely(page_count(desc_cb->priv) == 1)) {
> -				/* flip page offset to other buffer */
> -				desc_cb->page_offset ^= truesize;
> -
> -				desc_cb->reuse_flag = 1;
> -				/* bump ref count on page before it is given*/
> -				get_page(desc_cb->priv);
> -			}
> -			return;
> -		}
> -#endif
> -		/* move offset up to the next cache line */
> -		desc_cb->page_offset += truesize;
> +	if (unlikely(page_to_nid(desc_cb->priv) != numa_node_id()))
> +		return;
> +
> +	if (twobufs) {
> +		/* if we are only owner of page we can reuse it */
> +		if (likely(page_count(desc_cb->priv) == 1)) {
> +			/* flip page offset to other buffer */
> +			desc_cb->page_offset ^= truesize;
>  
> -		if (desc_cb->page_offset <= last_offset) {
>  			desc_cb->reuse_flag = 1;
>  			/* bump ref count on page before it is given*/
>  			get_page(desc_cb->priv);
>  		}
> +		return;
> +	}
> +
> +	/* move offset up to the next cache line */
> +	desc_cb->page_offset += truesize;
> +
> +	if (desc_cb->page_offset <= last_offset) {
> +		desc_cb->reuse_flag = 1;
> +		/* bump ref count on page before it is given*/
> +		get_page(desc_cb->priv);
>  	}
>  }
>  
> 
> 
> .
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1302402

FromDavid Miller <davem@davemloft.net>
Date2016-01-06 06:10 +0100
Message-ID<qNOwa-546-13@gated-at.bofh.it>
In reply to#1300003
From: Arnd Bergmann <arnd@arndb.de>
Date: Fri, 01 Jan 2016 23:27:57 +0100

> gcc fails to see that the use of the 'last_offset' variable
> in hns_nic_reuse_page() is used correctly and issues a bogus
> warning:
> 
> drivers/net/ethernet/hisilicon/hns/hns_enet.c: In function 'hns_nic_reuse_page':
> drivers/net/ethernet/hisilicon/hns/hns_enet.c:541:6: warning: 'last_offset' may be used uninitialized in this function [-Wmaybe-uninitialized]
> 
> This simplifies the function to make it more obvious what is
> going on to both readers and compilers, which makes the warning
> go away.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Applied, thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web