diff options
author | Uwe Kleine-König <u.kleine-koenig@baylibre.com> | 2025-04-30 13:55:58 +0200 |
---|---|---|
committer | Uwe Kleine-König <ukleinek@kernel.org> | 2025-05-07 11:48:35 +0200 |
commit | e866834c8baabc33b431902beeeb0c94dfbc1024 (patch) | |
tree | 6000b9248a43557075627edf192c6db3b1bf2efd | |
parent | 2006016ec6b3a18f2659704cb2f70ad3387f4a62 (diff) |
pwm: Let pwm_set_waveform_might_sleep() fail for exact but impossible requests
Up to now pwm_set_waveform_might_sleep() returned 1 for exact requests
that couldn't be served exactly. In contrast to
pwm_round_waveform_might_sleep() and pwm_set_waveform_might_sleep() with
exact = false this is an error condition. So simplify handling for
callers of pwm_set_waveform_might_sleep() by returning -EDOM instead of
1 in this case.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Link: https://lore.kernel.org/r/20538a46719584dafd8a1395c886780a97dcdf79.1746010245.git.u.kleine-koenig@baylibre.com
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
-rw-r--r-- | drivers/pwm/core.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index e0a90c4cd723..28cb6ab0f62d 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -404,15 +404,16 @@ static int __pwm_set_waveform(struct pwm_device *pwm, * Typically a requested waveform cannot be implemented exactly, e.g. because * you requested .period_length_ns = 100 ns, but the hardware can only set * periods that are a multiple of 8.5 ns. With that hardware passing @exact = - * true results in pwm_set_waveform_might_sleep() failing and returning 1. If - * @exact = false you get a period of 93.5 ns (i.e. the biggest period not bigger - * than the requested value). + * true results in pwm_set_waveform_might_sleep() failing and returning -EDOM. + * If @exact = false you get a period of 93.5 ns (i.e. the biggest period not + * bigger than the requested value). * Note that even with @exact = true, some rounding by less than 1 ns is * possible/needed. In the above example requesting .period_length_ns = 94 and * @exact = true, you get the hardware configured with period = 93.5 ns. * - * Returns: 0 on success, 1 if was rounded up (if !@exact) or no perfect match was - * possible (if @exact), or a negative errno + * Returns: 0 on success, 1 if was rounded up (if !@exact), -EDOM if setting + * failed due to the exact waveform not being possible (if @exact), or a + * different negative errno on failure. * Context: May sleep. */ int pwm_set_waveform_might_sleep(struct pwm_device *pwm, @@ -440,6 +441,16 @@ int pwm_set_waveform_might_sleep(struct pwm_device *pwm, err = __pwm_set_waveform(pwm, wf, exact); } + /* + * map err == 1 to -EDOM for exact requests. Also make sure that -EDOM is + * only returned in exactly that case. Note that __pwm_set_waveform() + * should never return -EDOM which justifies the unlikely(). + */ + if (unlikely(err == -EDOM)) + err = -EINVAL; + else if (exact && err == 1) + err = -EDOM; + return err; } EXPORT_SYMBOL_GPL(pwm_set_waveform_might_sleep); |