Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

md: raid1: check if adding pages to resync bio fails

Check if adding pages to resync bio fails and if bail out.

As the comment above suggests this cannot happen, WARN if it actually
happens. Technically __bio_add_pages() would be sufficient here, but
asserting the pages actually get added to the bio is preferred.

This way we can mark bio_add_pages as __must_check.

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Acked-by: Song Liu <song@kernel.org>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Link: https://lore.kernel.org/r/33aea4c271220dc9bcab58c4b7bec478c1511142.1685532726.git.johannes.thumshirn@wdc.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Johannes Thumshirn and committed by
Jens Axboe
0c67dd64 f8312322

+16 -15
+6 -5
drivers/md/raid1-10.c
··· 101 101 struct page *page = resync_fetch_page(rp, idx); 102 102 int len = min_t(int, size, PAGE_SIZE); 103 103 104 - /* 105 - * won't fail because the vec table is big 106 - * enough to hold all these pages 107 - */ 108 - bio_add_page(bio, page, len, 0); 104 + if (WARN_ON(!bio_add_page(bio, page, len, 0))) { 105 + bio->bi_status = BLK_STS_RESOURCE; 106 + bio_endio(bio); 107 + return; 108 + } 109 + 109 110 size -= len; 110 111 } while (idx++ < RESYNC_PAGES && size > 0); 111 112 }
+10 -10
drivers/md/raid10.c
··· 3819 3819 for (bio= biolist ; bio ; bio=bio->bi_next) { 3820 3820 struct resync_pages *rp = get_resync_pages(bio); 3821 3821 page = resync_fetch_page(rp, page_idx); 3822 - /* 3823 - * won't fail because the vec table is big enough 3824 - * to hold all these pages 3825 - */ 3826 - bio_add_page(bio, page, len, 0); 3822 + if (WARN_ON(!bio_add_page(bio, page, len, 0))) { 3823 + bio->bi_status = BLK_STS_RESOURCE; 3824 + bio_endio(bio); 3825 + goto giveup; 3826 + } 3827 3827 } 3828 3828 nr_sectors += len>>9; 3829 3829 sector_nr += len>>9; ··· 4997 4997 if (len > PAGE_SIZE) 4998 4998 len = PAGE_SIZE; 4999 4999 for (bio = blist; bio ; bio = bio->bi_next) { 5000 - /* 5001 - * won't fail because the vec table is big enough 5002 - * to hold all these pages 5003 - */ 5004 - bio_add_page(bio, page, len, 0); 5000 + if (WARN_ON(!bio_add_page(bio, page, len, 0))) { 5001 + bio->bi_status = BLK_STS_RESOURCE; 5002 + bio_endio(bio); 5003 + return sectors_done; 5004 + } 5005 5005 } 5006 5006 sector_nr += len >> 9; 5007 5007 nr_sectors += len >> 9;