slab: move validate_slab_ptr() from check_slab() to its callers

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>
This commit is contained in:
Vlastimil Babka 2025-09-15 15:55:10 +02:00
parent 86169b00f8
commit 6f6fcd4634

View File

@ -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;