From patchwork Thu Jun 16 21:27:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 70236 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp465471qgy; Thu, 16 Jun 2016 14:31:36 -0700 (PDT) X-Received: by 10.107.4.195 with SMTP id 186mr11940406ioe.143.1466112696776; Thu, 16 Jun 2016 14:31:36 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g132si7984299pfc.38.2016.06.16.14.31.36; Thu, 16 Jun 2016 14:31:36 -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 S1755363AbcFPVbc (ORCPT + 30 others); Thu, 16 Jun 2016 17:31:32 -0400 Received: from mail-wm0-f51.google.com ([74.125.82.51]:37315 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755368AbcFPV32 (ORCPT ); Thu, 16 Jun 2016 17:29:28 -0400 Received: by mail-wm0-f51.google.com with SMTP id a66so75567567wme.0 for ; Thu, 16 Jun 2016 14:29:28 -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=OQIKqYD9R/luvd2Uzh5nF8Hk1dZV68TiJh0dpKsZGcQ=; b=fXt4IhZZlbQ6frJV6OVe2LiHDFKGBOpQJKBrweodeVkoFYueuEwGomX8OilzqGXwXV OnWYpzR9OPz0/o7NCsjLZ2GKyq4tzrvYIeSNRX3G1Occy3LOlUKJaV5zTL0fG+F6tbWn HJ/frXJCKiVffY7PRcvu2sDApezDQNhYcsKjs= 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=OQIKqYD9R/luvd2Uzh5nF8Hk1dZV68TiJh0dpKsZGcQ=; b=Ii5eXfm+V8VowI20u4PnuaXhDY6eYgmT8hC8q4SmVVz2MxzwzKaVMHFExPUKAS1oIk 4XiEywmf3iw7zk+GZ8vHhd13S0kJBgW2wuiZSWyw+jJzjA/Z8pUxuYv2QmAM2qEhWDKk ZoJWEVoGzDhR8I2NOp0IcelolzXTxpFaR0FeeaMg+1vJGTJfVDP+iHkilRfdBkLi0Acg fNl/9J79yFRPS3DD1hFTE97FNjbGiCwp6v6Hk2cNv1go61RqczRUeKBS+MsBjPD1X1v9 /wpgMxD9Ad9hjPN7d5ews7tDvwbDV0uCWHhdqVFTHgvZco/d/0C3wnmne/4Yqrg9asHm Bm1Q== X-Gm-Message-State: ALyK8tLJkICjzrt6ZHqaz7Ldt6X0i6wPfcTF5jNOEbZW36CgKpfzrA6d20yKeA7K5cbioLTS X-Received: by 10.194.113.136 with SMTP id iy8mr1472953wjb.174.1466112567435; Thu, 16 Jun 2016 14:29:27 -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 x128sm16705606wmf.6.2016.06.16.14.29.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 16 Jun 2016 14:29:26 -0700 (PDT) From: Daniel Lezcano To: daniel.lezcano@linaro.org, tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, Ley Foon Tan , "Rafael J. Wysocki" , Viresh Kumar , Marc Zyngier , nios2-dev@lists.rocketboards.org (moderated list:NIOS2 ARCHITECTURE) Subject: [PATCH V2 58/63] clocksource/drivers/nios2: Convert init function to return error Date: Thu, 16 Jun 2016 23:27:17 +0200 Message-Id: <1466112442-31105-59-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1466112442-31105-1-git-send-email-daniel.lezcano@linaro.org> References: <1466112442-31105-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 --- arch/nios2/kernel/time.c | 69 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 21 deletions(-) -- 1.9.1 diff --git a/arch/nios2/kernel/time.c b/arch/nios2/kernel/time.c index e835dda..9fa7739 100644 --- a/arch/nios2/kernel/time.c +++ b/arch/nios2/kernel/time.c @@ -206,15 +206,21 @@ irqreturn_t timer_interrupt(int irq, void *dev_id) return IRQ_HANDLED; } -static void __init nios2_timer_get_base_and_freq(struct device_node *np, +static int __init nios2_timer_get_base_and_freq(struct device_node *np, void __iomem **base, u32 *freq) { *base = of_iomap(np, 0); - if (!*base) - panic("Unable to map reg for %s\n", np->name); + if (!*base) { + pr_crit("Unable to map reg for %s\n", np->name); + return -ENXIO; + } + + if (of_property_read_u32(np, "clock-frequency", freq)) { + pr_crit("Unable to get %s clock frequency\n", np->name); + return -EINVAL; + } - if (of_property_read_u32(np, "clock-frequency", freq)) - panic("Unable to get %s clock frequency\n", np->name); + return 0; } static struct nios2_clockevent_dev nios2_ce = { @@ -231,17 +237,21 @@ static struct nios2_clockevent_dev nios2_ce = { }, }; -static __init void nios2_clockevent_init(struct device_node *timer) +static __init int nios2_clockevent_init(struct device_node *timer) { void __iomem *iobase; u32 freq; - int irq; + int irq, ret; - nios2_timer_get_base_and_freq(timer, &iobase, &freq); + ret = nios2_timer_get_base_and_freq(timer, &iobase, &freq); + if (ret) + return ret; irq = irq_of_parse_and_map(timer, 0); - if (!irq) - panic("Unable to parse timer irq\n"); + if (!irq) { + pr_crit("Unable to parse timer irq\n"); + return -EINVAL; + } nios2_ce.timer.base = iobase; nios2_ce.timer.freq = freq; @@ -253,25 +263,35 @@ static __init void nios2_clockevent_init(struct device_node *timer) /* clear pending interrupt */ timer_writew(&nios2_ce.timer, 0, ALTERA_TIMER_STATUS_REG); - if (request_irq(irq, timer_interrupt, IRQF_TIMER, timer->name, - &nios2_ce.ced)) - panic("Unable to setup timer irq\n"); + ret = request_irq(irq, timer_interrupt, IRQF_TIMER, timer->name, + &nios2_ce.ced); + if (ret) { + pr_crit("Unable to setup timer irq\n"); + return ret; + } clockevents_config_and_register(&nios2_ce.ced, freq, 1, ULONG_MAX); + + return 0; } -static __init void nios2_clocksource_init(struct device_node *timer) +static __init int nios2_clocksource_init(struct device_node *timer) { unsigned int ctrl; void __iomem *iobase; u32 freq; + int ret; - nios2_timer_get_base_and_freq(timer, &iobase, &freq); + ret = nios2_timer_get_base_and_freq(timer, &iobase, &freq); + if (ret) + return ret; nios2_cs.timer.base = iobase; nios2_cs.timer.freq = freq; - clocksource_register_hz(&nios2_cs.cs, freq); + ret = clocksource_register_hz(&nios2_cs.cs, freq); + if (ret) + return ret; timer_writew(&nios2_cs.timer, USHRT_MAX, ALTERA_TIMER_PERIODL_REG); timer_writew(&nios2_cs.timer, USHRT_MAX, ALTERA_TIMER_PERIODH_REG); @@ -282,6 +302,8 @@ static __init void nios2_clocksource_init(struct device_node *timer) /* Calibrate the delay loop directly */ lpj_fine = freq / HZ; + + return 0; } /* @@ -289,22 +311,25 @@ static __init void nios2_clocksource_init(struct device_node *timer) * more instances, the second one gets used as clocksource and all * others are unused. */ -static void __init nios2_time_init(struct device_node *timer) +static int __init nios2_time_init(struct device_node *timer) { static int num_called; + int ret; switch (num_called) { case 0: - nios2_clockevent_init(timer); + ret = nios2_clockevent_init(timer); break; case 1: - nios2_clocksource_init(timer); + ret = nios2_clocksource_init(timer); break; default: break; } num_called++; + + return ret; } void read_persistent_clock(struct timespec *ts) @@ -321,10 +346,12 @@ void __init time_init(void) for_each_compatible_node(np, NULL, ALTR_TIMER_COMPATIBLE) count++; - if (count < 2) + if (count < 2) { panic("%d timer is found, it needs 2 timers in system\n", count); clocksource_probe(); + + return 0; } -CLOCKSOURCE_OF_DECLARE(nios2_timer, ALTR_TIMER_COMPATIBLE, nios2_time_init); +CLOCKSOURCE_OF_DECLARE_RET(nios2_timer, ALTR_TIMER_COMPATIBLE, nios2_time_init);