From patchwork Mon Feb 26 21:19:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Rossak X-Patchwork-Id: 10243581 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BD259602DC for ; Mon, 26 Feb 2018 21:21:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ADEDE2A400 for ; Mon, 26 Feb 2018 21:21:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A25F32A419; Mon, 26 Feb 2018 21:21:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 552F82A400 for ; Mon, 26 Feb 2018 21:21:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=xiN54dudySusl0ZLOYO+Nx/O+Tr9NfZChWsCRY2YSkY=; b=U+g vzrNgk70bzON30GHzKexGvP7KWnWEVMTGXsraNoCH39ZBvia2Wxb9imfQg9k5zS8/8pY+f1Tm332G IhxMDsRht+QtqmuJGn4p7puO9++KTACYe4f/sE72bZaH95ZgI85TPlVJ66r2NUpTlWGP8qk5RFhIc 8SjhTXiK+krpt0TPYqy96rpgECcKx7IHKXfL+tcmn/BTZJ2omxDcqj1UhF4FJpY4Fha2vntUtRtC4 rn2TQSfOM7Qe2NGMsmG/Os2GDO5kT753Tp+mt7IDuV33u699QaPy4OIjYr6vJIK+3U+/IHLf9QIRT O6QwHcpANT6RcfLQyb6P+3+9+cATaTA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eqQCj-0000s0-I7; Mon, 26 Feb 2018 21:21:01 +0000 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eqQB3-0006wL-6b for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2018 21:19:30 +0000 Received: by mail-wr0-x242.google.com with SMTP id p104so22679817wrc.12 for ; Mon, 26 Feb 2018 13:19:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=ZGf4BHoSQ7ywu2FoyHLLITJ7FQmsB4J1dy+5ZQNCPJY=; b=WEY0L20XM2Tlh7OuztIgqgtCl5aS36jFn6q9trzOhsp9ptSP8w2wv0ZeZoy97epz0C nOZ8BjQcP35r6qake6OM6HEKDKcH4dyzZGlXuhCXZVGapoGm+9eZPVhAFhLUAO9AjXpI hK9m/9+rttf9YomAxYBKNxEPBpNgfFLnbX1a6xyjmv0El29aM1GywKwvnVNYT6KcSrxS L7r38fYCSCfrnTAJJ9mGPFzQAUFyMzZ5hvGIrtQODKuzN8fCMJQ5fTTUShEJnp9oHrVP shU30hJtJ8r4GrmXDQMqAjkZ+arKTjV7rsYECdJmiPaLZpd6kKb5TjlmSKkrknSZZmcW aFTQ== 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; bh=ZGf4BHoSQ7ywu2FoyHLLITJ7FQmsB4J1dy+5ZQNCPJY=; b=jdxZmcjHvhll9En/LW48z5fKOI9LIVdm5EXFUdvrMh9DI9dioExQlRReAydnB8sRGZ G4EZU2VedW7aG8bng5UN+Y4FyXCDwIYhHApey89pOmQ7ADjyhx+RwgzcLSYNYqHX1j20 KobOHNV9XY+aGTBc98TDeunEDET9uW6CpTC66qghnp+7xWYB4h+RtAyP6urWBFQKjDAF KtyPz4i67CMJLbd4p4sWlgESmTNK0PYtdAtBTfTKIsFXUw7VJCplonLKufSDYicvNKie xUEwdZiuG8i+jO+xVNcbuWTh5L1GXlZLl4T6NTibvnYJrlKPHQ29R++9MQlT8WG1g+3t TeCg== X-Gm-Message-State: APf1xPB9sMeRZacCne1EKp98bfb3Lf7zE9SvrRFZW73eMa9KM3Wb5X8C Nks1vs/Ce164KZHcRSz0AwDXWQ== X-Google-Smtp-Source: AH8x22637ZWM189j6YlqSxRjneLYeQ5L+mqLcXWTwhxmli1D7B2cJlGYP1kuv2QHzbrZ8Yy2prx8dQ== X-Received: by 10.223.209.11 with SMTP id a11mr10743257wri.122.1519679944183; Mon, 26 Feb 2018 13:19:04 -0800 (PST) Received: from debian-laptop.fritz.box (p578F0A16.dip0.t-ipconnect.de. [87.143.10.22]) by smtp.gmail.com with ESMTPSA id z73sm16453481wrb.50.2018.02.26.13.19.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 13:19:03 -0800 (PST) From: Philipp Rossak To: wens@csie.org, a.zummo@towertech.it, alexandre.belloni@bootlin.com, maxime.ripard@bootlin.com, mturquette@baylibre.com, sboyd@codeaurora.org Subject: [PATCH v4] rtc: ac100: Fix ac100 determine rate bug Date: Mon, 26 Feb 2018 22:19:01 +0100 Message-Id: <20180226211901.9805-1-embed3d@gmail.com> X-Mailer: git-send-email 2.11.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180226_131917_935414_F78DCE64 X-CRM114-Status: GOOD ( 20.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-rtc@vger.kernel.org, linux-sunxi@googlegroups.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch fixes a bug, that prevents the Allwinner A83T and the A80 from a successful boot. The bug is there since v4.16-rc1 and appeared after the clk branch was merged. You can find the shortend trace below: Unable to handle kernel NULL pointer dereference at virtual address 00000000 pgd = (ptrval) [00000000] *pgd=00000000 Internal error: Oops: 5 [#1] SMP ARM Modules linked in: CPU: 0 PID: 49 Comm: kworker/0:1 Not tainted 4.15.0-10190-gb89e32ccd1be #2 Hardware name: Allwinner sun8i Family Workqueue: events deferred_probe_work_func PC is at clk_hw_get_rate+0x0/0x34 LR is at ac100_clkout_determine_rate+0x48/0x19c [ ... ] (clk_hw_get_rate) from (ac100_clkout_determine_rate+0x48/0x19c) (ac100_clkout_determine_rate) from (clk_core_set_rate_nolock+0x3c/0x1a0) (clk_core_set_rate_nolock) from (clk_set_rate+0x30/0x88) (clk_set_rate) from (of_clk_set_defaults+0x200/0x364) (of_clk_set_defaults) from (platform_drv_probe+0x18/0xb0) To fix that bug, we first check if the return of the clk_hw_get_parent_by_index is non zero. If it is zero we skip that clock parent. The BUG report could be found here: https://lkml.org/lkml/2018/2/10/198 Fixes: 04940631b8d2 ("rtc: ac100: Add clk output support") Signed-off-by: Philipp Rossak Acked-by: Maxime Ripard --- Changes in v4: * add more information to the comment Changes in v3: * add information when the bug appeared * make the comment more clear Changes in v2: * add tag Fixes: ... to commit message * add comment to if statement why we are doing this check drivers/rtc/rtc-ac100.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/rtc/rtc-ac100.c b/drivers/rtc/rtc-ac100.c index 8ff9dc3fe5bf..08ca8c46a8ff 100644 --- a/drivers/rtc/rtc-ac100.c +++ b/drivers/rtc/rtc-ac100.c @@ -183,7 +183,29 @@ static int ac100_clkout_determine_rate(struct clk_hw *hw, for (i = 0; i < num_parents; i++) { struct clk_hw *parent = clk_hw_get_parent_by_index(hw, i); - unsigned long tmp, prate = clk_hw_get_rate(parent); + unsigned long tmp, prate; + + /* + * The clock has two parents, one is a fixed clock which is + * internally registered by the ac100 driver. The other parent + * is a clock from the codec side of the chip, which we + * properly declare and reference in the devicetree and is + * not implemented in any driver right now. + * If the clock core looks for the parent of that second + * missing clock, it can't find one that is registered and + * returns NULL. + * So we end up in a situation where clk_hw_get_num_parents + * returns the amount of clocks we can be parented to, but + * clk_hw_get_parent_by_index will not return the orphan + * clocks. + * Thus we need to check if the parent exists before + * we get the parent rate, so we could use the RTC + * without waiting for the codec to be supported. + */ + if (!parent) + continue; + + prate = clk_hw_get_rate(parent); tmp = ac100_clkout_round_rate(hw, req->rate, prate);