On Wed, 30 Apr 2025, Christoph Hellwig wrote:
> Convert the __bio_add_page(..., virt_to_page(), ...) pattern to the
> bio_add_virt_nofail helper implementing it, and do the same for the
> similar pattern using bio_add_page for adding the first segment after
> a bio allocation as that can't fail either.
>
> Signed-off-by: Christoph Hellwig <h...@lst.de>
> Reviewed-by: Damien Le Moal <dlem...@kernel.org>
> Reviewed-by: Johannes Thumshirn <johannes.thumsh...@wdc.com>
Acked-by: Mikulas Patocka <mpato...@redhat.com>
> ---
> drivers/md/dm-integrity.c | 16 ++++++----------
> 1 file changed, 6 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c
> index 2a283feb3319..9dca9dbabfaa 100644
> --- a/drivers/md/dm-integrity.c
> +++ b/drivers/md/dm-integrity.c
> @@ -2557,14 +2557,8 @@ static void dm_integrity_inline_recheck(struct
> work_struct *w)
> char *mem;
>
> outgoing_bio = bio_alloc_bioset(ic->dev->bdev, 1, REQ_OP_READ,
> GFP_NOIO, &ic->recheck_bios);
> -
> - r = bio_add_page(outgoing_bio, virt_to_page(outgoing_data),
> ic->sectors_per_block << SECTOR_SHIFT, 0);
> - if (unlikely(r != (ic->sectors_per_block << SECTOR_SHIFT))) {
> - bio_put(outgoing_bio);
> - bio->bi_status = BLK_STS_RESOURCE;
> - bio_endio(bio);
> - return;
> - }
> + bio_add_virt_nofail(outgoing_bio, outgoing_data,
> + ic->sectors_per_block << SECTOR_SHIFT);
>
> bip = bio_integrity_alloc(outgoing_bio, GFP_NOIO, 1);
> if (IS_ERR(bip)) {
> @@ -3211,7 +3205,8 @@ static void integrity_recalc_inline(struct work_struct
> *w)
>
> bio = bio_alloc_bioset(ic->dev->bdev, 1, REQ_OP_READ, GFP_NOIO,
> &ic->recalc_bios);
> bio->bi_iter.bi_sector = ic->start + SB_SECTORS + range.logical_sector;
> - __bio_add_page(bio, virt_to_page(recalc_buffer), range.n_sectors <<
> SECTOR_SHIFT, offset_in_page(recalc_buffer));
> + bio_add_virt_nofail(bio, recalc_buffer,
> + range.n_sectors << SECTOR_SHIFT);
> r = submit_bio_wait(bio);
> bio_put(bio);
> if (unlikely(r)) {
> @@ -3228,7 +3223,8 @@ static void integrity_recalc_inline(struct work_struct
> *w)
>
> bio = bio_alloc_bioset(ic->dev->bdev, 1, REQ_OP_WRITE, GFP_NOIO,
> &ic->recalc_bios);
> bio->bi_iter.bi_sector = ic->start + SB_SECTORS + range.logical_sector;
> - __bio_add_page(bio, virt_to_page(recalc_buffer), range.n_sectors <<
> SECTOR_SHIFT, offset_in_page(recalc_buffer));
> + bio_add_virt_nofail(bio, recalc_buffer,
> + range.n_sectors << SECTOR_SHIFT);
>
> bip = bio_integrity_alloc(bio, GFP_NOIO, 1);
> if (unlikely(IS_ERR(bip))) {
> --
> 2.47.2
>
>