From patchwork Wed May 13 06:54:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 6394331 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4EBA69F32E for ; Wed, 13 May 2015 06:55:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C85F22038A for ; Wed, 13 May 2015 06:55:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DBACD20426 for ; Wed, 13 May 2015 06:55:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754164AbbEMGzU (ORCPT ); Wed, 13 May 2015 02:55:20 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:42959 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753926AbbEMGzR (ORCPT ); Wed, 13 May 2015 02:55:17 -0400 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NOA0069Z0K4DF50@mailout2.w1.samsung.com>; Wed, 13 May 2015 07:55:16 +0100 (BST) X-AuditID: cbfec7f5-f794b6d000001495-97-5552f554daef Received: from eusync4.samsung.com ( [203.254.199.214]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 03.86.05269.455F2555; Wed, 13 May 2015 07:55:16 +0100 (BST) Received: from localhost.localdomain ([10.252.80.64]) by eusync4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0NOA00ELI0JC0J80@eusync4.samsung.com>; Wed, 13 May 2015 07:55:16 +0100 (BST) From: Krzysztof Kozlowski To: Tero Kristo , Mike Turquette , Stephen Boyd , linux-omap@vger.kernel.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Krzysztof Kozlowski Subject: [RFT PATCH 7/8] clk: ti: clk-54xx: Prevent possible ERR_PTR dereference Date: Wed, 13 May 2015 15:54:46 +0900 Message-id: <1431500087-2275-8-git-send-email-k.kozlowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1431500087-2275-1-git-send-email-k.kozlowski@samsung.com> References: <1431500087-2275-1-git-send-email-k.kozlowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprILMWRmVeSWpSXmKPExsVy+t/xa7ohX4NCDaY3Cli8fmFo8bHnHqvF 5V1z2CxmL+lnsXg64SKbxY8z3SwWS552sDmwe1zu62XyuHNtD5tH35ZVjB7Hb2xn8vi8SS6A NYrLJiU1J7MstUjfLoErY/nRL+wFV0UrLv45zdbAOFmoi5GTQ0LARGLb06fMELaYxIV769m6 GLk4hASWMkrsOL6BCcL5zyix9cQ6dpAqNgFjic3Ll4BViQgcZ5RYsacfLMEsYCjx890fIJuD Q1ggQKKtWQMkzCKgKtH9/zgjiM0r4Cax8v1jFohtchInj01mBSnnFHCXuDRPDMQUAirZ11A3 gZF3ASPDKkbR1NLkguKk9FwjveLE3OLSvHS95PzcTYyQgPq6g3HpMatDjAIcjEo8vDPeBoYK sSaWFVfmHmKU4GBWEuFd+i4oVIg3JbGyKrUoP76oNCe1+BCjNAeLkjjvzF3vQ4QE0hNLUrNT UwtSi2CyTBycUg2MypycDofztBvOpYkJMHHnbeBmmDd5c1+nPXv3W1GlnRKnLtz7vcBfSeRf YMParX/39/4tUp+2r3KHd0jsEQOhtdwd31dumacaXqxq/rFj4U9V+c2OvZm5qdOuCz9oby8+ m230be7OzDVnzkrULLm+Utj/5szbVgslV+c8XvLJj9lVXsS571GqEktxRqKhFnNRcSIAzc2f fyQCAAA= Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The return value of clk_get_sys() was immediately used in clk_set_parent() and clk_set_rate(). The first one may return ERR_PTR and the latter only checks if supplied argument is non-NULL. Signed-off-by: Krzysztof Kozlowski --- drivers/clk/ti/clk-54xx.c | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/drivers/clk/ti/clk-54xx.c b/drivers/clk/ti/clk-54xx.c index 96c69a335975..1e7ed6334ab4 100644 --- a/drivers/clk/ti/clk-54xx.c +++ b/drivers/clk/ti/clk-54xx.c @@ -222,39 +222,56 @@ static struct ti_dt_clk omap54xx_clks[] = { { .node_name = NULL }, }; -int __init omap5xxx_dt_clk_init(void) +static void __init omap5xxx_dt_clk_abe_dpll_init(void) { int rc; - struct clk *abe_dpll_ref, *abe_dpll, *sys_32k_ck, *usb_dpll; - - ti_dt_clocks_register(omap54xx_clks); - - omap2_clk_disable_autoidle_all(); + struct clk *abe_dpll_ref, *abe_dpll, *sys_32k_ck; abe_dpll_ref = clk_get_sys(NULL, "abe_dpll_clk_mux"); sys_32k_ck = clk_get_sys(NULL, "sys_32k_ck"); + if (IS_ERR(abe_dpll_ref) || IS_ERR(sys_32k_ck)) { + pr_err("%s: failed to configure ABE DPLL!\n", __func__); + return; + } + rc = clk_set_parent(abe_dpll_ref, sys_32k_ck); + abe_dpll = clk_get_sys(NULL, "dpll_abe_ck"); - if (!rc) + if (!rc && !IS_ERR(abe_dpll)) rc = clk_set_rate(abe_dpll, OMAP5_DPLL_ABE_DEFFREQ); if (rc) pr_err("%s: failed to configure ABE DPLL!\n", __func__); abe_dpll = clk_get_sys(NULL, "dpll_abe_m2x2_ck"); - if (!rc) + if (!rc && !IS_ERR(abe_dpll)) rc = clk_set_rate(abe_dpll, OMAP5_DPLL_ABE_DEFFREQ * 2); if (rc) pr_err("%s: failed to configure ABE m2x2 DPLL!\n", __func__); +} - usb_dpll = clk_get_sys(NULL, "dpll_usb_ck"); - rc = clk_set_rate(usb_dpll, OMAP5_DPLL_USB_DEFFREQ); - if (rc) - pr_err("%s: failed to configure USB DPLL!\n", __func__); +static void __init omap5xxx_dt_clk_usb_dpll_init(const char *clk_name, + unsigned long rate) +{ + int rc = -EINVAL; + struct clk *clk; + + clk = clk_get_sys(NULL, clk_name); + if (!IS_ERR(clk)) + rc = clk_set_rate(clk, rate); - usb_dpll = clk_get_sys(NULL, "dpll_usb_m2_ck"); - rc = clk_set_rate(usb_dpll, OMAP5_DPLL_USB_DEFFREQ/2); if (rc) - pr_err("%s: failed to set USB_DPLL M2 OUT\n", __func__); + pr_err("%s: failed to configure %s!\n", __func__, clk_name); +} + +int __init omap5xxx_dt_clk_init(void) +{ + ti_dt_clocks_register(omap54xx_clks); + + omap2_clk_disable_autoidle_all(); + + omap5xxx_dt_clk_abe_dpll_init(); + omap5xxx_dt_clk_usb_dpll_init("dpll_usb_ck", OMAP5_DPLL_USB_DEFFREQ); + omap5xxx_dt_clk_usb_dpll_init("dpll_usb_m2_ck", OMAP5_DPLL_USB_DEFFREQ/2); return 0; }