Linux-Raid Archives mirror
 help / color / mirror / Atom feed
From: Yu Kuai <yukuai1@huaweicloud.com>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: linux-raid@vger.kernel.org, "yukuai (C)" <yukuai3@huawei.com>
Subject: Re: [bug report] md: also clone new io if io accounting is disabled
Date: Thu, 1 Feb 2024 09:35:38 +0800	[thread overview]
Message-ID: <0efa13dc-f877-30b9-1f3f-e7ec500ad7f5@huaweicloud.com> (raw)
In-Reply-To: <2cf10b2e-3703-414b-99b6-457dd4b14177@moroto.mountain>

Hi,

在 2024/01/31 19:17, Dan Carpenter 写道:
> Hello Yu Kuai,
> 
> The patch c687297b8845: "md: also clone new io if io accounting is
> disabled" from Jun 22, 2023 (linux-next), leads to the following
> Smatch static checker warning:
> 
> 	drivers/md/md.c:8718 md_clone_bio()
> 	potential NULL container_of 'clone'
> 
> drivers/md/md.c
>      8711 static void md_clone_bio(struct mddev *mddev, struct bio **bio)
>      8712 {
>      8713         struct block_device *bdev = (*bio)->bi_bdev;
>      8714         struct md_io_clone *md_io_clone;
>      8715         struct bio *clone =
>      8716                 bio_alloc_clone(bdev, *bio, GFP_NOIO, &mddev->io_clone_set);

If you ever look at the comment, you'll know that this will never fail.

  * If %__GFP_DIRECT_RECLAIM is set then bio_alloc will always be able to
  * allocate a bio.  This is due to the mempool guarantees.

Thanks,
Kuai

> 
> Generally in the kernel, you have to check for allocation failure.  In
> this case if the allocation fails it leads to a NULL dereference.
> 
>      8717
> --> 8718         md_io_clone = container_of(clone, struct md_io_clone, bio_clone);
>      8719         md_io_clone->orig_bio = *bio;
>      8720         md_io_clone->mddev = mddev;
>      8721         if (blk_queue_io_stat(bdev->bd_disk->queue))
>      8722                 md_io_clone->start_time = bio_start_io_acct(*bio);
>      8723
>      8724         clone->bi_end_io = md_end_clone_io;
>      8725         clone->bi_private = md_io_clone;
>      8726         *bio = clone;
>      8727 }
> 
> regards,
> dan carpenter
> .
> 


      reply	other threads:[~2024-02-01  1:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-31 11:17 [bug report] md: also clone new io if io accounting is disabled Dan Carpenter
2024-02-01  1:35 ` Yu Kuai [this message]

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=0efa13dc-f877-30b9-1f3f-e7ec500ad7f5@huaweicloud.com \
    --to=yukuai1@huaweicloud.com \
    --cc=dan.carpenter@linaro.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=yukuai3@huawei.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).