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

power: reset: ltc2952: check trigger value before starting timer

In ltc2952_poweroff_handler it is theoretically possible that the timer
fails to start on first pass (button press), but succeeds in starting on
the second (button release). This will cause the button press to be
misinterpreted, and will incorrectly shut down the system. Because a
picture says more than a thousand words:

Expected behavior:
tmr: ++++++++++
btn: -----__________-----

Faulty behavior:
tmr: +++++
btn: -----__________-----

Legend:
+ timer runs
_ button pressed
- button depressed

To prevent this from happening, check the value of the gpio before
starting the timer. If the button is active, we should start the timer,
else we should stop it.

The situation described can now still occur if the polarity of the input
pin is set incorrectly, but that at least is predictable behavior and
can be detected during the first tests.

Signed-off-by: Frans Klaver <frans.klaver@xsens.com>
Signed-off-by: Sebastian Reichel <sre@kernel.org>

authored by

Frans Klaver and committed by
Sebastian Reichel
c1ada2ff 2f6ea8ad

+1 -1
+1 -1
drivers/power/reset/ltc2952-poweroff.c
··· 160 160 return IRQ_HANDLED; 161 161 } 162 162 163 - if (!hrtimer_active(&data->timer_trigger)) { 163 + if (gpiod_get_value(data->gpio_trigger)) { 164 164 if (hrtimer_start(&data->timer_trigger, data->trigger_delay, 165 165 HRTIMER_MODE_REL)) 166 166 dev_err(data->dev, "unable to start the wait timer\n");