From patchwork Mon Mar 5 09:17:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeffy Chen X-Patchwork-Id: 10258461 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 1E75060211 for ; Mon, 5 Mar 2018 09:17:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D3392832B for ; Mon, 5 Mar 2018 09:17:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01AA1283AD; Mon, 5 Mar 2018 09:17:54 +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_SIGNED, DKIM_VALID autolearn=ham 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 9A6142832B for ; Mon, 5 Mar 2018 09:17:54 +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=bY/kJUVns1JjURNW5jVCkBlY/d7rMwFO7pIrATmK6Ek=; b=tY4 L2OpJoPvXSIZwlSY1mmxBS2uVKvQTRQgoE1lbVqaRAR/njd0IEPZAdJOeR9LZfpwA6Zbpr2fvk8v8 AyYIe/78Z+VdPcaVEXriDftXc+n43uJJqxIQxFiEfN30NMD1J7v1Ldc/z1t8jP+3G9oDFQSmaQfIp 8c5r05CLd7ZqrzsuLCg0jaXg2beFyg59UD+LF530eiTw18zfEKD7i0EY14fs4rxNp3WsuexcB7DIp jYGI+E6oEXOEMN98O1fuTfYGD2NLIVs+eXlYHJt8AUh1Bi5IV8Lzo6OcHm8aoX+AMkdl7Hw6oPCOy hQ88Ctzkrx2DpipM9P4TcQrUq06/4wQ==; 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 1esmFg-0004eX-T6; Mon, 05 Mar 2018 09:17:48 +0000 Received: from regular1.263xmail.com ([211.150.99.133]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1esmFd-0004cR-GS; Mon, 05 Mar 2018 09:17:46 +0000 Received: from jeffy.chen?rock-chips.com (unknown [192.168.167.138]) by regular1.263xmail.com (Postfix) with ESMTP id 016C3912C; Mon, 5 Mar 2018 17:17:28 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-KSVirus-check: 0 X-ABS-CHECKED: 4 Received: from localhost (localhost [127.0.0.1]) by smtp.263.net (Postfix) with ESMTPA id 282D338A; Mon, 5 Mar 2018 17:17:24 +0800 (CST) X-RL-SENDER: jeffy.chen@rock-chips.com X-FST-TO: linux-kernel@vger.kernel.org X-SENDER-IP: 103.29.142.67 X-LOGIN-NAME: jeffy.chen@rock-chips.com X-UNIQUE-TAG: <6ecf75e644352cd27eb3f50a7505cc27> X-ATTACHMENT-NUM: 0 X-SENDER: cjf@rock-chips.com X-DNS-TYPE: 0 Received: from localhost (unknown [103.29.142.67]) by smtp.263.net (Postfix) whith ESMTP id 24401M7X6F5; Mon, 05 Mar 2018 17:17:29 +0800 (CST) From: Jeffy Chen To: linux-kernel@vger.kernel.org Subject: [PATCH] soc: rockchip: power-domain: Add a sanity check on pd->num_clks Date: Mon, 5 Mar 2018 17:17:22 +0800 Message-Id: <20180305091722.22246-1-jeffy.chen@rock-chips.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-20180305_011745_755705_DEC0EC56 X-CRM114-Status: UNSURE ( 8.47 ) X-CRM114-Notice: Please train this message. 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: Jeffy Chen , Heiko Stuebner , Geert Uytterhoeven , "Rafael J. Wysocki" , linux-rockchip@lists.infradead.org, Elaine Zhang , linux-arm-kernel@lists.infradead.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 The of_count_phandle_with_args() can fail and return error(for example, rk3399 pd_vio doesn't have clocks). That would break the pd probe. Add a sanity check on pd->num_clks to avoid that. Fixes: 65084121d59d ("soc: rockchip: power-domain: use clk_bulk APIs") Reported-by: Shawn Lin Signed-off-by: Jeffy Chen Tested-by: Shawn Lin --- drivers/soc/rockchip/pm_domains.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/soc/rockchip/pm_domains.c b/drivers/soc/rockchip/pm_domains.c index ad96ddeaeb78..fd58fd475950 100644 --- a/drivers/soc/rockchip/pm_domains.c +++ b/drivers/soc/rockchip/pm_domains.c @@ -402,11 +402,16 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, pd->num_clks = of_count_phandle_with_args(node, "clocks", "#clock-cells"); - - pd->clks = devm_kcalloc(pmu->dev, pd->num_clks, sizeof(*pd->clks), - GFP_KERNEL); - if (!pd->clks) - return -ENOMEM; + if (pd->num_clks > 0) { + pd->clks = devm_kcalloc(pmu->dev, pd->num_clks, + sizeof(*pd->clks), GFP_KERNEL); + if (!pd->clks) + return -ENOMEM; + } else { + dev_dbg(pmu->dev, "%s: don't have clocks: %d\n", + node->name, pd->num_clks); + pd->num_clks = 0; + } for (i = 0; i < pd->num_clks; i++) { pd->clks[i].clk = of_clk_get(node, i);