lkml.org 
[lkml]   [2013]   [Dec]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v3 2/6] locks: consolidate checks for compatible filp->f_mode values in setlk handlers
Date
Move this check into the posix_lock_setup_common handler instead of
duplicating this check in two places. This also fixes a minor wart in
the code where we continue referring to the struct flock after
converting it to struct file_lock.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
fs/locks.c | 46 ++++++++++++----------------------------------
1 file changed, 12 insertions(+), 34 deletions(-)

diff --git a/fs/locks.c b/fs/locks.c
index a5848ed..f96c455 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -354,6 +354,18 @@ flock_to_posix_lock_common(struct file_lock *fl, struct file *filp, short type)
fl->fl_ops = NULL;
fl->fl_lmops = NULL;

+ /* Ensure that fl->fl_filp has compatible f_mode */
+ switch (type) {
+ case F_RDLCK:
+ if (!(filp->f_mode & FMODE_READ))
+ return -EBADF;
+ break;
+ case F_WRLCK:
+ if (!(filp->f_mode & FMODE_WRITE))
+ return -EBADF;
+ break;
+ }
+
return assign_type(fl, type);
}

@@ -2060,23 +2072,6 @@ again:
file_lock->fl_flags |= FL_SLEEP;
}

- error = -EBADF;
- switch (flock.l_type) {
- case F_RDLCK:
- if (!(filp->f_mode & FMODE_READ))
- goto out;
- break;
- case F_WRLCK:
- if (!(filp->f_mode & FMODE_WRITE))
- goto out;
- break;
- case F_UNLCK:
- break;
- default:
- error = -EINVAL;
- goto out;
- }
-
error = do_lock_file_wait(filp, cmd, file_lock);

/*
@@ -2178,23 +2173,6 @@ again:
file_lock->fl_flags |= FL_SLEEP;
}

- error = -EBADF;
- switch (flock.l_type) {
- case F_RDLCK:
- if (!(filp->f_mode & FMODE_READ))
- goto out;
- break;
- case F_WRLCK:
- if (!(filp->f_mode & FMODE_WRITE))
- goto out;
- break;
- case F_UNLCK:
- break;
- default:
- error = -EINVAL;
- goto out;
- }
-
error = do_lock_file_wait(filp, cmd, file_lock);

/*
--
1.8.4.2


\
 
 \ /
  Last update: 2013-12-11 16:41    [W:0.154 / U:0.036 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site