SUNRPC: Cleanup - make rpc_new_task() call rpc_release_calldata on failure
authorTrond Myklebust <Trond.Myklebust@netapp.com>
Fri, 16 Apr 2010 20:41:10 +0000 (16:41 -0400)
committerTrond Myklebust <Trond.Myklebust@netapp.com>
Fri, 14 May 2010 19:09:29 +0000 (15:09 -0400)
Also have it return an ERR_PTR(-ENOMEM) instead of a null pointer.

Reviewed-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
net/sunrpc/clnt.c
net/sunrpc/sched.c

index 19c9983d53607483cce29654b8e589dca6da539d..8c7b5433022a24a33afdb8c5add46725a15b2850 100644 (file)
@@ -556,26 +556,16 @@ static const struct rpc_call_ops rpc_default_ops = {
  */
 struct rpc_task *rpc_run_task(const struct rpc_task_setup *task_setup_data)
 {
-       struct rpc_task *task, *ret;
+       struct rpc_task *task;
 
        task = rpc_new_task(task_setup_data);
-       if (task == NULL) {
-               rpc_release_calldata(task_setup_data->callback_ops,
-                               task_setup_data->callback_data);
-               ret = ERR_PTR(-ENOMEM);
+       if (IS_ERR(task))
                goto out;
-       }
 
-       if (task->tk_status != 0) {
-               ret = ERR_PTR(task->tk_status);
-               rpc_put_task(task);
-               goto out;
-       }
        atomic_inc(&task->tk_count);
        rpc_execute(task);
-       ret = task;
 out:
-       return ret;
+       return task;
 }
 EXPORT_SYMBOL_GPL(rpc_run_task);
 
@@ -657,9 +647,8 @@ struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req,
         * Create an rpc_task to send the data
         */
        task = rpc_new_task(&task_setup_data);
-       if (!task) {
+       if (IS_ERR(task)) {
                xprt_free_bc_request(req);
-               task = ERR_PTR(-ENOMEM);
                goto out;
        }
        task->tk_rqstp = req;
index aae6907fd546916317e69615dc1cb5e8040259c4..c8979ce5d88ae3fc7bd5554bc89c5697b1dfc549 100644 (file)
@@ -856,16 +856,23 @@ struct rpc_task *rpc_new_task(const struct rpc_task_setup *setup_data)
 
        if (task == NULL) {
                task = rpc_alloc_task();
-               if (task == NULL)
-                       goto out;
+               if (task == NULL) {
+                       rpc_release_calldata(setup_data->callback_ops,
+                                       setup_data->callback_data);
+                       return ERR_PTR(-ENOMEM);
+               }
                flags = RPC_TASK_DYNAMIC;
        }
 
        rpc_init_task(task, setup_data);
+       if (task->tk_status < 0) {
+               int err = task->tk_status;
+               rpc_put_task(task);
+               return ERR_PTR(err);
+       }
 
        task->tk_flags |= flags;
        dprintk("RPC:       allocated task %p\n", task);
-out:
        return task;
 }