From patchwork Fri Jan 1 22:27:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 101219 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp4160405lbb; Fri, 1 Jan 2016 14:28:53 -0800 (PST) X-Received: by 10.98.12.218 with SMTP id 87mr52680698pfm.54.1451687333800; Fri, 01 Jan 2016 14:28:53 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id rq5si31865679pab.160.2016.01.01.14.28.53; Fri, 01 Jan 2016 14:28:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752567AbcAAW2v (ORCPT + 29 others); Fri, 1 Jan 2016 17:28:51 -0500 Received: from mout.kundenserver.de ([217.72.192.73]:60469 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752086AbcAAW2r (ORCPT ); Fri, 1 Jan 2016 17:28:47 -0500 Received: from wuerfel.localnet ([134.3.118.24]) by mrelayeu.kundenserver.de (mreue104) with ESMTPSA (Nemesis) id 0MDgeU-1aSokX1G8M-00H5zp; Fri, 01 Jan 2016 23:28:03 +0100 From: Arnd Bergmann To: "David S. Miller" Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Yisen Zhuang , yankejian@huawei.com, lisheng011@huawei.com, huangdaode@hisilicon.com, salil.mehta@huawei.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH] net: hns: avoid uninitialized variable warning: Date: Fri, 01 Jan 2016 23:27:57 +0100 Message-ID: <6649249.INrAY8KJG0@wuerfel> User-Agent: KMail/4.11.5 (Linux/3.16.0-10-generic; KDE/4.11.5; x86_64; ; ) MIME-Version: 1.0 X-Provags-ID: V03:K0:xM1HYmiuvjWPqs9QUGcx0+tbBBmD5+LPd8Mf2xUPAstPp5690WS uKryNtmpQB7YwI4WFsnsVwsrMi6ncpwR10YWOXVFyZ9W2Nf92Z1/aTI2ITD/VGHkHun6Rlr lWZgTpFb8Hwn9Wpxrhzm/ivhrVJrN1vxNl1o0EnPC6/fiyZ8e5+xzpHaq7eB8BctFPAav3K vovCXT8Ixe7M1790c94Vw== X-UI-Out-Filterresults: notjunk:1; V01:K0:o+mDNlf/upQ=:U88bGBLU7JgvI6cDpnEuHI egwJ1VgO43wNg43GDwABb6/GausdqEEHuR8WRX3oVnZvfaAJvNPEpXc6bXcCEMl071VFkOubQ U2iX3Zqprs7v33Jh5iLaaISiuFzILncl6ZNg+P2QgkR2PMrdK9wJQ84USM6B+E3ThsvWCPd3r RH1eicsHWGn15ilLi7ndKXZN9LEDla50+nhhP5ksdjRc4Mp3QIao5KZpqzenI50RGbeYukqYv eY+VAFmYGf7dSCNHc2FghA7ytda0UUEDDi46CfGj9Vvb1ffOgccfC6Tmam9eeAvBCz+kmOd+h bbxxwncX5sJH/D64FOqbJK2Fg+ec4Q2hikb8WDclWBNCNMoc1AzWQltSUQ1lJT3SQqcGb6GBc x2njambFGV6yrjvGKs18LJBVsJ/fSDHtahRLcOQaJJbatzcO+U4JDiwTX9/gzoGY34q8iSYlQ yODT1RsY5pnTyfK2fpwl+is9NxAZRtn4c5ywPCdE3nd5Jad5uPLuaRaf0s2mJ/JKwNN2leFmv dYpvdde8nUR4nwCJqS1HmHXUsuWnTVyIqfBdtMgESXNyuM8gGCJzjtBofCJq9CRg9ZARdqd0l wDGZ1xtSrxNzfqSft2eObdfxNRlHBmZgnlSPqRVwjj58ZDHhksfUr9/A00KBWeoxnE1EXLiaj XnPmpzs6z61MOdYX2uAQlG6L/t6WT/8ARn7X+9o27Cn015ngJKVbJM+85j2ttUXPAfU7CpYah RRY7vzwAAFGrwlZB Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Compile-tested only, and complex enough that this requires a proper review and testing before it gets apply. Please have a look at this. -- 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/ 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); } }