From patchwork Wed Apr 25 16:49:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Potyra, Stefan" X-Patchwork-Id: 10363917 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 0E181601D3 for ; Wed, 25 Apr 2018 16:50:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF1BB28BB0 for ; Wed, 25 Apr 2018 16:50:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E35FA28DB7; Wed, 25 Apr 2018 16:50:16 +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 7A7F828DD1 for ; Wed, 25 Apr 2018 16:50:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754813AbeDYQtu (ORCPT ); Wed, 25 Apr 2018 12:49:50 -0400 Received: from smtpgwcipde.automotive.elektrobit.com ([213.95.163.141]:58477 "EHLO smtpgwcipde.elektrobit.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754585AbeDYQtq (ORCPT ); Wed, 25 Apr 2018 12:49:46 -0400 Received: from denue6es003.localdomain (denue6es003.automotive.elektrobit.com [213.95.163.136]) by smtpgwcipde.elektrobit.com with ESMTP id w3PGn7IS016539-w3PGn7IU016539 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 25 Apr 2018 18:49:07 +0200 Received: from denue6es003.securemail.local (localhost [127.0.0.1]) by denue6es003.localdomain (Postfix) with SMTP id 73F0A2D481; Wed, 25 Apr 2018 18:49:07 +0200 (CEST) Received: from denue6es008.ebgroup.elektrobit.com (denue6es008.ebgroup.elektrobit.com [10.5.139.25]) by denue6es003.localdomain (Postfix) with ESMTPS; Wed, 25 Apr 2018 18:49:07 +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; Wed, 25 Apr 2018 18:49:06 +0200 Date: Wed, 25 Apr 2018 18:49:06 +0200 From: Stefan Potyra To: Mark Brown CC: Florian Fainelli , Florian Fainelli , , , , , Jonas Gorski , , Subject: [PATCH v4] spi/bcm63xx-hspi: Enable the clock before calling clk_get_rate(). Message-ID: <20180425164904.GA30349@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> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180425155028.GF24769@sirena.org.uk> User-Agent: Mutt/1.9.5 (2018-04-13) X-Originating-IP: [10.0.24.181] X-ClientProxiedBy: denue6es008.ebgroup.elektrobit.com (10.5.139.25) 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 | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/spi/spi-bcm63xx-hsspi.c b/drivers/spi/spi-bcm63xx-hsspi.c index cbcba614b253..8475703543e5 100644 --- a/drivers/spi/spi-bcm63xx-hsspi.c +++ b/drivers/spi/spi-bcm63xx-hsspi.c @@ -352,22 +352,27 @@ 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; + } + rate = clk_get_rate(pll_clk); - if (!rate) - return -EINVAL; + 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;