]> www.infradead.org Git - users/hch/misc.git/commitdiff
slab: move validate_slab_ptr() from check_slab() to its callers
authorVlastimil Babka <vbabka@suse.cz>
Mon, 15 Sep 2025 13:55:10 +0000 (15:55 +0200)
committerVlastimil Babka <vbabka@suse.cz>
Mon, 15 Sep 2025 14:10:10 +0000 (16:10 +0200)
We will want to do the validation earlier in some callers or remove it
completely, so extract it from check_slab() first. No functional change.

Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
mm/slub.c

index 75e4388d507d1abcbce8c7d5d2581381de46cf4d..6fb24010c17019ed304b4ef61f402212dd634efb 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1458,15 +1458,15 @@ static int check_object(struct kmem_cache *s, struct slab *slab,
        return ret;
 }
 
+/*
+ * Checks if the slab state looks sane. Assumes the struct slab pointer
+ * was either obtained in a way that ensures it's valid, or validated
+ * by validate_slab_ptr()
+ */
 static int check_slab(struct kmem_cache *s, struct slab *slab)
 {
        int maxobj;
 
-       if (!validate_slab_ptr(slab)) {
-               slab_err(s, slab, "Not a valid slab page");
-               return 0;
-       }
-
        maxobj = order_objects(slab_order(slab), s->size);
        if (slab->objects > maxobj) {
                slab_err(s, slab, "objects %u > max %u",
@@ -1633,6 +1633,11 @@ void setup_slab_debug(struct kmem_cache *s, struct slab *slab, void *addr)
 static inline int alloc_consistency_checks(struct kmem_cache *s,
                                        struct slab *slab, void *object)
 {
+       if (!validate_slab_ptr(slab)) {
+               slab_err(s, slab, "Not a valid slab page");
+               return 0;
+       }
+
        if (!check_slab(s, slab))
                return 0;
 
@@ -3485,6 +3490,11 @@ static inline bool free_debug_processing(struct kmem_cache *s,
        int cnt = 0;
 
        if (s->flags & SLAB_CONSISTENCY_CHECKS) {
+               if (!validate_slab_ptr(slab)) {
+                       slab_err(s, slab, "Not a valid slab page");
+                       goto out;
+               }
+
                if (!check_slab(s, slab))
                        goto out;
        }
@@ -6519,6 +6529,11 @@ static void validate_slab(struct kmem_cache *s, struct slab *slab,
        void *p;
        void *addr = slab_address(slab);
 
+       if (!validate_slab_ptr(slab)) {
+               slab_err(s, slab, "Not a valid slab page");
+               return;
+       }
+
        if (!check_slab(s, slab) || !on_freelist(s, slab, NULL))
                return;