Commit 26dd5cfe authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] loop: fix file refcount leak

- Fix an error-path file refcount leak

- Remove unnecessary get_file()/fput() pair.

- Clean up error handling a little
parent 9644d0d9
...@@ -676,7 +676,6 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file, ...@@ -676,7 +676,6 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file,
if (!file) if (!file)
goto out; goto out;
error = -EINVAL;
inode = file->f_dentry->d_inode; inode = file->f_dentry->d_inode;
if (!(file->f_mode & FMODE_WRITE)) if (!(file->f_mode & FMODE_WRITE))
...@@ -686,7 +685,7 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file, ...@@ -686,7 +685,7 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file,
lo_device = inode->i_bdev; lo_device = inode->i_bdev;
if (lo_device == bdev) { if (lo_device == bdev) {
error = -EBUSY; error = -EBUSY;
goto out; goto out_putf;
} }
lo_blocksize = block_size(lo_device); lo_blocksize = block_size(lo_device);
if (bdev_read_only(lo_device)) if (bdev_read_only(lo_device))
...@@ -697,6 +696,7 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file, ...@@ -697,6 +696,7 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file,
* If we can't read - sorry. If we only can't write - well, * If we can't read - sorry. If we only can't write - well,
* it's going to be read-only. * it's going to be read-only.
*/ */
error = -EINVAL;
if (!inode->i_fop->sendfile) if (!inode->i_fop->sendfile)
goto out_putf; goto out_putf;
...@@ -709,8 +709,6 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file, ...@@ -709,8 +709,6 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file,
} else } else
goto out_putf; goto out_putf;
get_file(file);
if (!(lo_file->f_mode & FMODE_WRITE)) if (!(lo_file->f_mode & FMODE_WRITE))
lo_flags |= LO_FLAGS_READ_ONLY; lo_flags |= LO_FLAGS_READ_ONLY;
...@@ -725,7 +723,6 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file, ...@@ -725,7 +723,6 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file,
lo->lo_sizelimit = 0; lo->lo_sizelimit = 0;
if (figure_loop_size(lo)) { if (figure_loop_size(lo)) {
error = -EFBIG; error = -EFBIG;
fput(file);
goto out_putf; goto out_putf;
} }
lo->old_gfp_mask = mapping_gfp_mask(inode->i_mapping); lo->old_gfp_mask = mapping_gfp_mask(inode->i_mapping);
...@@ -760,8 +757,6 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file, ...@@ -760,8 +757,6 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file,
kernel_thread(loop_thread, lo, CLONE_KERNEL); kernel_thread(loop_thread, lo, CLONE_KERNEL);
down(&lo->lo_sem); down(&lo->lo_sem);
fput(file);
return 0; return 0;
out_putf: out_putf:
......
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