Skip to content

Commit 6bea022

Browse files
committed
zonefs: fix page reference and BIO leak
In zonefs_file_dio_append(), the pages obtained using bio_iov_iter_get_pages() are not released on completion of the REQ_OP_APPEND BIO, nor when bio_iov_iter_get_pages() fails. Furthermore, a call to bio_put() is missing when bio_iov_iter_get_pages() fails. Fix these resource leaks by adding BIO resource release code (bio_put()i and bio_release_pages()) at the end of the function after the BIO execution and add a jump to this resource cleanup code in case of bio_iov_iter_get_pages() failure. While at it, also fix the call to task_io_account_write() to be passed the correct BIO size instead of bio_iov_iter_get_pages() return value. Reported-by: Christoph Hellwig <[email protected]> Fixes: 02ef12a ("zonefs: use REQ_OP_ZONE_APPEND for sync DIO") Cc: [email protected] Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]>
1 parent 0477e92 commit 6bea022

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

fs/zonefs/super.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -691,21 +691,23 @@ static ssize_t zonefs_file_dio_append(struct kiocb *iocb, struct iov_iter *from)
691691
bio->bi_opf |= REQ_FUA;
692692

693693
ret = bio_iov_iter_get_pages(bio, from);
694-
if (unlikely(ret)) {
695-
bio_io_error(bio);
696-
return ret;
697-
}
694+
if (unlikely(ret))
695+
goto out_release;
696+
698697
size = bio->bi_iter.bi_size;
699-
task_io_account_write(ret);
698+
task_io_account_write(size);
700699

701700
if (iocb->ki_flags & IOCB_HIPRI)
702701
bio_set_polled(bio, iocb);
703702

704703
ret = submit_bio_wait(bio);
705704

705+
zonefs_file_write_dio_end_io(iocb, size, ret, 0);
706+
707+
out_release:
708+
bio_release_pages(bio, false);
706709
bio_put(bio);
707710

708-
zonefs_file_write_dio_end_io(iocb, size, ret, 0);
709711
if (ret >= 0) {
710712
iocb->ki_pos += size;
711713
return size;

0 commit comments

Comments
 (0)