Skip to content

Commit 45f3b71

Browse files
MarcelKrkartben
authored andcommitted
input_gpio: Fix not using latest pin state on pm resume
When the device was suspended and the pin level changed during that time, the pin level of course isn't updated in the pins cb_data. Once the device is resumed, this leads to potentially having a wrong value in the pin state data leading to swallowing the first event due to comparing the stored level vs. the new level before reporting. Also added some `const`s and deleted an unused struct element. Signed-off-by: Marcel Krüger <[email protected]>
1 parent b31251b commit 45f3b71

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

drivers/input/input_gpio_keys.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ struct gpio_keys_pin_data {
3333
const struct device *dev;
3434
struct gpio_keys_callback cb_data;
3535
struct k_work_delayable work;
36-
int8_t pin_state;
3736
};
3837

3938
struct gpio_keys_config {
@@ -107,11 +106,12 @@ static __maybe_unused void gpio_keys_poll_pins(struct k_work *work)
107106

108107
static __maybe_unused void gpio_keys_change_deferred(struct k_work *work)
109108
{
110-
struct k_work_delayable *dwork = k_work_delayable_from_work(work);
111-
struct gpio_keys_pin_data *pin_data = CONTAINER_OF(dwork, struct gpio_keys_pin_data, work);
109+
const struct k_work_delayable *dwork = k_work_delayable_from_work(work);
110+
const struct gpio_keys_pin_data *pin_data =
111+
CONTAINER_OF(dwork, struct gpio_keys_pin_data, work);
112112
const struct device *dev = pin_data->dev;
113113
const struct gpio_keys_config *cfg = dev->config;
114-
int key_index = pin_data - (struct gpio_keys_pin_data *)cfg->pin_data;
114+
const int key_index = pin_data - (struct gpio_keys_pin_data *)cfg->pin_data;
115115

116116
#ifdef CONFIG_PM_DEVICE
117117
struct gpio_keys_data *data = dev->data;
@@ -267,6 +267,7 @@ static int gpio_keys_pm_action(const struct device *dev,
267267
k_work_reschedule(&pin_data[0].work,
268268
K_MSEC(cfg->debounce_interval_ms));
269269
} else {
270+
pin_data[i].cb_data.pin_state = gpio_pin_get_dt(gpio);
270271
ret = gpio_pin_interrupt_configure_dt(gpio, GPIO_INT_EDGE_BOTH);
271272
if (ret < 0) {
272273
LOG_ERR("interrupt configuration failed: %d", ret);

0 commit comments

Comments
 (0)