Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Uwe Kleine-König and committed by
Uwe Kleine-König
e866834c 2006016e

+16 -5
+16 -5
drivers/pwm/core.c
··· 404 404 * Typically a requested waveform cannot be implemented exactly, e.g. because 405 405 * you requested .period_length_ns = 100 ns, but the hardware can only set 406 406 * periods that are a multiple of 8.5 ns. With that hardware passing @exact = 407 - * true results in pwm_set_waveform_might_sleep() failing and returning 1. If 408 - * @exact = false you get a period of 93.5 ns (i.e. the biggest period not bigger 409 - * than the requested value). 407 + * true results in pwm_set_waveform_might_sleep() failing and returning -EDOM. 408 + * If @exact = false you get a period of 93.5 ns (i.e. the biggest period not 409 + * bigger than the requested value). 410 410 * Note that even with @exact = true, some rounding by less than 1 ns is 411 411 * possible/needed. In the above example requesting .period_length_ns = 94 and 412 412 * @exact = true, you get the hardware configured with period = 93.5 ns. 413 413 * 414 - * Returns: 0 on success, 1 if was rounded up (if !@exact) or no perfect match was 415 - * possible (if @exact), or a negative errno 414 + * Returns: 0 on success, 1 if was rounded up (if !@exact), -EDOM if setting 415 + * failed due to the exact waveform not being possible (if @exact), or a 416 + * different negative errno on failure. 416 417 * Context: May sleep. 417 418 */ 418 419 int pwm_set_waveform_might_sleep(struct pwm_device *pwm, ··· 440 439 } else { 441 440 err = __pwm_set_waveform(pwm, wf, exact); 442 441 } 442 + 443 + /* 444 + * map err == 1 to -EDOM for exact requests. Also make sure that -EDOM is 445 + * only returned in exactly that case. Note that __pwm_set_waveform() 446 + * should never return -EDOM which justifies the unlikely(). 447 + */ 448 + if (unlikely(err == -EDOM)) 449 + err = -EINVAL; 450 + else if (exact && err == 1) 451 + err = -EDOM; 443 452 444 453 return err; 445 454 }