Commit af8f6f39 authored by Liang He's avatar Liang He Committed by Bjorn Andersson

soc: qcom: smsm: Fix refcount leak bugs in qcom_smsm_probe()

There are two refcount leak bugs in qcom_smsm_probe():

(1) The 'local_node' is escaped out from for_each_child_of_node() as
the break of iteration, we should call of_node_put() for it in error
path or when it is not used anymore.
(2) The 'node' is escaped out from for_each_available_child_of_node()
as the 'goto', we should call of_node_put() for it in goto target.

Fixes: c97c4090 ("soc: qcom: smsm: Add driver for Qualcomm SMSM")
Signed-off-by: default avatarLiang He <windhl@126.com>
Signed-off-by: default avatarBjorn Andersson <bjorn.andersson@linaro.org>
Link: https://lore.kernel.org/r/20220721135217.1301039-1-windhl@126.com
parent 14af4ce0
...@@ -526,7 +526,7 @@ static int qcom_smsm_probe(struct platform_device *pdev) ...@@ -526,7 +526,7 @@ static int qcom_smsm_probe(struct platform_device *pdev)
for (id = 0; id < smsm->num_hosts; id++) { for (id = 0; id < smsm->num_hosts; id++) {
ret = smsm_parse_ipc(smsm, id); ret = smsm_parse_ipc(smsm, id);
if (ret < 0) if (ret < 0)
return ret; goto out_put;
} }
/* Acquire the main SMSM state vector */ /* Acquire the main SMSM state vector */
...@@ -534,13 +534,14 @@ static int qcom_smsm_probe(struct platform_device *pdev) ...@@ -534,13 +534,14 @@ static int qcom_smsm_probe(struct platform_device *pdev)
smsm->num_entries * sizeof(u32)); smsm->num_entries * sizeof(u32));
if (ret < 0 && ret != -EEXIST) { if (ret < 0 && ret != -EEXIST) {
dev_err(&pdev->dev, "unable to allocate shared state entry\n"); dev_err(&pdev->dev, "unable to allocate shared state entry\n");
return ret; goto out_put;
} }
states = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_SMSM_SHARED_STATE, NULL); states = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_SMSM_SHARED_STATE, NULL);
if (IS_ERR(states)) { if (IS_ERR(states)) {
dev_err(&pdev->dev, "Unable to acquire shared state entry\n"); dev_err(&pdev->dev, "Unable to acquire shared state entry\n");
return PTR_ERR(states); ret = PTR_ERR(states);
goto out_put;
} }
/* Acquire the list of interrupt mask vectors */ /* Acquire the list of interrupt mask vectors */
...@@ -548,13 +549,14 @@ static int qcom_smsm_probe(struct platform_device *pdev) ...@@ -548,13 +549,14 @@ static int qcom_smsm_probe(struct platform_device *pdev)
ret = qcom_smem_alloc(QCOM_SMEM_HOST_ANY, SMEM_SMSM_CPU_INTR_MASK, size); ret = qcom_smem_alloc(QCOM_SMEM_HOST_ANY, SMEM_SMSM_CPU_INTR_MASK, size);
if (ret < 0 && ret != -EEXIST) { if (ret < 0 && ret != -EEXIST) {
dev_err(&pdev->dev, "unable to allocate smsm interrupt mask\n"); dev_err(&pdev->dev, "unable to allocate smsm interrupt mask\n");
return ret; goto out_put;
} }
intr_mask = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_SMSM_CPU_INTR_MASK, NULL); intr_mask = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_SMSM_CPU_INTR_MASK, NULL);
if (IS_ERR(intr_mask)) { if (IS_ERR(intr_mask)) {
dev_err(&pdev->dev, "unable to acquire shared memory interrupt mask\n"); dev_err(&pdev->dev, "unable to acquire shared memory interrupt mask\n");
return PTR_ERR(intr_mask); ret = PTR_ERR(intr_mask);
goto out_put;
} }
/* Setup the reference to the local state bits */ /* Setup the reference to the local state bits */
...@@ -565,7 +567,8 @@ static int qcom_smsm_probe(struct platform_device *pdev) ...@@ -565,7 +567,8 @@ static int qcom_smsm_probe(struct platform_device *pdev)
smsm->state = qcom_smem_state_register(local_node, &smsm_state_ops, smsm); smsm->state = qcom_smem_state_register(local_node, &smsm_state_ops, smsm);
if (IS_ERR(smsm->state)) { if (IS_ERR(smsm->state)) {
dev_err(smsm->dev, "failed to register qcom_smem_state\n"); dev_err(smsm->dev, "failed to register qcom_smem_state\n");
return PTR_ERR(smsm->state); ret = PTR_ERR(smsm->state);
goto out_put;
} }
/* Register handlers for remote processor entries of interest. */ /* Register handlers for remote processor entries of interest. */
...@@ -595,16 +598,19 @@ static int qcom_smsm_probe(struct platform_device *pdev) ...@@ -595,16 +598,19 @@ static int qcom_smsm_probe(struct platform_device *pdev)
} }
platform_set_drvdata(pdev, smsm); platform_set_drvdata(pdev, smsm);
of_node_put(local_node);
return 0; return 0;
unwind_interfaces: unwind_interfaces:
of_node_put(node);
for (id = 0; id < smsm->num_entries; id++) for (id = 0; id < smsm->num_entries; id++)
if (smsm->entries[id].domain) if (smsm->entries[id].domain)
irq_domain_remove(smsm->entries[id].domain); irq_domain_remove(smsm->entries[id].domain);
qcom_smem_state_unregister(smsm->state); qcom_smem_state_unregister(smsm->state);
out_put:
of_node_put(local_node);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment