From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932814AbcA0ONa (ORCPT ); Wed, 27 Jan 2016 09:13:30 -0500 Received: from unicorn.mansr.com ([81.2.72.234]:36403 "EHLO unicorn.mansr.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932457AbcA0ONZ convert rfc822-to-8bit (ORCPT ); Wed, 27 Jan 2016 09:13:25 -0500 From: =?iso-8859-1?Q?M=E5ns_Rullg=E5rd?= To: Arnd Bergmann Cc: "David S. Miller" , linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 8/9] net: nb8800: avoid uninitialized variable warning References: <1453903507-3427225-1-git-send-email-arnd@arndb.de> <1453903507-3427225-9-git-send-email-arnd@arndb.de> Date: Wed, 27 Jan 2016 14:13:16 +0000 In-Reply-To: <1453903507-3427225-9-git-send-email-arnd@arndb.de> (Arnd Bergmann's message of "Wed, 27 Jan 2016 15:04:58 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Arnd Bergmann writes: > The nb8800_poll() function initializes the 'next' variable in the > loop looking for new input data. We know this will be called at > least once because 'budget' is a guaranteed to be a positive number > when we enter the function, but the compiler doesn't know that > and warns when the variable is used later: > > drivers/net/ethernet/aurora/nb8800.c: In function 'nb8800_poll': > drivers/net/ethernet/aurora/nb8800.c:350:21: warning: 'next' may be used uninitialized in this function [-Wmaybe-uninitialized] Which gcc version is this? 4.9 doesn't warn here, presumably because it's clever enough to notice that the offending use of 'next' is under a condition that can only be true if the first one was. Of course fixing the code so older compilers don't warn is a good idea. > Changing the 'while() {}' loop to 'do {} while()' makes it obvious > to the compiler what is going on so it no longer warns. > > Signed-off-by: Arnd Bergmann Acked-by: Mans Rullgard > --- > drivers/net/ethernet/aurora/nb8800.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/ethernet/aurora/nb8800.c b/drivers/net/ethernet/aurora/nb8800.c > index ecc4a334c507..f71ab2647a3b 100644 > --- a/drivers/net/ethernet/aurora/nb8800.c > +++ b/drivers/net/ethernet/aurora/nb8800.c > @@ -302,7 +302,7 @@ static int nb8800_poll(struct napi_struct *napi, int budget) > nb8800_tx_done(dev); > > again: > - while (work < budget) { > + do { > struct nb8800_rx_buf *rxb; > unsigned int len; > > @@ -330,7 +330,7 @@ again: > rxd->report = 0; > last = next; > work++; > - } > + } while (work < budget); > > if (work) { > priv->rx_descs[last].desc.config |= DESC_EOC; > -- > 2.7.0 > -- Måns Rullgård