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: Disable PWM_DEBUG check for disabled states

When a PWM is requested to be disabled, the result is unspecified, the only
intention is to save some power. So skip all checks in this case.

All but two checks already only triggered for states with .enabled = true.
The first resulted in some false positive diagnostics, the other checked
for a condition that depending on hardware might not be implementable.

Similar if the lowlevel driver disabled the hardware this might be a valid
reaction and with .enabled = false all other state parameters are
unreliable, so skip further tests in this case, too.

All later usages of .enabled can be assumed to yield true, and so several
if conditions can be simplified.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Link: https://lore.kernel.org/r/16d29212b09b66c286c1232b1ab0ec0f8d510aae.1751994988.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
5364e70b 09cbe546

+20 -12
+20 -12
drivers/pwm/core.c
··· 497 497 return; 498 498 499 499 /* 500 + * If a disabled PWM was requested the result is unspecified, so nothing 501 + * to check. 502 + */ 503 + if (!state->enabled) 504 + return; 505 + 506 + /* 500 507 * *state was just applied. Read out the hardware state and do some 501 508 * checks. 502 509 */ ··· 515 508 return; 516 509 517 510 /* 511 + * If the PWM was disabled that's maybe strange but there is nothing 512 + * that can be sensibly checked then. So return early. 513 + */ 514 + if (!s1.enabled) 515 + return; 516 + 517 + /* 518 518 * The lowlevel driver either ignored .polarity (which is a bug) or as 519 519 * best effort inverted .polarity and fixed .duty_cycle respectively. 520 520 * Undo this inversion and fixup for further tests. 521 521 */ 522 - if (s1.enabled && s1.polarity != state->polarity) { 522 + if (s1.polarity != state->polarity) { 523 523 s2.polarity = state->polarity; 524 524 s2.duty_cycle = s1.period - s1.duty_cycle; 525 525 s2.period = s1.period; 526 - s2.enabled = s1.enabled; 526 + s2.enabled = true; 527 527 } else { 528 528 s2 = s1; 529 529 } ··· 539 525 state->duty_cycle < state->period) 540 526 dev_warn(pwmchip_parent(chip), ".apply ignored .polarity\n"); 541 527 542 - if (state->enabled && s2.enabled && 543 - last->polarity == state->polarity && 528 + if (last->polarity == state->polarity && 544 529 last->period > s2.period && 545 530 last->period <= state->period) 546 531 dev_warn(pwmchip_parent(chip), ··· 550 537 * Rounding period up is fine only if duty_cycle is 0 then, because a 551 538 * flat line doesn't have a characteristic period. 552 539 */ 553 - if (state->enabled && s2.enabled && state->period < s2.period && s2.duty_cycle) 540 + if (state->period < s2.period && s2.duty_cycle) 554 541 dev_warn(pwmchip_parent(chip), 555 542 ".apply is supposed to round down period (requested: %llu, applied: %llu)\n", 556 543 state->period, s2.period); 557 544 558 - if (state->enabled && 559 - last->polarity == state->polarity && 545 + if (last->polarity == state->polarity && 560 546 last->period == s2.period && 561 547 last->duty_cycle > s2.duty_cycle && 562 548 last->duty_cycle <= state->duty_cycle) ··· 565 553 s2.duty_cycle, s2.period, 566 554 last->duty_cycle, last->period); 567 555 568 - if (state->enabled && s2.enabled && state->duty_cycle < s2.duty_cycle) 556 + if (state->duty_cycle < s2.duty_cycle) 569 557 dev_warn(pwmchip_parent(chip), 570 558 ".apply is supposed to round down duty_cycle (requested: %llu/%llu, applied: %llu/%llu)\n", 571 559 state->duty_cycle, state->period, 572 560 s2.duty_cycle, s2.period); 573 - 574 - if (!state->enabled && s2.enabled && s2.duty_cycle > 0) 575 - dev_warn(pwmchip_parent(chip), 576 - "requested disabled, but yielded enabled with duty > 0\n"); 577 561 578 562 /* reapply the state that the driver reported being configured. */ 579 563 err = chip->ops->apply(chip, pwm, &s1);