From 22985caf3ff3d5845d5c03c4516be12f6d004d5e Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Mon, 11 Nov 2024 15:12:37 +0100 Subject: [PATCH] panfrost: sanity-check alignment The page-alignment should always be a positive power of two. Let's assert that, to avoid confusion. Reviewed-by: Boris Brezillon Reviewed-by: Mary Guillemard CID: 1605086 Part-of: --- src/gallium/drivers/panfrost/pan_mempool.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gallium/drivers/panfrost/pan_mempool.c b/src/gallium/drivers/panfrost/pan_mempool.c index 91119997ccf..1a59974df11 100644 --- a/src/gallium/drivers/panfrost/pan_mempool.c +++ b/src/gallium/drivers/panfrost/pan_mempool.c @@ -137,7 +137,9 @@ panfrost_pool_alloc_aligned(struct panfrost_pool *pool, size_t sz, #ifdef PAN_DBG_OVERFLOW if (unlikely(pool->dev->debug & PAN_DBG_OVERFLOW) && !(pool->create_flags & PAN_BO_INVISIBLE)) { - unsigned aligned = ALIGN_POT(sz, sysconf(_SC_PAGESIZE)); + long alignment = sysconf(_SC_PAGESIZE); + assert(alignment > 0 && util_is_power_of_two_nonzero(alignment)); + unsigned aligned = ALIGN_POT(sz, alignment); unsigned bo_size = aligned + PAN_GUARD_SIZE; bo = panfrost_pool_alloc_backing(pool, bo_size);