Received: by 10.223.185.116 with SMTP id b49csp4215436wrg; Mon, 26 Feb 2018 13:20:47 -0800 (PST) X-Google-Smtp-Source: AH8x225YjdLxAUGUkgXaVF1ZDPTh1olbkWrmdbIasySoZ7CGK5BeDonhB9k1Pf+9t2WjGVvfPOJ0 X-Received: by 2002:a17:902:e83:: with SMTP id 3-v6mr11860858plx.158.1519680046939; Mon, 26 Feb 2018 13:20:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519680046; cv=none; d=google.com; s=arc-20160816; b=P7dU2X1cwJXk6p0HK7yEXHGo7B9QmEY1q47uQqiHAywamECXPTuuAS2z6tLKaguLhd /l8qUlRiwY7clG24WG5GaVbra0ESqXJ9XGWAFi//ovRBeIKbhzy7ZoCrSm0x+JGnsMuf ezrn8gdriRJXvn2o3CGldMsK1e14p5/XtFTV3ffiDmwVM6J6ZLagzgICoIp51KdV01pf Tm3uwc788hbj8tKcYrPAZlWr85Oxd89GezCo7vsUgIntybISFAQnTV0bjC1sz8TEEKRq M9UtRRrj+CGyZwYmExtpqVXVuGnKMAhGnu9frEXGJ8tvHjx71+FRosgdxn+LVbbeg9gO MRvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=ZGf4BHoSQ7ywu2FoyHLLITJ7FQmsB4J1dy+5ZQNCPJY=; b=ZWSIwbE9xymOAt4a+nJ8CHZXLQwmIHTqlK67+3xjUDi7cG7eA2AydpxIn/LL8YAnQ0 ZgOuJTGcT0BO/jhTodOE/rsRC05C6uOiMT/AspUVfBf2DcxBqNHuwJghgF1YBEdUVyuJ /LzLJyu3yhHQwkCahf0bHsTY3Mz0/XZaV8iKqAtKjprGHqlZAm0JevArcH+c4kb0IjhB U2rooJM8ZMz4XHQ20pRHzLIgszoieXsjfDN7ruHIkH42/KGaijwZaKYGAZv/KM32v7dH 8QCJE9g/N/Vc0QVkpYehVW5kRJKkxBXeaaajZ54spLRbHnMe7grpwqw4VUJfojjnTtyD IY9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WEY0L20X; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z14si5999402pge.393.2018.02.26.13.20.30; Mon, 26 Feb 2018 13:20:46 -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=@gmail.com header.s=20161025 header.b=WEY0L20X; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751782AbeBZVTH (ORCPT + 99 others); Mon, 26 Feb 2018 16:19:07 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:42750 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751733AbeBZVTF (ORCPT ); Mon, 26 Feb 2018 16:19:05 -0500 Received: by mail-wr0-f193.google.com with SMTP id k9so22720787wre.9; Mon, 26 Feb 2018 13:19:04 -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=hs6QAvgcIuHN7Z6evnQQVNi831Ej4fTxYmmlNLz7DPwfEshD9g0TNIUL/bGq1JgVNE f5z5Anytbqm9VrxaV/R23DTMSaqXxm8X+EyMnS4ykszaT2WO/beAqaxa0kRKNMypNOp4 Snwh6gYOqLUKGVTcOmlh+2nZ6YL64Jehj/xS6ZABqDkXH1GhI4P5U8fjSKdQCxomHDs+ AIS3S2uvV4qEgGzHvLJ9c3OkQuYbVrXf1kVX0WDYJEHjrEgWpNuW+aQkw+vp5p+5XIB1 qjowwECrf6wy+BJe6LGu7a7lFwmE0yl9opNqYbKVgolUwQYoTX9byAn6WgC4IlC1ZQBY IttA== X-Gm-Message-State: APf1xPDwcc9zQ7clakfbUTHqOtRIqws9+SNA8vJJPYvAWCdj9NfhO/NU 4aRu9EZLcW+AchryfofAH1Q= 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 Cc: linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, linux-rtc@vger.kernel.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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); -- 2.11.0