Skip to content

Commit ba8c696

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: cleanup bio_endio
Replace the while loop that unecessarily checks for a NULL bio in the fast path with a simple goto loop. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent 38f8baa commit ba8c696

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

block/bio.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,26 +1745,25 @@ static inline bool bio_remaining_done(struct bio *bio)
17451745
**/
17461746
void bio_endio(struct bio *bio)
17471747
{
1748-
while (bio) {
1749-
if (unlikely(!bio_remaining_done(bio)))
1750-
break;
1748+
again:
1749+
if (unlikely(!bio_remaining_done(bio)))
1750+
return;
17511751

1752-
/*
1753-
* Need to have a real endio function for chained bios,
1754-
* otherwise various corner cases will break (like stacking
1755-
* block devices that save/restore bi_end_io) - however, we want
1756-
* to avoid unbounded recursion and blowing the stack. Tail call
1757-
* optimization would handle this, but compiling with frame
1758-
* pointers also disables gcc's sibling call optimization.
1759-
*/
1760-
if (bio->bi_end_io == bio_chain_endio) {
1761-
bio = __bio_chain_endio(bio);
1762-
} else {
1763-
if (bio->bi_end_io)
1764-
bio->bi_end_io(bio);
1765-
bio = NULL;
1766-
}
1752+
/*
1753+
* Need to have a real endio function for chained bios, otherwise
1754+
* various corner cases will break (like stacking block devices that
1755+
* save/restore bi_end_io) - however, we want to avoid unbounded
1756+
* recursion and blowing the stack. Tail call optimization would
1757+
* handle this, but compiling with frame pointers also disables
1758+
* gcc's sibling call optimization.
1759+
*/
1760+
if (bio->bi_end_io == bio_chain_endio) {
1761+
bio = __bio_chain_endio(bio);
1762+
goto again;
17671763
}
1764+
1765+
if (bio->bi_end_io)
1766+
bio->bi_end_io(bio);
17681767
}
17691768
EXPORT_SYMBOL(bio_endio);
17701769

0 commit comments

Comments
 (0)