From patchwork Tue Jun 28 10:31:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 71031 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp1512562qgy; Tue, 28 Jun 2016 03:42:01 -0700 (PDT) X-Received: by 10.66.165.145 with SMTP id yy17mr599401pab.116.1467110521034; Tue, 28 Jun 2016 03:42:01 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id os6si33073664pac.128.2016.06.28.03.42.00; Tue, 28 Jun 2016 03:42:01 -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; dkim=pass header.i=@linaro.org; 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; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932204AbcF1KkL (ORCPT + 30 others); Tue, 28 Jun 2016 06:40:11 -0400 Received: from mail-wm0-f50.google.com ([74.125.82.50]:35299 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752720AbcF1KeF (ORCPT ); Tue, 28 Jun 2016 06:34:05 -0400 Received: by mail-wm0-f50.google.com with SMTP id v199so133616065wmv.0 for ; Tue, 28 Jun 2016 03:34:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uW6VMjIbB5TVTRTxV19Fw/xR8qsEt3ZTY2Fa9xHeLTA=; b=MLbgiGblv5SmIfB2zcZFfCFcUF8ExgW8Fg4nAIgpC1HcNMbxW6siqwIJUFn0jLq1zI cvJCE29XAtJ9PpSQHp8yzrmRMrl/6uFduO0TNXf61GwpD/YYNelsQVsejtoNLmUXAHnO RbfS3WOMnsFeR0x9S4WsccmuUmjRcoPbv+9Uk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uW6VMjIbB5TVTRTxV19Fw/xR8qsEt3ZTY2Fa9xHeLTA=; b=PPkxreAjy8UHBNRfA+KH1umJeWAiRFKlZeXicJ2TAICc8CCaEbO6yPZluW0pzY1mMp dPCAQSS+r/opIHoUHmRU12lmA8WmmfUyFrDfLIKbDWxWuAPLFZl/6GieBLlZUcGhPVNE B/kjuSChxJBTyxNP86K4E7G+uk2ft2RCsjLGTyFJaJkrZiBzfKSfmORbTZNYhvHz6BBY OtnSZ93Yg7WU34U+KeK982Byosg3RutL5EVCeZJmKuIku8Cs8WRjGK5gix88vEYNQEBC Vtme1weSQlx3f3QJio4UP0Ps5isoY2RHthA6zm3aruKXjKcKQM11qyginJCgH8Nase7n IDKg== X-Gm-Message-State: ALyK8tJEHtirugwiRzSNPfwIUhzFDIjrRDtZ480e0MKVJVBHzyxvLzT9xYFebhJNv83Pj15n X-Received: by 10.28.181.80 with SMTP id e77mr15908152wmf.24.1467110043998; Tue, 28 Jun 2016 03:34:03 -0700 (PDT) Received: from localhost.localdomain (sju31-1-78-210-255-2.fbx.proxad.net. [78.210.255.2]) by smtp.gmail.com with ESMTPSA id a84sm5377403wma.0.2016.06.28.03.34.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 28 Jun 2016 03:34:03 -0700 (PDT) From: Daniel Lezcano To: daniel.lezcano@linaro.org, tglx@linutronix.de Cc: linux-kernel@vger.kernel.org Subject: [PATCH 54/92] clocksource/drivers/integrator-ap: Convert init function to return error Date: Tue, 28 Jun 2016 12:31:13 +0200 Message-Id: <1467109911-11060-54-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1467109911-11060-1-git-send-email-daniel.lezcano@linaro.org> References: <577251A4.7030508@linaro.org> <1467109911-11060-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The init functions do not return any error. They behave as the following: - panic, thus leading to a kernel crash while another timer may work and make the system boot up correctly or - print an error and let the caller unaware if the state of the system Change that by converting the init functions to return an error conforming to the CLOCKSOURCE_OF_RET prototype. Proper error handling (rollback, errno value) will be changed later case by case, thus this change just return back an error or success in the init function. Signed-off-by: Daniel Lezcano --- drivers/clocksource/timer-integrator-ap.c | 59 ++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 21 deletions(-) -- 1.9.1 diff --git a/drivers/clocksource/timer-integrator-ap.c b/drivers/clocksource/timer-integrator-ap.c index 3f59ac2..675face 100644 --- a/drivers/clocksource/timer-integrator-ap.c +++ b/drivers/clocksource/timer-integrator-ap.c @@ -36,11 +36,12 @@ static u64 notrace integrator_read_sched_clock(void) return -readl(sched_clk_base + TIMER_VALUE); } -static void integrator_clocksource_init(unsigned long inrate, - void __iomem *base) +static int integrator_clocksource_init(unsigned long inrate, + void __iomem *base) { u32 ctrl = TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC; unsigned long rate = inrate; + int ret; if (rate >= 1500000) { rate /= 16; @@ -50,11 +51,15 @@ static void integrator_clocksource_init(unsigned long inrate, writel(0xffff, base + TIMER_LOAD); writel(ctrl, base + TIMER_CTRL); - clocksource_mmio_init(base + TIMER_VALUE, "timer2", - rate, 200, 16, clocksource_mmio_readl_down); + ret = clocksource_mmio_init(base + TIMER_VALUE, "timer2", + rate, 200, 16, clocksource_mmio_readl_down); + if (ret) + return ret; sched_clk_base = base; sched_clock_register(integrator_read_sched_clock, 16, rate); + + return 0; } static unsigned long timer_reload; @@ -138,11 +143,12 @@ static struct irqaction integrator_timer_irq = { .dev_id = &integrator_clockevent, }; -static void integrator_clockevent_init(unsigned long inrate, - void __iomem *base, int irq) +static int integrator_clockevent_init(unsigned long inrate, + void __iomem *base, int irq) { unsigned long rate = inrate; unsigned int ctrl = 0; + int ret; clkevt_base = base; /* Calculate and program a divisor */ @@ -156,14 +162,18 @@ static void integrator_clockevent_init(unsigned long inrate, timer_reload = rate / HZ; writel(ctrl, clkevt_base + TIMER_CTRL); - setup_irq(irq, &integrator_timer_irq); + ret = setup_irq(irq, &integrator_timer_irq); + if (ret) + return ret; + clockevents_config_and_register(&integrator_clockevent, rate, 1, 0xffffU); + return 0; } -static void __init integrator_ap_timer_init_of(struct device_node *node) +static int __init integrator_ap_timer_init_of(struct device_node *node) { const char *path; void __iomem *base; @@ -176,12 +186,12 @@ static void __init integrator_ap_timer_init_of(struct device_node *node) base = of_io_request_and_map(node, 0, "integrator-timer"); if (IS_ERR(base)) - return; + return PTR_ERR(base); clk = of_clk_get(node, 0); if (IS_ERR(clk)) { pr_err("No clock for %s\n", node->name); - return; + return PTR_ERR(clk); } clk_prepare_enable(clk); rate = clk_get_rate(clk); @@ -189,31 +199,38 @@ static void __init integrator_ap_timer_init_of(struct device_node *node) err = of_property_read_string(of_aliases, "arm,timer-primary", &path); - if (WARN_ON(err)) - return; + if (err) { + pr_warn("Failed to read property"); + return err; + } + pri_node = of_find_node_by_path(path); + err = of_property_read_string(of_aliases, "arm,timer-secondary", &path); - if (WARN_ON(err)) - return; + if (err) { + pr_warn("Failed to read property"); + return err; + } + + sec_node = of_find_node_by_path(path); - if (node == pri_node) { + if (node == pri_node) /* The primary timer lacks IRQ, use as clocksource */ - integrator_clocksource_init(rate, base); - return; - } + return integrator_clocksource_init(rate, base); if (node == sec_node) { /* The secondary timer will drive the clock event */ irq = irq_of_parse_and_map(node, 0); - integrator_clockevent_init(rate, base, irq); - return; + return integrator_clockevent_init(rate, base, irq); } pr_info("Timer @%p unused\n", base); clk_disable_unprepare(clk); + + return 0; } -CLOCKSOURCE_OF_DECLARE(integrator_ap_timer, "arm,integrator-timer", +CLOCKSOURCE_OF_DECLARE_RET(integrator_ap_timer, "arm,integrator-timer", integrator_ap_timer_init_of);