From: Simon Glass <simon.glass@canonical.com> Update list_sort() to use const qualifiers for the list_head parameters in the comparison callback, matching the Linux kernel interface. Changes to the API: - Add list_cmp_func_t typedef with const qualifiers - Update list_sort() declaration to use the new typedef - Update internal merge functions to use const qualifiers Update all callers: - lib/efi_loader/efi_memory.c: efi_mem_cmp() - fs/ubifs/replay.c: replay_entries_cmp() - fs/ubifs/gc.c: data_nodes_cmp() and nondata_nodes_cmp() - arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c: part_cmp() Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- .../mach-stm32mp/cmd_stm32prog/stm32prog.c | 9 +++++---- fs/ubifs/gc.c | 19 ++++++++++--------- fs/ubifs/replay.c | 6 +++--- include/linux/list_sort.h | 8 +++++--- lib/efi_loader/efi_memory.c | 7 ++++--- lib/list_sort.c | 12 ++++++------ 6 files changed, 33 insertions(+), 28 deletions(-) diff --git a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c index 353aecc09de..a66e003cfb4 100644 --- a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c +++ b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c @@ -708,12 +708,13 @@ static int parse_flash_layout(struct stm32prog_data *data, return 0; } -static int __init part_cmp(void *priv, struct list_head *a, struct list_head *b) +static int __init part_cmp(void *priv, const struct list_head *a, + const struct list_head *b) { - struct stm32prog_part_t *parta, *partb; + const struct stm32prog_part_t *parta, *partb; - parta = container_of(a, struct stm32prog_part_t, list); - partb = container_of(b, struct stm32prog_part_t, list); + parta = container_of(a, const struct stm32prog_part_t, list); + partb = container_of(b, const struct stm32prog_part_t, list); if (parta->part_id != partb->part_id) return parta->part_id - partb->part_id; diff --git a/fs/ubifs/gc.c b/fs/ubifs/gc.c index 6a4ada62c82..0577d91104a 100644 --- a/fs/ubifs/gc.c +++ b/fs/ubifs/gc.c @@ -114,18 +114,19 @@ static int switch_gc_head(struct ubifs_info *c) * This function compares data nodes @a and @b. Returns %1 if @a has greater * inode or block number, and %-1 otherwise. */ -static int data_nodes_cmp(void *priv, struct list_head *a, struct list_head *b) +static int data_nodes_cmp(void *priv, const struct list_head *a, + const struct list_head *b) { ino_t inuma, inumb; struct ubifs_info *c = priv; - struct ubifs_scan_node *sa, *sb; + const struct ubifs_scan_node *sa, *sb; cond_resched(); if (a == b) return 0; - sa = list_entry(a, struct ubifs_scan_node, list); - sb = list_entry(b, struct ubifs_scan_node, list); + sa = list_entry(a, const struct ubifs_scan_node, list); + sb = list_entry(b, const struct ubifs_scan_node, list); ubifs_assert(key_type(c, &sa->key) == UBIFS_DATA_KEY); ubifs_assert(key_type(c, &sb->key) == UBIFS_DATA_KEY); @@ -157,19 +158,19 @@ static int data_nodes_cmp(void *priv, struct list_head *a, struct list_head *b) * first and sorted by length in descending order. Directory entry nodes go * after inode nodes and are sorted in ascending hash valuer order. */ -static int nondata_nodes_cmp(void *priv, struct list_head *a, - struct list_head *b) +static int nondata_nodes_cmp(void *priv, const struct list_head *a, + const struct list_head *b) { ino_t inuma, inumb; struct ubifs_info *c = priv; - struct ubifs_scan_node *sa, *sb; + const struct ubifs_scan_node *sa, *sb; cond_resched(); if (a == b) return 0; - sa = list_entry(a, struct ubifs_scan_node, list); - sb = list_entry(b, struct ubifs_scan_node, list); + sa = list_entry(a, const struct ubifs_scan_node, list); + sb = list_entry(b, const struct ubifs_scan_node, list); ubifs_assert(key_type(c, &sa->key) != UBIFS_DATA_KEY && key_type(c, &sb->key) != UBIFS_DATA_KEY); diff --git a/fs/ubifs/replay.c b/fs/ubifs/replay.c index b6e03b76d41..a323ae6d058 100644 --- a/fs/ubifs/replay.c +++ b/fs/ubifs/replay.c @@ -268,10 +268,10 @@ static int apply_replay_entry(struct ubifs_info *c, struct replay_entry *r) * entries @a and @b by comparing their sequence numer. Returns %1 if @a has * greater sequence number and %-1 otherwise. */ -static int replay_entries_cmp(void *priv, struct list_head *a, - struct list_head *b) +static int replay_entries_cmp(void *priv, const struct list_head *a, + const struct list_head *b) { - struct replay_entry *ra, *rb; + const struct replay_entry *ra, *rb; cond_resched(); if (a == b) diff --git a/include/linux/list_sort.h b/include/linux/list_sort.h index 1a2df2efb77..dc760a60644 100644 --- a/include/linux/list_sort.h +++ b/include/linux/list_sort.h @@ -5,7 +5,9 @@ struct list_head; -void list_sort(void *priv, struct list_head *head, - int (*cmp)(void *priv, struct list_head *a, - struct list_head *b)); +typedef int (*list_cmp_func_t)(void *priv, const struct list_head *a, + const struct list_head *b); + +void list_sort(void *priv, struct list_head *head, list_cmp_func_t cmp); + #endif diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index 4a56dfca37c..190937cf1ff 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -116,10 +116,11 @@ static u64 checksum(struct efi_pool_allocation *alloc) * @b: second memory area * Return: 1 if @a is before @b, -1 if @b is before @a, 0 if equal */ -static int efi_mem_cmp(void *priv, struct list_head *a, struct list_head *b) +static int efi_mem_cmp(void *priv, const struct list_head *a, + const struct list_head *b) { - struct mem_node *mema = list_entry(a, struct mem_node, link); - struct mem_node *memb = list_entry(b, struct mem_node, link); + const struct mem_node *mema = list_entry(a, struct mem_node, link); + const struct mem_node *memb = list_entry(b, struct mem_node, link); if (mema->base == memb->base) return 0; diff --git a/lib/list_sort.c b/lib/list_sort.c index cf5cac17720..5298990b3e7 100644 --- a/lib/list_sort.c +++ b/lib/list_sort.c @@ -21,8 +21,8 @@ * sentinel head node, "prev" links not maintained. */ static struct list_head *merge(void *priv, - int (*cmp)(void *priv, struct list_head *a, - struct list_head *b), + int (*cmp)(void *priv, const struct list_head *a, + const struct list_head *b), struct list_head *a, struct list_head *b) { struct list_head head, *tail = &head; @@ -50,8 +50,8 @@ static struct list_head *merge(void *priv, * throughout. */ static void merge_and_restore_back_links(void *priv, - int (*cmp)(void *priv, struct list_head *a, - struct list_head *b), + int (*cmp)(void *priv, const struct list_head *a, + const struct list_head *b), struct list_head *head, struct list_head *a, struct list_head *b) { @@ -104,8 +104,8 @@ static void merge_and_restore_back_links(void *priv, * ordering is to be preserved, @cmp must return 0. */ void list_sort(void *priv, struct list_head *head, - int (*cmp)(void *priv, struct list_head *a, - struct list_head *b)) + int (*cmp)(void *priv, const struct list_head *a, + const struct list_head *b)) { struct list_head *part[MAX_LIST_LENGTH_BITS+1]; /* sorted partial lists -- last slot is a sentinel */ -- 2.43.0