From nobody Mon Jun 15 15:20:23 2026 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (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 E698819DF62 for ; Sat, 11 Apr 2026 12:35:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775910925; cv=none; b=HxGktCiTQkGG601Xh8EGxrHL+Itoe+oTrASyhkLVdmPecfmttvj3u6mdMYxixTEBjZOqaK+YJA3aZsXeoCKV4SLLfwgrCSQzQQD6L8qfk7fVDYMOQ6aF36piNCNxOtdk9KJt7Gnq4O8u6+9ntjzHPVB2fUoLL7uvWDyXGkPyPW4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775910925; c=relaxed/simple; bh=mjPeDXhKfleOqWQe5ymw3i8wHdAtO3jnVFCC15yVock=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=p3lKtPfdbyLJvytw5/TcbmkTXubL8NPL4nE4cfB2Gkr79ku1qdpC+CH34+MrGo9dTLkpZ2mTsyx2f6rthzbblJCXG1BdasyNm3RKgF2mARUGXfzZaWj9E8XT0H9xrRmKS9X8GNYcUHZFvEHqUmurW5Ciwi4H7fx3bq3CyPA+IpI= 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=RKtkvoqD; arc=none smtp.client-ip=209.85.221.48 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="RKtkvoqD" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-43cf3ee0fc1so1813035f8f.1 for ; Sat, 11 Apr 2026 05:35:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775910921; x=1776515721; 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=JGoFfy0QWc8BwYX8irlGqExRr/Ktk1fkaAh03XIjtf4=; b=RKtkvoqDGzgSlUGMHdcgZr5A9I+AFP68QkxYw+ftn2E0soWrYZXeIcJXfkix/f61Xq Zd+Xhv3Q1zFW8airfWMTc7tQuBQXeZv82LvU02wG+iM3AdX0XlHvMbQ4uiGBqFo+YNe/ 8aBuKwrNSVqE5Umy0XHFEU+W0WypEDthCr7+NQyyb10BvmpUcgQP9uIrkLcOZPan7tFg UZWB7rcXEqSXuG4JNJto9GyNyBU4EbrHs+9/WXt44hf0ocB9lUE6Q1qPYbWaJPuIQVpv RK8QgYhN+RzuKszoq0baJGBDV17yvx9QjD4qNhk92YIiyphAzrNjDVXZMUqNivIvEQIc 9eIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775910921; x=1776515721; 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=JGoFfy0QWc8BwYX8irlGqExRr/Ktk1fkaAh03XIjtf4=; b=MckbM+9KIUejThut0aJmadEA0Ql66Mz/dFpxNW++ednylhsAZeKuh9LjJUfgIE7IRx FtXHojWrvXBBhfU/3w/i4ni7BcayWD300vXomf5oaJrdxjTQJXCNpQ3Ew5b6Oi+Nfs83 aeiItmaEyvxPgbQm2sKO8COPYm0GGZCegW4+pxXq3IQ8znHeLvrk5m3t5rfUH92V/E5p 8zbnXTX0GLWW22LWw9qaet9DPG5l843jF9szyRQbe0crq+msABrOfaL2Z4eZi+wg3rJy dhxJGRZiPP2P7L9Gfd+c9KLlGax8AHCQa9VH77giGN+zgtHkqhRG5rIGu9a9lQVvTbPz J+xg== X-Forwarded-Encrypted: i=1; AJvYcCUWsbO48C4A6ViGtleITEdxUzc3gJlePozWyb8s2cFMETcl52RWuLKkYjRcUfudDQWOKRmP/aw4hfHsbzw=@vger.kernel.org X-Gm-Message-State: AOJu0YyBAB+1eFc6+GK5E77m0iXbSKtUY67c7HqlOScMdXx+PEZ+Scc7 shB056Na+D8hAnfnV0Lnf2nrPyeBZSp0dvZTzS1zDxUDgwlkJ4CXTMIv X-Gm-Gg: AeBDievv4gh6K/MG6Rrz2+JZ6849PsX+Kv+hWOnBuHqb0//jxEOqvri7qnwCl4LAuEX 53BQ5+Uiama/5+hl1XR0O861G7naTUtkDgiTN+xQ8WAvbc7JNQD654chzcO98SFtsheZBkwafN8 /eeD/0aM0OSf3pT2mWvvSWupU0AcG75nzAYTnOdIi7/4MfeBB2pN0sgb+PrTJJn+DL8hNODb7Vb Rrf+JLYJdY4gYAWa+GPqNSzOrjIznj3CEk081lXhV9R7ZRss6lA0hEBpVAvI7I3/8M4T3fJ12Es zs+4T0xwpL8ZeMio5GUNCRDVuYGZ0RaEiSU90w7mYSqIlbgD/yoheaRc2ZDVpvszSAPrr8bRN/4 WflhD7NH2TtM+M3zv8evLPAh35dDJ/WwKxztOvlZ+sgNfAeEnTSsTX+nUkkC5xOS6YwdAjMh9Xd Zu355fHg1OxA0dXQ/1WZPThAszw073lSigw3T/8o8CFzgHuwtxupcur/P8jZANsVZhlot9KU7Ng 0tXV18mG1KU X-Received: by 2002:a05:600d:a:b0:485:3428:774c with SMTP id 5b1f17b1804b1-488d682bb48mr68343125e9.4.1775910921131; Sat, 11 Apr 2026 05:35:21 -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-488d532ef00sm163047155e9.5.2026.04.11.05.35.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Apr 2026 05:35:20 -0700 (PDT) From: David Carlier To: Jonathan Cameron Cc: Tomer Maimon , Avi Fishman , Tali Perry , Andrew Jeffery , Patrick Venture , Nancy Yuen , Benjamin Fair , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , linux-iio@vger.kernel.org, openbmc@lists.ozlabs.org, linux-kernel@vger.kernel.org, David Carlier Subject: [PATCH] iio: adc: npcm: fix unbalanced clk_disable_unprepare() Date: Sat, 11 Apr 2026 13:35:17 +0100 Message-ID: <20260411123517.15083-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: quoted-printable Content-Type: text/plain; charset="utf-8" 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(). Fixes: 9bf85fbc9d8f ("iio: adc: add NPCM ADC driver") Signed-off-by: David Carlier Reviewed-by: Nuno S=C3=A1 --- drivers/iio/adc/npcm_adc.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/drivers/iio/adc/npcm_adc.c b/drivers/iio/adc/npcm_adc.c index ddabb9600d46..6acafef3e7c7 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); =20 - info->adc_clk =3D devm_clk_get(&pdev->dev, NULL); + info->adc_clk =3D 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,16 +244,14 @@ static int npcm_adc_probe(struct platform_device *pde= v) info->adc_sample_hz =3D clk_get_rate(info->adc_clk) / ((div + 1) * 2); =20 irq =3D platform_get_irq(pdev, 0); - if (irq < 0) { - ret =3D irq; - goto err_disable_clk; - } + if (irq < 0) + return irq; =20 ret =3D 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; + return ret; } =20 reg_con =3D ioread32(info->regs + NPCM_ADCCON); @@ -262,7 +260,7 @@ static int npcm_adc_probe(struct platform_device *pdev) ret =3D regulator_enable(info->vref); if (ret) { dev_err(&pdev->dev, "Can't enable ADC reference voltage\n"); - goto err_disable_clk; + return ret; } =20 iowrite32(reg_con & ~NPCM_ADCCON_REFSEL, @@ -274,7 +272,7 @@ static int npcm_adc_probe(struct platform_device *pdev) */ if (PTR_ERR(info->vref) !=3D -ENODEV) { ret =3D PTR_ERR(info->vref); - goto err_disable_clk; + return ret; } =20 /* Use internal reference */ @@ -314,8 +312,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); =20 return ret; } @@ -332,7 +328,6 @@ static void npcm_adc_remove(struct platform_device *pde= v) 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); } =20 static struct platform_driver npcm_adc_driver =3D { --=20 2.53.0