From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7978C410D1A for ; Thu, 4 Jun 2026 11:25:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780572360; cv=none; b=W2OC0uOPcM9HIXy0+7j2mroYzahQ0tuse2OMI70Ef0rXR0cAxBwKvbsGtYr2NFt2DkDBwiyXQuVc61OD51gee7ZF6psY3vTMFqv6n7DhF60oAcqOCf+AKzUOkCXjZWtSK9tgef+mpSm0zYI/ZNHJZ0j6dlPaCMIDSdztFVvxEu0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780572360; c=relaxed/simple; bh=swLtrDZwC+utkyy8X5iNJ7Q6q840hnfzNr7USuEpQrE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g8UxykfkxSqYzUKj+n+DeSqIndP7jIhhwLRD6vhwsK12iSYl+2KNfStcpZVI18ZU9UjAnNAKrJJ+PZc338vDZgs0JWnWfcH1PB7M4fYKujs1jvjymzrDgJYrpmBJS15+IVuHabmjQO8IxasLs+ltp2PHzwfU54qnvTFe5f50F4c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Eevbz9H+; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Eevbz9H+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76F161F00898; Thu, 4 Jun 2026 11:25:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780572359; bh=LtOn8sCBG3bF7XcWZ/trwhNuBWmMfJaHiY033fLgy/k=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Eevbz9H+L0on8vQW/rbMQMWaeFinUS0ZLPxo+NUJ97G6ElIhXH2V3jECguQEdR5fw UZJKRA+9JDiPSXKhndrqA18hmKG9cWugxxFXPMeaVEOkDLYOG6SiFrw+cTjmemtxMA FK4A/6GYmmyS+A7u+Ngo4ktyflds/Tb23rob3v5/h5BIOxQEKTta3RKu1KUwzMBrws WOL6YB6ZRAc9a9aTY32CBmgbkYcnkEomhvBuOWIkwYRXavvrzdHud4Br+mogsx2+PS 2PhLvu41pqbI3cFKDyyDe6jyBhAGjVsDT9BKnqxRqmNYdXDtgUqwyC9ZDRzQ1q3LEw O2YQFeM85NZlQ== From: Sasha Levin To: stable@vger.kernel.org Cc: David Carlier , Andy Shevchenko , Stable@vger.kernel.org, Jonathan Cameron , Sasha Levin Subject: [PATCH 6.6.y 2/2] iio: adc: npcm: fix unbalanced clk_disable_unprepare() Date: Thu, 4 Jun 2026 07:25:56 -0400 Message-ID: <20260604112556.3253850-2-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260604112556.3253850-1-sashal@kernel.org> References: <2026060417-editor-stylishly-7101@gregkh> <20260604112556.3253850-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: David Carlier [ Upstream commit 0d42e2c0bd6ceb89e44c6e065f9bdf9b1df3ef0c ] 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 Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Sasha Levin --- 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 3a55465951e793..84f306b76c57d3 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