diff --git a/src/include/hlib.h b/src/include/hlib.h index eba70c7..364956a 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -81,6 +81,7 @@ extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); #define listAdd(list, data) _listAdd(malloc, list, data) +extern void listClear(ListElement **list, bool freeData); #define REQUEST(functionName, service, function) \ uint32_t functionName(uint32_t data1, uint32_t data2) { \ diff --git a/src/include/hlib.h b/src/include/hlib.h index eba70c7..364956a 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -81,6 +81,7 @@ extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); #define listAdd(list, data) _listAdd(malloc, list, data) +extern void listClear(ListElement **list, bool freeData); #define REQUEST(functionName, service, function) \ uint32_t functionName(uint32_t data1, uint32_t data2) { \ diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index 7b7ef96..2b6cb53 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -91,11 +91,6 @@ return "Unknown"; } -void listClear(ListElement **list) { - // TODO - *list = NULL; -} - void input(uint32_t padding, uint32_t data, uint32_t reportCount, uint32_t reportSize, uint32_t currentUsagePage, ListElement **usages) { // https://www.usb.org/sites/default/files/hid1_11.pdf // page 38, section 6.2.2.4, Main items table @@ -126,7 +121,7 @@ } else { printf("%p Input parser cannot deduce the usage of the reports, having %i reports and %i usages\n", padding, reportCount, usageCount); } - listClear(usages); + listClear(usages, false); } void parseReportDescriptor(uint8_t *descriptor) { @@ -181,12 +176,12 @@ case 0x28: startCollection(data, padding); padding += 2; - listClear(&usages); + listClear(&usages, false); break; case 0x30: padding -= 2; printf("%pEnd collection\n", padding); - listClear(&usages); + listClear(&usages, false); break; default: printf("%pUnknown Item %x with data %x\n", padding, item >> 2, data); diff --git a/src/include/hlib.h b/src/include/hlib.h index eba70c7..364956a 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -81,6 +81,7 @@ extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); #define listAdd(list, data) _listAdd(malloc, list, data) +extern void listClear(ListElement **list, bool freeData); #define REQUEST(functionName, service, function) \ uint32_t functionName(uint32_t data1, uint32_t data2) { \ diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index 7b7ef96..2b6cb53 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -91,11 +91,6 @@ return "Unknown"; } -void listClear(ListElement **list) { - // TODO - *list = NULL; -} - void input(uint32_t padding, uint32_t data, uint32_t reportCount, uint32_t reportSize, uint32_t currentUsagePage, ListElement **usages) { // https://www.usb.org/sites/default/files/hid1_11.pdf // page 38, section 6.2.2.4, Main items table @@ -126,7 +121,7 @@ } else { printf("%p Input parser cannot deduce the usage of the reports, having %i reports and %i usages\n", padding, reportCount, usageCount); } - listClear(usages); + listClear(usages, false); } void parseReportDescriptor(uint8_t *descriptor) { @@ -181,12 +176,12 @@ case 0x28: startCollection(data, padding); padding += 2; - listClear(&usages); + listClear(&usages, false); break; case 0x30: padding -= 2; printf("%pEnd collection\n", padding); - listClear(&usages); + listClear(&usages, false); break; default: printf("%pUnknown Item %x with data %x\n", padding, item >> 2, data); diff --git a/src/userland/hlib/list.c b/src/userland/hlib/list.c index 897e0a5..0f2ee65 100644 --- a/src/userland/hlib/list.c +++ b/src/userland/hlib/list.c @@ -60,3 +60,19 @@ } return false; } + +void listClear(ListElement **list, bool freeData) { + ListElement *current = *list; + if (!current) { + return; + } + while (current->next) { + if (freeData) { + free(current->data); + } + ListElement *next = current->next; + free(current); + current = next; + } + *list = NULL; +}