mongoose-os icon indicating copy to clipboard operation
mongoose-os copied to clipboard

Prevent infinite loop when calling mgos_gpio_clear_int in an interrupt

Open mac-michael opened this issue 5 years ago • 1 comments

If mgos_gpio_clear_int is called in an interrupt callback cnt is set to 0 in the clear function. Then it's decremented in mgos_gpio_int_cb: 0-1=2^16-1 which can start an infinite loop.

IRAM void mgos_gpio_clear_int(int pin) {
  struct mgos_gpio_state *s = mgos_gpio_get_state(pin);
  if (s == NULL) return;
  mgos_gpio_hal_clear_int(pin);
  s->cnt = 0;
}

static void mgos_gpio_int_cb(void *arg) {
[...]
  if (s->button.debounce_ms == 0) {
    while (s->cnt > 0) {
      mgos_runlock(s_lock);
      s->cb(pin, s->cb_arg);
      mgos_rlock(s_lock);
      s->cnt--;
    }
  } [...]
}

mac-michael avatar Jan 09 '20 17:01 mac-michael

Are there any chances to merge this pull request? Thanks.

mac-michael avatar Jul 26 '20 10:07 mac-michael