[PATCH] zsmalloc: use temporary unsigned long for min_alloc_size calculations

From: Sergey Senozhatsky
Date: Sun Oct 30 2022 - 22:15:13 EST


kbuild reported the following warning:

mm/zsmalloc.c: In function 'zs_create_pool':
mm/zsmalloc.c:2220:69: warning: right shift count >= width of type [-Wshift-count-overflow]

Use unsigned long temp variable for calculations in zs_create_pool().

Reported-by: kernel test robot <lkp@xxxxxxxxx>
Signed-off-by: Sergey Senozhatsky <senozhatsky@xxxxxxxxxxxx>
---
mm/zsmalloc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index 0bc9ed1f1a5d..181bfc66249b 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -2211,6 +2211,7 @@ struct zs_pool *zs_create_pool(const char *name, u32 max_pages_per_zspage)
int i;
struct zs_pool *pool;
struct size_class *prev_class = NULL;
+ unsigned long num_pages = max_pages_per_zspage;

if (WARN_ON(max_pages_per_zspage < ZS_MIN_PAGES_PER_ZSPAGE ||
max_pages_per_zspage > ZS_MAX_PAGES_PER_ZSPAGE))
@@ -2221,8 +2222,7 @@ struct zs_pool *zs_create_pool(const char *name, u32 max_pages_per_zspage)
return NULL;

/* min_alloc_size must be multiple of ZS_ALIGN */
- pool->min_alloc_size = (max_pages_per_zspage << PAGE_SHIFT) >>
- OBJ_INDEX_BITS;
+ pool->min_alloc_size = num_pages << PAGE_SHIFT >> OBJ_INDEX_BITS;
pool->min_alloc_size = max(pool->min_alloc_size, ZS_MIN_ALLOC_SIZE);

pool->num_size_classes =
--
2.38.1.273.g43a17bfeac-goog