Skip to content

Commit

Permalink
misc: fastrpc: fix potential fastrpc_invoke_ctx leak
Browse files Browse the repository at this point in the history
fastrpc_invoke_ctx can have refcount of 2 in error path where
rpmsg_send() fails to send invoke message. decrement the refcount
properly in the error path to fix this leak.

This also fixes below static checker warning:

drivers/misc/fastrpc.c:990 fastrpc_internal_invoke()
warn: 'ctx->refcount.refcount.ref.counter' not decremented on lines: 990.

Fixes: c68cfb7 ("misc: fastrpc: Add support for context")
Reported-by: Dan Carpenter <[email protected]>
Signed-off-by: Srinivas Kandagatla <[email protected]>
Reviewed-by: Bjorn Andersson <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
Srinivas-Kandagatla authored and gregkh committed May 15, 2020
1 parent 0978de9 commit 7400338
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion drivers/misc/fastrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,7 @@ static int fastrpc_invoke_send(struct fastrpc_session_ctx *sctx,
struct fastrpc_channel_ctx *cctx;
struct fastrpc_user *fl = ctx->fl;
struct fastrpc_msg *msg = &ctx->msg;
int ret;

cctx = fl->cctx;
msg->pid = fl->tgid;
Expand All @@ -919,7 +920,13 @@ static int fastrpc_invoke_send(struct fastrpc_session_ctx *sctx,
msg->size = roundup(ctx->msg_sz, PAGE_SIZE);
fastrpc_context_get(ctx);

return rpmsg_send(cctx->rpdev->ept, (void *)msg, sizeof(*msg));
ret = rpmsg_send(cctx->rpdev->ept, (void *)msg, sizeof(*msg));

if (ret)
fastrpc_context_put(ctx);

return ret;

}

static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel,
Expand Down

0 comments on commit 7400338

Please sign in to comment.