[RHEL7,COMMIT] ploop: Fix discard iocb leak

Submitted by Vasily Averin on Aug. 5, 2020, 6:55 p.m.

Details

Message ID 202008051855.075It6pi002207@vz7build.vvs.sw.ru
State New
Series "ploop: Fix discard iocb leak"
Headers show

Commit Message

Vasily Averin Aug. 5, 2020, 6:55 p.m.
The commit is pushed to "branch-rh7-3.10.0-1127.18.2.vz7.163.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1127.18.2.el7
------>
commit efbc4b30dfcfa07c0009a6f075fb5e31cfad2fe2
Author: Kirill Tkhai <ktkhai@virtuozzo.com>
Date:   Wed Aug 5 21:55:06 2020 +0300

    ploop: Fix discard iocb leak
    
    Swap iocb allocation and ext4 check.
    
    This is only used in experimental kaio over ext4 code,
    and the patch *does not* require RK.
    
    Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 drivers/block/ploop/io_kaio.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/block/ploop/io_kaio.c b/drivers/block/ploop/io_kaio.c
index 6d6517dc..89e39ff 100644
--- a/drivers/block/ploop/io_kaio.c
+++ b/drivers/block/ploop/io_kaio.c
@@ -181,10 +181,6 @@  static int kaio_kernel_submit(struct file *file, struct kaio_req *kreq,
 	struct iov_iter iter;
 	int err;
 
-	iocb = aio_kernel_alloc(GFP_NOIO);
-	if (!iocb)
-		return -ENOMEM;
-
 	if (rw & REQ_DISCARD) {
 		op = IOCB_CMD_UNMAP_ITER;
 		if (file_inode(file)->i_sb->s_magic == EXT4_SUPER_MAGIC)
@@ -194,6 +190,10 @@  static int kaio_kernel_submit(struct file *file, struct kaio_req *kreq,
 	else
 		op = IOCB_CMD_READ_ITER;
 
+	iocb = aio_kernel_alloc(GFP_NOIO);
+	if (!iocb)
+		return -ENOMEM;
+
 	iov_iter_init_bvec(&iter, kreq->bvecs, nr_segs, count, 0);
 	aio_kernel_init_iter(iocb, file, op, &iter, pos);
 	aio_kernel_init_callback(iocb, kaio_rw_kreq_complete, (u64)kreq);