From patchwork Wed Nov 16 14:18:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 9431695 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D6CF960469 for ; Wed, 16 Nov 2016 14:21:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C511528682 for ; Wed, 16 Nov 2016 14:21:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B715128DEC; Wed, 16 Nov 2016 14:21:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4D39C28682 for ; Wed, 16 Nov 2016 14:21:23 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1c713g-00015X-F8; Wed, 16 Nov 2016 14:19:28 +0000 Received: from mout.kundenserver.de ([212.227.17.13]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1c713a-000148-HL for linux-arm-kernel@lists.infradead.org; Wed, 16 Nov 2016 14:19:24 +0000 Received: from wuerfel.lan ([78.43.21.235]) by mrelayeu.kundenserver.de (mreue101 [212.227.15.145]) with ESMTPA (Nemesis) id 0LsyHC-1cnO0E1EmQ-012cS5; Wed, 16 Nov 2016 15:18:52 +0100 From: Arnd Bergmann To: Linus Walleij Subject: [PATCH] pinctrl: sunxi: fix theoretical uninitialized variable access Date: Wed, 16 Nov 2016 15:18:18 +0100 Message-Id: <20161116141841.2030776-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:l3EmxQoWRKFJuqqXb9/f4YZIqAAeH7LZjeE7kjbWoVAIsKl8SPD pKq2yvanp7bwsnOAsWAy4w8v7e+OiCYiORlFryz3dLsQAZEhONFjRSR2MtZ7jUQt+h/p+F4 1TChL9z6c+awqCONYkRMMlUBzYuVuyFlECYAqjPsXnERbOfga5IgBxiyfph8YxFBkODwSub ROUKkA0lhYey4XHuwb4LA== X-UI-Out-Filterresults: notjunk:1; V01:K0:ecOrMZZAo5o=:6/pnibH6eX2te+1R4rrpPa FILLKUXcj0B4NSt9UbiZVC4kbf+woFlGEszrxgjivCYJ5fX3QSKvQLsnfwysAIDMIqjS7/vwD a/e3XGwwvUXc6bEz/n6KuV4YPwcRqrM/Mub/MBXDg1Hx5hw0rDEWjFxzrB+3Y8tGzu8akcQ0W ZshTjm2qaPdw6zH57jADtlNFDNmbro+0/fzTUXAL5s7YCDG8sDtqf1Ts+Exdh78srkmwo3i9B uVIqeEf3jh0d4Wb/4asrT7JtNjk73f5YoQuLDPClMCQLEXluxFzCOZxmgmVBq2oPqNGHO7cfu YCqHv78qclcK5fwxIYUBRyDLqCh3yCrcDqYwG0nc2/+D9V9LBtzf067I9uITXWP7bz/IpgYNl ZSf3ItPmcizBqf/o1qOWyhpUTv7hfESlGrFPX54I0DkoLUCq1CsGZLG6Nn7HVE8SSK+G2/DtA tYvvHmh6TZ+/D7d9/NMZVjstFqsOqlAiiAdUS3P7DqXc0kj8d4yuMJBkQhm9R0P4suzAfgUnG SqbS27FsyFS+xRxtdLEDbBJuXl4EFVKS8mJjwyNgPoK9+ltmRpjJ3MoGwWtIOXDyu/SgbW3es RBhPQcfa0q06NKHvNIXo6UN45iYxL9YpQepUuxZalfdZnubalctSb7oZ5a5ectCUxHZx91DPM vKaZmegoR3JKLYR/eB09eY1jm7wzsK9Uo4/WymY3DZBrkJlAfx1rmHlIqcvQlaeaEgIfnqCgC btMOEeK0B6bRQB5jEP8bl4gHuPrBZNAhcFNKXZuHoB7fb0LOEvDBvX6nkI3VhOzIuzHrFb1yt rbLx+2g X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161116_061922_912173_757A1138 X-CRM114-Status: GOOD ( 13.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Arnd Bergmann , linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, Chen-Yu Tsai , Maxime Ripard , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP gcc warns about a way that it could use an uninitialized variable: drivers/pinctrl/sunxi/pinctrl-sunxi.c: In function 'sunxi_pinctrl_init': drivers/pinctrl/sunxi/pinctrl-sunxi.c:1191:8: error: 'best_div' may be used uninitialized in this function [-Werror=maybe-uninitialized] This cannot really happen except if 'freq' is UINT_MAX and 'clock' is zero, and both of these are forbidden. To shut up the warning anyway, this changes the logic to initialize the return code to the first divider value before looking at the others. Fixes: 7c926492d38a ("pinctrl: sunxi: Add support for interrupt debouncing") Signed-off-by: Arnd Bergmann --- drivers/pinctrl/sunxi/pinctrl-sunxi.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c index 2339d4718b4d..6b7953da4228 100644 --- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c +++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c @@ -1125,10 +1125,13 @@ static int sunxi_pinctrl_build_state(struct platform_device *pdev) static int sunxi_pinctrl_get_debounce_div(struct clk *clk, int freq, int *diff) { unsigned long clock = clk_get_rate(clk); - unsigned int best_diff = ~0, best_div; + unsigned int best_diff, best_div; int i; - for (i = 0; i < 8; i++) { + best_diff = abs(freq - clock); + best_div = 0; + + for (i = 1; i < 8; i++) { int cur_diff = abs(freq - (clock >> i)); if (cur_diff < best_diff) {