Skip to content

Commit 96d20cf

Browse files
ukleinekUwe Kleine-König
authored andcommitted
pwm: Do stricter return value checking for .round_waveform_tohw()
The .round_waveform_tohw() is supposed to return 0 if the request could be rounded down to match the hardware capabilities and return 1 if rounding down wasn't possible. Expand the PWM_DEBUG check to not only assert proper downrounding if 0 was returned but also check that it was actually rounded up when the callback signalled uprounding. Signed-off-by: Uwe Kleine-König <[email protected]> Link: https://lore.kernel.org/r/dfb824ae37f99df068c752d48cbd163c044a74fb.1743844730.git.u.kleine-koenig@baylibre.com Signed-off-by: Uwe Kleine-König <[email protected]>
1 parent fa829c1 commit 96d20cf

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

drivers/pwm/core.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,10 @@ int pwm_round_waveform_might_sleep(struct pwm_device *pwm, struct pwm_waveform *
270270
wf_req.duty_length_ns, wf_req.period_length_ns, wf_req.duty_offset_ns, ret_tohw);
271271

272272
if (IS_ENABLED(CONFIG_PWM_DEBUG) &&
273-
ret_tohw == 0 && !pwm_check_rounding(&wf_req, wf))
274-
dev_err(&chip->dev, "Wrong rounding: requested %llu/%llu [+%llu], result %llu/%llu [+%llu]\n",
273+
(ret_tohw == 0) != pwm_check_rounding(&wf_req, wf))
274+
dev_err(&chip->dev, "Wrong rounding: requested %llu/%llu [+%llu], result %llu/%llu [+%llu], ret: %d\n",
275275
wf_req.duty_length_ns, wf_req.period_length_ns, wf_req.duty_offset_ns,
276-
wf->duty_length_ns, wf->period_length_ns, wf->duty_offset_ns);
276+
wf->duty_length_ns, wf->period_length_ns, wf->duty_offset_ns, ret_tohw);
277277

278278
return ret_tohw;
279279
}
@@ -341,10 +341,10 @@ static int __pwm_set_waveform(struct pwm_device *pwm,
341341
if (err)
342342
return err;
343343

344-
if (IS_ENABLED(CONFIG_PWM_DEBUG) && ret_tohw == 0 && !pwm_check_rounding(wf, &wf_rounded))
345-
dev_err(&chip->dev, "Wrong rounding: requested %llu/%llu [+%llu], result %llu/%llu [+%llu]\n",
344+
if (IS_ENABLED(CONFIG_PWM_DEBUG) && (ret_tohw == 0) != pwm_check_rounding(wf, &wf_rounded))
345+
dev_err(&chip->dev, "Wrong rounding: requested %llu/%llu [+%llu], result %llu/%llu [+%llu], ret: %d\n",
346346
wf->duty_length_ns, wf->period_length_ns, wf->duty_offset_ns,
347-
wf_rounded.duty_length_ns, wf_rounded.period_length_ns, wf_rounded.duty_offset_ns);
347+
wf_rounded.duty_length_ns, wf_rounded.period_length_ns, wf_rounded.duty_offset_ns, ret_tohw);
348348

349349
if (exact && pwmwfcmp(wf, &wf_rounded)) {
350350
dev_dbg(&chip->dev, "Requested no rounding, but %llu/%llu [+%llu] -> %llu/%llu [+%llu]\n",

0 commit comments

Comments
 (0)