fs/locks: Use allocation rather than the stack in fcntl_getlk()
authorBenjamin Coddington <bcodding@redhat.com>
Sun, 16 Jul 2017 14:28:21 +0000 (10:28 -0400)
committerJeff Layton <jlayton@redhat.com>
Sun, 16 Jul 2017 14:28:21 +0000 (10:28 -0400)
Struct file_lock is fairly large, so let's save some space on the stack by
using an allocation for struct file_lock in fcntl_getlk(), just as we do
for fcntl_setlk().

Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
Signed-off-by: Jeff Layton <jlayton@redhat.com>
fs/locks.c

index afefeb4ad6ded4229d7ba69517c512a59177b3a1..d7daa6c8932fc40a14fb2b5c296f9c7b977629cc 100644 (file)
@@ -2086,14 +2086,17 @@ static void posix_lock_to_flock64(struct flock64 *flock, struct file_lock *fl)
  */
 int fcntl_getlk(struct file *filp, unsigned int cmd, struct flock *flock)
 {
-       struct file_lock file_lock;
+       struct file_lock *fl;
        int error;
 
+       fl = locks_alloc_lock();
+       if (fl == NULL)
+               return -ENOMEM;
        error = -EINVAL;
        if (flock->l_type != F_RDLCK && flock->l_type != F_WRLCK)
                goto out;
 
-       error = flock_to_posix_lock(filp, &file_lock, flock);
+       error = flock_to_posix_lock(filp, fl, flock);
        if (error)
                goto out;
 
@@ -2103,23 +2106,22 @@ int fcntl_getlk(struct file *filp, unsigned int cmd, struct flock *flock)
                        goto out;
 
                cmd = F_GETLK;
-               file_lock.fl_flags |= FL_OFDLCK;
-               file_lock.fl_owner = filp;
+               fl->fl_flags |= FL_OFDLCK;
+               fl->fl_owner = filp;
        }
 
-       error = vfs_test_lock(filp, &file_lock);
+       error = vfs_test_lock(filp, fl);
        if (error)
                goto out;
  
-       flock->l_type = file_lock.fl_type;
-       if (file_lock.fl_type != F_UNLCK) {
-               error = posix_lock_to_flock(flock, &file_lock);
+       flock->l_type = fl->fl_type;
+       if (fl->fl_type != F_UNLCK) {
+               error = posix_lock_to_flock(flock, fl);
                if (error)
-                       goto rel_priv;
+                       goto out;
        }
-rel_priv:
-       locks_release_private(&file_lock);
 out:
+       locks_free_lock(fl);
        return error;
 }
 
@@ -2298,14 +2300,18 @@ out:
  */
 int fcntl_getlk64(struct file *filp, unsigned int cmd, struct flock64 *flock)
 {
-       struct file_lock file_lock;
+       struct file_lock *fl;
        int error;
 
+       fl = locks_alloc_lock();
+       if (fl == NULL)
+               return -ENOMEM;
+
        error = -EINVAL;
        if (flock->l_type != F_RDLCK && flock->l_type != F_WRLCK)
                goto out;
 
-       error = flock64_to_posix_lock(filp, &file_lock, flock);
+       error = flock64_to_posix_lock(filp, fl, flock);
        if (error)
                goto out;
 
@@ -2315,20 +2321,20 @@ int fcntl_getlk64(struct file *filp, unsigned int cmd, struct flock64 *flock)
                        goto out;
 
                cmd = F_GETLK64;
-               file_lock.fl_flags |= FL_OFDLCK;
-               file_lock.fl_owner = filp;
+               fl->fl_flags |= FL_OFDLCK;
+               fl->fl_owner = filp;
        }
 
-       error = vfs_test_lock(filp, &file_lock);
+       error = vfs_test_lock(filp, fl);
        if (error)
                goto out;
 
-       flock->l_type = file_lock.fl_type;
-       if (file_lock.fl_type != F_UNLCK)
-               posix_lock_to_flock64(flock, &file_lock);
+       flock->l_type = fl->fl_type;
+       if (fl->fl_type != F_UNLCK)
+               posix_lock_to_flock64(flock, fl);
 
-       locks_release_private(&file_lock);
 out:
+       locks_free_lock(fl);
        return error;
 }