From patchwork Wed Jan 21 22:08:15 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1728 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1769033360; bh=JN0+KVMH648fRxNcf+SD+9B/j9PwAdsIvdJ+Nk9RC6Q=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=lMEuxAK1/BBBndZm3puahy3dY9Lqbixv1s2eqoB4CzSp/UKp7JcijXstn9Hi+4Mmc ORoT0mcK+fH9dlagfBgrjmKrD9QfLCFwecsqb7M1VW6EW0MAYZgRiSu8rsqtKWIVam OQtQgi/Go2bFTuQ1D0PuUoIuxSUB8dlQfRcfEMBpoYjcFtDR5Z9Pc+04+mo/41kj/q JA1K7iTkFRm93rk9kj/jIXF8H1RqNatNZvizDVIjkndJb4zos+mNafLkO7iku1stF5 oM3tjWbBFCaWPEulUpC+ERFBMxCT/yqrEETvp+9r2/tc1+C79WFWPOC0oJT2kkbIIy eQFVp2eDMbmPw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0AA3C695FD for ; Wed, 21 Jan 2026 15:09:20 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id vd1P0-sC-UI2 for ; Wed, 21 Jan 2026 15:09:19 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1769033359; bh=JN0+KVMH648fRxNcf+SD+9B/j9PwAdsIvdJ+Nk9RC6Q=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=kiG6rOPhhBOR+5lbDQGPCCtu9rip4DvEF5cLmKcZKuoLv0KwCDl2W5KSCN5F+auYn 9XH8prdHvrjo04n6vX6Fyu7DsPzM8G+otj2Ag1FtpYpt8AnEr/GgDJayyB/QbKR2jh E/7Yi5JkDw0xblafgSwNH8B6OPMIgy+E4T9xCLCx8DY4tQV6vNsB+wTCghFj3dK+TF bQsYIdpWHay2Pj7QUk5IDZqFq7p8T+FX3vkVbC+oD7ZuJuhzPw58BoQO9uqarman5Y /UTk9PvYdZO1MM+tq3wAYKm7faLV4JxX5H0Wy8l4NpYQw8QhDl7zk0KvKApmkaFTU8 lyEwPDpzML+WQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id EE29D695FC for ; Wed, 21 Jan 2026 15:09:19 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1769033358; bh=va+iu2fMV6TpX7b4mvFK0i2oMUllN1lEFK0qvKCfN5A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JiOOOhyDrs6Uhh+MVkZwLE3LE31P00XND4aoXt6fcPpPR9W0PldTmmfbxBC6EcVWu Nr+Dytoi0FG5yBLM/gKA3K/ZOf4XMQnw3Gm9lTtDQ6yCuEWssBHQ99MCr5zrVZAfM9 FbAPczKhFEHGKSqRzu4pwBrR73CvH8rOZbrBnArAtkGS4aa+PafafaJmqPlAjMzAiM iPR4x7qT1pQWOHn5/OWJI7mNiAfqSWx90qocShudbhZZ4yXCOpiOQj45b0pDrwZRjd NB70pINrfFjUErGd+uYhKrjO0/rg6SonoPvcrKdy/CtbVnu7G+ladhltMu9CBXS6pJ 8CuOYkHNrnocQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9653A695F7; Wed, 21 Jan 2026 15:09:18 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id Fk2rK0g65qQH; Wed, 21 Jan 2026 15:09:18 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1769033352; bh=rgAw/BMzBv4tklqkoRXzOvMHs6+Lan260Hg/abOh0Ic=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z17/syZjJDusYQ4Qf8ZKfI0YaMwpNvPgmxKRk8IU4ClmNeoQDLhEndvpzwMsDDL7O MQPYKjBC8u4DDFNYSODnGpQEVWAMCfbYekd/sAllRLcIOIXfS5/iKc1qOQ9OuXy2XD RUAU49BJppJPIwE0/HU4rc2PxxEHLXqk2rO+bZ9PWNTXLvzeZpXD6ywX7NzrXDefHH Fc9f0nxMrEMHFYk9hSl3kxBvyotL47H3+vb5bKcKq/NY20zo/lcQ16DbhKwcVQ+Ij9 aJBy7K3mexPWWytWmYgP/8i2p+CqAEubA/lHh1DdAOKf52DeKaqbp3EC6BVsMuSIW3 2SL5nD82plS7A== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id EC84A695F2; Wed, 21 Jan 2026 15:09:11 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 21 Jan 2026 15:08:15 -0700 Message-ID: <20260121220857.2137568-3-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260121220857.2137568-1-sjg@u-boot.org> References: <20260121220857.2137568-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: WVJUHVWEMDMAU6YGKLLMKMU5WTZ7LQM3 X-Message-ID-Hash: WVJUHVWEMDMAU6YGKLLMKMU5WTZ7LQM3 X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 02/33] list: Add const qualifiers to list_sort callback signature List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass 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 Signed-off-by: Simon Glass --- .../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 */