Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iomap: free the bio before completing the dio

There are good arguments for processing the user completions ASAP vs.
freeing resources ASAP, but freeing the bio first here removes potential
use after free hazards when checking flags, and will simplify the
upcoming bounce buffer support.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Tested-by: Anuj Gupta <anuj20.g@samsung.com>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
45cec0de e2fcff5b

+9 -8
+9 -8
fs/iomap/direct-io.c
··· 214 214 static void __iomap_dio_bio_end_io(struct bio *bio, bool inline_completion) 215 215 { 216 216 struct iomap_dio *dio = bio->bi_private; 217 - bool should_dirty = (dio->flags & IOMAP_DIO_DIRTY); 217 + 218 + if (dio->flags & IOMAP_DIO_DIRTY) { 219 + bio_check_pages_dirty(bio); 220 + } else { 221 + bio_release_pages(bio, false); 222 + bio_put(bio); 223 + } 224 + 225 + /* Do not touch bio below, we just gave up our reference. */ 218 226 219 227 if (atomic_dec_and_test(&dio->ref)) { 220 228 /* ··· 232 224 if (inline_completion) 233 225 dio->flags &= ~IOMAP_DIO_COMP_WORK; 234 226 iomap_dio_done(dio); 235 - } 236 - 237 - if (should_dirty) { 238 - bio_check_pages_dirty(bio); 239 - } else { 240 - bio_release_pages(bio, false); 241 - bio_put(bio); 242 227 } 243 228 } 244 229