Skip to content

Commit 6f6fcd4

Browse files
committed
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 <[email protected]> Signed-off-by: Vlastimil Babka <[email protected]>
1 parent 86169b0 commit 6f6fcd4

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

mm/slub.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,15 +1458,15 @@ static int check_object(struct kmem_cache *s, struct slab *slab,
14581458
return ret;
14591459
}
14601460

1461+
/*
1462+
* Checks if the slab state looks sane. Assumes the struct slab pointer
1463+
* was either obtained in a way that ensures it's valid, or validated
1464+
* by validate_slab_ptr()
1465+
*/
14611466
static int check_slab(struct kmem_cache *s, struct slab *slab)
14621467
{
14631468
int maxobj;
14641469

1465-
if (!validate_slab_ptr(slab)) {
1466-
slab_err(s, slab, "Not a valid slab page");
1467-
return 0;
1468-
}
1469-
14701470
maxobj = order_objects(slab_order(slab), s->size);
14711471
if (slab->objects > maxobj) {
14721472
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)
16331633
static inline int alloc_consistency_checks(struct kmem_cache *s,
16341634
struct slab *slab, void *object)
16351635
{
1636+
if (!validate_slab_ptr(slab)) {
1637+
slab_err(s, slab, "Not a valid slab page");
1638+
return 0;
1639+
}
1640+
16361641
if (!check_slab(s, slab))
16371642
return 0;
16381643

@@ -3485,6 +3490,11 @@ static inline bool free_debug_processing(struct kmem_cache *s,
34853490
int cnt = 0;
34863491

34873492
if (s->flags & SLAB_CONSISTENCY_CHECKS) {
3493+
if (!validate_slab_ptr(slab)) {
3494+
slab_err(s, slab, "Not a valid slab page");
3495+
goto out;
3496+
}
3497+
34883498
if (!check_slab(s, slab))
34893499
goto out;
34903500
}
@@ -6519,6 +6529,11 @@ static void validate_slab(struct kmem_cache *s, struct slab *slab,
65196529
void *p;
65206530
void *addr = slab_address(slab);
65216531

6532+
if (!validate_slab_ptr(slab)) {
6533+
slab_err(s, slab, "Not a valid slab page");
6534+
return;
6535+
}
6536+
65226537
if (!check_slab(s, slab) || !on_freelist(s, slab, NULL))
65236538
return;
65246539

0 commit comments

Comments
 (0)