]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mm: shmem: add missing shmem_unacct_size() in __shmem_file_setup()
authorKemeng Shi <shikemeng@huaweicloud.com>
Fri, 16 May 2025 17:09:36 +0000 (01:09 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Sun, 1 Jun 2025 05:46:10 +0000 (22:46 -0700)
We will miss shmem_unacct_size() when is_idmapped_mnt() returns a failure.
Move is_idmapped_mnt() before shmem_acct_size() to fix the issue.

Link: https://lkml.kernel.org/r/20250516170939.965736-3-shikemeng@huaweicloud.com
Fixes: 7a80e5b8c6fa ("shmem: support idmapped mounts for tmpfs")
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Kairui Song <kasong@tencent.com>
Cc: kernel test robot <oliver.sang@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/shmem.c

index 980fa15f393e753e0b77d1a7b05c8ab801bdd50d..495e661eb8bb4ffbcea19d6c1d222e8fcc7d055b 100644 (file)
@@ -5812,12 +5812,12 @@ static struct file *__shmem_file_setup(struct vfsmount *mnt, const char *name,
        if (size < 0 || size > MAX_LFS_FILESIZE)
                return ERR_PTR(-EINVAL);
 
-       if (shmem_acct_size(flags, size))
-               return ERR_PTR(-ENOMEM);
-
        if (is_idmapped_mnt(mnt))
                return ERR_PTR(-EINVAL);
 
+       if (shmem_acct_size(flags, size))
+               return ERR_PTR(-ENOMEM);
+
        inode = shmem_get_inode(&nop_mnt_idmap, mnt->mnt_sb, NULL,
                                S_IFREG | S_IRWXUGO, 0, flags);
        if (IS_ERR(inode)) {