提交 0f0b6bd9 编写于 作者: M Misono Tomohiro 提交者: Yang Yingliang

NFS: direct.c: Fix memory leak of dreq when nfs_get_lock_context fails

stable inclusion
from linux-4.19.118
commit 2f5253c5e9ecacd0c9724022e94acaf3c7c545ce

--------------------------------

[ Upstream commit 8605cf0e ]

When dreq is allocated by nfs_direct_req_alloc(), dreq->kref is
initialized to 2. Therefore we need to call nfs_direct_req_release()
twice to release the allocated dreq. Usually it is called in
nfs_file_direct_{read, write}() and nfs_direct_complete().

However, current code only calls nfs_direct_req_relese() once if
nfs_get_lock_context() fails in nfs_file_direct_{read, write}().
So, that case would result in memory leak.

Fix this by adding the missing call.
Signed-off-by: NMisono Tomohiro <misono.tomohiro@jp.fujitsu.com>
Signed-off-by: NTrond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 1fa459f2
...@@ -600,6 +600,7 @@ ssize_t nfs_file_direct_read(struct kiocb *iocb, struct iov_iter *iter) ...@@ -600,6 +600,7 @@ ssize_t nfs_file_direct_read(struct kiocb *iocb, struct iov_iter *iter)
l_ctx = nfs_get_lock_context(dreq->ctx); l_ctx = nfs_get_lock_context(dreq->ctx);
if (IS_ERR(l_ctx)) { if (IS_ERR(l_ctx)) {
result = PTR_ERR(l_ctx); result = PTR_ERR(l_ctx);
nfs_direct_req_release(dreq);
goto out_release; goto out_release;
} }
dreq->l_ctx = l_ctx; dreq->l_ctx = l_ctx;
...@@ -1023,6 +1024,7 @@ ssize_t nfs_file_direct_write(struct kiocb *iocb, struct iov_iter *iter) ...@@ -1023,6 +1024,7 @@ ssize_t nfs_file_direct_write(struct kiocb *iocb, struct iov_iter *iter)
l_ctx = nfs_get_lock_context(dreq->ctx); l_ctx = nfs_get_lock_context(dreq->ctx);
if (IS_ERR(l_ctx)) { if (IS_ERR(l_ctx)) {
result = PTR_ERR(l_ctx); result = PTR_ERR(l_ctx);
nfs_direct_req_release(dreq);
goto out_release; goto out_release;
} }
dreq->l_ctx = l_ctx; dreq->l_ctx = l_ctx;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册