mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andreas Gruenbacher <agruenba@redhat.com>
To: Christoph Hellwig <hch@infradead.org>,
	Jens Axboe <axboe@kernel.dk>, Chris Mason <clm@fb.com>,
	David Sterba <dsterba@suse.com>
Cc: Andreas Gruenbacher <agruenba@redhat.com>,
	linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org,
	linux-raid@vger.kernel.org, dm-devel@lists.linux.dev,
	linux-kernel@vger.kernel.org
Subject: [RFC 11/12] bio: add bio_endio_errno
Date: Mon,  8 Dec 2025 12:10:18 +0000	[thread overview]
Message-ID: <20251208121020.1780402-12-agruenba@redhat.com> (raw)
In-Reply-To: <20251208121020.1780402-1-agruenba@redhat.com>

Add a bio_endio_errno() helper as a shortcut for calling bio_set_errno()
and bio_endio() in sequence. Use the new helper throughout the code.

Created with Coccinelle using the following semantic patch:

@@
expression bio, errno;
@@
- bio_set_errno(bio, errno);
- bio_endio(bio);
+ bio_endio_errno(bio, errno);

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
 block/blk-merge.c                | 6 ++----
 drivers/block/drbd/drbd_req.c    | 3 +--
 drivers/md/dm-integrity.c        | 9 +++------
 drivers/md/dm-pcache/dm_pcache.c | 3 +--
 drivers/md/dm-vdo/data-vio.c     | 3 +--
 drivers/md/raid10.c              | 6 ++----
 drivers/nvdimm/pmem.c            | 4 +---
 fs/btrfs/raid56.c                | 6 ++----
 fs/iomap/ioend.c                 | 3 +--
 fs/xfs/xfs_aops.c                | 3 +--
 include/linux/bio.h              | 6 ++++++
 11 files changed, 21 insertions(+), 31 deletions(-)

diff --git a/block/blk-merge.c b/block/blk-merge.c
index 441013bf59d7..25057d57e9ac 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -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_set_errno(bio, PTR_ERR(split));
-		bio_endio(bio);
+		bio_endio_errno(bio, 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_set_errno(bio, split_sectors);
-		bio_endio(bio);
+		bio_endio_errno(bio, split_sectors);
 		return NULL;
 	}
 
diff --git a/drivers/block/drbd/drbd_req.c b/drivers/block/drbd/drbd_req.c
index 95a58ad6fdcf..5bedc972b622 100644
--- a/drivers/block/drbd/drbd_req.c
+++ b/drivers/block/drbd/drbd_req.c
@@ -176,8 +176,7 @@ void start_new_tl_epoch(struct drbd_connection *connection)
 void complete_master_bio(struct drbd_device *device,
 		struct bio_and_error *m)
 {
-	bio_set_errno(m->bio, m->error);
-	bio_endio(m->bio);
+	bio_endio_errno(m->bio, m->error);
 	dec_ap_bio(device);
 }
 
diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c
index 5220e15b6537..90780a112009 100644
--- a/drivers/md/dm-integrity.c
+++ b/drivers/md/dm-integrity.c
@@ -2594,8 +2594,7 @@ static int dm_integrity_map_inline(struct dm_integrity_io *dio, bool from_map)
 
 	bip = bio_integrity_alloc(bio, GFP_NOIO, 1);
 	if (IS_ERR(bip)) {
-		bio_set_errno(bio, PTR_ERR(bip));
-		bio_endio(bio);
+		bio_endio_errno(bio, PTR_ERR(bip));
 		return DM_MAPIO_SUBMITTED;
 	}
 
@@ -2662,8 +2661,7 @@ static void dm_integrity_inline_recheck(struct work_struct *w)
 		bip = bio_integrity_alloc(outgoing_bio, GFP_NOIO, 1);
 		if (IS_ERR(bip)) {
 			bio_put(outgoing_bio);
-			bio_set_errno(bio, PTR_ERR(bip));
-			bio_endio(bio);
+			bio_endio_errno(bio, PTR_ERR(bip));
 			return;
 		}
 
@@ -2680,8 +2678,7 @@ static void dm_integrity_inline_recheck(struct work_struct *w)
 		r = submit_bio_wait(outgoing_bio);
 		if (unlikely(r != 0)) {
 			bio_put(outgoing_bio);
-			bio_set_errno(bio, r);
-			bio_endio(bio);
+			bio_endio_errno(bio, r);
 			return;
 		}
 		bio_put(outgoing_bio);
diff --git a/drivers/md/dm-pcache/dm_pcache.c b/drivers/md/dm-pcache/dm_pcache.c
index 4acfaab91170..b3795e88f364 100644
--- a/drivers/md/dm-pcache/dm_pcache.c
+++ b/drivers/md/dm-pcache/dm_pcache.c
@@ -74,8 +74,7 @@ static void end_req(struct kref *ref)
 		pcache_req_get(pcache_req);
 		defer_req(pcache_req);
 	} else {
-		bio_set_errno(bio, ret);
-		bio_endio(bio);
+		bio_endio_errno(bio, ret);
 
 		if (atomic_dec_and_test(&pcache->inflight_reqs))
 			wake_up(&pcache->inflight_wq);
diff --git a/drivers/md/dm-vdo/data-vio.c b/drivers/md/dm-vdo/data-vio.c
index eaa435dd8e60..47827ea61d91 100644
--- a/drivers/md/dm-vdo/data-vio.c
+++ b/drivers/md/dm-vdo/data-vio.c
@@ -287,8 +287,7 @@ static void acknowledge_data_vio(struct data_vio *data_vio)
 	if (data_vio->is_partial)
 		vdo_count_bios(&vdo->stats.bios_acknowledged_partial, bio);
 
-	bio_set_errno(bio, error);
-	bio_endio(bio);
+	bio_endio_errno(bio, error);
 }
 
 static void copy_to_bio(struct bio *bio, char *data_ptr)
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 62d5bc9f7b3e..7cc27819beb5 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -1665,8 +1665,7 @@ static int raid10_handle_discard(struct mddev *mddev, struct bio *bio)
 		split_size = stripe_size - remainder;
 		split = bio_split(bio, split_size, GFP_NOIO, &conf->bio_split);
 		if (IS_ERR(split)) {
-			bio_set_errno(bio, PTR_ERR(split));
-			bio_endio(bio);
+			bio_endio_errno(bio, PTR_ERR(split));
 			return 0;
 		}
 
@@ -1682,8 +1681,7 @@ static int raid10_handle_discard(struct mddev *mddev, struct bio *bio)
 		split_size = bio_sectors(bio) - remainder;
 		split = bio_split(bio, split_size, GFP_NOIO, &conf->bio_split);
 		if (IS_ERR(split)) {
-			bio_set_errno(bio, PTR_ERR(split));
-			bio_endio(bio);
+			bio_endio_errno(bio, PTR_ERR(split));
 			return 0;
 		}
 
diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index aa2a486522b5..ed763c1ec955 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -232,9 +232,7 @@ static void pmem_submit_bio(struct bio *bio)
 	if (bio->bi_opf & REQ_FUA)
 		ret = nvdimm_flush(nd_region, bio);
 
-	bio_set_errno(bio, ret);
-
-	bio_endio(bio);
+	bio_endio_errno(bio, ret);
 }
 
 /* see "strong" declaration in tools/testing/nvdimm/pmem-dax.c */
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
index ff802b6513af..bf45e8fd3aa1 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -1750,8 +1750,7 @@ void raid56_parity_write(struct bio *bio, struct btrfs_io_context *bioc)
 
 	rbio = alloc_rbio(fs_info, bioc);
 	if (IS_ERR(rbio)) {
-		bio_set_errno(bio, PTR_ERR(rbio));
-		bio_endio(bio);
+		bio_endio_errno(bio, PTR_ERR(rbio));
 		return;
 	}
 	rbio->operation = BTRFS_RBIO_WRITE;
@@ -2148,8 +2147,7 @@ void raid56_parity_recover(struct bio *bio, struct btrfs_io_context *bioc,
 
 	rbio = alloc_rbio(fs_info, bioc);
 	if (IS_ERR(rbio)) {
-		bio_set_errno(bio, PTR_ERR(rbio));
-		bio_endio(bio);
+		bio_endio_errno(bio, PTR_ERR(rbio));
 		return;
 	}
 
diff --git a/fs/iomap/ioend.c b/fs/iomap/ioend.c
index 67cd48180fb2..d9e9659b55b3 100644
--- a/fs/iomap/ioend.c
+++ b/fs/iomap/ioend.c
@@ -87,8 +87,7 @@ int iomap_ioend_writeback_submit(struct iomap_writepage_ctx *wpc, int error)
 		error = -EIO;
 
 	if (error) {
-		bio_set_errno(&ioend->io_bio, error);
-		bio_endio(&ioend->io_bio);
+		bio_endio_errno(&ioend->io_bio, error);
 		return error;
 	}
 
diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
index 61368223a069..4da13a15cb62 100644
--- a/fs/xfs/xfs_aops.c
+++ b/fs/xfs/xfs_aops.c
@@ -653,8 +653,7 @@ xfs_zoned_writeback_submit(
 
 	ioend->io_bio.bi_end_io = xfs_end_bio;
 	if (error) {
-		bio_set_errno(&ioend->io_bio, error);
-		bio_endio(&ioend->io_bio);
+		bio_endio_errno(&ioend->io_bio, error);
 		return error;
 	}
 	xfs_zone_alloc_and_submit(ioend, &XFS_ZWPC(wpc)->open_zone);
diff --git a/include/linux/bio.h b/include/linux/bio.h
index ad70a88cef09..06fb8ae018c4 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -403,6 +403,12 @@ static inline void bio_set_errno(struct bio *bio, int errno)
 		WRITE_ONCE(bio->bi_status, errno_to_blk_status(errno));
 }
 
+static inline void bio_endio_errno(struct bio *bio, int errno)
+{
+	bio_set_errno(bio, errno);
+	bio_endio(bio);
+}
+
 /*
  * Calculate number of bvec segments that should be allocated to fit data
  * pointed by @iter. If @iter is backed by bvec it's going to be reused
-- 
2.51.0


  parent reply	other threads:[~2025-12-08 12:11 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-08 12:10 [RFC 00/12] bio cleanups Andreas Gruenbacher
2025-12-08 12:10 ` [RFC 01/12] bio: rename bio_chain arguments Andreas Gruenbacher
2025-12-16  7:57   ` Christoph Hellwig
2025-12-08 12:10 ` [RFC 02/12] bio: use bio_io_error more often Andreas Gruenbacher
2025-12-16  7:57   ` Christoph Hellwig
2025-12-08 12:10 ` [RFC 03/12] bio: add bio_set_errno Andreas Gruenbacher
2025-12-16  7:58   ` Christoph Hellwig
2025-12-08 12:10 ` [RFC 04/12] bio: use bio_set_errno in more places Andreas Gruenbacher
2025-12-08 12:10 ` [RFC 05/12] bio: add bio_set_status Andreas Gruenbacher
2025-12-16  7:59   ` Christoph Hellwig
2025-12-08 12:10 ` [RFC 06/12] bio: don't check target->bi_status on error Andreas Gruenbacher
2025-12-16  7:59   ` Christoph Hellwig
2025-12-16  8:41     ` Andreas Gruenbacher
2025-12-16 10:44       ` Christoph Hellwig
2025-12-16 11:20         ` Andreas Gruenbacher
2025-12-18  8:47           ` Christoph Hellwig
2025-12-19 20:14             ` Andreas Gruenbacher
2025-12-08 12:10 ` [RFC 07/12] bio: use bio_set_status for BLK_STS_* status codes Andreas Gruenbacher
2025-12-08 12:10 ` [RFC 08/12] bio: use bio_set_status in some more places Andreas Gruenbacher
2025-12-08 12:10 ` [RFC 09/12] bio: switch to bio_set_status in submit_bio_noacct Andreas Gruenbacher
2025-12-08 12:10 ` [RFC 10/12] bio: never set bi_status to BLK_STS_OK during completion Andreas Gruenbacher
2025-12-08 12:10 ` Andreas Gruenbacher [this message]
2025-12-16  8:00   ` [RFC 11/12] bio: add bio_endio_errno Christoph Hellwig
2025-12-08 12:10 ` [RFC 12/12] bio: add bio_endio_status Andreas Gruenbacher
2025-12-16  8:01   ` Christoph Hellwig
2025-12-08 19:37 ` [RFC 00/12] bio cleanups David Sterba
2025-12-08 21:16   ` Andreas Gruenbacher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251208121020.1780402-12-agruenba@redhat.com \
    --to=agruenba@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=clm@fb.com \
    --cc=dm-devel@lists.linux.dev \
    --cc=dsterba@suse.com \
    --cc=hch@infradead.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®