crc_pwm_apply() computes the duty cycle register value by dividing by the requested period: u64 level = state->duty_cycle * PWM_MAX_LEVEL; do_div(level, state->period); The PWM core accepts a period of zero for a disabled PWM: pwm_state_valid() returns true early in that case, and period_store() writes the user supplied value to state.period without further validation. Writing 0 to the period attribute of a disabled PWM therefore reaches this code with a zero divisor and crashes the kernel: $ echo 0 > /sys/class/pwm/pwmchip0/pwm0/period divide error: 0000 [#1] SMP Return early for disabled PWMs once the backlight has been switched off. The duty cycle and clock divider are irrelevant while the output is off and are programmed again when the PWM gets enabled. Fixes: a3f37a104bc4 ("pwm: crc: Add Crystalcove (CRC) PWM driver") Cc: stable@vger.kernel.org Signed-off-by: Lin Huiyi --- drivers/pwm/pwm-crc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/pwm/pwm-crc.c b/drivers/pwm/pwm-crc.c index 98ee5cdbd0..05f6517443 100644 --- a/drivers/pwm/pwm-crc.c +++ b/drivers/pwm/pwm-crc.c @@ -72,6 +72,9 @@ static int crc_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, } } + if (!state->enabled) + return 0; + if (pwm_get_duty_cycle(pwm) != state->duty_cycle || pwm_get_period(pwm) != state->period) { u64 level = state->duty_cycle * PWM_MAX_LEVEL; -- 2.56.1