]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
f2fs: deallocate compressed pages when error happens
authorJaegeuk Kim <jaegeuk@kernel.org>
Mon, 30 Aug 2021 18:37:32 +0000 (11:37 -0700)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 5 Nov 2021 09:18:06 +0000 (10:18 +0100)
BugLink: https://bugs.launchpad.net/bugs/1947781
[ Upstream commit 827f02842e40ea2e00f401e8f4cb1bccf3b8cd86 ]

In f2fs_write_multi_pages(), f2fs_compress_pages() allocates pages for
compression work in cc->cpages[]. Then, f2fs_write_compressed_pages() initiates
bio submission. But, if there's any error before submitting the IOs like early
f2fs_cp_error(), previously it didn't free cpages by f2fs_compress_free_page().
Let's fix memory leak by putting that just before deallocating cc->cpages.

Fixes: 4c8ff7095bef ("f2fs: support data compression")
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
fs/f2fs/compress.c

index 3a503e5a8c11364edd57f965d3a333c77ee15e8e..c0bd474a44d93ce84ce9ecf1832236b29ff057db 100644 (file)
@@ -1330,12 +1330,6 @@ out_destroy_crypt:
 
        for (--i; i >= 0; i--)
                fscrypt_finalize_bounce_page(&cc->cpages[i]);
-       for (i = 0; i < cc->nr_cpages; i++) {
-               if (!cc->cpages[i])
-                       continue;
-               f2fs_compress_free_page(cc->cpages[i]);
-               cc->cpages[i] = NULL;
-       }
 out_put_cic:
        kmem_cache_free(cic_entry_slab, cic);
 out_put_dnode:
@@ -1346,6 +1340,12 @@ out_unlock_op:
        else
                f2fs_unlock_op(sbi);
 out_free:
+       for (i = 0; i < cc->nr_cpages; i++) {
+               if (!cc->cpages[i])
+                       continue;
+               f2fs_compress_free_page(cc->cpages[i]);
+               cc->cpages[i] = NULL;
+       }
        page_array_free(cc->inode, cc->cpages, cc->nr_cpages);
        cc->cpages = NULL;
        return -EAGAIN;