From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5125E3E5EF5 for ; Tue, 14 Apr 2026 12:30:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776169813; cv=none; b=RtoIwXMarF0ZNu2HiOQWFvi2zhHJ79nzB6kKBc6v1tHhLFHj4bbxMX3bpielbZfazYZ9HFZygwCR7HiLT8Vrl8OUsQDUa+w2NVhrIPf4qT6gzAYrzktCzVPnxTLFgg8m9UeCKezC377eFN/6Mz0MbPp22gueZCnAXG6w/Q/5xgM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776169813; c=relaxed/simple; bh=9sTV1Z9z8WDg4IMrXvQiXfpITvPwawHzhSeoN2l5Z58=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=e0C9t3yDI1jckzeAEyLsCax/avCytNMxb4iDaVwz+NLo1vdm72I+U8ekGX3yChWfKdlYBLKY9+pJ2C5+qKWzo9130/Sx8e4lAb/idOIX89edpceoOHy0EY9PlT864fzhUrbVGyVqCK0JRJjSoNIE2o08nHe/Dd71K5VFLXQW/0w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ifHodL94; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ifHodL94" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-48897fd88ebso58452215e9.2 for ; Tue, 14 Apr 2026 05:30:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776169811; x=1776774611; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=WW4kcmfHDRNiC/0ztPa+kXKA3hUAYvX9T4RsXBiI8d8=; b=ifHodL94i2HgJj3sVE1p3w0eICYev48dcEETIdAV5F2OI8TUa9qD8EBAyQwWQBFok2 dFrzB+BXKFWmIgasqbGvA8uEQQTHmE3/O/n0OvM22E8V78Lit7bLl+VU8iRBc3YvFNqJ 7/vsq5lf3+WIFuB4S/UNaznEBm7uFVK1gx4AFS8qIXa2jZ4+aq32d9kGwIvFeTMwuA5C yMWnTLcdy4asWSqzXoI9U7pv1wKJjupfmv9IrawCoZCfwJm4jmYVwywuHnfzcrKPKDU5 nwVej78fLc9B7YYJTRU4rhZ3iAoOfVLzTZuCXiT1OmXiLDO2D2CFtCAymw0J7MYNH4pR Qw7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776169811; x=1776774611; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=WW4kcmfHDRNiC/0ztPa+kXKA3hUAYvX9T4RsXBiI8d8=; b=WjKVzHb2hI2s/dQXHajKHszua9MPi7URsD/KB9Cp1Q/j3OniRImZ0xs0uf6B014Kaq x8oiYKZLA2GnaC5Kyb53d05xtBQHvnOJWUUIE8G87jM48BjQYVa0Z8DL5fPMR0CZM2cZ Z9T2dEDGncL7kJSkd0PH+EbrPle57CRzQIaaS2e/JVvAvdavXnbcJNIkycNYWyCZsQej jYQ3B13/S40+u/duSfPEXl2HHkUWxkRL6H4YWax9axx8PBB3LuBptxETjjwKIKL5VrLr jkTG4+irPXCvT8OfC5mpooSrVu7jcH7zhbo23/r5ZITNiHLjAWu/5wKzD+mTxLPO7q/t aXvg== X-Forwarded-Encrypted: i=1; AFNElJ907SRv8HtZJHPgMRTRcJiR0Pqv7kXDJVO9vFMn/5P3OQ/KF8MT0Crqnkt1u7QxBBoSE445Uoj8bFQqegk=@vger.kernel.org X-Gm-Message-State: AOJu0YzwJX47KlwLQ+lbjt/yzTaXWH45HgXcNUdlJBhmpQIyeMOaiDPU qJmT3hpjn2iiInIz0bcFWQrOvTubkRv/tskzvjTzXDiMSMZ/Y8fy31vt X-Gm-Gg: AeBDievyZZJFSEtjf29dcuh7e5X6flTQHEKCtboVccfJCl0LQ2bjsIh0eXUJW3VWXon 29ls8xAXoI2d1/OuCY+UiAwdbqyrGqSCoNty++alCt4h6pcKqyV7wleX033T/voB2GXcE8ARODw 6+CM10FUmQe3wRFKhtK5vXUqV/VFcCM/9dn/8vxGerF/g99jkQ5r7ufE9hVQsABu2McMBXQ3N7X c2QYEI0Yh/8oBt7o1k9OzNQXa73Pa3BPdICaAzoa8tcNXejEz2AUoRpAii5Ycvl90d7wNOte5QT KDymS5rj2QHjyLgpWNufUXutE3kyMPytLgBXIBMYPx9yfL3yFw2PCv1rYy/DC6lAc2Q1Tl0YZuX 6m4RkSkGxk5f0GiHPaTzF2WcGRWQpAwOFJA1PA1BsJ84fJEzajsxyBptbFjWWfi6idReeZFHKKt ZA6avcMJPqiCNFO3+d9T+67mzDhc1OD0SPx1Lx904qPeNVg5WJtpiYBTmeYlgpCCuZPLeI+lBLV MD2d5fxrfOL X-Received: by 2002:a05:600c:5249:b0:488:c40b:c8bf with SMTP id 5b1f17b1804b1-488d680577dmr229609355e9.2.1776169810158; Tue, 14 Apr 2026 05:30:10 -0700 (PDT) Received: from dohko.chello.ie (188-141-5-72.dynamic.upc.ie. [188.141.5.72]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488d681edc7sm118080145e9.17.2026.04.14.05.30.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Apr 2026 05:30:09 -0700 (PDT) From: David Carlier To: jic23@kernel.org Cc: tmaimon77@gmail.com, avifishman70@gmail.com, tali.perry1@gmail.com, andrew@codeconstruct.com.au, venture@google.com, yuenn@google.com, benjaminfair@google.com, dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, andriy.shevchenko@intel.com, openbmc@lists.ozlabs.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, David Carlier Subject: [PATCH v3] iio: adc: npcm: fix unbalanced clk_disable_unprepare() Date: Tue, 14 Apr 2026 13:30:06 +0100 Message-ID: <20260414123006.262152-1-devnexen@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The driver acquired the ADC clock with devm_clk_get() and read its rate, but never called clk_prepare_enable(). The probe error path and npcm_adc_remove() both called clk_disable_unprepare() unconditionally, causing the clk framework's enable/prepare counts to underflow on probe failure or module unbind. The issue went unnoticed because NPCM BMC firmware leaves the ADC clock enabled at boot, so the driver happened to work in practice. Switch to devm_clk_get_enabled() so the clock is properly enabled during probe and automatically released by the device-managed cleanup, and drop the now-redundant clk_disable_unprepare() from both the probe error path and remove(). While at it, drop the duplicate error message on devm_request_irq() failure since the IRQ core already logs it. Fixes: 9bf85fbc9d8f ("iio: adc: add NPCM ADC driver") Signed-off-by: David Carlier Reviewed-by: Andy Shevchenko --- v3: mention the dev_err drop in the commit log and collapse the single-statement -ENODEV branch (Andy Shevchenko). v2: drop redundant dev_err() on devm_request_irq() failure since the IRQ core already logs it, and remove the now-single-statement braces (Andy Shevchenko). drivers/iio/adc/npcm_adc.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/drivers/iio/adc/npcm_adc.c b/drivers/iio/adc/npcm_adc.c index ddabb9600d46..61c8b825bda1 100644 --- a/drivers/iio/adc/npcm_adc.c +++ b/drivers/iio/adc/npcm_adc.c @@ -231,7 +231,7 @@ static int npcm_adc_probe(struct platform_device *pdev) if (IS_ERR(info->reset)) return PTR_ERR(info->reset); - info->adc_clk = devm_clk_get(&pdev->dev, NULL); + info->adc_clk = devm_clk_get_enabled(&pdev->dev, NULL); if (IS_ERR(info->adc_clk)) { dev_warn(&pdev->dev, "ADC clock failed: can't read clk\n"); return PTR_ERR(info->adc_clk); @@ -244,17 +244,13 @@ static int npcm_adc_probe(struct platform_device *pdev) info->adc_sample_hz = clk_get_rate(info->adc_clk) / ((div + 1) * 2); irq = platform_get_irq(pdev, 0); - if (irq < 0) { - ret = irq; - goto err_disable_clk; - } + if (irq < 0) + return irq; ret = devm_request_irq(&pdev->dev, irq, npcm_adc_isr, 0, "NPCM_ADC", indio_dev); - if (ret < 0) { - dev_err(dev, "failed requesting interrupt\n"); - goto err_disable_clk; - } + if (ret < 0) + return ret; reg_con = ioread32(info->regs + NPCM_ADCCON); info->vref = devm_regulator_get_optional(&pdev->dev, "vref"); @@ -262,7 +258,7 @@ static int npcm_adc_probe(struct platform_device *pdev) ret = regulator_enable(info->vref); if (ret) { dev_err(&pdev->dev, "Can't enable ADC reference voltage\n"); - goto err_disable_clk; + return ret; } iowrite32(reg_con & ~NPCM_ADCCON_REFSEL, @@ -272,10 +268,8 @@ static int npcm_adc_probe(struct platform_device *pdev) * Any error which is not ENODEV indicates the regulator * has been specified and so is a failure case. */ - if (PTR_ERR(info->vref) != -ENODEV) { - ret = PTR_ERR(info->vref); - goto err_disable_clk; - } + if (PTR_ERR(info->vref) != -ENODEV) + return PTR_ERR(info->vref); /* Use internal reference */ iowrite32(reg_con | NPCM_ADCCON_REFSEL, @@ -314,8 +308,6 @@ static int npcm_adc_probe(struct platform_device *pdev) iowrite32(reg_con & ~NPCM_ADCCON_ADC_EN, info->regs + NPCM_ADCCON); if (!IS_ERR(info->vref)) regulator_disable(info->vref); -err_disable_clk: - clk_disable_unprepare(info->adc_clk); return ret; } @@ -332,7 +324,6 @@ static void npcm_adc_remove(struct platform_device *pdev) iowrite32(regtemp & ~NPCM_ADCCON_ADC_EN, info->regs + NPCM_ADCCON); if (!IS_ERR(info->vref)) regulator_disable(info->vref); - clk_disable_unprepare(info->adc_clk); } static struct platform_driver npcm_adc_driver = { -- 2.53.0