To allow individual bootentry providers to more easily sort their entries, pass each provider an empty list that's spliced onto the tail of the aggregated list at the end.
This way we maintain that boot entries of different providers are sorted by provider priority and boot entries of a single provider can be sorted by each provider without having to worry about foreign boot entries. Signed-off-by: Ahmad Fatoum <[email protected]> --- common/boot.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/common/boot.c b/common/boot.c index 78d990f1617e..8ccc269ac5bd 100644 --- a/common/boot.c +++ b/common/boot.c @@ -26,6 +26,14 @@ int bootentries_add_entry(struct bootentries *entries, struct bootentry *entry) return 0; } +#define BOOTENTRIES(name) \ + struct bootentries name = { .entries = LIST_HEAD_INIT(name.entries) } + +static inline void bootentries_merge(struct bootentries *dst, struct bootentries *src) +{ + list_splice_tail_init(&src->entries, &dst->entries); +} + struct bootentries *bootentries_alloc(void) { struct bootentries *bootentries; @@ -452,9 +460,17 @@ int bootentry_create_from_name(struct bootentries *bootentries, name = nfspath; list_for_each_entry(p, &bootentry_providers, list) { - ret = p->generate(bootentries, name); + BOOTENTRIES(provider_bootentries); + + ret = p->generate(&provider_bootentries, name); if (ret > 0) found += ret; + + /* We want to allow for providers to sort their bootentries as + * they see fit, so they are passed an empty list above with + * only their own entries and then we aggregate here + */ + bootentries_merge(bootentries, &provider_bootentries); } free(nfspath); -- 2.47.3
