Skip to content

Commit 46d7160

Browse files
krisman-at-collaborajankara
authored andcommitted
direct-io: clean up error paths of do_blockdev_direct_IO
In preparation to resort DIO checks, reduce code duplication of error handling in do_blockdev_direct_IO. Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Jan Kara <[email protected]> Reviewed-by: Jens Axboe <[email protected]> Signed-off-by: Gabriel Krisman Bertazi <[email protected]> Signed-off-by: Jan Kara <[email protected]>
1 parent c85fb28 commit 46d7160

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

fs/direct-io.c

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,17 +1170,16 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
11701170
blkbits = blksize_bits(bdev_logical_block_size(bdev));
11711171
blocksize_mask = (1 << blkbits) - 1;
11721172
if (align & blocksize_mask)
1173-
goto out;
1173+
return -EINVAL;
11741174
}
11751175

11761176
/* watch out for a 0 len io from a tricksy fs */
11771177
if (iov_iter_rw(iter) == READ && !count)
11781178
return 0;
11791179

11801180
dio = kmem_cache_alloc(dio_cache, GFP_KERNEL);
1181-
retval = -ENOMEM;
11821181
if (!dio)
1183-
goto out;
1182+
return -ENOMEM;
11841183
/*
11851184
* Believe it or not, zeroing out the page array caused a .5%
11861185
* performance regression in a database benchmark. So, we take
@@ -1199,22 +1198,16 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
11991198

12001199
retval = filemap_write_and_wait_range(mapping, offset,
12011200
end - 1);
1202-
if (retval) {
1203-
inode_unlock(inode);
1204-
kmem_cache_free(dio_cache, dio);
1205-
goto out;
1206-
}
1201+
if (retval)
1202+
goto fail_dio;
12071203
}
12081204
}
12091205

12101206
/* Once we sampled i_size check for reads beyond EOF */
12111207
dio->i_size = i_size_read(inode);
12121208
if (iov_iter_rw(iter) == READ && offset >= dio->i_size) {
1213-
if (dio->flags & DIO_LOCKING)
1214-
inode_unlock(inode);
1215-
kmem_cache_free(dio_cache, dio);
12161209
retval = 0;
1217-
goto out;
1210+
goto fail_dio;
12181211
}
12191212

12201213
/*
@@ -1258,14 +1251,8 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
12581251
*/
12591252
retval = sb_init_dio_done_wq(dio->inode->i_sb);
12601253
}
1261-
if (retval) {
1262-
/*
1263-
* We grab i_mutex only for reads so we don't have
1264-
* to release it here
1265-
*/
1266-
kmem_cache_free(dio_cache, dio);
1267-
goto out;
1268-
}
1254+
if (retval)
1255+
goto fail_dio;
12691256
}
12701257

12711258
/*
@@ -1368,7 +1355,13 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
13681355
} else
13691356
BUG_ON(retval != -EIOCBQUEUED);
13701357

1371-
out:
1358+
return retval;
1359+
1360+
fail_dio:
1361+
if (dio->flags & DIO_LOCKING && iov_iter_rw(iter) == READ)
1362+
inode_unlock(inode);
1363+
1364+
kmem_cache_free(dio_cache, dio);
13721365
return retval;
13731366
}
13741367

0 commit comments

Comments
 (0)