From: Johannes Thumshirn Date: Wed, 31 May 2023 11:50:36 +0000 (-0700) Subject: md: check for failure when adding pages in alloc_behind_master_bio X-Git-Tag: v6.6.7~2487^2~154 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b42473cdbab7661535516ae76e0a871d98b5cb97;p=platform%2Fkernel%2Flinux-starfive.git md: check for failure when adding pages in alloc_behind_master_bio alloc_behind_master_bio() can possibly add multiple pages to a bio, but it is not checking for the return value of bio_add_page() if adding really succeeded. Check if the page adding succeeded and if not bail out. Reviewed-by: Christoph Hellwig Acked-by: Song Liu Reviewed-by: Damien Le Moal Signed-off-by: Johannes Thumshirn Link: https://lore.kernel.org/r/827aa12d44ebf3f50b41b47f5cedc0f80179f2c1.1685532726.git.johannes.thumshirn@wdc.com [axboe: fold in s/free_page/put_page fix] Signed-off-by: Jens Axboe --- diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c index 68a9e2d..9cfb259 100644 --- a/drivers/md/raid1.c +++ b/drivers/md/raid1.c @@ -1147,7 +1147,10 @@ static void alloc_behind_master_bio(struct r1bio *r1_bio, if (unlikely(!page)) goto free_pages; - bio_add_page(behind_bio, page, len, 0); + if (!bio_add_page(behind_bio, page, len, 0)) { + put_page(page); + goto free_pages; + } size -= len; i++;