Merge tag 'for-5.12/block-2021-02-17' of git://git.kernel.dk/linux-block
[linux-2.6-microblaze.git] / fs / iomap / direct-io.c
index e4c258a..e2c4991 100644 (file)
@@ -279,11 +279,8 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,
        orig_count = iov_iter_count(dio->submit.iter);
        iov_iter_truncate(dio->submit.iter, length);
 
-       nr_pages = iov_iter_npages(dio->submit.iter, BIO_MAX_PAGES);
-       if (nr_pages <= 0) {
-               ret = nr_pages;
+       if (!iov_iter_count(dio->submit.iter))
                goto out;
-       }
 
        if (need_zeroout) {
                /* zero out from the start of the block to the write offset */
@@ -299,6 +296,7 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,
         */
        bio_opf = iomap_dio_bio_opflags(dio, iomap, use_fua);
 
+       nr_pages = bio_iov_vecs_to_alloc(dio->submit.iter, BIO_MAX_PAGES);
        do {
                size_t n;
                if (dio->error) {
@@ -339,7 +337,8 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,
                dio->size += n;
                copied += n;
 
-               nr_pages = iov_iter_npages(dio->submit.iter, BIO_MAX_PAGES);
+               nr_pages = bio_iov_vecs_to_alloc(dio->submit.iter,
+                                                BIO_MAX_PAGES);
                iomap_dio_submit_bio(dio, iomap, bio, pos);
                pos += n;
        } while (nr_pages);