]> www.infradead.org Git - users/jedix/linux-maple.git/commit
lib min_heap: improve type safety in min_heap macros by using container_of
authorKuan-Wei Chiu <visitorckw@gmail.com>
Fri, 29 Nov 2024 18:12:19 +0000 (02:12 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 13 Jan 2025 04:20:57 +0000 (20:20 -0800)
commitec01e9d001fef6278df1900df4207c70166095b4
tree9944ff3299595fac66d36fe5491d28dee6227882
parentcd6313beaeaea0b2e6d428afef7a86a986b50abe
lib min_heap: improve type safety in min_heap macros by using container_of

Patch series "lib min_heap: Improve min_heap safety, testing, and
documentation".

Improve the min heap implementation by enhancing type safety with
container_of, reducing the attack vector by replacing test function calls
with inline variants, and adding a brief API introduction in min_heap.h.
It also includes author information in
Documentation/core-api/min_heap.rst.

This patch (of 4):

The current implementation of min_heap macros uses explicit casting to
min_heap_char *, which prevents the compiler from detecting incorrect
pointer types.  This can lead to errors if non-min_heap pointers are
passed inadvertently.

To enhance safety, replace all explicit casts to min_heap_char * with the
use of container_of(&(_heap)->nr, min_heap_char, nr).  This approach
ensures that the _heap parameter is indeed a min_heap_char-compatible
structure, allowing the compiler to catch improper usages.

Link: https://lkml.kernel.org/r/20241129181222.646855-1-visitorckw@gmail.com
Link: https://lore.kernel.org/lkml/CAMuHMdVO5DPuD9HYWBFqKDHphx7+0BEhreUxtVC40A=8p6VAhQ@mail.gmail.com
Link: https://lkml.kernel.org/r/20241129181222.646855-2-visitorckw@gmail.com
Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Ching-Chun (Jim) Huang <jserv@ccns.ncku.edu.tw>
Cc: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/min_heap.h