]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
staging: erofs: refine erofs_allocpage()
authorGao Xiang <gaoxiang25@huawei.com>
Wed, 31 Jul 2019 15:57:43 +0000 (23:57 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 2 Aug 2019 11:52:06 +0000 (13:52 +0200)
remove duplicated code in decompressor by introducing
failable erofs_allocpage().

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Link: https://lore.kernel.org/r/20190731155752.210602-14-gaoxiang25@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/erofs/decompressor.c
drivers/staging/erofs/internal.h
drivers/staging/erofs/utils.c
drivers/staging/erofs/zdata.c

index ee5762351f80996ae869c5384e646c33d6630cc5..744c43a456e928fe5eeb16b8af4e7695c77ed0bd 100644 (file)
@@ -74,15 +74,9 @@ static int lz4_prepare_destpages(struct z_erofs_decompress_req *rq,
                        victim = availables[--top];
                        get_page(victim);
                } else {
-                       if (!list_empty(pagepool)) {
-                               victim = lru_to_page(pagepool);
-                               list_del(&victim->lru);
-                               DBG_BUGON(page_ref_count(victim) != 1);
-                       } else {
-                               victim = alloc_pages(GFP_KERNEL, 0);
-                               if (!victim)
-                                       return -ENOMEM;
-                       }
+                       victim = erofs_allocpage(pagepool, GFP_KERNEL, false);
+                       if (unlikely(!victim))
+                               return -ENOMEM;
                        victim->mapping = Z_EROFS_MAPPING_STAGING;
                }
                rq->out[i] = victim;
index 5e1ef2b5a458725d5393ecd455d54efb5a3c2320..a631acd0dc627123d0435b654c4f366fba845909 100644 (file)
@@ -516,7 +516,7 @@ int erofs_namei(struct inode *dir, struct qstr *name,
 extern const struct file_operations erofs_dir_fops;
 
 /* utils.c / zdata.c */
-struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp);
+struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp, bool nofail);
 
 #if (EROFS_PCPUBUF_NR_PAGES > 0)
 void *erofs_get_pcpubuf(unsigned int pagenr);
index 0e86e44d60d07aa179b570cf4811496b929a24cf..260ea2970b4b462ac3b4262f2cc6252b51d7d904 100644 (file)
@@ -9,15 +9,16 @@
 #include "internal.h"
 #include <linux/pagevec.h>
 
-struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp)
+struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp, bool nofail)
 {
        struct page *page;
 
        if (!list_empty(pool)) {
                page = lru_to_page(pool);
+               DBG_BUGON(page_ref_count(page) != 1);
                list_del(&page->lru);
        } else {
-               page = alloc_pages(gfp | __GFP_NOFAIL, 0);
+               page = alloc_pages(gfp | (nofail ? __GFP_NOFAIL : 0), 0);
        }
        return page;
 }
index bc478eebf509a5987bcc07f4999ff15c9b0bf27f..3078510e350dea1622a2455ae91651420a237f8d 100644 (file)
@@ -634,10 +634,7 @@ z_erofs_vle_work_iter_end(struct z_erofs_vle_work_builder *builder)
 static inline struct page *__stagingpage_alloc(struct list_head *pagepool,
                                               gfp_t gfp)
 {
-       struct page *page = erofs_allocpage(pagepool, gfp);
-
-       if (unlikely(!page))
-               return NULL;
+       struct page *page = erofs_allocpage(pagepool, gfp, true);
 
        page->mapping = Z_EROFS_MAPPING_STAGING;
        return page;