Usually ptr lists are accessed iteratively via the FOR/END macros but in few case we may need to access a given element in a list, like for example when accessing a given argument of a function. Create an helper doing that instead of open coding it. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- ptrlist.c | 18 ++++++++++++++++++ ptrlist.h | 1 + 2 files changed, 19 insertions(+) diff --git a/ptrlist.c b/ptrlist.c index 5dc1117c5..29aafac7d 100644 --- a/ptrlist.c +++ b/ptrlist.c @@ -246,3 +246,21 @@ void __free_ptr_list(struct ptr_list **listp) *listp = NULL; } + +void *ptr_list_nth_entry(struct ptr_list *list, unsigned int idx) +{ + struct ptr_list *head = list; + + if (!head) + return NULL; + + do { + unsigned int nr = list->nr; + + if (idx < nr) + return list->list[idx]; + else + idx -= nr; + } while ((list = list->next) != head); + return NULL; +} diff --git a/ptrlist.h b/ptrlist.h index d09be2f51..bf171f89f 100644 --- a/ptrlist.h +++ b/ptrlist.h @@ -44,6 +44,7 @@ extern void concat_ptr_list(struct ptr_list *a, struct ptr_list **b); extern void __free_ptr_list(struct ptr_list **); extern int ptr_list_size(struct ptr_list *); extern int linearize_ptr_list(struct ptr_list *, void **, int); +extern void *ptr_list_nth_entry(struct ptr_list *, unsigned int idx); /* * Hey, who said that you can't do overloading in C? -- 2.11.1 -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html