Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent infinite loop when calling mgos_gpio_clear_int in an interrupt #523

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mac-michael
Copy link

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant