diff mbox series

[42/62] mm/slub: Convert check_valid_pointer() to struct slab

Message ID 20211004134650.4031813-43-willy@infradead.org (mailing list archive)
State New
Headers show
Series Separate struct slab from struct page | expand

Commit Message

Matthew Wilcox Oct. 4, 2021, 1:46 p.m. UTC
Improves type safety and removes a lot of calls to slab_page().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 mm/slub.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/mm/slub.c b/mm/slub.c
index b1122b8cb36f..524e3c7eac30 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -638,19 +638,19 @@  static inline void metadata_access_disable(void)
  * Object debugging
  */
 
-/* Verify that a pointer has an address that is valid within a slab page */
+/* Verify that a pointer has an address that is valid within a slab */
 static inline int check_valid_pointer(struct kmem_cache *s,
-				struct page *page, void *object)
+				struct slab *slab, void *object)
 {
 	void *base;
 
 	if (!object)
 		return 1;
 
-	base = page_address(page);
+	base = slab_address(slab);
 	object = kasan_reset_tag(object);
 	object = restore_red_left(s, object);
-	if (object < base || object >= base + page->objects * s->size ||
+	if (object < base || object >= base + slab->objects * s->size ||
 		(object - base) % s->size) {
 		return 0;
 	}
@@ -803,7 +803,7 @@  static bool freelist_corrupted(struct kmem_cache *s, struct slab *slab,
 			       void **freelist, void *nextfree)
 {
 	if ((s->flags & SLAB_CONSISTENCY_CHECKS) &&
-	    !check_valid_pointer(s, slab_page(slab), nextfree) && freelist) {
+	    !check_valid_pointer(s, slab, nextfree) && freelist) {
 		object_err(s, slab_page(slab), *freelist, "Freechain corrupt");
 		*freelist = NULL;
 		slab_fix(s, "Isolate corrupted freechain");
@@ -1072,7 +1072,7 @@  static int check_object(struct kmem_cache *s, struct slab *slab,
 		return 1;
 
 	/* Check free pointer validity */
-	if (!check_valid_pointer(s, slab_page(slab), get_freepointer(s, p))) {
+	if (!check_valid_pointer(s, slab, get_freepointer(s, p))) {
 		object_err(s, slab_page(slab), p, "Freepointer corrupt");
 		/*
 		 * No choice but to zap it and thus lose the remainder
@@ -1125,7 +1125,7 @@  static int on_freelist(struct kmem_cache *s, struct slab *slab, void *search)
 	while (fp && nr <= slab->objects) {
 		if (fp == search)
 			return 1;
-		if (!check_valid_pointer(s, slab_page(slab), fp)) {
+		if (!check_valid_pointer(s, slab, fp)) {
 			if (object) {
 				object_err(s, slab_page(slab), object,
 					"Freechain corrupt");
@@ -1266,7 +1266,7 @@  static inline int alloc_consistency_checks(struct kmem_cache *s,
 	if (!check_slab(s, slab))
 		return 0;
 
-	if (!check_valid_pointer(s, slab_page(slab), object)) {
+	if (!check_valid_pointer(s, slab, object)) {
 		object_err(s, slab_page(slab), object, "Freelist Pointer check fails");
 		return 0;
 	}
@@ -1310,7 +1310,7 @@  static noinline int alloc_debug_processing(struct kmem_cache *s,
 static inline int free_consistency_checks(struct kmem_cache *s,
 		struct slab *slab, void *object, unsigned long addr)
 {
-	if (!check_valid_pointer(s, slab_page(slab), object)) {
+	if (!check_valid_pointer(s, slab, object)) {
 		slab_err(s, slab_page(slab), "Invalid object pointer 0x%p", object);
 		return 0;
 	}