Commit 51ee4b84 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Linus Torvalds

locks: let the caller free file_lock on ->setlease failure

The caller allocated it, the caller should free it.

The only issue so far is that we could change the flp pointer even on an
error return if the fl_change callback failed.  But we can simply move
the flp assignment after the fl_change invocation, as the callers don't
care about the flp return value if the setlease call failed.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 96f93593
...@@ -625,11 +625,8 @@ static int cifs_setlease(struct file *file, long arg, struct file_lock **lease) ...@@ -625,11 +625,8 @@ static int cifs_setlease(struct file *file, long arg, struct file_lock **lease)
knows that the file won't be changed on the server knows that the file won't be changed on the server
by anyone else */ by anyone else */
return generic_setlease(file, arg, lease); return generic_setlease(file, arg, lease);
else { else
if (arg != F_UNLCK)
locks_free_lock(*lease);
return -EAGAIN; return -EAGAIN;
}
} }
struct file_system_type cifs_fs_type = { struct file_system_type cifs_fs_type = {
......
...@@ -629,8 +629,6 @@ static ssize_t gfs2_file_aio_write(struct kiocb *iocb, const struct iovec *iov, ...@@ -629,8 +629,6 @@ static ssize_t gfs2_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
static int gfs2_setlease(struct file *file, long arg, struct file_lock **fl) static int gfs2_setlease(struct file *file, long arg, struct file_lock **fl)
{ {
if (arg != F_UNLCK)
locks_free_lock(*fl);
return -EINVAL; return -EINVAL;
} }
......
...@@ -1428,8 +1428,9 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp) ...@@ -1428,8 +1428,9 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
goto out; goto out;
if (my_before != NULL) { if (my_before != NULL) {
*flp = *my_before;
error = lease->fl_lmops->fl_change(my_before, arg); error = lease->fl_lmops->fl_change(my_before, arg);
if (!error)
*flp = *my_before;
goto out; goto out;
} }
...@@ -1444,8 +1445,6 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp) ...@@ -1444,8 +1445,6 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
return 0; return 0;
out: out:
if (arg != F_UNLCK)
locks_free_lock(lease);
return error; return error;
} }
EXPORT_SYMBOL(generic_setlease); EXPORT_SYMBOL(generic_setlease);
...@@ -1524,8 +1523,11 @@ static int do_fcntl_add_lease(unsigned int fd, struct file *filp, long arg) ...@@ -1524,8 +1523,11 @@ static int do_fcntl_add_lease(unsigned int fd, struct file *filp, long arg)
} }
lock_flocks(); lock_flocks();
error = __vfs_setlease(filp, arg, &fl); error = __vfs_setlease(filp, arg, &fl);
if (error) if (error) {
goto out_unlock; unlock_flocks();
locks_free_lock(fl);
goto out_free_fasync;
}
/* /*
* fasync_insert_entry() returns the old entry if any. * fasync_insert_entry() returns the old entry if any.
...@@ -1541,12 +1543,12 @@ static int do_fcntl_add_lease(unsigned int fd, struct file *filp, long arg) ...@@ -1541,12 +1543,12 @@ static int do_fcntl_add_lease(unsigned int fd, struct file *filp, long arg)
fl->fl_type = F_UNLCK | F_INPROGRESS; fl->fl_type = F_UNLCK | F_INPROGRESS;
fl->fl_break_time = jiffies - 10; fl->fl_break_time = jiffies - 10;
time_out_leases(inode); time_out_leases(inode);
goto out_unlock; } else {
}
error = __f_setown(filp, task_pid(current), PIDTYPE_PID, 0); error = __f_setown(filp, task_pid(current), PIDTYPE_PID, 0);
out_unlock: }
unlock_flocks(); unlock_flocks();
out_free_fasync:
if (new) if (new)
fasync_free(new); fasync_free(new);
return error; return error;
......
...@@ -884,7 +884,5 @@ static int nfs_setlease(struct file *file, long arg, struct file_lock **fl) ...@@ -884,7 +884,5 @@ static int nfs_setlease(struct file *file, long arg, struct file_lock **fl)
dprintk("NFS: setlease(%s/%s, arg=%ld)\n", dprintk("NFS: setlease(%s/%s, arg=%ld)\n",
file->f_path.dentry->d_parent->d_name.name, file->f_path.dentry->d_parent->d_name.name,
file->f_path.dentry->d_name.name, arg); file->f_path.dentry->d_name.name, arg);
if (arg != F_UNLCK)
locks_free_lock(*fl);
return -EINVAL; return -EINVAL;
} }
...@@ -2652,6 +2652,7 @@ nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, struct nfs4_sta ...@@ -2652,6 +2652,7 @@ nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, struct nfs4_sta
if ((status = vfs_setlease(fl->fl_file, fl->fl_type, &fl))) { if ((status = vfs_setlease(fl->fl_file, fl->fl_type, &fl))) {
dprintk("NFSD: setlease failed [%d], no delegation\n", status); dprintk("NFSD: setlease failed [%d], no delegation\n", status);
dp->dl_flock = NULL; dp->dl_flock = NULL;
locks_free_lock(fl);
unhash_delegation(dp); unhash_delegation(dp);
flag = NFS4_OPEN_DELEGATE_NONE; flag = NFS4_OPEN_DELEGATE_NONE;
goto out; goto out;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment