From patchwork Thu Jun 16 21:26:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 70220 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp464745qgy; Thu, 16 Jun 2016 14:29:31 -0700 (PDT) X-Received: by 10.107.39.149 with SMTP id n143mr11664955ion.50.1466112556582; Thu, 16 Jun 2016 14:29:16 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l17si7967338pfa.42.2016.06.16.14.29.15; Thu, 16 Jun 2016 14:29:16 -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 S932256AbcFPV3A (ORCPT + 30 others); Thu, 16 Jun 2016 17:29:00 -0400 Received: from mail-wm0-f43.google.com ([74.125.82.43]:38363 "EHLO mail-wm0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755325AbcFPV24 (ORCPT ); Thu, 16 Jun 2016 17:28:56 -0400 Received: by mail-wm0-f43.google.com with SMTP id m124so86968932wme.1 for ; Thu, 16 Jun 2016 14:28:56 -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=Rppz3v5gNpusD1VccxqkljhLAz1wr0hTxBbJlb1itzU=; b=dSqbDPGBE8sCnDBfjo5ZPWbUD1wNXXU+tp7PakEqqnQrtgCb9+sgZ5++x/y6YF2Wxl JCjxoJNQ7ijGG7Fcaf02Hrk+QPxEv83aPx6ybcHKzvseaFn/Kt/HCqRtLA+joQsobdDp +ec6bS/iH1jEMzVJkrzuaF4BlGo4b3L7nmBmI= 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=Rppz3v5gNpusD1VccxqkljhLAz1wr0hTxBbJlb1itzU=; b=J+cOSgpL18WdUlN33BUwUdhv4SdUCZpltZxwlADaTkz2spsH31QEC5QJl0f1+CCbop gokuBa4lpC1b4RIUPPvsE2WqTZu3jJfG1pxdP3u+jBx6i06mmIlqJxznk9jmMbGaUWWB havv65iPKK0EPj701H/ppeLwQQRu3k4+Sp+WSLib84kumY/lnYuQrxsGJvPoH2ziMEhA WFBJajTOy0CHqGMycaBtXQCjdX1yrcn0Bct6tmaopSiPHivkoCToTyYWBoLlcOOVRvTM hfRiBCUEFopysekjAle26EDtmObC5dmUoGcSFfbiJzvl4Mx76yMCJsoFJmDB6AnJTtZF qvaQ== X-Gm-Message-State: ALyK8tJ/24Q3lTRrpG8Fb232jxQjEDESG2c4puibMILWuNpfIwmLTJQf/tbcPqgWYqANdssT X-Received: by 10.194.151.73 with SMTP id uo9mr1326838wjb.177.1466112535348; Thu, 16 Jun 2016 14:28:55 -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.28.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 16 Jun 2016 14:28:54 -0700 (PDT) From: Daniel Lezcano To: daniel.lezcano@linaro.org, tglx@linutronix.de Cc: linux-kernel@vger.kernel.org Subject: [PATCH V2 40/63] clocksource/drivers/timer-atmel-pit: Convert init function to return error Date: Thu, 16 Jun 2016 23:26:59 +0200 Message-Id: <1466112442-31105-41-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 --- drivers/clocksource/timer-atmel-pit.c | 43 +++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 14 deletions(-) -- 1.9.1 diff --git a/drivers/clocksource/timer-atmel-pit.c b/drivers/clocksource/timer-atmel-pit.c index d911c5d..ffaca7c 100644 --- a/drivers/clocksource/timer-atmel-pit.c +++ b/drivers/clocksource/timer-atmel-pit.c @@ -177,7 +177,7 @@ static irqreturn_t at91sam926x_pit_interrupt(int irq, void *dev_id) /* * Set up both clocksource and clockevent support. */ -static void __init at91sam926x_pit_common_init(struct pit_data *data) +static int __init at91sam926x_pit_common_init(struct pit_data *data) { unsigned long pit_rate; unsigned bits; @@ -204,14 +204,21 @@ static void __init at91sam926x_pit_common_init(struct pit_data *data) data->clksrc.rating = 175; data->clksrc.read = read_pit_clk; data->clksrc.flags = CLOCK_SOURCE_IS_CONTINUOUS; - clocksource_register_hz(&data->clksrc, pit_rate); + + ret = clocksource_register_hz(&data->clksrc, pit_rate); + if (ret) { + pr_err("Failed to register clocksource"); + return ret; + } /* Set up irq handler */ ret = request_irq(data->irq, at91sam926x_pit_interrupt, IRQF_SHARED | IRQF_TIMER | IRQF_IRQPOLL, "at91_tick", data); - if (ret) - panic(pr_fmt("Unable to setup IRQ\n")); + if (ret) { + pr_err("Unable to setup IRQ\n"); + return ret; + } /* Set up and register clockevents */ data->clkevt.name = "pit"; @@ -226,34 +233,42 @@ static void __init at91sam926x_pit_common_init(struct pit_data *data) data->clkevt.resume = at91sam926x_pit_resume; data->clkevt.suspend = at91sam926x_pit_suspend; clockevents_register_device(&data->clkevt); + + return 0; } -static void __init at91sam926x_pit_dt_init(struct device_node *node) +static int __init at91sam926x_pit_dt_init(struct device_node *node) { struct pit_data *data; data = kzalloc(sizeof(*data), GFP_KERNEL); if (!data) - panic(pr_fmt("Unable to allocate memory\n")); + return -ENOMEM; data->base = of_iomap(node, 0); - if (!data->base) - panic(pr_fmt("Could not map PIT address\n")); + if (!data->base) { + pr_err("Could not map PIT address\n"); + return -ENXIO; + } data->mck = of_clk_get(node, 0); if (IS_ERR(data->mck)) /* Fallback on clkdev for !CCF-based boards */ data->mck = clk_get(NULL, "mck"); - if (IS_ERR(data->mck)) - panic(pr_fmt("Unable to get mck clk\n")); + if (IS_ERR(data->mck)) { + pr_err("Unable to get mck clk\n"); + return PTR_ERR(data->mck); + } /* Get the interrupts property */ data->irq = irq_of_parse_and_map(node, 0); - if (!data->irq) - panic(pr_fmt("Unable to get IRQ from DT\n")); + if (!data->irq) { + pr_err("Unable to get IRQ from DT\n"); + return -EINVAL; + } - at91sam926x_pit_common_init(data); + return at91sam926x_pit_common_init(data); } -CLOCKSOURCE_OF_DECLARE(at91sam926x_pit, "atmel,at91sam9260-pit", +CLOCKSOURCE_OF_DECLARE_RET(at91sam926x_pit, "atmel,at91sam9260-pit", at91sam926x_pit_dt_init);