summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMing Lei <tom.leiming@gmail.com>2026-04-09 16:30:15 +0300
committerJens Axboe <axboe@kernel.dk>2026-04-10 04:08:35 +0300
commit8ea8566a9aeef746699d8c84bed3ac44edbfaa0e (patch)
treebdbdc65abdc23b85d5c1c1fdb7b9e241a92299b2
parent211ff1602b67e26125977f8b2f369d7c2847628c (diff)
downloadlinux-8ea8566a9aeef746699d8c84bed3ac44edbfaa0e.tar.xz
ublk: simplify PFN range loop in __ublk_ctrl_reg_buf
Use the for-loop increment instead of a manual `i++` past the last page, and fix the mtree_insert_range end key accordingly. Suggested-by: Caleb Sander Mateos <csander@purestorage.com> Signed-off-by: Ming Lei <tom.leiming@gmail.com> Link: https://patch.msgid.link/20260409133020.3780098-4-tom.leiming@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--drivers/block/ublk_drv.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 8fef6dfee271..1257acc4522a 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -5287,7 +5287,7 @@ static int __ublk_ctrl_reg_buf(struct ublk_device *ub,
unsigned long i;
int ret;
- for (i = 0; i < nr_pages; ) {
+ for (i = 0; i < nr_pages; i++) {
unsigned long pfn = page_to_pfn(pages[i]);
unsigned long start = i;
struct ublk_buf_range *range;
@@ -5296,7 +5296,6 @@ static int __ublk_ctrl_reg_buf(struct ublk_device *ub,
while (i + 1 < nr_pages &&
page_to_pfn(pages[i + 1]) == pfn + (i - start) + 1)
i++;
- i++; /* past the last page in this run */
range = kzalloc(sizeof(*range), GFP_KERNEL);
if (!range) {
@@ -5308,7 +5307,7 @@ static int __ublk_ctrl_reg_buf(struct ublk_device *ub,
range->base_offset = start << PAGE_SHIFT;
ret = mtree_insert_range(&ub->buf_tree, pfn,
- pfn + (i - start) - 1,
+ pfn + (i - start),
range, GFP_KERNEL);
if (ret) {
kfree(range);