Re: [bug report] md: also clone new io if io accounting is disabled
From: Yu Kuai <hidden>
Date: 2024-02-01 01:35:49
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
.