diff options
author | David Howells <dhowells@redhat.com> | 2017-03-16 19:27:48 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-12-20 12:01:31 +0300 |
commit | b1718fdda0f2d47634c0e8e96b0a77cfc34d4424 (patch) | |
tree | dc3a872032855755d8a23557acbb9966146fa66b /fs/afs | |
parent | b422c709f72bec2787723aa7c2afdca4246df2f3 (diff) | |
download | linux-b1718fdda0f2d47634c0e8e96b0a77cfc34d4424.tar.xz |
afs: Fix page leak in afs_write_begin()
[ Upstream commit 6d06b0d25209c80e99c1e89700f1e09694a3766b ]
afs_write_begin() leaks a ref and a lock on a page if afs_fill_page()
fails. Fix the leak by unlocking and releasing the page in the error path.
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/afs')
-rw-r--r-- | fs/afs/write.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/fs/afs/write.c b/fs/afs/write.c index 24f11d2deeb2..9f816624e212 100644 --- a/fs/afs/write.c +++ b/fs/afs/write.c @@ -149,12 +149,12 @@ int afs_write_begin(struct file *file, struct address_space *mapping, kfree(candidate); return -ENOMEM; } - *pagep = page; - /* page won't leak in error case: it eventually gets cleaned off LRU */ if (!PageUptodate(page) && len != PAGE_CACHE_SIZE) { ret = afs_fill_page(vnode, key, index << PAGE_CACHE_SHIFT, page); if (ret < 0) { + unlock_page(page); + put_page(page); kfree(candidate); _leave(" = %d [prep]", ret); return ret; @@ -162,6 +162,9 @@ int afs_write_begin(struct file *file, struct address_space *mapping, SetPageUptodate(page); } + /* page won't leak in error case: it eventually gets cleaned off LRU */ + *pagep = page; + try_again: spin_lock(&vnode->writeback_lock); |