OSDN Git Service

ANDROID: sdcardfs: Allocate temporary name buffer on the stack
authorSultan Alsawaf <sultan@kerneltoast.com>
Thu, 1 Aug 2019 01:34:31 +0000 (18:34 -0700)
committer0ranko0P <ranko0p@outlook.com>
Sat, 7 Dec 2019 10:22:19 +0000 (18:22 +0800)
Since this 4 KiB name buffer is only used temporarily, allocate it on
the stack to improve performance. This is confirmed to be safe according
to runtime stack usage measurements.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
fs/sdcardfs/lookup.c

index a671ae2..64d47e4 100644 (file)
@@ -281,37 +281,31 @@ static struct dentry *__sdcardfs_lookup(struct dentry *dentry,
        if (err == -ENOENT) {
                struct file *file;
                const struct cred *cred = current_cred();
+               char name_onstack[PATH_MAX] __aligned(sizeof(long));
 
                struct sdcardfs_name_data buffer = {
                        .ctx.actor = sdcardfs_name_match,
                        .to_find = name,
-                       .name = __getname(),
+                       .name = name_onstack,
                        .found = false,
                };
 
-               if (!buffer.name) {
-                       err = -ENOMEM;
-                       goto out;
-               }
                file = dentry_open(lower_parent_path, O_RDONLY, cred);
                if (IS_ERR(file)) {
                        err = PTR_ERR(file);
-                       goto put_name;
+               } else {
+                       err = iterate_dir(file, &buffer.ctx);
+                       fput(file);
+                       if (!err) {
+                               if (buffer.found)
+                                       err = vfs_path_lookup(lower_dir_dentry,
+                                                               lower_dir_mnt,
+                                                               buffer.name, 0,
+                                                               &lower_path);
+                               else
+                                       err = -ENOENT;
+                       }
                }
-               err = iterate_dir(file, &buffer.ctx);
-               fput(file);
-               if (err)
-                       goto put_name;
-
-               if (buffer.found)
-                       err = vfs_path_lookup(lower_dir_dentry,
-                                               lower_dir_mnt,
-                                               buffer.name, 0,
-                                               &lower_path);
-               else
-                       err = -ENOENT;
-put_name:
-               __putname(buffer.name);
        }
 
        /* no error: handle positive dentries */