summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Begunkov <asml.silence@gmail.com>2025-11-10 13:04:49 +0000
committerJens Axboe <axboe@kernel.dk>2025-11-11 07:53:33 -0700
commit4aed5b4e6d276d2308d0ea8932b0c6ebfd3d19f8 (patch)
tree0174d8328b8ae30afa74af28413a70f01731cd19
parent21bd7b14a32de35bc6c4fff7a739dc5d33ce04f1 (diff)
io_uring: add helper calculating region byte size
There has been type related issues with region size calculation, add an utility helper function that returns the size and handles type conversions right. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--io_uring/memmap.c4
-rw-r--r--io_uring/memmap.h5
2 files changed, 7 insertions, 2 deletions
diff --git a/io_uring/memmap.c b/io_uring/memmap.c
index 24da17a5f08f..dc4bfc5b6fb8 100644
--- a/io_uring/memmap.c
+++ b/io_uring/memmap.c
@@ -134,7 +134,7 @@ static int io_region_init_ptr(struct io_mapped_region *mr)
static int io_region_pin_pages(struct io_mapped_region *mr,
struct io_uring_region_desc *reg)
{
- unsigned long size = mr->nr_pages << PAGE_SHIFT;
+ size_t size = io_region_size(mr);
struct page **pages;
int nr_pages;
@@ -154,7 +154,7 @@ static int io_region_allocate_pages(struct io_mapped_region *mr,
unsigned long mmap_offset)
{
gfp_t gfp = GFP_KERNEL_ACCOUNT | __GFP_ZERO | __GFP_NOWARN;
- size_t size = (size_t) mr->nr_pages << PAGE_SHIFT;
+ size_t size = io_region_size(mr);
unsigned long nr_allocated;
struct page **pages;
diff --git a/io_uring/memmap.h b/io_uring/memmap.h
index a6c63ca2c6f1..a39d9e518905 100644
--- a/io_uring/memmap.h
+++ b/io_uring/memmap.h
@@ -43,4 +43,9 @@ static inline void io_region_publish(struct io_ring_ctx *ctx,
*dst_region = *src_region;
}
+static inline size_t io_region_size(struct io_mapped_region *mr)
+{
+ return (size_t) mr->nr_pages << PAGE_SHIFT;
+}
+
#endif