[RFC v2 12/17] bio: do not check bio->bi_status before assigning to it (part 2)

Andreas Gruenbacher <[email protected]>
Newsgroups gmane.linux.raid,gmane.linux.block,gmane.comp.file-systems.btrfs,gmane.linux.kernel
Message-ID <[email protected]>
Don't check bio->bi_status before assigning to it.  These are the cases
that involve an errno instead of a block status.

See commit "do not check bio->bi_status before assigning to it" for a
rationale.

Created with Coccinelle using the following semantic patch and option
'--disable-iso unlikely':

@@
expression errno;
struct bio *bio;
@@
-if (unlikely(errno) && !bio->bi_status)
-	bio->bi_status = errno_to_blk_status(errno);
+if (unlikely(errno))
+	bio_set_status(bio, errno_to_blk_status(errno));

@@
expression errno;
struct bio *bio;
@@
-if (errno && !bio->bi_status)
-	bio->bi_status = errno_to_blk_status(errno);
+bio_set_status(bio, errno_to_blk_status(errno));

@@
expression errno;
struct bio bio;
@@
-if (errno < 0 && !bio.bi_status)
-	bio.bi_status = errno_to_blk_status(errno);
+if (errno < 0)
+	bio_set_status(&bio, errno_to_blk_status(errno));

Signed-off-by: Andreas Gruenbacher <[email protected]>
---
 drivers/md/dm-integrity.c | 4 ++--
 drivers/md/dm-thin.c      | 3 +--
 fs/erofs/fileio.c         | 4 ++--
 3 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c
index c5c7c167b45d..4a6e27c0d510 100644
--- a/drivers/md/dm-integrity.c
+++ b/drivers/md/dm-integrity.c
@@ -1580,8 +1580,8 @@ static void do_endio(struct dm_integrity_c *ic, struct bio *bio)
 	int r;
 
 	r = dm_integrity_failed(ic);
-	if (unlikely(r) && !bio->bi_status)
-		bio->bi_status = errno_to_blk_status(r);
+	if (unlikely(r))
+		bio_set_status(bio, errno_to_blk_status(r));
 	if (unlikely(ic->synchronous_mode) && bio_op(bio) == REQ_OP_WRITE) {
 		unsigned long flags;
 
diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c
index 00ede45a3d27..42261bbe4771 100644
--- a/drivers/md/dm-thin.c
+++ b/drivers/md/dm-thin.c
@@ -422,8 +422,7 @@ static void end_discard(struct discard_op *op, int r)
 	 * Even if r is set, there could be sub discards in flight that we
 	 * need to wait for.
 	 */
-	if (r && !op->parent_bio->bi_status)
-		op->parent_bio->bi_status = errno_to_blk_status(r);
+	bio_set_status(op->parent_bio, errno_to_blk_status(r));
 	bio_endio(op->parent_bio);
 }
 
diff --git a/fs/erofs/fileio.c b/fs/erofs/fileio.c
index b7b3432a9882..7ed32cb9e670 100644
--- a/fs/erofs/fileio.c
+++ b/fs/erofs/fileio.c
@@ -32,8 +32,8 @@ static void erofs_fileio_ki_complete(struct kiocb *iocb, long ret)
 		ret = 0;
 	}
 	if (rq->bio.bi_end_io) {
-		if (ret < 0 && !rq->bio.bi_status)
-			rq->bio.bi_status = errno_to_blk_status(ret);
+		if (ret < 0)
+			bio_set_status(&rq->bio, errno_to_blk_status(ret));
 		rq->bio.bi_end_io(&rq->bio);
 	} else {
 		bio_for_each_folio_all(fi, &rq->bio) {
-- 
2.52.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.