[PATCH v2 1/1] mm: move bad zone checking in gfp_zone()

From: Wang Yibo
Date: Thu Sep 05 2024 - 06:48:28 EST


When flags in gfp_zone() has an error combination,
VM_BUG_ON() should first know it before use it.

Signed-off-by: Wang Yibo <wangyibo@xxxxxxxxxxxxx>
---
include/linux/gfp.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index f53f76e0b17e..ca61b2440ab3 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -133,10 +133,11 @@ static inline enum zone_type gfp_zone(gfp_t flags)
{
enum zone_type z;
int bit = (__force int) (flags & GFP_ZONEMASK);
+ VM_BUG_ON((GFP_ZONE_BAD >> bit) & 1);

z = (GFP_ZONE_TABLE >> (bit * GFP_ZONES_SHIFT)) &
((1 << GFP_ZONES_SHIFT) - 1);
- VM_BUG_ON((GFP_ZONE_BAD >> bit) & 1);
+
return z;
}

--
2.20.1