]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ubifs: vmalloc(array_size()) -> vmalloc_array()
authorQianfeng Rong <rongqianfeng@vivo.com>
Sun, 17 Aug 2025 08:12:38 +0000 (16:12 +0800)
committerRichard Weinberger <richard@nod.at>
Fri, 28 Nov 2025 20:52:55 +0000 (21:52 +0100)
Remove array_size() calls and replace vmalloc() with vmalloc_array() in
ubifs_create_dflt_lpt()/lpt_init_rd()/lpt_init_wr(). vmalloc_array() is
optimized better, resulting in less instructions being used [1].

[1]: https://lore.kernel.org/lkml/abc66ec5-85a4-47e1-9759-2f60ab111971@vivo.com/

Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
fs/ubifs/lpt.c

index 441d0beca4cf3e82ffa813d6691211637def50af..dde0aa3287f4b5d2c580c15d7551230e0e747287 100644 (file)
@@ -628,8 +628,8 @@ int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
        pnode = kzalloc(sizeof(struct ubifs_pnode), GFP_KERNEL);
        nnode = kzalloc(sizeof(struct ubifs_nnode), GFP_KERNEL);
        buf = vmalloc(c->leb_size);
-       ltab = vmalloc(array_size(sizeof(struct ubifs_lpt_lprops),
-                                 c->lpt_lebs));
+       ltab = vmalloc_array(c->lpt_lebs,
+                            sizeof(struct ubifs_lpt_lprops));
        if (!pnode || !nnode || !buf || !ltab || !lsave) {
                err = -ENOMEM;
                goto out;
@@ -1777,8 +1777,8 @@ static int lpt_init_rd(struct ubifs_info *c)
 {
        int err, i;
 
-       c->ltab = vmalloc(array_size(sizeof(struct ubifs_lpt_lprops),
-                                    c->lpt_lebs));
+       c->ltab = vmalloc_array(c->lpt_lebs,
+                               sizeof(struct ubifs_lpt_lprops));
        if (!c->ltab)
                return -ENOMEM;
 
@@ -1846,8 +1846,8 @@ static int lpt_init_wr(struct ubifs_info *c)
 {
        int err, i;
 
-       c->ltab_cmt = vmalloc(array_size(sizeof(struct ubifs_lpt_lprops),
-                                        c->lpt_lebs));
+       c->ltab_cmt = vmalloc_array(c->lpt_lebs,
+                                   sizeof(struct ubifs_lpt_lprops));
        if (!c->ltab_cmt)
                return -ENOMEM;