soc: qcom: apr: Add check for idr_alloc and of_property_read_string_index
authorJiasheng Jiang <jiasheng@iscas.ac.cn>
Mon, 7 Nov 2022 01:44:03 +0000 (09:44 +0800)
committerBjorn Andersson <andersson@kernel.org>
Mon, 7 Nov 2022 23:15:20 +0000 (17:15 -0600)
As idr_alloc() and of_property_read_string_index() can return negative
numbers, it should be better to check the return value and deal with
the exception.
Therefore, it should be better to use goto statement to stop and return
error.

Fixes: 6adba21eb434 ("soc: qcom: Add APR bus driver")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Bjorn Andersson <andersson@kernel.org>
Signed-off-by: Bjorn Andersson <andersson@kernel.org>
Link: https://lore.kernel.org/r/20221107014403.3606-1-jiasheng@iscas.ac.cn
drivers/soc/qcom/apr.c

index b4046f393575eaefeab9bebc37a4e5e6b6f65276..cd44f17dad3d04cd3ec1f6b8d8614e3fb9828456 100644 (file)
@@ -454,11 +454,19 @@ 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);
+               goto out;
+       }
 
-       of_property_read_string_index(np, "qcom,protection-domain",
-                                     1, &adev->service_path);
+       ret = of_property_read_string_index(np, "qcom,protection-domain",
+                                           1, &adev->service_path);
+       if (ret < 0) {
+               dev_err(dev, "Failed to read second value of qcom,protection-domain\n");
+               goto out;
+       }
 
        dev_info(dev, "Adding APR/GPR dev: %s\n", dev_name(&adev->dev));
 
@@ -468,6 +476,7 @@ static int apr_add_device(struct device *dev, struct device_node *np,
                put_device(&adev->dev);
        }
 
+out:
        return ret;
 }