Commit 6f6fcd46 authored by Vlastimil Babka's avatar Vlastimil Babka
Browse files

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: default avatarHarry Yoo <harry.yoo@oracle.com>
Signed-off-by: default avatarVlastimil Babka <vbabka@suse.cz>
parent 86169b00
Loading
Loading
Loading
Loading
+20 −5
Original line number Diff line number Diff line
@@ -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;