@@ -404,15 +404,16 @@ static int __pwm_set_waveform(struct pwm_device *pwm,
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,6 +441,16 @@ int pwm_set_waveform_might_sleep(struct pwm_device *pwm,
440
441
err = __pwm_set_waveform (pwm , wf , exact );
441
442
}
442
443
444
+ /*
445
+ * map err == 1 to -EDOM for exact requests. Also make sure that -EDOM is
446
+ * only returned in exactly that case. Note that __pwm_set_waveform()
447
+ * should never return -EDOM which justifies the unlikely().
448
+ */
449
+ if (unlikely (err == - EDOM ))
450
+ err = - EINVAL ;
451
+ else if (exact && err == 1 )
452
+ err = - EDOM ;
453
+
443
454
return err ;
444
455
}
445
456
EXPORT_SYMBOL_GPL (pwm_set_waveform_might_sleep );
0 commit comments