CIFS: Fix lock consistensy bug in cifs_setlk
authorPavel Shilovsky <piastry@etersoft.ru>
Thu, 22 Nov 2012 14:56:39 +0000 (18:56 +0400)
committerSteve French <smfrench@gmail.com>
Wed, 5 Dec 2012 19:27:29 +0000 (13:27 -0600)
If we netogiate mandatory locking style, have a read lock and try
to set a write lock we end up with a write lock in vfs cache and
no lock in cifs lock cache - that's wrong. Fix it by returning
from cifs_setlk immediately if a error occurs during setting a lock.

Reviewed-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: Pavel Shilovsky <piastry@etersoft.ru>
Signed-off-by: Steve French <smfrench@gmail.com>
fs/cifs/file.c

index 67fe0b811f2303098e19233b8fb7846cdfd32f15..bceffa8c034eb55dba9d0be7ec53086ea5c2a2a9 100644 (file)
@@ -1443,16 +1443,18 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
                        return -ENOMEM;
 
                rc = cifs_lock_add_if(cfile, lock, wait_flag);
-               if (rc < 0)
+               if (rc < 0) {
                        kfree(lock);
-               if (rc <= 0)
+                       return rc;
+               }
+               if (!rc)
                        goto out;
 
                rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length,
                                            type, 1, 0, wait_flag);
                if (rc) {
                        kfree(lock);
-                       goto out;
+                       return rc;
                }
 
                cifs_lock_add(cfile, lock);