Skip to content

Commit

Permalink
Merge pull request #11726 from keestux/usb-some-refactoring
Browse files Browse the repository at this point in the history
usbus: simplify adding entry to list
  • Loading branch information
bergzand authored Jun 20, 2019
2 parents 14d9f54 + 4a06b91 commit 968e53b
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions sys/usb/usbus/usbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,37 +107,24 @@ uint16_t usbus_add_interface(usbus_t *usbus, usbus_interface_t *iface)
* usages. Furthermore, the O(1) append is not really necessary as this is
* only used at init */
uint16_t idx = 0;
usbus_interface_t *last = usbus->iface;

if (last) {
usbus_interface_t **last = &usbus->iface;
while (*last) {
last = &(*last)->next;
idx++;
while (last->next) {
last = last->next;
idx++;
}
last->next = iface;
}
else {
usbus->iface = iface;
}
iface->idx = idx;
*last = iface;
return idx;
}

void usbus_register_event_handler(usbus_t *usbus, usbus_handler_t *handler)
{
/* See note above for reasons against clist.h */
usbus_handler_t *last = usbus->handlers;

if (last) {
while (last->next) {
last = last->next;
}
last->next = handler;
}
else {
usbus->handlers = handler;
usbus_handler_t **last = &usbus->handlers;
while (*last) {
last = &(*last)->next;
}
*last = handler;
}

usbus_endpoint_t *usbus_add_endpoint(usbus_t *usbus, usbus_interface_t *iface,
Expand Down

0 comments on commit 968e53b

Please sign in to comment.