From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98446C33CB3 for ; Tue, 28 Jan 2020 14:18:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 70DD524688 for ; Tue, 28 Jan 2020 14:18:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580221100; bh=2+zt9w0dPhXUYGeChpEfFxz4XryLf0XEQmx5DRlOAlc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=i+t45pcmPiA0fmJfcSQCife2J5S6tAHrL867IAQsnsNLv3VSMOTpaDmlnM2YvfXQy iO/tmDxKjV4njNs8+94Bqekuk10D+Z3x7ssj4S/YiiA/vh6U4oGIYRm/CjJ4IL+qvq f6y9sxY0n0C3G5G0bstV7LSCZ4u+OvEmqDwA4rgY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729950AbgA1OST (ORCPT ); Tue, 28 Jan 2020 09:18:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:42194 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730433AbgA1OSP (ORCPT ); Tue, 28 Jan 2020 09:18:15 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2D13824681; Tue, 28 Jan 2020 14:18:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580221094; bh=2+zt9w0dPhXUYGeChpEfFxz4XryLf0XEQmx5DRlOAlc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P3lDNuubHuMCuj25O4V/ygLjnq9p7dPfm34GAiPqRnytQuKS4i+1ipmF8gZ9JGN4H Ybsix96yZVGQABRVodVXxMUi0aIkn219FVa5JCXYMqUs4/Bw1XG9uoA5tRDnTfqAsY 7KWlO5565ZmXUVholF5FRgW+WcKJvs8VobiRtDpA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chen-Yu Tsai , Maxime Ripard , Daniel Lezcano , Sasha Levin Subject: [PATCH 4.9 087/271] clocksource/drivers/sun5i: Fail gracefully when clock rate is unavailable Date: Tue, 28 Jan 2020 15:03:56 +0100 Message-Id: <20200128135859.062879949@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200128135852.449088278@linuxfoundation.org> References: <20200128135852.449088278@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chen-Yu Tsai [ Upstream commit e7e7e0d7beafebd11b0c065cd5fbc1e5759c5aab ] 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 Signed-off-by: Sasha Levin --- drivers/clocksource/timer-sun5i.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/clocksource/timer-sun5i.c b/drivers/clocksource/timer-sun5i.c index 4f87f3e76d832..c3e96de525a24 100644 --- a/drivers/clocksource/timer-sun5i.c +++ b/drivers/clocksource/timer-sun5i.c @@ -201,6 +201,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; @@ -274,6 +279,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); -- 2.20.1