Skip to content

Commit 8ea8566

Browse files
ming1axboe
authored andcommitted
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>
1 parent 211ff16 commit 8ea8566

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

drivers/block/ublk_drv.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5287,7 +5287,7 @@ static int __ublk_ctrl_reg_buf(struct ublk_device *ub,
52875287
unsigned long i;
52885288
int ret;
52895289

5290-
for (i = 0; i < nr_pages; ) {
5290+
for (i = 0; i < nr_pages; i++) {
52915291
unsigned long pfn = page_to_pfn(pages[i]);
52925292
unsigned long start = i;
52935293
struct ublk_buf_range *range;
@@ -5296,7 +5296,6 @@ static int __ublk_ctrl_reg_buf(struct ublk_device *ub,
52965296
while (i + 1 < nr_pages &&
52975297
page_to_pfn(pages[i + 1]) == pfn + (i - start) + 1)
52985298
i++;
5299-
i++; /* past the last page in this run */
53005299

53015300
range = kzalloc(sizeof(*range), GFP_KERNEL);
53025301
if (!range) {
@@ -5308,7 +5307,7 @@ static int __ublk_ctrl_reg_buf(struct ublk_device *ub,
53085307
range->base_offset = start << PAGE_SHIFT;
53095308

53105309
ret = mtree_insert_range(&ub->buf_tree, pfn,
5311-
pfn + (i - start) - 1,
5310+
pfn + (i - start),
53125311
range, GFP_KERNEL);
53135312
if (ret) {
53145313
kfree(range);

0 commit comments

Comments
 (0)