diff mbox series

[v2] block: Fix uninitialized symbol 'bio' in blk_rq_prep_clone

Message ID 20241007195836.52576-1-surajsonawane0215@gmail.com (mailing list archive)
State New, archived
Headers show
Series [v2] block: Fix uninitialized symbol 'bio' in blk_rq_prep_clone | expand

Commit Message

Suraj Sonawane Oct. 7, 2024, 7:58 p.m. UTC
Fix the uninitialized symbol 'bio' in the function blk_rq_prep_clone
to resolve the following error:
block/blk-mq.c:3199 blk_rq_prep_clone() error: uninitialized symbol 'bio'.

Signed-off-by: SurajSonawane2415 <surajsonawane0215@gmail.com>
---
V1 - https://lore.kernel.org/lkml/20241004100842.9052-1-surajsonawane0215@gmail.com/
V2 - Move bio_put(bio) into the bio_ctr error handling block, 
ensuring memory cleanup occurs only when the bio_ctr fail.

 block/blk-mq.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Christoph Hellwig Oct. 8, 2024, 4:23 a.m. UTC | #1
On Tue, Oct 08, 2024 at 01:28:36AM +0530, SurajSonawane2415 wrote:
> Fix the uninitialized symbol 'bio' in the function blk_rq_prep_clone
> to resolve the following error:
> block/blk-mq.c:3199 blk_rq_prep_clone() error: uninitialized symbol 'bio'.

Jens' comment baout the commit logs apply here as well.  Otherwise
this looks much better than the first version, but please also move
the bio variable into the loop scope while you're at it, which also
removes the need to clear it to NULL at the end of the loop.
diff mbox series

Patch

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 4b2c8e940..32f99116c 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -3167,8 +3167,10 @@  int blk_rq_prep_clone(struct request *rq, struct request *rq_src,
 		if (!bio)
 			goto free_and_out;
 
-		if (bio_ctr && bio_ctr(bio, bio_src, data))
+		if (bio_ctr && bio_ctr(bio, bio_src, data)) {
+			bio_put(bio);
 			goto free_and_out;
+		}
 
 		if (rq->bio) {
 			rq->biotail->bi_next = bio;
@@ -3196,8 +3198,6 @@  int blk_rq_prep_clone(struct request *rq, struct request *rq_src,
 	return 0;
 
 free_and_out:
-	if (bio)
-		bio_put(bio);
 	blk_rq_unprep_clone(rq);
 
 	return -ENOMEM;