From patchwork Sun May 9 11:41:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12246401 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82631C433ED for ; Sun, 9 May 2021 11:42:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5C5F261285 for ; Sun, 9 May 2021 11:42:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229602AbhEILnZ (ORCPT ); Sun, 9 May 2021 07:43:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:59210 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229585AbhEILnZ (ORCPT ); Sun, 9 May 2021 07:43:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id ED2C86128C; Sun, 9 May 2021 11:42:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1620560542; bh=U0s+p5WV13iA2iaJd8cYUx5HB1MBxeE5PINOZVEifZM=; h=From:To:Cc:Subject:Date:From; b=CqNmNV/225GD+0NLqf2sSC4r+wsYKcFlitvI3UDLOJ34Ymo7DPpJUnibvjgRUeEqT HMAd8CnifI+IUQwKkhOfcV0Dv7Pejt2WPogziC/o4jL1is2oRT8iPglfzU2iYVr/R4 icKYuEukd4WhwimVGL/vlxrKF65pPXb3ePTsSpiOAvE1F/9ICeONIxRkcKEBGZFmVk 5KtAVqJcubmZ6wA0zPdwgriVw5WQwK2jW07kS3HW6pu4jRZhuiuykldItu5er/z3WF fW4gYN1z9Sij4M7qi5zfE1DlwoysgLAFY+3/AO0Vhe1qPsED24849N8b1bX/DsN91C TNshCTqPQ/S1w== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Jonathan Cameron , Alexandru Tachici , Alexandru Ardelean Subject: [PATCH] iio: adc: ad7192: Avoid disabling a clock that was never enabled. Date: Sun, 9 May 2021 12:41:18 +0100 Message-Id: <20210509114118.660422-1-jic23@kernel.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron Found by inspection. If the internal clock source is being used, the driver doesn't call clk_prepare_enable() and as such we should not call clk_disable_unprepare() Use the same condition to protect the disable path as is used on the enable one. Note this will all get simplified when the driver moves over to a full devm_ flow, but that would make backporting the fix harder. Fix obviously predates move out of staging, but backporting will become more complex (and is unlikely to happen), hence that patch is given in the fixes tag. Fixes: b581f748cce0 ("staging: iio: adc: ad7192: move out of staging") Signed-off-by: Jonathan Cameron Cc: Alexandru Tachici Cc: Alexandru Ardelean Reviewed-by: Alexandru Ardelean --- drivers/iio/adc/ad7192.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c index 2ed580521d81..d3be67aa0522 100644 --- a/drivers/iio/adc/ad7192.c +++ b/drivers/iio/adc/ad7192.c @@ -1014,7 +1014,9 @@ static int ad7192_probe(struct spi_device *spi) return 0; error_disable_clk: - clk_disable_unprepare(st->mclk); + if (st->clock_sel == AD7192_CLK_EXT_MCLK1_2 || + st->clock_sel == AD7192_CLK_EXT_MCLK2) + clk_disable_unprepare(st->mclk); error_remove_trigger: ad_sd_cleanup_buffer_and_trigger(indio_dev); error_disable_dvdd: @@ -1031,7 +1033,9 @@ static int ad7192_remove(struct spi_device *spi) struct ad7192_state *st = iio_priv(indio_dev); iio_device_unregister(indio_dev); - clk_disable_unprepare(st->mclk); + if (st->clock_sel == AD7192_CLK_EXT_MCLK1_2 || + st->clock_sel == AD7192_CLK_EXT_MCLK2) + clk_disable_unprepare(st->mclk); ad_sd_cleanup_buffer_and_trigger(indio_dev); regulator_disable(st->dvdd);