mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nicolae-Daniel Deaconescu <Nicolae-daniel.Deaconescu@analog.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: "Uwe Kleine-König" <ukleinek@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Michael Hennerich" <michael.hennerich@analog.com>,
	"Trevor Gamblin" <tgamblin@baylibre.com>,
	"Joshua Crofts" <crofts@kernel.org>,
	"Sergiu Cuciurean" <sergiu.cuciurean@analog.com>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-pwm@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	"Nicolae-Daniel Deaconescu"
	<Nicolae-daniel.Deaconescu@analog.com>
Subject: [PATCH v2 3/5] iio: adc: ad7625: fix sampling frequency handling
Date: Wed, 4 Nov 2026 15:21:41 +0200	[thread overview]
Message-ID: <20261104132143.215581-4-Nicolae-daniel.Deaconescu@analog.com> (raw)
In-Reply-To: <20261104132143.215581-1-Nicolae-daniel.Deaconescu@analog.com>

Fix the following issues in the handling of the sampling frequency:

- Fix the issue where writing 0 to sampling_frequency caused a division
  by zero. Return -EINVAL instead.
- Fix the issue where a waveform that the PWM had to round up was not
  reported as an error. pwm_round_waveform_might_sleep() returns 1 in that
  case and ad7625_set_sampling_freq() passed it on, so the write to
  sampling_frequency returned 1 and the new waveforms were dropped. Return
  -EINVAL instead.
- Fix the issue where probe() went on after failing to set the initial
  sampling frequency. The result of dev_err_probe() was not returned, so
  the PWMs stayed unconfigured. Return the error.

Fixes: b7ffd0fa65e9 ("iio: adc: ad7625: add driver")
Signed-off-by: Nicolae-Daniel Deaconescu <Nicolae-daniel.Deaconescu@analog.com>
---
 drivers/iio/adc/ad7625.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/adc/ad7625.c b/drivers/iio/adc/ad7625.c
index e73a5c9e7f0b..0de7f29797ef 100644
--- a/drivers/iio/adc/ad7625.c
+++ b/drivers/iio/adc/ad7625.c
@@ -178,6 +178,9 @@ static int ad7625_set_sampling_freq(struct ad7625_state *st, u32 freq)
 	unsigned long target;
 	int ret;
 
+	if (!freq)
+		return -EINVAL;
+
 	target = DIV_ROUND_UP(NSEC_PER_SEC, freq);
 	cnv_wf.period_length_ns = clamp(target, 100UL, 10UL * NSEC_PER_USEC);
 
@@ -189,7 +192,7 @@ static int ad7625_set_sampling_freq(struct ad7625_state *st, u32 freq)
 
 	ret = pwm_round_waveform_might_sleep(st->cnv_pwm, &cnv_wf);
 	if (ret)
-		return ret;
+		return ret < 0 ? ret : -EINVAL;
 
 	/*
 	 * Set up the burst signal for transferring data. period and
@@ -206,7 +209,7 @@ static int ad7625_set_sampling_freq(struct ad7625_state *st, u32 freq)
 
 	ret = pwm_round_waveform_might_sleep(st->clk_gate_pwm, &clk_gate_wf);
 	if (ret)
-		return ret;
+		return ret < 0 ? ret : -EINVAL;
 
 	st->cnv_wf = cnv_wf;
 	st->clk_gate_wf = clk_gate_wf;
@@ -646,8 +649,8 @@ static int ad7625_probe(struct platform_device *pdev)
 
 	ret = ad7625_set_sampling_freq(st, default_sample_freq);
 	if (ret)
-		dev_err_probe(dev, ret,
-			      "failed to set valid sampling frequency\n");
+		return dev_err_probe(dev, ret,
+				     "failed to set valid sampling frequency\n");
 
 	return devm_iio_device_register(dev, indio_dev);
 }
-- 
2.34.1


  parent reply	other threads:[~2026-11-04 13:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04 13:21 [PATCH v2 0/5] iio: adc: ad7625: add LTC2387 and ADAQ2387x support Nicolae-Daniel Deaconescu
2026-11-04 13:21 ` [PATCH v2 1/5] pwm: core: add pwm_get_waveform_step_might_sleep() Nicolae-Daniel Deaconescu
2026-11-04 19:51   ` Andy Shevchenko
2026-11-06 16:11     ` Nicolae-Daniel Deaconescu
2026-11-04 13:21 ` [PATCH v2 2/5] pwm: axi-pwmgen: report the waveform step Nicolae-Daniel Deaconescu
2026-11-04 13:21 ` Nicolae-Daniel Deaconescu [this message]
2026-11-04 13:21 ` [PATCH v2 4/5] dt-bindings: iio: adc: adi,ad7625: add LTC2387 and ADAQ2387x Nicolae-Daniel Deaconescu
2026-11-05  0:23   ` Conor Dooley
2026-11-06 16:11     ` Nicolae-Daniel Deaconescu
2026-11-04 13:21 ` [PATCH v2 5/5] iio: adc: ad7625: add LTC2387 and ADAQ2387x support Nicolae-Daniel Deaconescu
2026-11-04 20:22   ` Andy Shevchenko
2026-11-06 16:10     ` Nicolae-Daniel Deaconescu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261104132143.215581-4-Nicolae-daniel.Deaconescu@analog.com \
    --to=nicolae-daniel.deaconescu@analog.com \
    --cc=andy@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=crofts@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=michael.hennerich@analog.com \
    --cc=nuno.sa@analog.com \
    --cc=robh@kernel.org \
    --cc=sergiu.cuciurean@analog.com \
    --cc=tgamblin@baylibre.com \
    --cc=ukleinek@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®