]> www.infradead.org Git - users/hch/misc.git/commitdiff
mm/kasan: use SLAB_NO_MERGE flag instead of an empty constructor
authorHarry Yoo <harry.yoo@oracle.com>
Tue, 18 Mar 2025 01:59:26 +0000 (10:59 +0900)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 1 Apr 2025 22:17:10 +0000 (15:17 -0700)
Use SLAB_NO_MERGE flag to prevent merging instead of providing an empty
constructor.  Using an empty constructor in this manner is an abuse of
slab interface.

The SLAB_NO_MERGE flag should be used with caution, but in this case, it
is acceptable as the cache is intended solely for debugging purposes.

No functional changes intended.

Link: https://lkml.kernel.org/r/20250318015926.1629748-1-harry.yoo@oracle.com
Signed-off-by: Harry Yoo <harry.yoo@oracle.com>
Reviewed-by: Alexander Potapenko <glider@google.com>
Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com>
Acked-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/kasan/kasan_test_c.c

index 59d673400085f5d0184fd109d2b8cb887a243ec0..3ea317837c2d3724ecec3ca44f93aa327e753317 100644 (file)
@@ -1073,14 +1073,11 @@ static void kmem_cache_rcu_uaf(struct kunit *test)
        kmem_cache_destroy(cache);
 }
 
-static void empty_cache_ctor(void *object) { }
-
 static void kmem_cache_double_destroy(struct kunit *test)
 {
        struct kmem_cache *cache;
 
-       /* Provide a constructor to prevent cache merging. */
-       cache = kmem_cache_create("test_cache", 200, 0, 0, empty_cache_ctor);
+       cache = kmem_cache_create("test_cache", 200, 0, SLAB_NO_MERGE, NULL);
        KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache);
        kmem_cache_destroy(cache);
        KUNIT_EXPECT_KASAN_FAIL(test, kmem_cache_destroy(cache));