Skip to contentSkip to conversation

test_list_sort: fix up const mismatch

PATCH In review Greg Kroah-Hartman 2 participants 2 messages Dec 17, 2025 – Dec 18, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test_list_sort: fix up const mismatch

In the internal cmp function, a const pointer is cast out to a non-const pointer by using container_of(). This is probably not what is intended at all, so fix up the const marking to properly preserve what is really happening (i.e. the const should flow through the container_of() call)

Cc Jakub Kicinski <[email protected]>
Cc David Gow <[email protected]>
Cc "Masami Hiramatsu (Google)" <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Kees Cook <[email protected]>
---
 lib/tests/test_list_sort.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/tests/test_list_sort.c +2 -2
index 30879abc8a42..28158557b164 100644
@@ -26,7 +26,7 @@ struct debug_el {
 	unsigned int serial;
 };
 
-static void check(struct kunit *test, struct debug_el *ela, struct debug_el *elb)
+static void check(struct kunit *test, const struct debug_el *ela, const struct debug_el *elb)
 {
 	struct debug_el **elts = test->priv;
 
@@ -46,7 +46,7 @@ static void check(struct kunit *test, struct debug_el *ela, struct debug_el *elb
 /* `priv` is the test pointer so check() can fail the test if the list is invalid. */
 static int cmp(void *priv, const struct list_head *a, const struct list_head *b)
 {
-	struct debug_el *ela, *elb;
+	const struct debug_el *ela, *elb;
 
 	ela = container_of(a, struct debug_el, list);
 	elb = container_of(b, struct debug_el, list);
Signature · 1 line
2.52.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Greg Kroah-Hartman

In the internal cmp function, a const pointer is cast out to a non-const pointer by using container_of(). This is probably not what is intended at all, so fix up the const marking to properly preserve what is really happening (i.e. the const should flow through the container_of() call)

Quoted 8 lines
Cc Jakub Kicinski <[email protected]>
Cc David Gow <[email protected]>
Cc "Masami Hiramatsu (Google)" <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Kees Cook <[email protected]>

---

Thanks very much!

Cheers,
-- David

Quoted 28 lines
 lib/tests/test_list_sort.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/tests/test_list_sort.c +2 -3
index 30879abc8a42..28158557b164 100644
@@ -26,7 +26,7 @@ struct debug_el {
        unsigned int serial;
 };
 
-static void check(struct kunit *test, struct debug_el *ela, struct debug_el *elb)
+static void check(struct kunit *test, const struct debug_el *ela, const struct debug_el *elb)
 {
        struct debug_el **elts = test->priv;
 
@@ -46,7 +46,7 @@ static void check(struct kunit *test, struct debug_el *ela, struct debug_el *elb
 /* `priv` is the test pointer so check() can fail the test if the list is invalid. */
 static int cmp(void *priv, const struct list_head *a, const struct list_head *b)
 {
-       struct debug_el *ela, *elb;
+       const struct debug_el *ela, *elb;
 
        ela = container_of(a, struct debug_el, list);
        elb = container_of(b, struct debug_el, list);
--

2.52.0