Skip to content

Commit 38b4353

Browse files
abattersbyaxboe
authored andcommitted
block: Fix page refcounts for unaligned buffers in __bio_release_pages()
Fix an incorrect number of pages being released for buffers that do not start at the beginning of a page. Fixes: 1b151e2 ("block: Remove special-casing of compound pages") Cc: [email protected] Signed-off-by: Tony Battersby <[email protected]> Tested-by: Greg Edwards <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 2682832 commit 38b4353

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

block/bio.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,18 +1153,19 @@ void __bio_release_pages(struct bio *bio, bool mark_dirty)
11531153

11541154
bio_for_each_folio_all(fi, bio) {
11551155
struct page *page;
1156-
size_t done = 0;
1156+
size_t nr_pages;
11571157

11581158
if (mark_dirty) {
11591159
folio_lock(fi.folio);
11601160
folio_mark_dirty(fi.folio);
11611161
folio_unlock(fi.folio);
11621162
}
11631163
page = folio_page(fi.folio, fi.offset / PAGE_SIZE);
1164+
nr_pages = (fi.offset + fi.length - 1) / PAGE_SIZE -
1165+
fi.offset / PAGE_SIZE + 1;
11641166
do {
11651167
bio_release_page(bio, page++);
1166-
done += PAGE_SIZE;
1167-
} while (done < fi.length);
1168+
} while (--nr_pages != 0);
11681169
}
11691170
}
11701171
EXPORT_SYMBOL_GPL(__bio_release_pages);

0 commit comments

Comments
 (0)