[rtems commit] gpio: free memory in error path

Gedare Bloom gedare at rtems.org
Wed Nov 11 15:56:08 UTC 2015


Module:    rtems
Branch:    master
Commit:    f8bdd12a48d82a26cd9ddb84bdfa1544a4592e0d
Changeset: http://git.rtems.org/rtems/commit/?id=f8bdd12a48d82a26cd9ddb84bdfa1544a4592e0d

Author:    Gedare Bloom <gedare at rtems.org>
Date:      Mon Nov  9 13:30:00 2015 -0500

gpio: free memory in error path

Updates #2462.

---

 c/src/lib/libbsp/shared/gpio.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/c/src/lib/libbsp/shared/gpio.c b/c/src/lib/libbsp/shared/gpio.c
index b806556..9ceeb407 100644
--- a/c/src/lib/libbsp/shared/gpio.c
+++ b/c/src/lib/libbsp/shared/gpio.c
@@ -1708,10 +1708,8 @@ rtems_status_code rtems_gpio_enable_interrupt(
     return RTEMS_RESOURCE_IN_USE;
   }
 
-  interrupt_state = gpio_pin_state[pin_number].interrupt_state;
-
   /* If an interrupt configuration is already in place for this pin. */
-  if ( interrupt_state != NULL ) {
+  if ( gpio_pin_state[pin_number].interrupt_state != NULL ) {
     RELEASE_LOCK(gpio_bank_state[bank].lock);
 
     return RTEMS_RESOURCE_IN_USE;
@@ -1724,15 +1722,12 @@ rtems_status_code rtems_gpio_enable_interrupt(
     return RTEMS_NO_MEMORY;
   }
 
-  gpio_pin_state[pin_number].interrupt_state->active_interrupt = NONE;
-  gpio_pin_state[pin_number].interrupt_state->debouncing_tick_count = 0;
-  gpio_pin_state[pin_number].interrupt_state->last_isr_tick = 0;
-
-  rtems_chain_initialize_empty(
-    &gpio_pin_state[pin_number].interrupt_state->handler_chain
-  );
-
   interrupt_state = gpio_pin_state[pin_number].interrupt_state;
+  interrupt_state->active_interrupt = NONE;
+  interrupt_state->debouncing_tick_count = 0;
+  interrupt_state->last_isr_tick = 0;
+
+  rtems_chain_initialize_empty( &interrupt_state->handler_chain );
 
   interrupt_state->active_interrupt = interrupt;
   interrupt_state->handler_flag = flag;
@@ -1742,6 +1737,8 @@ rtems_status_code rtems_gpio_enable_interrupt(
   sc = rtems_gpio_interrupt_handler_install(pin_number, handler, arg);
 
   if ( sc != RTEMS_SUCCESSFUL ) {
+    free(interrupt_state);
+    gpio_pin_state[pin_number].interrupt_state = NULL;
     RELEASE_LOCK(gpio_bank_state[bank].lock);
 
     return RTEMS_UNSATISFIED;



More information about the vc mailing list