]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
block: Rework bio_split() return value
authorJohn Garry <john.g.garry@oracle.com>
Mon, 11 Nov 2024 11:21:45 +0000 (11:21 +0000)
committerJens Axboe <axboe@kernel.dk>
Mon, 11 Nov 2024 15:35:46 +0000 (08:35 -0700)
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 <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: John Garry <john.g.garry@oracle.com>
Link: https://lore.kernel.org/r/20241111112150.3756529-2-john.g.garry@oracle.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/bio.c
block/blk-crypto-fallback.c

index daceb0a5c1d79b705e959f4bffa228b7dc820155..948b22825510b8268b5532a0327475e11c49d469 100644 (file)
@@ -1665,16 +1665,18 @@ struct bio *bio_split(struct bio *bio, int sectors,
 {
        struct bio *split;
 
-       BUG_ON(sectors <= 0);
-       BUG_ON(sectors >= bio_sectors(bio));
+       if (WARN_ON_ONCE(sectors <= 0))
+               return ERR_PTR(-EINVAL);
+       if (WARN_ON_ONCE(sectors >= bio_sectors(bio)))
+               return ERR_PTR(-EINVAL);
 
        /* Zone append commands cannot be split */
        if (WARN_ON_ONCE(bio_op(bio) == REQ_OP_ZONE_APPEND))
-               return NULL;
+               return ERR_PTR(-EINVAL);
 
        split = bio_alloc_clone(bio->bi_bdev, bio, gfp, bs);
        if (!split)
-               return NULL;
+               return ERR_PTR(-ENOMEM);
 
        split->bi_iter.bi_size = sectors << 9;
 
index b1e7415f8439c45d04c49f7fbeb48891e0392027..29a205482617c8479800b38c36881759cf1f9081 100644 (file)
@@ -226,7 +226,7 @@ static bool blk_crypto_fallback_split_bio_if_needed(struct bio **bio_ptr)
 
                split_bio = bio_split(bio, num_sectors, GFP_NOIO,
                                      &crypto_bio_split);
-               if (!split_bio) {
+               if (IS_ERR(split_bio)) {
                        bio->bi_status = BLK_STS_RESOURCE;
                        return false;
                }