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 D8457C32771 for ; Fri, 24 Jan 2020 11:11:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A210A20708 for ; Fri, 24 Jan 2020 11:11:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579864311; bh=GIE21lGTg8zeMS92gvovzXBxYOWIpN9X8YOBQHHr4xk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=wBmcqKfY8H3BXeOlSTw6IyL6R/w+wqHlSVuHRCC+Z9bQXwltVhkKgUuxqej4XjgDh Id03wmLKJIXbAH0NPcHV9Mp+sJb/OfWPnsydhpinSLijSxyraXsAPsCRlMcv4u01JI lVZirgoX6M+9Dpb/o6dd2a2SY/cjbHA6N0LS3fko= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389920AbgAXLLv (ORCPT ); Fri, 24 Jan 2020 06:11:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:47868 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388725AbgAXLLs (ORCPT ); Fri, 24 Jan 2020 06:11:48 -0500 Received: from localhost (ip-213-127-102-57.ip.prioritytelecom.net [213.127.102.57]) (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 F2D6520663; Fri, 24 Jan 2020 11:11:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579864307; bh=GIE21lGTg8zeMS92gvovzXBxYOWIpN9X8YOBQHHr4xk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NGAp/ulODcS/wxg9+2GW6z6UvioOkj66eYkC3JS6sYh6Uo7j+8a+/CvbnyLgucAXs mcYiaFtNvY1SNix3HlYKSzXktTXW+xyEqfqfKxNTWLxaz1nWj3RcH3YnVbM2tonq+I N3RWHR7pUFBd4izXvIUEEbUR2OQVDxTrk4qbShaU= 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.19 230/639] clocksource/drivers/sun5i: Fail gracefully when clock rate is unavailable Date: Fri, 24 Jan 2020 10:26:40 +0100 Message-Id: <20200124093115.675229393@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200124093047.008739095@linuxfoundation.org> References: <20200124093047.008739095@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 3b56ea3f52afc..552c5254390cb 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); -- 2.20.1