[PATCH] gpio: free memory in error path

Gedare Bloom gedare at rtems.org
Mon Nov 9 18:36:08 UTC 2015


I noticed while reading the code to install interrupts in GPIO that it
does not clean-up in error case. There remains a similar problem in
the "threaded" case as well that should be dealt with, and I'm filing
a ticket for it.

On Mon, Nov 9, 2015 at 1:33 PM, Gedare Bloom <gedare at rtems.org> wrote:
> ---
>  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;
> --
> 1.9.1
>



More information about the devel mailing list