From patchwork Thu Jul 7 08:01:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 71539 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp1276344qgy; Thu, 7 Jul 2016 01:15:05 -0700 (PDT) X-Received: by 10.98.47.129 with SMTP id v123mr3013712pfv.71.1467879305019; Thu, 07 Jul 2016 01:15:05 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e28si2946906pfk.242.2016.07.07.01.15.04; Thu, 07 Jul 2016 01:15:05 -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 S1756648AbcGGIEX (ORCPT + 30 others); Thu, 7 Jul 2016 04:04:23 -0400 Received: from mail-wm0-f41.google.com ([74.125.82.41]:35564 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933581AbcGGIDw (ORCPT ); Thu, 7 Jul 2016 04:03:52 -0400 Received: by mail-wm0-f41.google.com with SMTP id z126so138063438wme.0 for ; Thu, 07 Jul 2016 01:03:51 -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=BTZHTql8KBkNgNLgAaptTtOTMqlImVISI93t+ewICEMnhk2EQQy7b1FyzWXGu8dGLy sfb9mEjF52O334wB1W+wpPMGXdVdsDrW7uaNSDa3LMqI9fxApA6xMhszo/eyYffANYXA A+RFUNftS4m6nSjSZd0liLyWPuf0wQq6etnXg= 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=iMI1CzYzp/Ew3COm+55sq3yEK3/hrSjBHicdxblAljZYFwFrDDb2EWGV1Uh2rH2qO2 YkTSEFs+33omL/ewRpMzzdnUMnJTx+0HiAAtFu+06IX9qjhPeWkDa3WLIKL05LZSDOSY cr2hQ0IT+GRJaJ1Y6MNyzplOAyc2aydGybwgcgFqjg33i4vWJW7gztSCkSwqKZNUCywW PjCklJLk0L3fwu1lon/PiaVlg7M7lOv9rdWvFnti7Uyb3TZqZ+63jchTIAJw2tx/i9Bf EtoWU1UyBKjX1FoDyJ4D2Tq7zTvuic4PXX8wPzsq6ZIb/Bjrorr9H01B8Z2fvNJ/6JWg HG1Q== X-Gm-Message-State: ALyK8tL2CCVE575Qdi08zxwyuNY98WI0Ab0KiruCbqXrinpSvcWtI8jcomTe/gZC8Jb1ksQk X-Received: by 10.194.192.38 with SMTP id hd6mr22764187wjc.129.1467878630645; Thu, 07 Jul 2016 01:03:50 -0700 (PDT) Received: from localhost.localdomain (lft31-1-88-121-166-205.fbx.proxad.net. [88.121.166.205]) by smtp.gmail.com with ESMTPSA id v70sm51327wmf.18.2016.07.07.01.03.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Jul 2016 01:03:50 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de, daniel.lezcano@linaro.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 54/93] clocksource/drivers/integrator-ap: Convert init function to return error Date: Thu, 7 Jul 2016 10:01:27 +0200 Message-Id: <1467878526-1238-54-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1467878526-1238-1-git-send-email-daniel.lezcano@linaro.org> References: <577E0BED.3020608@linaro.org> <1467878526-1238-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);