#include "super-io.h"
 
 #include <linux/lz4.h>
-#include <linux/sched/mm.h>
 #include <linux/zlib.h>
 #include <linux/zstd.h>
 
        struct bbuf ret;
        struct bio_vec bv;
        struct bvec_iter iter;
-       unsigned nr_pages = 0, flags;
+       unsigned nr_pages = 0;
        struct page *stack_pages[16];
        struct page **pages = NULL;
        void *data;
        __bio_for_each_segment(bv, bio, iter, start)
                pages[nr_pages++] = bv.bv_page;
 
-       flags = memalloc_nofs_save();
        data = vmap(pages, nr_pages, VM_MAP, PAGE_KERNEL);
-       memalloc_nofs_restore(flags);
-
        if (pages != stack_pages)
                kfree(pages);
 
 
 
 #include <linux/blkdev.h>
 #include <linux/random.h>
+#include <linux/sched/mm.h>
 
 #ifndef CONFIG_BCACHEFS_NO_LATENCY_ACCT
 
        struct write_point *wp;
        struct bio *bio;
        bool skip_put = true;
+       unsigned nofs_flags;
        int ret;
+
+       nofs_flags = memalloc_nofs_save();
 again:
        memset(&op->failed, 0, sizeof(op->failed));
 
 
        if (!skip_put)
                continue_at(cl, bch2_write_index, index_update_wq(op));
+out:
+       memalloc_nofs_restore(nofs_flags);
        return;
 err:
        op->error = ret;
        op->flags |= BCH_WRITE_DONE;
 
        continue_at(cl, bch2_write_index, index_update_wq(op));
-       return;
+       goto out;
 flush_io:
        /*
         * If the write can't all be submitted at once, we generally want to
         */
        if (current->flags & PF_WQ_WORKER) {
                continue_at(cl, bch2_write_index, index_update_wq(op));
-               return;
+               goto out;
        }
 
        closure_sync(cl);
                if (op->error) {
                        op->flags |= BCH_WRITE_DONE;
                        continue_at_nobarrier(cl, bch2_write_done, NULL);
-                       return;
+                       goto out;
                }
        }