Paul Richards wrote:
> +++ b/src/jtag/core.c
> @@ -296,27 +296,25 @@ int jtag_register_event_callback(jtag_event_handler_t 
> callback, void *priv)
>  
>  int jtag_unregister_event_callback(jtag_event_handler_t callback, void *priv)
>  {
> -     struct jtag_event_callback **callbacks_p;
> -     struct jtag_event_callback **next;
> +     struct jtag_event_callback **callbacks_p = &jtag_event_callbacks;
>  
>       if (callback == NULL)
>       {
>               return ERROR_INVALID_ARGUMENTS;
>       }
>  
> -     for (callbacks_p = &jtag_event_callbacks;
> -                     *callbacks_p != NULL;
> -                     callbacks_p = next)
> +     while (*callbacks_p != NULL)
>       {
> -             next = &((*callbacks_p)->next);
> -
> -             if ((*callbacks_p)->priv != priv)
> -                     continue;
> +             if (((*callbacks_p)->priv != priv) && ((*callbacks_p)->callback 
> == callback))

The priv comparison logic is reversed.


> +             {
> +                     struct jtag_event_callback *free_callback = 
> *callbacks_p;
>  
> -             if ((*callbacks_p)->callback == callback)
> +                     *callbacks_p = (*callbacks_p)->next;
> +                     free(free_callback);
> +             }
> +             else
>               {
> -                     free(*callbacks_p);
> -                     *callbacks_p = *next;
> +                     callbacks_p = &((*callbacks_p)->next);
>               }
>       }

Paul Richards wrote:
> I just saw your mail after submitting a patch.  I kept the double
> pointer usage for consistency but simplified the logic.

The code is horrible. (Certainly not your fault!) Sorry if that's
offensive to the original author. The variable names do not help.
Will this work:

int jtag_unregister_event_callback(callback,priv) {
  struct jtag_event_callback *p, *prev = NULL, *next;

  if (!callback)
    return ERROR_INVALID_ARGUMENTS;

  for (p = jtag_event_callbacks; p; p = next) {
    next = p->next;

    if (p->priv != priv || p->callback != callback) {
      prev = p;
      continue;
    }

    if (prev)
      prev->next = next;
    else
      jtag_events_callbacks = next;

    free(p);
  }
}

?


//Peter
_______________________________________________
Openocd-development mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to