Skip to content

Commit 25cf32a

Browse files
author
Trond Myklebust
committed
SUNRPC: Handle allocation failure in rpc_new_task()
If the call to rpc_alloc_task() fails, then ensure that the calldata is released, and that rpc_run_task() and rpc_run_bc_task() bail out early. Reported-by: NeilBrown <[email protected]> Fixes: 910ad38 ("NFS: Fix memory allocation in rpc_alloc_task()") Signed-off-by: Trond Myklebust <[email protected]>
1 parent 88dee0c commit 25cf32a

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

net/sunrpc/clnt.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,8 @@ struct rpc_task *rpc_run_task(const struct rpc_task_setup *task_setup_data)
11271127
struct rpc_task *task;
11281128

11291129
task = rpc_new_task(task_setup_data);
1130+
if (IS_ERR(task))
1131+
return task;
11301132

11311133
if (!RPC_IS_ASYNC(task))
11321134
task->tk_flags |= RPC_TASK_CRED_NOREF;
@@ -1227,6 +1229,11 @@ struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req)
12271229
* Create an rpc_task to send the data
12281230
*/
12291231
task = rpc_new_task(&task_setup_data);
1232+
if (IS_ERR(task)) {
1233+
xprt_free_bc_request(req);
1234+
return task;
1235+
}
1236+
12301237
xprt_init_bc_request(req, task);
12311238

12321239
task->tk_action = call_bc_encode;

net/sunrpc/sched.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,11 @@ struct rpc_task *rpc_new_task(const struct rpc_task_setup *setup_data)
11281128

11291129
if (task == NULL) {
11301130
task = rpc_alloc_task();
1131+
if (task == NULL) {
1132+
rpc_release_calldata(setup_data->callback_ops,
1133+
setup_data->callback_data);
1134+
return ERR_PTR(-ENOMEM);
1135+
}
11311136
flags = RPC_TASK_DYNAMIC;
11321137
}
11331138

0 commit comments

Comments
 (0)