From patchwork Thu Apr 26 07:28:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Potyra, Stefan" X-Patchwork-Id: 10364837 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 B623760225 for ; Thu, 26 Apr 2018 07:44:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A88AB29008 for ; Thu, 26 Apr 2018 07:44:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C42D29068; Thu, 26 Apr 2018 07:44:26 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,T_TVD_MIME_EPI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4885029008 for ; Thu, 26 Apr 2018 07:44:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753670AbeDZHoK (ORCPT ); Thu, 26 Apr 2018 03:44:10 -0400 Received: from smtpgwcipde.automotive.elektrobit.com ([213.95.163.141]:42558 "EHLO smtpgwcipde.elektrobit.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754278AbeDZHoF (ORCPT ); Thu, 26 Apr 2018 03:44:05 -0400 X-Greylist: delayed 906 seconds by postgrey-1.27 at vger.kernel.org; Thu, 26 Apr 2018 03:44:04 EDT Received: from denue6es003.localdomain (denue6es003.automotive.elektrobit.com [213.95.163.136]) by smtpgwcipde.elektrobit.com with ESMTP id w3Q7S5fd002845-w3Q7S5ff002845 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 26 Apr 2018 09:28:05 +0200 Received: from denue6es003.securemail.local (localhost [127.0.0.1]) by denue6es003.localdomain (Postfix) with SMTP id 535BB2D487; Thu, 26 Apr 2018 09:28:05 +0200 (CEST) Received: from denue6es008.ebgroup.elektrobit.com (denue6es008.ebgroup.elektrobit.com [10.5.139.25]) by denue6es003.localdomain (Postfix) with ESMTPS; Thu, 26 Apr 2018 09:28:04 +0200 (CEST) Received: from localhost (10.0.24.181) by denue6es008.ebgroup.elektrobit.com (10.5.139.25) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Thu, 26 Apr 2018 09:28:02 +0200 Date: Thu, 26 Apr 2018 09:28:02 +0200 From: Stefan Potyra To: Mark Brown CC: Florian Fainelli , Florian Fainelli , , , , , Jonas Gorski , , Subject: [PATCH v5] spi/bcm63xx-hspi: Enable the clock before calling clk_get_rate(). Message-ID: <20180426072801.GB4117@er01809n.ebgroup.elektrobit.com> References: <20180419130358.r7dva6owy2izyfus@agrajag.zerfleddert.de> <20180424161605.GA17825@er01809n.ebgroup.elektrobit.com> <20180424173253.GF22073@sirena.org.uk> <20180425134728.GA20897@er01809n.ebgroup.elektrobit.com> <20180425155028.GF24769@sirena.org.uk> <20180425164904.GA30349@er01809n.ebgroup.elektrobit.com> <20180425172816.GI24769@sirena.org.uk> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180425172816.GI24769@sirena.org.uk> User-Agent: Mutt/1.9.5 (2018-04-13) X-Originating-IP: [10.0.24.181] X-ClientProxiedBy: denue6es007.ebgroup.elektrobit.com (10.5.139.21) To denue6es008.ebgroup.elektrobit.com (10.5.139.25) Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Enable the clock prior to calling clk_get_rate(), because clk_get_rate() should only be called if the clock is enabled. Additionally, prepare/enable the pll_clk before calling clk_get_rate() for the same reason. Found by Linux Driver Verification project (linuxtesting.org). Fixes: 142168eba9dc ("spi: bcm63xx-hsspi: add bcm63xx HSSPI driver") Signed-off-by: Stefan Potyra --- drivers/spi/spi-bcm63xx-hsspi.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/drivers/spi/spi-bcm63xx-hsspi.c b/drivers/spi/spi-bcm63xx-hsspi.c index cbcba614b253..c23849f7aa7b 100644 --- a/drivers/spi/spi-bcm63xx-hsspi.c +++ b/drivers/spi/spi-bcm63xx-hsspi.c @@ -352,22 +352,31 @@ static int bcm63xx_hsspi_probe(struct platform_device *pdev) if (IS_ERR(clk)) return PTR_ERR(clk); + ret = clk_prepare_enable(clk); + if (ret) + return ret; + rate = clk_get_rate(clk); if (!rate) { struct clk *pll_clk = devm_clk_get(dev, "pll"); - if (IS_ERR(pll_clk)) - return PTR_ERR(pll_clk); + if (IS_ERR(pll_clk)) { + ret = PTR_ERR(pll_clk); + goto out_disable_clk; + } + + ret = clk_prepare_enable(pll_clk); + if (ret) + goto out_disable_clk; rate = clk_get_rate(pll_clk); - if (!rate) - return -EINVAL; + clk_disable_unprepare(pll_clk); + if (!rate) { + ret = -EINVAL; + goto out_disable_clk; + } } - ret = clk_prepare_enable(clk); - if (ret) - return ret; - master = spi_alloc_master(&pdev->dev, sizeof(*bs)); if (!master) { ret = -ENOMEM;