Skip to content

Commit e546fe1

Browse files
johnpgarryaxboe
authored andcommitted
block: Rework bio_split() return value
Instead of returning an inconclusive value of NULL for an error in calling bio_split(), return a ERR_PTR() always. Also remove the BUG_ON() calls, and WARN_ON_ONCE() instead. Indeed, since almost all callers don't check the return code from bio_split(), we'll crash anyway (for those failures). Fix up the only user which checks bio_split() return code today (directly or indirectly), blk_crypto_fallback_split_bio_if_needed(). The md/bcache code does check the return code in cached_dev_cache_miss() -> bio_next_split() -> bio_split(), but only to see if there was a split, so there would be no change in behaviour here (when returning a ERR_PTR()). Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: John Garry <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent d369735 commit e546fe1

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

block/bio.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,16 +1665,18 @@ struct bio *bio_split(struct bio *bio, int sectors,
16651665
{
16661666
struct bio *split;
16671667

1668-
BUG_ON(sectors <= 0);
1669-
BUG_ON(sectors >= bio_sectors(bio));
1668+
if (WARN_ON_ONCE(sectors <= 0))
1669+
return ERR_PTR(-EINVAL);
1670+
if (WARN_ON_ONCE(sectors >= bio_sectors(bio)))
1671+
return ERR_PTR(-EINVAL);
16701672

16711673
/* Zone append commands cannot be split */
16721674
if (WARN_ON_ONCE(bio_op(bio) == REQ_OP_ZONE_APPEND))
1673-
return NULL;
1675+
return ERR_PTR(-EINVAL);
16741676

16751677
split = bio_alloc_clone(bio->bi_bdev, bio, gfp, bs);
16761678
if (!split)
1677-
return NULL;
1679+
return ERR_PTR(-ENOMEM);
16781680

16791681
split->bi_iter.bi_size = sectors << 9;
16801682

block/blk-crypto-fallback.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ static bool blk_crypto_fallback_split_bio_if_needed(struct bio **bio_ptr)
226226

227227
split_bio = bio_split(bio, num_sectors, GFP_NOIO,
228228
&crypto_bio_split);
229-
if (!split_bio) {
229+
if (IS_ERR(split_bio)) {
230230
bio->bi_status = BLK_STS_RESOURCE;
231231
return false;
232232
}

0 commit comments

Comments
 (0)