From patchwork Sat Feb 23 13:06:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 159111 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp33084jad; Sat, 23 Feb 2019 05:07:58 -0800 (PST) X-Google-Smtp-Source: AHgI3IbvJTqKznbKuvFQL4h0xt5xhiVobq/Aoo/innOjxvUlrRRANmTRprRhfD7z0oP/CL3RwPNj X-Received: by 2002:a17:902:207:: with SMTP id 7mr9211537plc.142.1550927278360; Sat, 23 Feb 2019 05:07:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550927278; cv=none; d=google.com; s=arc-20160816; b=VhX//R2ifx0IJvNg+fwj+JAd9F1z67avGOU+cqA+VL/c+A7ZX/HBwzDbGREnQJEcFr 11DBcoeNYgGrlFNJ4QOennnd21RBLVHPLuQ60LBw4Z7QC9RI3mSs0WAmDTTR4RwPZIyM YPNhvUk1pHAHWgdmzQA2SaPhHD5whQV5Z0bVhmy6xZoE7LaTtE/tGSCLxTQARMbKG4lG 0jyG4vs1YAwoQvYSZKIaT9gmBv8D+ju+5kTBLLcQbH61Qj/QqRupaXfAJdSD3uqmUdcR ucbxfJSGYUDT9HSwVwCVFFN2nWnw193WMAiBbgWYiFvLILB/2gf8UAJXjHhrQt3BxFjp ZHjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=AKSyCQMNYBv5nWh/KBmSW8hTM6N2dO+8FV84ST3V3Mk=; b=whuUvNjsHsdQXDoDXpXM/EcApjC2Ogbs8+9xtlcWlnx7vWQriKZ5OBq3pC4iDWaN4R vvk/OW2ZKB1GrXxs5d+7zpBFi8uESn03OZkEp2cBmDhvOcwbqiNS2XKp+dP9pmGNh3y3 sJVmsvav+5RX6mbGHYOzs+vGwkvxQCB+H8QjcV0mTEvt5IfgR1iykGhFS+7xbmmX7n/G nqYlswy+yQV3OdJY9KstiQw/55RdDJJp40rXuNoMetmGhvdmjvUrJ1fs7w4ZhqhrX7Pg h8TXZHdIX2pRBx5ycr4WDb56nK2zxrLZVCqH+Gc8QkatMkDJpFju8tpubZSBVioKdGF8 q2+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FweXRpwO; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 91si3868840ply.214.2019.02.23.05.07.57; Sat, 23 Feb 2019 05:07:58 -0800 (PST) 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 header.s=google header.b=FweXRpwO; 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 S1727740AbfBWNH4 (ORCPT + 32 others); Sat, 23 Feb 2019 08:07:56 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:38848 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725859AbfBWNH4 (ORCPT ); Sat, 23 Feb 2019 08:07:56 -0500 Received: by mail-wm1-f67.google.com with SMTP id v26so4259688wmh.3 for ; Sat, 23 Feb 2019 05:07:54 -0800 (PST) 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=AKSyCQMNYBv5nWh/KBmSW8hTM6N2dO+8FV84ST3V3Mk=; b=FweXRpwO5ayiperaVHweKq29vXe1C65x4VoJdxMjwwWtiWIxgUPzCZSzW/8DqrMai2 hSqP3E3K3ifNxd/Gge8QibnK+XGe5pOOfv6rSIwfhdIzMgxiKHeXGHgBQZD67QYnbf3T 5AyEFpWFeSFb9IroZT//XYiQONOYhenc402TUug3Kwux0CPMkKHM7Ok/1DudjXLDOMoB JJGa2pFrr/icqFrcL/atpIBLOKxtWwg2LpQrIS5j9KWr+r2vmmO9iXOd2KbvoV3YbDsm ieFGVDuJm5mkrKNy57dTXf2e/gdauqaWwYdmLPBjZWjspQo9InxfgMSmMlisfgfN+EFX FesQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=AKSyCQMNYBv5nWh/KBmSW8hTM6N2dO+8FV84ST3V3Mk=; b=dk6Fhi9URNDq3gYQTEHaauxDbvi8L/ODWkCHe9FU8iqm3hHSEVznr+15eI9L/iPkJi ePH7qIl0v8ujMyFBcM2WaJFfwh3aKNxsilertRMg9W9jfpOSvIPsv0rvo/55ycxVdbOq U3IA/pU5EtcNHl3khnk017Ri6IrtiE+igcewOhZ8LetF5d/V4LQRShOisGooYtZfV7oH oLgxgbjlOnIJUYDavJogW3ly4rZAbKGeYUCycroXDJ6qnstD6yoTlxleEq4MHU5nbb/U EnAzJznaIiWegazpglhORxS+BxCRZz52T2hCvesuynvepZUbq5hPHqYe+lcRue1ZdbWP G0dQ== X-Gm-Message-State: AHQUAuZz1PeNenzvg3S9FNJ6zMdaCrculZFzxZy/Z+DyLVv3Z3UMSZTm /WEBKPmng+E6zt/y7TdjAmiFJoiYQeI= X-Received: by 2002:a1c:96c5:: with SMTP id y188mr5548250wmd.103.1550927273393; Sat, 23 Feb 2019 05:07:53 -0800 (PST) Received: from clegane.local (189.126.130.77.rev.sfr.net. [77.130.126.189]) by smtp.gmail.com with ESMTPSA id i12sm7830746wrq.21.2019.02.23.05.07.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 23 Feb 2019 05:07:52 -0800 (PST) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, Chen-Yu Tsai , Maxime Ripard , linux-arm-kernel@lists.infradead.org (moderated list:ARM/Allwinner sunXi SoC support) Subject: [PATCH 01/18] clocksource/drivers/sun5i: Fail gracefully when clock rate is unavailable Date: Sat, 23 Feb 2019 14:06:49 +0100 Message-Id: <20190223130707.16704-1-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chen-Yu Tsai If the clock tree is not fully populated when the timer-sun5i init code is called, attempts to get the clock rate for the timer would fail and return 0. Make the init code for both clock events and clocksource check the returned clock rate and fail gracefully if the result is 0, instead of causing a divide by 0 exception later on. Fixes: 4a59058f0b09 ("clocksource/drivers/sun5i: Refactor the current code") Signed-off-by: Chen-Yu Tsai Acked-by: Maxime Ripard Signed-off-by: Daniel Lezcano --- drivers/clocksource/timer-sun5i.c | 10 ++++++++++ 1 file changed, 10 insertions(+) -- 2.17.1 diff --git a/drivers/clocksource/timer-sun5i.c b/drivers/clocksource/timer-sun5i.c index 3b56ea3f52af..552c5254390c 100644 --- a/drivers/clocksource/timer-sun5i.c +++ b/drivers/clocksource/timer-sun5i.c @@ -202,6 +202,11 @@ static int __init sun5i_setup_clocksource(struct device_node *node, } rate = clk_get_rate(clk); + if (!rate) { + pr_err("Couldn't get parent clock rate\n"); + ret = -EINVAL; + goto err_disable_clk; + } cs->timer.base = base; cs->timer.clk = clk; @@ -275,6 +280,11 @@ static int __init sun5i_setup_clockevent(struct device_node *node, void __iomem } rate = clk_get_rate(clk); + if (!rate) { + pr_err("Couldn't get parent clock rate\n"); + ret = -EINVAL; + goto err_disable_clk; + } ce->timer.base = base; ce->timer.ticks_per_jiffy = DIV_ROUND_UP(rate, HZ);