Skip to content

Commit af537c7

Browse files
include: gpio: Avoid undefined behavior
Putting #ifdef inside a macro invocation is undefined behavior. Signed-off-by: Reto Schneider <[email protected]>
1 parent d5e8679 commit af537c7

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

include/zephyr/drivers/gpio.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -901,15 +901,16 @@ static inline int z_impl_gpio_pin_interrupt_configure(const struct device *port,
901901
"Only one of GPIO_INT_LOW_0, GPIO_INT_HIGH_1 can be "
902902
"enabled for a level interrupt.");
903903

904-
__ASSERT(((flags & GPIO_INT_ENABLE) == 0) ||
905904
#ifdef CONFIG_GPIO_ENABLE_DISABLE_INTERRUPT
905+
__ASSERT(((flags & GPIO_INT_ENABLE) == 0) ||
906906
((flags & (GPIO_INT_LOW_0 | GPIO_INT_HIGH_1)) != 0) ||
907907
(flags & GPIO_INT_ENABLE_DISABLE_ONLY) != 0,
908+
"At least one of GPIO_INT_LOW_0, GPIO_INT_HIGH_1 has to be enabled.");
908909
#else
910+
__ASSERT(((flags & GPIO_INT_ENABLE) == 0) ||
909911
((flags & (GPIO_INT_LOW_0 | GPIO_INT_HIGH_1)) != 0),
912+
"At least one of GPIO_INT_LOW_0, GPIO_INT_HIGH_1 has to be enabled.");
910913
#endif /* CONFIG_GPIO_ENABLE_DISABLE_INTERRUPT */
911-
"At least one of GPIO_INT_LOW_0, GPIO_INT_HIGH_1 has to be "
912-
"enabled.");
913914

914915
__ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U,
915916
"Unsupported pin");

0 commit comments

Comments
 (0)