* [PATCH v2] soc: qcom: apr: Add check for idr_alloc
@ 2022-09-13 7:31 Jiasheng Jiang
0 siblings, 0 replies; only message in thread
From: Jiasheng Jiang @ 2022-09-13 7:31 UTC (permalink / raw)
To: quic_jjohnson, agross, bjorn.andersson, konrad.dybcio
Cc: linux-arm-msm, linux-kernel, Jiasheng Jiang
As idr_alloc() can return negative numbers,
it should be better to check the return value and
deal with the exception.
Fixes: 6adba21eb434 ("soc: qcom: Add APR bus driver")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
Changelog:
v1 -> v2:
1. Add dev_err and put_device in order to maintain the code consistency.
---
drivers/soc/qcom/apr.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/soc/qcom/apr.c b/drivers/soc/qcom/apr.c
index b4046f393575..5fef2750623a 100644
--- a/drivers/soc/qcom/apr.c
+++ b/drivers/soc/qcom/apr.c
@@ -454,8 +454,14 @@ static int apr_add_device(struct device *dev, struct device_node *np,
adev->dev.driver = NULL;
spin_lock(&apr->svcs_lock);
- idr_alloc(&apr->svcs_idr, svc, svc_id, svc_id + 1, GFP_ATOMIC);
+ ret = idr_alloc(&apr->svcs_idr, svc, svc_id, svc_id + 1, GFP_ATOMIC);
spin_unlock(&apr->svcs_lock);
+ if (ret < 0) {
+ dev_err(dev, "idr_alloc failed: %d\n", ret);
+ put_device(&adev->dev);
+ kfree(adev);
+ return ret;
+ }
of_property_read_string_index(np, "qcom,protection-domain",
1, &adev->service_path);
--
2.25.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2022-09-13 7:31 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-13 7:31 [PATCH v2] soc: qcom: apr: Add check for idr_alloc Jiasheng Jiang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.