@@ -1080,7 +1080,7 @@ static int __bio_iov_append_get_pages(struct bio *bio, struct iov_iter *iter)
len = min_t(size_t, PAGE_SIZE - offset, left);
if (bio_add_hw_page(q, bio, page, len, offset,
max_append_sectors, &same_page) != len)
- return -EINVAL;
+ goto put_pages;
if (same_page)
put_page(page);
offset = 0;
@@ -1088,6 +1088,16 @@ static int __bio_iov_append_get_pages(struct bio *bio, struct iov_iter *iter)
iov_iter_advance(iter, size);
return 0;
+put_pages:
+ iov_iter_advance(iter, size - left);
+ for (; left > 0; left -= len, i++) {
+ struct page *page = pages[i];
+
+ len = min_t(size_t, PAGE_SIZE - offset, left);
+ put_page(page);
+ offset = 0;
+ }
+ return -EINVAL;
}
/**