Skip to content

stm32: Detach GPIO IRQ callbacks upon clearing "setevent"#19520

Open
Javinator9889 wants to merge 2 commits into
apache:masterfrom
Javinator9889:bugfix/stm32_detach_callbacks_upon_gpio_clearing
Open

stm32: Detach GPIO IRQ callbacks upon clearing "setevent"#19520
Javinator9889 wants to merge 2 commits into
apache:masterfrom
Javinator9889:bugfix/stm32_detach_callbacks_upon_gpio_clearing

Conversation

@Javinator9889

Copy link
Copy Markdown
Contributor

Summary

When the interrupts get disabled, the callback(s) are still attached. That structure is never cleared, causing several calls to attach/detach to eventually fail as the callback queue gets full.

When the error occurs, the registration fails with error 12 (ENOMEM). By detaching the IRQ and clearing the callbacks, this error doesn't happen again

Impact

Calling stm32_gpiosetevent several times enabling and disabling the event ends up fulling the callback's queue, causing future calls to fail with ENOMEM without recovering from the error.

Testing

This has been tested thoroughly by attaching/detaching the events several times in a row. The behavior is now deterministic and one can add and remove GPIO events as much as wanted

@Javinator9889
Javinator9889 force-pushed the bugfix/stm32_detach_callbacks_upon_gpio_clearing branch from d6efcec to be784d2 Compare July 24, 2026 10:31
@github-actions github-actions Bot added Arch: arm Issues related to ARM (32-bit) architecture Size: XS The size of the change in this PR is very small labels Jul 24, 2026
When the interrupts get disabled, the callback(s) are still attached.
That structure is never cleared, causing several calls to attach/detach
to eventually fail as the callback queue gets full.

When the error occurs, the registration fails with error 12 (ENOMEM).
By detaching the IRQ and clearing the callbacks, this error doesn't
happen again

Signed-off-by: Javier Alonso <javieralonso@geotab.com>
@Javinator9889
Javinator9889 force-pushed the bugfix/stm32_detach_callbacks_upon_gpio_clearing branch from be784d2 to 577bf5a Compare July 24, 2026 10:39
@github-actions github-actions Bot added Size: S The size of the change in this PR is small and removed Size: XS The size of the change in this PR is very small labels Jul 24, 2026
@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:


if (i == nshared)
{
/* remove any leftover callback */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you port this change to all STM32 ports? it can be simple copy-paste, all STM32 use the same driver for EXTI GPIO.

  • src/common/stm32/stm32_exti_gpio_m3m4_v1v2.c
  • src/stm32f7/stm32_exti_gpio.c
  • src/stm32h7/stm32_exti_gpio.c
  • src/stm32l4/stm32l4_exti_gpio.c
  • src/stm32l5/stm32l5_exti_gpio.c
  • src/stm32u5/stm32_exti_gpio.c
  • src/stm32wb/stm32wb_exti_gpio.c
  • src/stm32wl5/stm32wl5_exti_gpio.c

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing, let me populate the change to those files as well :)

I just populated it on the STM32G0 because it's the one I have to test. I guess others will work just fine as the change is self contained

@Javinator9889 Javinator9889 Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 33d7af4

The fix was ported from the STM32G0 to all the STM32 platforms,
as the code is mostly the same hence presents the same failure

Signed-off-by: Javier Alonso <javieralonso@geotab.com>
@Javinator9889
Javinator9889 force-pushed the bugfix/stm32_detach_callbacks_upon_gpio_clearing branch from ed0134f to 33d7af4 Compare July 24, 2026 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: arm Issues related to ARM (32-bit) architecture Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants