[PATCH 2/5] block: unify the synchronous bi_end_io callbacks

Christoph Hellwig
2026-04-07T14:05:54Z

Put the bio in bio_await_chain after waiting for the completion, and
share the now identical callbacks between submit_bio_wait and
bio_await_chain.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
---
block/bio.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/block/bio.c b/block/bio.c
index c8234d347fc5..434e41182c05 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1462,7 +1462,7 @@ void bio_iov_iter_unbounce(struct bio *bio, bool is_error, bool mark_dirty)
bio_iov_iter_unbounce_read(bio, is_error, mark_dirty);
}

-static void submit_bio_wait_endio(struct bio *bio)
+static void bio_wait_end_io(struct bio *bio)
{
complete(bio->bi_private);
}
@@ -1484,7 +1484,7 @@ int submit_bio_wait(struct bio *bio)
bio->bi_bdev->bd_disk->lockdep_map);

bio->bi_private = &done;
- bio->bi_end_io = submit_bio_wait_endio;
+ bio->bi_end_io = bio_wait_end_io;
bio->bi_opf |= REQ_SYNC;
submit_bio(bio);
blk_wait_io(&done);
@@ -1523,12 +1523,6 @@ int bdev_rw_virt(struct block_device *bdev, sector_t sector, void *data,
}
EXPORT_SYMBOL_GPL(bdev_rw_virt);

-static void bio_wait_end_io(struct bio *bio)
-{
- complete(bio->bi_private);
- bio_put(bio);
-}
-
/*
* bio_await_chain - ends @bio and waits for every chained bio to complete
*/
@@ -1541,6 +1535,7 @@ void bio_await_chain(struct bio *bio)
bio->bi_end_io = bio_wait_end_io;
bio_endio(bio);
blk_wait_io(&done);
+ bio_put(bio);
}

void __bio_advance(struct bio *bio, unsigned bytes)
--
2.47.3