Skip to content

Commit

Permalink
rpmsg: glink: Fix memory leak in qcom_glink_alloc_intent()
Browse files Browse the repository at this point in the history
We need to free "intent" and "intent->data" on a couple error paths.

Fixes: 933b45d ("rpmsg: glink: Add support for TX intents")
Acked-by: Sricharan R <sricharan@codeaurora.org>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
  • Loading branch information
Dan Carpenter authored and Bjorn Andersson committed Oct 10, 2017
1 parent 0a7480b commit b775d15
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions drivers/rpmsg/qcom_glink_native.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,19 +635,18 @@ qcom_glink_alloc_intent(struct qcom_glink *glink,
unsigned long flags;

intent = kzalloc(sizeof(*intent), GFP_KERNEL);

if (!intent)
return NULL;

intent->data = kzalloc(size, GFP_KERNEL);
if (!intent->data)
return NULL;
goto free_intent;

spin_lock_irqsave(&channel->intent_lock, flags);
ret = idr_alloc_cyclic(&channel->liids, intent, 1, -1, GFP_ATOMIC);
if (ret < 0) {
spin_unlock_irqrestore(&channel->intent_lock, flags);
return NULL;
goto free_data;
}
spin_unlock_irqrestore(&channel->intent_lock, flags);

Expand All @@ -656,6 +655,12 @@ qcom_glink_alloc_intent(struct qcom_glink *glink,
intent->reuse = reuseable;

return intent;

free_data:
kfree(intent->data);
free_intent:
kfree(intent);
return NULL;
}

static void qcom_glink_handle_rx_done(struct qcom_glink *glink,
Expand Down

0 comments on commit b775d15

Please sign in to comment.