struct page *page = resync_fetch_page(rp, idx);
                int len = min_t(int, size, PAGE_SIZE);
 
-               /*
-                * won't fail because the vec table is big
-                * enough to hold all these pages
-                */
-               bio_add_page(bio, page, len, 0);
+               if (WARN_ON(!bio_add_page(bio, page, len, 0))) {
+                       bio->bi_status = BLK_STS_RESOURCE;
+                       bio_endio(bio);
+                       return;
+               }
+
                size -= len;
        } while (idx++ < RESYNC_PAGES && size > 0);
 }
 
                for (bio= biolist ; bio ; bio=bio->bi_next) {
                        struct resync_pages *rp = get_resync_pages(bio);
                        page = resync_fetch_page(rp, page_idx);
-                       /*
-                        * won't fail because the vec table is big enough
-                        * to hold all these pages
-                        */
-                       bio_add_page(bio, page, len, 0);
+                       if (WARN_ON(!bio_add_page(bio, page, len, 0))) {
+                               bio->bi_status = BLK_STS_RESOURCE;
+                               bio_endio(bio);
+                               goto giveup;
+                       }
                }
                nr_sectors += len>>9;
                sector_nr += len>>9;
                if (len > PAGE_SIZE)
                        len = PAGE_SIZE;
                for (bio = blist; bio ; bio = bio->bi_next) {
-                       /*
-                        * won't fail because the vec table is big enough
-                        * to hold all these pages
-                        */
-                       bio_add_page(bio, page, len, 0);
+                       if (WARN_ON(!bio_add_page(bio, page, len, 0))) {
+                               bio->bi_status = BLK_STS_RESOURCE;
+                               bio_endio(bio);
+                               return sectors_done;
+                       }
                }
                sector_nr += len >> 9;
                nr_sectors += len >> 9;