[PATCH v3 3/6] block: Handle bio_split() errors in bio_submit_split()

John Garry posted 6 patches 3 weeks, 3 days ago
There is a newer version of this series
[PATCH v3 3/6] block: Handle bio_split() errors in bio_submit_split()
Posted by John Garry 3 weeks, 3 days ago
bio_split() may error, so check this.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: John Garry <john.g.garry@oracle.com>
---
 block/blk-merge.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/block/blk-merge.c b/block/blk-merge.c
index a16abf7b65dc..4d7b6bc8814c 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -107,11 +107,8 @@ static unsigned int bio_allowed_max_sectors(const struct queue_limits *lim)
 
 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);
-		return NULL;
-	}
+	if (unlikely(split_sectors < 0))
+		goto error;
 
 
 	if (unlikely((bio_op(bio) == REQ_OP_DISCARD)))
@@ -123,6 +120,10 @@ static struct bio *bio_submit_split(struct bio *bio, int split_sectors)
 
 		split = bio_split(bio, split_sectors, GFP_NOIO,
 				&bio->bi_bdev->bd_disk->bio_split);
+		if (IS_ERR(split)) {
+			split_sectors = PTR_ERR(split);
+			goto error;
+		}
 		split->bi_opf |= REQ_NOMERGE;
 		blkcg_bio_issue_init(split);
 		bio_chain(split, bio);
@@ -133,6 +134,10 @@ static struct bio *bio_submit_split(struct bio *bio, int split_sectors)
 	}
 
 	return bio;
+error:
+	bio->bi_status = errno_to_blk_status(split_sectors);
+	bio_endio(bio);
+	return NULL;
 }
 
 struct bio *bio_split_discard(struct bio *bio, const struct queue_limits *lim,
-- 
2.31.1
Re: [PATCH v3 3/6] block: Handle bio_split() errors in bio_submit_split()
Posted by Hannes Reinecke 2 weeks, 5 days ago
On 10/31/24 10:59, John Garry wrote:
> bio_split() may error, so check this.
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> Signed-off-by: John Garry <john.g.garry@oracle.com>
> ---
>   block/blk-merge.c | 15 ++++++++++-----
>   1 file changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/block/blk-merge.c b/block/blk-merge.c
> index a16abf7b65dc..4d7b6bc8814c 100644
> --- a/block/blk-merge.c
> +++ b/block/blk-merge.c
> @@ -107,11 +107,8 @@ static unsigned int bio_allowed_max_sectors(const struct queue_limits *lim)
>   
>   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);
> -		return NULL;
> -	}
> +	if (unlikely(split_sectors < 0))
> +		goto error;
>   
>   
>   	if (unlikely((bio_op(bio) == REQ_OP_DISCARD)))
> @@ -123,6 +120,10 @@ static struct bio *bio_submit_split(struct bio *bio, int split_sectors)
>   
>   		split = bio_split(bio, split_sectors, GFP_NOIO,
>   				&bio->bi_bdev->bd_disk->bio_split);
> +		if (IS_ERR(split)) {
> +			split_sectors = PTR_ERR(split);
> +			goto error;
> +		}
>   		split->bi_opf |= REQ_NOMERGE;
>   		blkcg_bio_issue_init(split);
>   		bio_chain(split, bio);
> @@ -133,6 +134,10 @@ static struct bio *bio_submit_split(struct bio *bio, int split_sectors)
>   	}
>   
>   	return bio;
> +error:
> +	bio->bi_status = errno_to_blk_status(split_sectors);
> +	bio_endio(bio);
> +	return NULL;
>   }
>   
>   struct bio *bio_split_discard(struct bio *bio, const struct queue_limits *lim,

Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                  Kernel Storage Architect
hare@suse.de                                +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich