#endif
 #endif
 
-static inline int kmem_cache_debug(struct kmem_cache *s)
+/*
+ * Returns true if any of the specified slub_debug flags is enabled for the
+ * cache. Use only for flags parsed by setup_slub_debug() as it also enables
+ * the static key.
+ */
+static inline bool kmem_cache_debug_flags(struct kmem_cache *s, slab_flags_t flags)
 {
+       VM_WARN_ON_ONCE(!(flags & SLAB_DEBUG_FLAGS));
 #ifdef CONFIG_SLUB_DEBUG
        if (static_branch_unlikely(&slub_debug_enabled))
-               return s->flags & SLAB_DEBUG_FLAGS;
+               return s->flags & flags;
 #endif
-       return 0;
+       return false;
+}
+
+static inline bool kmem_cache_debug(struct kmem_cache *s)
+{
+       return kmem_cache_debug_flags(s, SLAB_DEBUG_FLAGS);
 }
 
 void *fixup_red_left(struct kmem_cache *s, void *p)
 {
-       if (kmem_cache_debug(s) && s->flags & SLAB_RED_ZONE)
+       if (kmem_cache_debug_flags(s, SLAB_RED_ZONE))
                p += s->red_left_pad;
 
        return p;
        offset = (ptr - page_address(page)) % s->size;
 
        /* Adjust for redzone and reject if within the redzone. */
-       if (kmem_cache_debug(s) && s->flags & SLAB_RED_ZONE) {
+       if (kmem_cache_debug_flags(s, SLAB_RED_ZONE)) {
                if (offset < s->red_left_pad)
                        usercopy_abort("SLUB object in left red zone",
                                       s->name, to_user, offset, n);