Skip to content

Commit

Permalink
rpmsg: glink: Resource cleanup on glink smem probe fail
Browse files Browse the repository at this point in the history
When glink smem probe fails before completion, allocated resources
are not freed properly before return.

Freeing up allocated resources before return, in case of glink smem
probe failure before completion.

CRs-Fixed: 2482441
Change-Id: Ia3834fe7a9555b4e4a9e225fe3002400523f0f1e
Signed-off-by: Deepak Kumar Singh <[email protected]>
  • Loading branch information
Deepak Kumar Singh authored and Gerrit - the friendly Code Review server committed Aug 6, 2019
1 parent b6f62dc commit ad317a3
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions drivers/rpmsg/qcom_glink_smem.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,42 +231,43 @@ struct qcom_glink *qcom_glink_smem_register(struct device *parent,
ret = device_register(dev);
if (ret) {
pr_err("failed to register glink edge\n");
kfree(dev);
return ERR_PTR(ret);
}

ret = of_property_read_u32(dev->of_node, "qcom,remote-pid",
&remote_pid);
if (ret) {
dev_err(dev, "failed to parse qcom,remote-pid\n");
goto err_put_dev;
goto unregister;
}

rx_pipe = devm_kzalloc(dev, sizeof(*rx_pipe), GFP_KERNEL);
tx_pipe = devm_kzalloc(dev, sizeof(*tx_pipe), GFP_KERNEL);
if (!rx_pipe || !tx_pipe) {
ret = -ENOMEM;
goto err_put_dev;
goto unregister;
}

ret = qcom_smem_alloc(remote_pid,
SMEM_GLINK_NATIVE_XPRT_DESCRIPTOR, 32);
if (ret && ret != -EEXIST) {
dev_err(dev, "failed to allocate glink descriptors\n");
goto err_put_dev;
goto unregister;
}

descs = qcom_smem_get(remote_pid,
SMEM_GLINK_NATIVE_XPRT_DESCRIPTOR, &size);
if (IS_ERR(descs)) {
dev_err(dev, "failed to acquire xprt descriptor\n");
ret = PTR_ERR(descs);
goto err_put_dev;
goto unregister;
}

if (size != 32) {
dev_err(dev, "glink descriptor of invalid size\n");
ret = -EINVAL;
goto err_put_dev;
goto unregister;
}

tx_pipe->tail = &descs[0];
Expand All @@ -278,15 +279,15 @@ struct qcom_glink *qcom_glink_smem_register(struct device *parent,
SZ_16K);
if (ret && ret != -EEXIST) {
dev_err(dev, "failed to allocate TX fifo\n");
goto err_put_dev;
goto unregister;
}

tx_pipe->fifo = qcom_smem_get(remote_pid, SMEM_GLINK_NATIVE_XPRT_FIFO_0,
&tx_pipe->native.length);
if (IS_ERR(tx_pipe->fifo)) {
dev_err(dev, "failed to acquire TX fifo\n");
ret = PTR_ERR(tx_pipe->fifo);
goto err_put_dev;
goto unregister;
}

rx_pipe->native.avail = glink_smem_rx_avail;
Expand All @@ -307,13 +308,13 @@ struct qcom_glink *qcom_glink_smem_register(struct device *parent,
false);
if (IS_ERR(glink)) {
ret = PTR_ERR(glink);
goto err_put_dev;
goto unregister;
}

return glink;

err_put_dev:
put_device(dev);
unregister:
device_unregister(dev);

return ERR_PTR(ret);
}
Expand Down

1 comment on commit ad317a3

@stefanhh0
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already cherry-picked, see: 00d0e1e

Please sign in to comment.