[RFC 08/12] bio: use bio_set_status in some more places

Andreas Gruenbacher
2025-12-08T12:11:03Z

In these places, the status is known not to be BLK_STS_OK (0), so the
'status != BLK_STS_OK' check in bio_set_status() will be optimized out
and we end up with identical code.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
block/blk-crypto-fallback.c | 4 ++--
block/blk-mq.c | 2 +-
block/t10-pi.c | 2 +-
drivers/md/dm-cache-target.c | 3 ++-
drivers/md/dm-integrity.c | 2 +-
drivers/md/dm-zoned-target.c | 2 +-
drivers/nvdimm/pmem.c | 2 +-
fs/btrfs/bio.c | 4 ++--
8 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/block/blk-crypto-fallback.c b/block/blk-crypto-fallback.c
index 0e135ba26346..8a2631b1e7e1 100644
--- a/block/blk-crypto-fallback.c
+++ b/block/blk-crypto-fallback.c
@@ -292,7 +292,7 @@ static bool blk_crypto_fallback_encrypt_bio(struct bio **bio_ptr)
blk_st = blk_crypto_get_keyslot(blk_crypto_fallback_profile,
bc->bc_key, &slot);
if (blk_st != BLK_STS_OK) {
- src_bio->bi_status = blk_st;
+ bio_set_status(src_bio, blk_st);
goto out_put_enc_bio;
}

@@ -395,7 +395,7 @@ static void blk_crypto_fallback_decrypt_bio(struct work_struct *work)
blk_st = blk_crypto_get_keyslot(blk_crypto_fallback_profile,
bc->bc_key, &slot);
if (blk_st != BLK_STS_OK) {
- bio->bi_status = blk_st;
+ bio_set_status(bio, blk_st);
goto out_no_keyslot;
}

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 4e13d9f9ea96..503ca259429f 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -3205,7 +3205,7 @@ void blk_mq_submit_bio(struct bio *bio)

ret = blk_crypto_rq_get_keyslot(rq);
if (ret != BLK_STS_OK) {
- bio->bi_status = ret;
+ bio_set_status(bio, ret);
bio_endio(bio);
blk_mq_free_request(rq);
return;
diff --git a/block/t10-pi.c b/block/t10-pi.c
index 0c4ed9702146..968cf1fe45f0 100644
--- a/block/t10-pi.c
+++ b/block/t10-pi.c
@@ -440,7 +440,7 @@ void blk_integrity_verify_iter(struct bio *bio, struct bvec_iter *saved_iter)
kunmap_local(kaddr);

if (ret) {
- bio->bi_status = ret;
+ bio_set_status(bio, ret);
return;
}
}
diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c
index 82d748eeb9aa..d1dbd4ddaadb 100644
--- a/drivers/md/dm-cache-target.c
+++ b/drivers/md/dm-cache-target.c
@@ -1190,7 +1190,8 @@ static void mg_complete(struct dm_cache_migration *mg, bool success)
if (success)
force_set_dirty(cache, cblock);
else if (mg->k.input)
- mg->overwrite_bio->bi_status = mg->k.input;
+ bio_set_status(mg->overwrite_bio,
+ mg->k.input);
else
bio_set_status(mg->overwrite_bio,
BLK_STS_IOERR);
diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c
index d2288b9f2b0d..5220e15b6537 100644
--- a/drivers/md/dm-integrity.c
+++ b/drivers/md/dm-integrity.c
@@ -1617,7 +1617,7 @@ static void dec_in_flight(struct dm_integrity_io *dio)

bio = dm_bio_from_per_bio_data(dio, sizeof(struct dm_integrity_io));
if (unlikely(dio->bi_status) && !bio->bi_status)
- bio->bi_status = dio->bi_status;
+ bio_set_status(bio, dio->bi_status);
if (likely(!bio->bi_status) && unlikely(bio_sectors(bio) != dio->range.n_sectors)) {
dio->range.logical_sector += dio->range.n_sectors;
bio_advance(bio, dio->range.n_sectors << SECTOR_SHIFT);
diff --git a/drivers/md/dm-zoned-target.c b/drivers/md/dm-zoned-target.c
index 9da329078ea4..d0218a9f1c4f 100644
--- a/drivers/md/dm-zoned-target.c
+++ b/drivers/md/dm-zoned-target.c
@@ -78,7 +78,7 @@ static inline void dmz_bio_endio(struct bio *bio, blk_status_t status)
dm_per_bio_data(bio, sizeof(struct dmz_bioctx));

if (status != BLK_STS_OK && bio->bi_status == BLK_STS_OK)
- bio->bi_status = status;
+ bio_set_status(bio, status);
if (bioctx->dev && bio->bi_status != BLK_STS_OK)
bioctx->dev->flags |= DMZ_CHECK_BDEV;

diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index a2f8b5a85326..aa2a486522b5 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -222,7 +222,7 @@ static void pmem_submit_bio(struct bio *bio)
rc = pmem_do_read(pmem, bvec.bv_page, bvec.bv_offset,
iter.bi_sector, bvec.bv_len);
if (rc) {
- bio->bi_status = rc;
+ bio_set_status(bio, rc);
break;
}
}
diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c
index 00a7a13fab0c..a63d69509d05 100644
--- a/fs/btrfs/bio.c
+++ b/fs/btrfs/bio.c
@@ -174,7 +174,7 @@ static void btrfs_end_repair_bio(struct btrfs_bio *repair_bbio,
mirror = next_repair_mirror(fbio, mirror);
if (mirror == fbio->bbio->mirror_num) {
btrfs_debug(fs_info, "no mirror left");
- fbio->bbio->bio.bi_status = BLK_STS_IOERR;
+ bio_set_status(&fbio->bbio->bio, BLK_STS_IOERR);
goto done;
}

@@ -225,7 +225,7 @@ static struct btrfs_failed_bio *repair_one_sector(struct btrfs_bio *failed_bbio,
num_copies = btrfs_num_copies(fs_info, logical, sectorsize);
if (num_copies == 1) {
btrfs_debug(fs_info, "no copy to repair from");
- failed_bbio->bio.bi_status = BLK_STS_IOERR;
+ bio_set_status(&failed_bbio->bio, BLK_STS_IOERR);
return fbio;
}

--
2.51.0