Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp461640ybl; Tue, 28 Jan 2020 06:20:28 -0800 (PST) X-Google-Smtp-Source: APXvYqwK+PVbmCIOssDYzwz0fMlEcAUbu+OnYqSH4rpKLMMfv1GlzpR6uCZf8f5M3i3aQS1ELpqf X-Received: by 2002:a9d:6184:: with SMTP id g4mr9761341otk.223.1580221227976; Tue, 28 Jan 2020 06:20:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580221227; cv=none; d=google.com; s=arc-20160816; b=hZtFErnDLOByJNsIg48b5rHNPhV/Pkg3Id8EoYvHxmSdsHn0UMsBSMR1SxFb+t0fgs wg6okBQd9elDbE0Phy8XYf/6Y2pbDwY73MZPiLXr+pGy02G7AX9zDtxfz7pne8A9MTzu ljcN6mSu7A3e11QnfesXr38iVcArAJf0xIeySkojBIYAN+M70yo22d0FqSfCFa6UzJuV R8crN60fxFzcqQuja4DBFyKSISmyi9gOoA8lEiWRbZ1P4vBAO1S2scUvuH/OLbSeAPAw +AxWZ/X1uXQoneAMhIwuYX8oUPQqUg1jLCs4oQ/Nsiw3keg0LqEtZ42XC7u916yrbEsa MeGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VJkN+KyX0pWYSOJA45kF64gPRNhzunZRXUUf940EJa8=; b=dKyZ7N92iE7WZouqZyZKpOBnf6p+Pj75Xr5JyRWqSvOq4oczygj6Gal9it4l0utLP3 YTFFRo0LrD/CYsgQL6Xw/uTLn7wTqPxKLjh3yVQDOYEm2/HhrUJcaVj/e4ap1IMpxKi6 2wZm2h5eM/srnoScEwJDOBIGJT7vnCe5zAs+y4KvTG66C75Hvdqp4ZgcgV/wIwRzguNE ojHowFn6Q/WwmfpcRGcf4NeK6MEZCBIup4yyVVsppV4JCHCEEa/SbENm4lF+XeIYWjF/ 1rGMB1KjMkrw7ntsMVgRZWCvdUZ+uLOWtHy4b0nWSCiMpZSsPn7IfuhsNrD9M9cWdpsN K94g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=P3lDNuub; 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 t25si5455334oic.183.2020.01.28.06.20.15; Tue, 28 Jan 2020 06:20:27 -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=@kernel.org header.s=default header.b=P3lDNuub; 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 S1729691AbgA1OSS (ORCPT + 99 others); Tue, 28 Jan 2020 09:18:18 -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