From patchwork Sat Aug 27 11:42:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 12956990 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5C945ECAAD2 for ; Sat, 27 Aug 2022 11:43:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ByvBSy4tzvq/aoZxpH+/1Hnv9CvufkWQpl7mu2yFuXg=; b=O3E3avAj+bYtBo iaIS8jtH4vWLY6AF9/lxacM4Apow40kbc/EiZqqUo/j4/iVmXyBb4PQH3bJhm08p0Z8G/5hWgtStT OnMrfNBsQwMTIV9nVuCuZ0zg4c+ms2vPNnpqaQMhptE2ech5PlCaJR9SE91Qfb4uROL1Hpc8aE6Qg M5O6NFFL34uJ2UT5MSi34ka3dKoJ6bpaQSc3UxV9JimvU2PTPuY/1RbjN+jlu1x26RcWuA8g4In2C W5SUkM38dcMJU6TDvkuoVnqOY8q9f0YADuRefp2g5bhcarCme65pmXSz5E+9cWHxDbHE5U7f2VSHy Z/RQ8VWoKbxrIUJchG4A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oRuCt-008zpL-9S; Sat, 27 Aug 2022 11:42:31 +0000 Received: from smtp03.smtpout.orange.fr ([80.12.242.125] helo=smtp.smtpout.orange.fr) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oRuCm-008zg0-E9 for linux-arm-kernel@lists.infradead.org; Sat, 27 Aug 2022 11:42:26 +0000 Received: from pop-os.home ([90.11.190.129]) by smtp.orange.fr with ESMTPA id RuCioaXfqLFqbRuCioufxe; Sat, 27 Aug 2022 13:42:21 +0200 X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sat, 27 Aug 2022 13:42:21 +0200 X-ME-IP: 90.11.190.129 From: Christophe JAILLET To: broonie@kernel.org, matthias.bgg@gmail.com, gregkh@linuxfoundation.org, neil@brown.name, blogic@openwrt.org Cc: linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH 2/4] spi: mt7621: Use the devm_clk_get_enabled() helper to simplify error handling Date: Sat, 27 Aug 2022 13:42:19 +0200 Message-Id: <05a7fd22719008c8a905d6328aa9548ce40f2a7a.1661599671.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220827_044224_678558_0FAB4DEF X-CRM114-Status: GOOD ( 14.58 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The devm_clk_get_enabled() helper: - calls devm_clk_get() - calls clk_prepare_enable() and registers what is needed in order to call clk_disable_unprepare() when needed, as a managed resource. This helper is well suited for cases where the clock would be kept prepared or enabled for the whole lifetime of the driver. This simplifies the error handling a lot. The order between spi_unregister_controller() (in the remove function) and the clk_disable_unprepare() (now handle by a managed resource) is kept the same. (see commit 46b5c4fb87ce ("spi: mt7621: Don't leak SPI master in probe error path") to see why it matters) Signed-off-by: Christophe JAILLET Reviewed-by: Matthias Brugger Reviewed-by: AngeloGioacchino Del Regno --- The order with devm_spi_release_controller() (which undoes devm_spi_alloc_master()) is reversed, but I don't think it is an issue. --- drivers/spi/spi-mt7621.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/drivers/spi/spi-mt7621.c b/drivers/spi/spi-mt7621.c index 351b0ef52bbc..2580b28042be 100644 --- a/drivers/spi/spi-mt7621.c +++ b/drivers/spi/spi-mt7621.c @@ -327,7 +327,6 @@ static int mt7621_spi_probe(struct platform_device *pdev) struct spi_controller *master; struct mt7621_spi *rs; void __iomem *base; - int status = 0; struct clk *clk; int ret; @@ -339,19 +338,14 @@ static int mt7621_spi_probe(struct platform_device *pdev) if (IS_ERR(base)) return PTR_ERR(base); - clk = devm_clk_get(&pdev->dev, NULL); + clk = devm_clk_get_enabled(&pdev->dev, NULL); if (IS_ERR(clk)) return dev_err_probe(&pdev->dev, PTR_ERR(clk), "unable to get SYS clock\n"); - status = clk_prepare_enable(clk); - if (status) - return status; - master = devm_spi_alloc_master(&pdev->dev, sizeof(*rs)); if (!master) { dev_info(&pdev->dev, "master allocation failed\n"); - clk_disable_unprepare(clk); return -ENOMEM; } @@ -376,13 +370,10 @@ static int mt7621_spi_probe(struct platform_device *pdev) ret = device_reset(&pdev->dev); if (ret) { dev_err(&pdev->dev, "SPI reset failed!\n"); - clk_disable_unprepare(clk); return ret; } ret = spi_register_controller(master); - if (ret) - clk_disable_unprepare(clk); return ret; } @@ -390,13 +381,10 @@ static int mt7621_spi_probe(struct platform_device *pdev) static int mt7621_spi_remove(struct platform_device *pdev) { struct spi_controller *master; - struct mt7621_spi *rs; master = dev_get_drvdata(&pdev->dev); - rs = spi_controller_get_devdata(master); spi_unregister_controller(master); - clk_disable_unprepare(rs->clk); return 0; }