]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
block: add a bio_endio_status helper
authorChristoph Hellwig <hch@lst.de>
Thu, 28 May 2026 08:46:13 +0000 (10:46 +0200)
committerJens Axboe <axboe@kernel.dk>
Thu, 28 May 2026 13:59:18 +0000 (07:59 -0600)
Add a helper that sets bi_status and call bio_endio() as that is a very
common pattern and convert the core block code over to it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Keith Busch <kbusch@kernel.org>
Reviewed-by: Md Haris Iqbal <haris.iqbal@linux.dev>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Hannes Reinecke <hare@kernel.org>
Link: https://patch.msgid.link/20260528084632.2505277-1-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-core.c
block/blk-crypto-fallback.c
block/blk-crypto.c
block/blk-merge.c
block/blk-mq.c
block/fops.c
include/linux/bio.h

index 22af5dec112b51f5af91d562230d3d789c00fc52..b0f0a304ea0b8284445e4e448a087d7d44e8bd71 100644 (file)
@@ -636,12 +636,10 @@ static void __submit_bio(struct bio *bio)
                struct gendisk *disk = bio->bi_bdev->bd_disk;
        
                if ((bio->bi_opf & REQ_POLLED) &&
-                   !(disk->queue->limits.features & BLK_FEAT_POLL)) {
-                       bio->bi_status = BLK_STS_NOTSUPP;
-                       bio_endio(bio);
-               } else {
+                   !(disk->queue->limits.features & BLK_FEAT_POLL))
+                       bio_endio_status(bio, BLK_STS_NOTSUPP);
+               else
                        disk->fops->submit_bio(bio);
-               }
                blk_queue_exit(disk->queue);
        }
 
@@ -886,8 +884,7 @@ void submit_bio_noacct(struct bio *bio)
 not_supported:
        status = BLK_STS_NOTSUPP;
 end_io:
-       bio->bi_status = status;
-       bio_endio(bio);
+       bio_endio_status(bio, status);
 }
 EXPORT_SYMBOL(submit_bio_noacct);
 
index 61f5954108329fd02554fbc7e98a7bb14ef33a18..8b04d9205b8dde48e9a309a6655f7c2e92b01781 100644 (file)
@@ -361,8 +361,7 @@ static void blk_crypto_fallback_encrypt_bio(struct bio *src_bio)
        status = blk_crypto_get_keyslot(blk_crypto_fallback_profile,
                                        bc->bc_key, &slot);
        if (status != BLK_STS_OK) {
-               src_bio->bi_status = status;
-               bio_endio(src_bio);
+               bio_endio_status(src_bio, status);
                return;
        }
        __blk_crypto_fallback_encrypt_bio(src_bio,
@@ -437,8 +436,7 @@ static void blk_crypto_fallback_decrypt_bio(struct work_struct *work)
        }
        mempool_free(f_ctx, bio_fallback_crypt_ctx_pool);
 
-       bio->bi_status = status;
-       bio_endio(bio);
+       bio_endio_status(bio, status);
 }
 
 /**
@@ -499,8 +497,7 @@ bool blk_crypto_fallback_bio_prep(struct bio *bio)
 
        if (!__blk_crypto_cfg_supported(blk_crypto_fallback_profile,
                                        &bc->bc_key->crypto_cfg)) {
-               bio->bi_status = BLK_STS_NOTSUPP;
-               bio_endio(bio);
+               bio_endio_status(bio, BLK_STS_NOTSUPP);
                return false;
        }
 
index 856d3c5b1fa0d189a05568e500955499d4100d92..165c9d2cce073cbda6a50cd0fb78d8a5d52cd90c 100644 (file)
@@ -267,8 +267,7 @@ bool __blk_crypto_submit_bio(struct bio *bio)
                if (!IS_ENABLED(CONFIG_BLK_INLINE_ENCRYPTION_FALLBACK)) {
                        pr_warn_once("%pg: crypto API fallback disabled; failing request.\n",
                                bdev);
-                       bio->bi_status = BLK_STS_NOTSUPP;
-                       bio_endio(bio);
+                       bio_endio_status(bio, BLK_STS_NOTSUPP);
                        return false;
                }
                return blk_crypto_fallback_bio_prep(bio);
index fcf09325b22e36296278a2f221392e4c83a41c58..7cc82a7a6f4ef0dbfb920d4b3d999f8b438187f8 100644 (file)
@@ -122,8 +122,7 @@ struct bio *bio_submit_split_bioset(struct bio *bio, unsigned int split_sectors,
        struct bio *split = bio_split(bio, split_sectors, GFP_NOIO, bs);
 
        if (IS_ERR(split)) {
-               bio->bi_status = errno_to_blk_status(PTR_ERR(split));
-               bio_endio(bio);
+               bio_endio_status(bio, errno_to_blk_status(PTR_ERR(split)));
                return NULL;
        }
 
@@ -143,8 +142,7 @@ EXPORT_SYMBOL_GPL(bio_submit_split_bioset);
 static struct bio *bio_submit_split(struct bio *bio, int split_sectors)
 {
        if (unlikely(split_sectors < 0)) {
-               bio->bi_status = errno_to_blk_status(split_sectors);
-               bio_endio(bio);
+               bio_endio_status(bio, errno_to_blk_status(split_sectors));
                return NULL;
        }
 
index 4c5c16cce4f8f3102f4d86964d4bf9f90df6582e..ade9d3a89743912ee2cd18e8398f2af3acb97035 100644 (file)
@@ -3187,8 +3187,7 @@ void blk_mq_submit_bio(struct bio *bio)
        }
 
        if ((bio->bi_opf & REQ_POLLED) && !blk_mq_can_poll(q)) {
-               bio->bi_status = BLK_STS_NOTSUPP;
-               bio_endio(bio);
+               bio_endio_status(bio, BLK_STS_NOTSUPP);
                goto queue_exit;
        }
 
@@ -3229,8 +3228,7 @@ new_request:
 
        ret = blk_crypto_rq_get_keyslot(rq);
        if (ret != BLK_STS_OK) {
-               bio->bi_status = ret;
-               bio_endio(bio);
+               bio_endio_status(bio, ret);
                blk_mq_free_request(rq);
                return;
        }
index ffe7b2042f4e2f4fee2e4be5bf954cd11fa85e11..15783a6180dec162b434f27d653fd9c611eecc6d 100644 (file)
@@ -218,8 +218,7 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
 
                ret = blkdev_iov_iter_get_pages(bio, iter, bdev);
                if (unlikely(ret)) {
-                       bio->bi_status = BLK_STS_IOERR;
-                       bio_endio(bio);
+                       bio_endio_status(bio, BLK_STS_IOERR);
                        break;
                }
                if (iocb->ki_flags & IOCB_NOWAIT) {
index e60d2f5bd3dc88800ae3082ff827649628735fc8..97f993d4d914e1d52739274105d8a19963460d9b 100644 (file)
@@ -370,16 +370,27 @@ void submit_bio(struct bio *bio);
 
 extern void bio_endio(struct bio *);
 
-static inline void bio_io_error(struct bio *bio)
+/**
+ * bio_endio_status - end I/O on a bio with a specific status
+ * @bio:       bio
+ * @status:    status to set
+ *
+ * Set @bio->bi_status to @status and call bio_endio().
+ **/
+static inline void bio_endio_status(struct bio *bio, blk_status_t status)
 {
-       bio->bi_status = BLK_STS_IOERR;
+       bio->bi_status = status;
        bio_endio(bio);
 }
 
+static inline void bio_io_error(struct bio *bio)
+{
+       bio_endio_status(bio, BLK_STS_IOERR);
+}
+
 static inline void bio_wouldblock_error(struct bio *bio)
 {
-       bio->bi_status = BLK_STS_AGAIN;
-       bio_endio(bio);
+       bio_endio_status(bio, BLK_STS_AGAIN);
 }
 
 /*