[{"id":3679389,"web_url":"http://patchwork.ozlabs.org/comment/3679389/","msgid":"<20260420132838.147d18b6@jic23-huawei>","list_archive_url":null,"date":"2026-04-20T12:28:38","subject":"Re: [PATCH v3] iio: adc: npcm: fix unbalanced\n clk_disable_unprepare()","submitter":{"id":10151,"url":"http://patchwork.ozlabs.org/api/people/10151/","name":"Jonathan Cameron","email":"jic23@kernel.org"},"content":"On Tue, 14 Apr 2026 13:30:06 +0100\nDavid Carlier <devnexen@gmail.com> wrote:\n\n> The driver acquired the ADC clock with devm_clk_get() and read its\n> rate, but never called clk_prepare_enable(). The probe error path and\n> npcm_adc_remove() both called clk_disable_unprepare() unconditionally,\n> causing the clk framework's enable/prepare counts to underflow on\n> probe failure or module unbind.\n> \n> The issue went unnoticed because NPCM BMC firmware leaves the ADC\n> clock enabled at boot, so the driver happened to work in practice.\n> \n> Switch to devm_clk_get_enabled() so the clock is properly enabled\n> during probe and automatically released by the device-managed\n> cleanup, and drop the now-redundant clk_disable_unprepare() from\n> both the probe error path and remove().\n> \n> While at it, drop the duplicate error message on devm_request_irq()\n> failure since the IRQ core already logs it.\n> \n> Fixes: 9bf85fbc9d8f (\"iio: adc: add NPCM ADC driver\")\n> Signed-off-by: David Carlier <devnexen@gmail.com>\n> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>\nApplied to the fixes-togreg branch of iio.git. Note I'll rebase that on rc1\nonce available, before sending a pull request.\n\nThanks,\n\nJonathan\n\n> ---\n> v3: mention the dev_err drop in the commit log and collapse the\n>     single-statement -ENODEV branch (Andy Shevchenko).\n> v2: drop redundant dev_err() on devm_request_irq() failure since the\n>     IRQ core already logs it, and remove the now-single-statement\n>     braces (Andy Shevchenko).\n> \n>  drivers/iio/adc/npcm_adc.c | 25 ++++++++-----------------\n>  1 file changed, 8 insertions(+), 17 deletions(-)\n> \n> diff --git a/drivers/iio/adc/npcm_adc.c b/drivers/iio/adc/npcm_adc.c\n> index ddabb9600d46..61c8b825bda1 100644\n> --- a/drivers/iio/adc/npcm_adc.c\n> +++ b/drivers/iio/adc/npcm_adc.c\n> @@ -231,7 +231,7 @@ static int npcm_adc_probe(struct platform_device *pdev)\n>  \tif (IS_ERR(info->reset))\n>  \t\treturn PTR_ERR(info->reset);\n>  \n> -\tinfo->adc_clk = devm_clk_get(&pdev->dev, NULL);\n> +\tinfo->adc_clk = devm_clk_get_enabled(&pdev->dev, NULL);\n>  \tif (IS_ERR(info->adc_clk)) {\n>  \t\tdev_warn(&pdev->dev, \"ADC clock failed: can't read clk\\n\");\n>  \t\treturn PTR_ERR(info->adc_clk);\n> @@ -244,17 +244,13 @@ static int npcm_adc_probe(struct platform_device *pdev)\n>  \tinfo->adc_sample_hz = clk_get_rate(info->adc_clk) / ((div + 1) * 2);\n>  \n>  \tirq = platform_get_irq(pdev, 0);\n> -\tif (irq < 0) {\n> -\t\tret = irq;\n> -\t\tgoto err_disable_clk;\n> -\t}\n> +\tif (irq < 0)\n> +\t\treturn irq;\n>  \n>  \tret = devm_request_irq(&pdev->dev, irq, npcm_adc_isr, 0,\n>  \t\t\t       \"NPCM_ADC\", indio_dev);\n> -\tif (ret < 0) {\n> -\t\tdev_err(dev, \"failed requesting interrupt\\n\");\n> -\t\tgoto err_disable_clk;\n> -\t}\n> +\tif (ret < 0)\n> +\t\treturn ret;\n>  \n>  \treg_con = ioread32(info->regs + NPCM_ADCCON);\n>  \tinfo->vref = devm_regulator_get_optional(&pdev->dev, \"vref\");\n> @@ -262,7 +258,7 @@ static int npcm_adc_probe(struct platform_device *pdev)\n>  \t\tret = regulator_enable(info->vref);\n>  \t\tif (ret) {\n>  \t\t\tdev_err(&pdev->dev, \"Can't enable ADC reference voltage\\n\");\n> -\t\t\tgoto err_disable_clk;\n> +\t\t\treturn ret;\n>  \t\t}\n>  \n>  \t\tiowrite32(reg_con & ~NPCM_ADCCON_REFSEL,\n> @@ -272,10 +268,8 @@ static int npcm_adc_probe(struct platform_device *pdev)\n>  \t\t * Any error which is not ENODEV indicates the regulator\n>  \t\t * has been specified and so is a failure case.\n>  \t\t */\n> -\t\tif (PTR_ERR(info->vref) != -ENODEV) {\n> -\t\t\tret = PTR_ERR(info->vref);\n> -\t\t\tgoto err_disable_clk;\n> -\t\t}\n> +\t\tif (PTR_ERR(info->vref) != -ENODEV)\n> +\t\t\treturn PTR_ERR(info->vref);\n>  \n>  \t\t/* Use internal reference */\n>  \t\tiowrite32(reg_con | NPCM_ADCCON_REFSEL,\n> @@ -314,8 +308,6 @@ static int npcm_adc_probe(struct platform_device *pdev)\n>  \tiowrite32(reg_con & ~NPCM_ADCCON_ADC_EN, info->regs + NPCM_ADCCON);\n>  \tif (!IS_ERR(info->vref))\n>  \t\tregulator_disable(info->vref);\n> -err_disable_clk:\n> -\tclk_disable_unprepare(info->adc_clk);\n>  \n>  \treturn ret;\n>  }\n> @@ -332,7 +324,6 @@ static void npcm_adc_remove(struct platform_device *pdev)\n>  \tiowrite32(regtemp & ~NPCM_ADCCON_ADC_EN, info->regs + NPCM_ADCCON);\n>  \tif (!IS_ERR(info->vref))\n>  \t\tregulator_disable(info->vref);\n> -\tclk_disable_unprepare(info->adc_clk);\n>  }\n>  \n>  static struct platform_driver npcm_adc_driver = {","headers":{"Return-Path":"\n <openbmc+bounces-1845-incoming=patchwork.ozlabs.org@lists.ozlabs.org>","X-Original-To":["incoming@patchwork.ozlabs.org","openbmc@lists.ozlabs.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=b03Nikmd;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org\n (client-ip=112.213.38.117; helo=lists.ozlabs.org;\n envelope-from=openbmc+bounces-1845-incoming=patchwork.ozlabs.org@lists.ozlabs.org;\n receiver=patchwork.ozlabs.org)","lists.ozlabs.org;\n arc=none smtp.remote-ip=\"2600:3c04:e001:324:0:1991:8:25\"","lists.ozlabs.org;\n dmarc=pass (p=quarantine dis=none) header.from=kernel.org","lists.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=b03Nikmd;\n\tdkim-atps=neutral","lists.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=kernel.org\n (client-ip=2600:3c04:e001:324:0:1991:8:25; helo=tor.source.kernel.org;\n envelope-from=jic23@kernel.org; receiver=lists.ozlabs.org)"],"Received":["from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1 raw public key)\n server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fzlCT5T9Zz1yD4\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 20 Apr 2026 22:28:52 +1000 (AEST)","from boromir.ozlabs.org (localhost [127.0.0.1])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 4fzlCQ4y2Yz2ynn;\n\tMon, 20 Apr 2026 22:28:50 +1000 (AEST)","from tor.source.kernel.org (tor.source.kernel.org\n [IPv6:2600:3c04:e001:324:0:1991:8:25])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n\t(No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 4fzlCP2J5Xz2xc8\n\tfor <openbmc@lists.ozlabs.org>; Mon, 20 Apr 2026 22:28:49 +1000 (AEST)","from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58])\n\tby tor.source.kernel.org (Postfix) with ESMTP id 0786B60055;\n\tMon, 20 Apr 2026 12:28:46 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id EFA23C2BCB4;\n\tMon, 20 Apr 2026 12:28:41 +0000 (UTC)"],"ARC-Seal":"i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1776688130;\n\tcv=none;\n b=f6/UGYmPaTrwKEyoaP4ckv2SPra4psMCDDtyaEpc8qgncLo3vvtboNmO2r51G++U0Pz+QGh9EhFsxwrzG2NewvQd6x3lYcDelHpl+UJI3MSxnGsbgN80phk7UTi8uLn837TE9P31EcmKbDc24Njke20ubyV9S11HCA+L7WF6lKPfo0Cc6sUFz+aTb96CcgKwTzCTTDYSW9u2RpDdixetu2YeArpiitmo4JAs5Lyo8OkA49eeLOmS506Hgmv9pNJZTRNjbAwU2zoVeq7EqrNRiAoIRI/qKA1Qs4NiCc2FxHOqO3Nj3FbKWbU9w/ADFi+VTN85eO7QqEwTWiONdQAWQQ==","ARC-Message-Signature":"i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707;\n\tt=1776688130; c=relaxed/relaxed;\n\tbh=C110ese3mih6LWdzBd8PmRBjkkaJpp8XvK4Gb2qqOQg=;\n\th=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References:\n\t MIME-Version:Content-Type;\n b=i2/0incbK99C6B0XlxPLC5y+xf5la+d9hcFFeS0mimvePUI8vYW3JI0dBKb9mr9em9ZpitlCSrlKrr8DcFFHxlXBbkuWwibqnhZl8gQ/i5nqDQR4yuCaHOHdopGTMBOyYLBwWcrefdCLq3apGHjgf5yLNGWH8C9ccR4p8LbjcD/mQIof9bP91l9ZX2nrUAZigW6k3d9j+ioHoN2UyiyZIx4aPN+6b62WXFyIOInNtciuCS58lqx0WWC9DybAPoxZLAkVP2KP50a4TQwXLJgwkaAgszgyVNGEjEwhJ8Cmo4KAg7Hvn2fa3ff2J4z4Et84X7TRm60BBOCXg0i6o/UkBw==","ARC-Authentication-Results":"i=1; lists.ozlabs.org;\n dmarc=pass (p=quarantine dis=none) header.from=kernel.org;\n dkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=b03Nikmd; dkim-atps=neutral;\n spf=pass (client-ip=2600:3c04:e001:324:0:1991:8:25;\n helo=tor.source.kernel.org; envelope-from=jic23@kernel.org;\n receiver=lists.ozlabs.org) smtp.mailfrom=kernel.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n\ts=k20201202; t=1776688125;\n\tbh=PWbi3uYEMLYl5AB0E9ZA8pTD7EAbj4oPfcLDQJ5dlTE=;\n\th=Date:From:To:Cc:Subject:In-Reply-To:References:From;\n\tb=b03NikmdD9k3sKoZWaBDQQ583FdvvV7wLwVmW259D07WRaPT9GkHTVqeh4t9cA9K7\n\t n62DM7AW/HMU2PBzjaE4ds/khF2bwr9zuxVPmyeSPOvqvre41Lo5dD5vQtgffBlYD2\n\t 1skE86YqGO5RLoOa6pjLk+dPixvXgiVWbrCXnyGRREXEjW3kxr5umi/zzPR24oqjlS\n\t PWWpA+YFDD94YYjbWbQw/58AJut6Er0d0T9By/LeM2Efo5+ejHXO41TZRhT4zr43vu\n\t Dsylx0uX5mlAvXepUawKNh4U+8KizNECwWkpn62y5Rj7zeyGyir0n42C248YSMNoGo\n\t aNvitnb6wk9lA==","Date":"Mon, 20 Apr 2026 13:28:38 +0100","From":"Jonathan Cameron <jic23@kernel.org>","To":"David Carlier <devnexen@gmail.com>","Cc":"tmaimon77@gmail.com, avifishman70@gmail.com, tali.perry1@gmail.com,\n andrew@codeconstruct.com.au, venture@google.com, yuenn@google.com,\n benjaminfair@google.com, dlechner@baylibre.com, nuno.sa@analog.com,\n andy@kernel.org, andriy.shevchenko@intel.com, openbmc@lists.ozlabs.org,\n linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org","Subject":"Re: [PATCH v3] iio: adc: npcm: fix unbalanced\n clk_disable_unprepare()","Message-ID":"<20260420132838.147d18b6@jic23-huawei>","In-Reply-To":"<20260414123006.262152-1-devnexen@gmail.com>","References":"<20260414123006.262152-1-devnexen@gmail.com>","X-Mailer":"Claws Mail 4.4.0 (GTK 3.24.52; x86_64-pc-linux-gnu)","X-Mailing-List":"openbmc@lists.ozlabs.org","List-Id":"<openbmc.lists.ozlabs.org>","List-Help":"<mailto:openbmc+help@lists.ozlabs.org>","List-Owner":"<mailto:openbmc+owner@lists.ozlabs.org>","List-Post":"<mailto:openbmc@lists.ozlabs.org>","List-Subscribe":"<mailto:openbmc+subscribe@lists.ozlabs.org>,\n  <mailto:openbmc+subscribe-digest@lists.ozlabs.org>,\n  <mailto:openbmc+subscribe-nomail@lists.ozlabs.org>","List-Unsubscribe":"<mailto:openbmc+unsubscribe@lists.ozlabs.org>","Precedence":"list","MIME-Version":"1.0","Content-Type":"text/plain; charset=US-ASCII","Content-Transfer-Encoding":"7bit","X-Spam-Status":"No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED,\n\tDKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS\n\tautolearn=disabled version=4.0.1","X-Spam-Checker-Version":"SpamAssassin 4.0.1 (2024-03-25) on lists.ozlabs.org"}}]