From patchwork Mon Jan 25 16:02:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 101108 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp1442785lbb; Mon, 25 Jan 2016 08:03:21 -0800 (PST) X-Received: by 10.98.32.156 with SMTP id m28mr26917093pfj.74.1453737801470; Mon, 25 Jan 2016 08:03:21 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qh1si3018528pac.241.2016.01.25.08.03.20; Mon, 25 Jan 2016 08:03:21 -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 S933412AbcAYQDR (ORCPT + 30 others); Mon, 25 Jan 2016 11:03:17 -0500 Received: from mout.kundenserver.de ([212.227.126.130]:54611 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932879AbcAYQDL (ORCPT ); Mon, 25 Jan 2016 11:03:11 -0500 Received: from wuerfel.lan. ([78.42.132.4]) by mrelayeu.kundenserver.de (mreue004) with ESMTPA (Nemesis) id 0MXkot-1aZXBV0Yf1-00WmhL; Mon, 25 Jan 2016 17:02:42 +0100 From: Arnd Bergmann To: Lee Jones Cc: linux-arm-kernel@lists.infradead.org, Arnd Bergmann , Linus Walleij , linux-kernel@vger.kernel.org Subject: [PATCH] mfd: db8500: avoid uninitialized variable reference Date: Mon, 25 Jan 2016 17:02:24 +0100 Message-Id: <1453737752-1960326-1-git-send-email-arnd@arndb.de> X-Mailer: git-send-email 2.7.0 X-Provags-ID: V03:K0:zjjCnkLHnEEABlVg88dpxKWVy0tX0qpXw4chjFwnoEtZNSWO/3t ylgMibg7unJ94H36M93bO5ftVX5YT11N0q+c2j8hiPVGoV3Vlpgt7hY0CZDh9bIjDEPJU/J ETf5IcomYlswbWqy9kdc6B7Hb0ZSofnwds/TrG9Eb5SYg2TAjZP/iaVlxrAD3W+WaOUj3xQ NvEep+LAvgxkXAycG4/PQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:SwduD2sc6c8=:zSwcz1h4TJPLkI6u34pRTi f0w76YFZrtJTArVTdlK5A3GtKdHOMnYkydy+LPUamSSJKo2iaPRW6gd8nWta+0daxMpyVRVzz uNYkqbsXcER8qkYrpOki8KP5KOixEYGENQa1dqdxyZppxI7fqHGcAQkBfRV6Q9GRhj/UTWxvN aV1/J9+JIGu0Q+K+osjElAj+XVZ3vNNFbUiUtzMb2yWschHwmW2hoPtctoknvrxKOAH5sJ6ku y3ITRyYH419UOYuy/v82iQUMwo8wXjOUbd2qzHRWKUffK5GgLO2F43Tg+po+P3IbULMzFUXW2 a33iK1nIUeggXmiVuZLR/N21b71SUIXq5lRrWZk+Qzgi2RFuse4pkkW4ElMIuIEXObD5dWiWz N0KiaVXfJf3XpqYd7ht9rNUB7KywvpeRvXPZC5ANBAEkOUQIeWy2I5A7W81SMO8Ymbd+56RsM gd3cRfgXoUJlKiNAdQz5gHblcWByqEdh3FL7FrDzxoPAEBiw3Qgr1gZ3oFOSxVoA0dyDWyE47 Xe0Hrj2aOkdvbvNHfimmfaLr8DAFIUHlh7gNTC9ogp3mxYmiMtkySI1QRZzYp6zO2OZd7/wf5 gAdkjzPP5lK6ye3PRzknXjAJGxobBAFjiRUwjNYFkrOcVNOSFVSdvqy1AHcs6pcb8RpcJukGX dCkxbbkxK1vgIHA9UCRh+m+ecLsSNErT09DocTqK4JWwExxBDp7U7gtqYD07vXjREFFI= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The prcmu_config_clkout() function ensures that the 'clkout' argument can only be '0' or '1' using an appropriate BUG_ON(), so the compiler should know that the div_mask, mask, and bits variables are always initialized later on. However, it doesn't understand this in gcc-5.2 and produces a false positive warning instead: drivers/mfd/db8500-prcmu.c: In function 'prcmu_config_clkout': drivers/mfd/db8500-prcmu.c:762:10: error: 'div_mask' may be used uninitialized in this function [-Werror=maybe-uninitialized] if (val & div_mask) { ^ drivers/mfd/db8500-prcmu.c:769:13: error: 'mask' may be used uninitialized in this function [-Werror=maybe-uninitialized] if ((val & mask & ~div_mask) != bits) { ^ drivers/mfd/db8500-prcmu.c:757:7: error: 'bits' may be used uninitialized in this function [-Werror=maybe-uninitialized] Replacing the switch() statement with an equivalent if() lets gcc figure this out reliably and avoids the warnings. Signed-off-by: Arnd Bergmann --- drivers/mfd/db8500-prcmu.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) -- 2.7.0 Acked-by: Linus Walleij diff --git a/drivers/mfd/db8500-prcmu.c b/drivers/mfd/db8500-prcmu.c index 12099b09a9a7..c0a86aeb1733 100644 --- a/drivers/mfd/db8500-prcmu.c +++ b/drivers/mfd/db8500-prcmu.c @@ -739,20 +739,17 @@ int prcmu_config_clkout(u8 clkout, u8 source, u8 div) if (!div && !requests[clkout]) return -EINVAL; - switch (clkout) { - case 0: + if (clkout == 0) { div_mask = PRCM_CLKOCR_CLKODIV0_MASK; mask = (PRCM_CLKOCR_CLKODIV0_MASK | PRCM_CLKOCR_CLKOSEL0_MASK); bits = ((source << PRCM_CLKOCR_CLKOSEL0_SHIFT) | (div << PRCM_CLKOCR_CLKODIV0_SHIFT)); - break; - case 1: + } else { div_mask = PRCM_CLKOCR_CLKODIV1_MASK; mask = (PRCM_CLKOCR_CLKODIV1_MASK | PRCM_CLKOCR_CLKOSEL1_MASK | PRCM_CLKOCR_CLK1TYPE); bits = ((source << PRCM_CLKOCR_CLKOSEL1_SHIFT) | (div << PRCM_CLKOCR_CLKODIV1_SHIFT)); - break; } bits &= mask;