[RFC PATCH 37/77] dtc: Add support for import symbols sorting
Herve Codina <[email protected]> Mon, 12 Jan 2026 15:19:27 +0100
| Newsgroups | org.kernel.vger.devicetree-spec,org.kernel.vger.devicetree-compiler,org.kernel.vger.linux-devicetree,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
dtc can sort items when the command line --sort option is set. Add support for import symbols sorting when this option is used. Signed-off-by: Herve Codina <[email protected]> --- livetree.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/livetree.c b/livetree.c index dac5359..285f6e1 100644 --- a/livetree.c +++ b/livetree.c @@ -1014,9 +1014,36 @@ static void sort_node(struct node *node) sort_node(c); } +static void sort_importsyms(struct dt_info *dti) +{ + int n = 0, i = 0; + struct symbol *symbol, **tbl; + + for_each_symbol(dti->importsymlist, symbol) + n++; + + if (n == 0) + return; + + tbl = xmalloc(n * sizeof(*tbl)); + + for_each_symbol(dti->importsymlist, symbol) + tbl[i++] = symbol; + + qsort(tbl, n, sizeof(*tbl), cmp_symbol); + + dti->importsymlist = tbl[0]; + for (i = 0; i < (n-1); i++) + tbl[i]->next = tbl[i+1]; + tbl[n-1]->next = NULL; + + free(tbl); +} + void sort_tree(struct dt_info *dti) { sort_reserve_entries(dti); + sort_importsyms(dti); sort_node(dti->dt); } -- 2.52.0