From: Suraj Sonawane <surajsonawane0215@gmail.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
hch@infradead.org
Subject: Re: [PATCH v4] block: Fix uninitialized symbol 'bio' in blk_rq_prep_clone
Date: Sat, 16 Nov 2024 17:02:57 +0530 [thread overview]
Message-ID: <f90b485d-a78e-4bcf-bb77-94f68ad575cf@gmail.com> (raw)
In-Reply-To: <f6a50924-e3f8-4175-a97e-4e77ed24b72b@kernel.dk>
On 15/11/24 21:40, Jens Axboe wrote:
> On 11/15/24 9:07 AM, Suraj Sonawane wrote:
>> On 08/10/24 23:22, 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'.
>>>
>>> Signed-off-by: SurajSonawane2415 <surajsonawane0215@gmail.com>
>>> ---
>>> V1 - Initialize 'bio' to NULL.
>>> V2 - Move bio_put(bio) into the bio_ctr error handling block,
>>> ensuring memory cleanup occurs only when the bio_ctr fail.
>>> V3 - Moved the bio declaration into the loop scope, eliminating
>>> the need to set it to NULL at the end of the loop.
>>> V4 - Adjusted position of arguments of bio_alloc_clone.
>>>
>>> block/blk-mq.c | 13 ++++++-------
>>> 1 file changed, 6 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/block/blk-mq.c b/block/blk-mq.c
>>> index 4b2c8e940..89c9a6c4d 100644
>>> --- a/block/blk-mq.c
>>> +++ b/block/blk-mq.c
>>> @@ -3156,19 +3156,21 @@ int blk_rq_prep_clone(struct request *rq, struct request *rq_src,
>>> int (*bio_ctr)(struct bio *, struct bio *, void *),
>>> void *data)
>>> {
>>> - struct bio *bio, *bio_src;
>>> + struct bio *bio_src;
>>> if (!bs)
>>> bs = &fs_bio_set;
>>> __rq_for_each_bio(bio_src, rq_src) {
>>> - bio = bio_alloc_clone(rq->q->disk->part0, bio_src, gfp_mask,
>>> - bs);
>>> + struct bio *bio = bio_alloc_clone(rq->q->disk->part0, bio_src,
>>> + gfp_mask, bs);
>>> 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;
>>> @@ -3176,7 +3178,6 @@ int blk_rq_prep_clone(struct request *rq, struct request *rq_src,
>>> } else {
>>> rq->bio = rq->biotail = bio;
>>> }
>>> - bio = NULL;
>>> }
>>> /* Copy attributes of the original request to the clone request. */
>>> @@ -3196,8 +3197,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;
>>
>> Hello Jens!
>>
>> I wanted to follow up on this patch I submitted. I have done all the
>> suggested changes till v4. I was wondering if you had a chance to
>> review it and if there are any comments or feedback.
>
> Sorry missed this one. Is this a legit case of it being used
> uninitialized, or is it just cleaning up the code so that smatch is
> happy? The commit is woefully non-descriptive, unfortunately. So perhaps
> resend this one and improve the commit message.
>
Apologies for any confusion earlier, and thank you for your attention to
this. After further analysis, I realize that this change isn't
necessary, as bio is already set to NULL by bio_alloc_clone on failure,
preventing any real case of uninitialized use. My initial patch aimed to
clean up the code and satisfy smatch, ensuring better readability and
error handling.
I appreciate your feedback and the opportunity to learn from this. I now
understand that no change is needed here. Thank you for your guidance
and understanding.
Best regards,
Suraj Sonawane
next prev parent reply other threads:[~2024-11-16 11:33 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-04 10:08 [PATCH] " SurajSonawane2415
2024-10-04 12:22 ` Christoph Hellwig
2024-10-04 14:10 ` Explanation on Uninitialized Variable bio " SurajSonawane2415
2024-10-04 14:15 ` Hannes Reinecke
2024-10-04 14:33 ` John Garry
2024-10-04 14:40 ` Keith Busch
2024-10-06 6:58 ` Suraj Sonawane
2024-10-06 7:11 ` Suraj Sonawane
2024-10-04 14:39 ` Keith Busch
2024-10-06 7:03 ` Suraj Sonawane
2024-10-07 5:50 ` Christoph Hellwig
2024-10-07 19:58 ` [PATCH v2] block: Fix uninitialized symbol 'bio' " SurajSonawane2415
2024-10-08 4:23 ` Christoph Hellwig
2024-10-08 12:04 ` [PATCH v3] " SurajSonawane2415
2024-10-08 12:06 ` Christoph Hellwig
2024-10-08 14:52 ` Keith Busch
2024-10-08 15:35 ` Keith Busch
2024-10-08 17:52 ` [PATCH v4] " SurajSonawane2415
2024-10-09 7:30 ` Christoph Hellwig
2024-10-09 11:00 ` Suraj Sonawane
2024-10-09 11:37 ` Christoph Hellwig
2024-10-09 11:40 ` Suraj Sonawane
2024-11-15 16:07 ` Suraj Sonawane
2024-11-15 16:10 ` Jens Axboe
2024-11-16 11:32 ` Suraj Sonawane [this message]
2024-11-18 6:28 ` Christoph Hellwig
2024-11-19 16:53 ` Suraj Sonawane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f90b485d-a78e-4bcf-bb77-94f68ad575cf@gmail.com \
--to=surajsonawane0215@gmail.com \
--cc=axboe@kernel.dk \
--cc=hch@infradead.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®