From patchwork Wed Aug 10 21:54:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 101955 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp610047qga; Wed, 10 Aug 2016 14:58:18 -0700 (PDT) X-Received: by 10.98.101.1 with SMTP id z1mr10900721pfb.53.1470866298592; Wed, 10 Aug 2016 14:58:18 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ba3si50443966pab.87.2016.08.10.14.58.18; Wed, 10 Aug 2016 14:58:18 -0700 (PDT) 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 S933051AbcHJV56 (ORCPT + 27 others); Wed, 10 Aug 2016 17:57:58 -0400 Received: from mout.kundenserver.de ([212.227.126.135]:50438 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932179AbcHJV5z (ORCPT ); Wed, 10 Aug 2016 17:57:55 -0400 Received: from wuerfel.lan. ([78.42.132.4]) by mrelayeu.kundenserver.de (mreue005) with ESMTPA (Nemesis) id 0MDkte-1bRY2G07Cw-00H96d; Wed, 10 Aug 2016 23:57:38 +0200 From: Arnd Bergmann To: Daniel Lezcano , Thomas Gleixner Cc: Arnd Bergmann , Florian Fainelli , Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com, linux-kernel@vger.kernel.org Subject: [PATCH 6/9] clocksource: kona: fix get_counter error handling Date: Wed, 10 Aug 2016 23:54:12 +0200 Message-Id: <20160810215424.1926658-7-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160810215424.1926658-1-arnd@arndb.de> References: <20160810215424.1926658-1-arnd@arndb.de> X-Provags-ID: V03:K0:YSYbOIqA4zASuo1U6oc7BNu/iItSNiQDl55gCC3vymsb8j/nOUX J55EHFahO7FpjtX229WWr9tnHeB06rhD+EjatyVB2daSsLpB+wGAnHZfRLUlug+FBBx4qfD cEsGtHvX+kBcqU0kmPbi7km7Sva43441LQk5AWgX9D5AWm3peI4kIez1WfKlrpDniXjvKYP fibnek65m+xffJHbiho0g== X-UI-Out-Filterresults: notjunk:1; V01:K0:Es1kl2Wf3JA=:Lr+IEHeK1dwVOBnyy0XUMp ctrTV9eWCDfSPQmFX/TkSjgKW3xJKInbRZE/X7FoDbg/o0H59xLExTv4INZY2PhDMEnmijVve e4rCOUP7fpaCHRp5xkC2JCXiMnW29MEAM/IeAHi9XREaa5iMC4isFVcOESIAcdW9cAAF7OUsl 54AAdtd+jawbsOmjBVm2dG9o41BkQfPR19oj07aUcEi4Fid9+5bCMuMornPpMiURO+prnOIAg jAHjJEhGfpVE41NyrGwzuz69mZamvEANra2CyNkIyd7KQoP0c4VsK5aD2H6OVLHUkzVPqlKw+ mAC2dadCg/oVpvlYzuNf9Hg05WRRZbDvpJXrOvD1CAw3flGGObyL891D8l2xl8Zf9eKP3Yr18 YKfi8xGEm2hTHwh9IcEU5OAi3TCKiHR+aYtM9yBaGffbNzt205fvsxKKcj/90CUn+dFq2sDRf SAQtZm3DJFS28+8V1+FcBS7u8o32rcLYMyaWLSiBdjan3w6ncpn/X8bzKZV/pnk61yGoIAmUb yT5MiesWCpNH1AjPIe2YN613w2+D14SK8N/KTBRx2BFF8RtpU5ewY0li3pVDTnLHII8u573QE /frni6ZuudHKY8+v8lEtQIglCrN+6hXaksGzGucwqlWqyg7Tw60LxWZ2JC9yDSAioVpvvkCgx KISxKZisJgrw+SDSO6F48hBx9Jggx8CXO0G5hLxQiX1gWeT1M2HWOFhdUj9uzaq3W79s= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I could not figure out why, but gcc cannot prove that the kona_timer_init function always initializes its two outputs, and we get a warning for the use of the 'lsw' variable later, which is obviously correct. drivers/clocksource/bcm_kona_timer.c: In function 'kona_timer_init': drivers/clocksource/bcm_kona_timer.c:119:13: error: 'lsw' may be used uninitialized in this function [-Werror=maybe-uninitialized] Slightly reordering the loop makes the warning disappear, after it becomes more obvious to the compiler that the loop is always entered on the first iteration. As pointed out by Ray Jui, there is a related problem in the way we deal with the loop running into the limit, as we just keep going there with an invalid counter data, so instead we now propagate a -ETIMEDOUT result to the caller. Signed-off-by: Arnd Bergmann Link: https://patchwork.kernel.org/patch/9174261/ --- Originally sent this as a warning fix only on June 13, this version actually fixes the incorrect data problem. --- drivers/clocksource/bcm_kona_timer.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) -- 2.9.0 diff --git a/drivers/clocksource/bcm_kona_timer.c b/drivers/clocksource/bcm_kona_timer.c index 7e3fd375a627..92f6e4deee74 100644 --- a/drivers/clocksource/bcm_kona_timer.c +++ b/drivers/clocksource/bcm_kona_timer.c @@ -66,10 +66,10 @@ static void kona_timer_disable_and_clear(void __iomem *base) } -static void +static int kona_timer_get_counter(void __iomem *timer_base, uint32_t *msw, uint32_t *lsw) { - int loop_limit = 4; + int loop_limit = 3; /* * Read 64-bit free running counter @@ -83,18 +83,19 @@ kona_timer_get_counter(void __iomem *timer_base, uint32_t *msw, uint32_t *lsw) * if new hi-word is equal to previously read hi-word then stop. */ - while (--loop_limit) { + do { *msw = readl(timer_base + KONA_GPTIMER_STCHI_OFFSET); *lsw = readl(timer_base + KONA_GPTIMER_STCLO_OFFSET); if (*msw == readl(timer_base + KONA_GPTIMER_STCHI_OFFSET)) break; - } + } while (--loop_limit); if (!loop_limit) { pr_err("bcm_kona_timer: getting counter failed.\n"); pr_err(" Timer will be impacted\n"); + return -ETIMEDOUT; } - return; + return 0; } static int kona_timer_set_next_event(unsigned long clc, @@ -112,8 +113,11 @@ static int kona_timer_set_next_event(unsigned long clc, uint32_t lsw, msw; uint32_t reg; + int ret; - kona_timer_get_counter(timers.tmr_regs, &msw, &lsw); + ret = kona_timer_get_counter(timers.tmr_regs, &msw, &lsw); + if (ret) + return ret; /* Load the "next" event tick value */ writel(lsw + clc, timers.tmr_regs + KONA_GPTIMER_STCM0_OFFSET);