Linux ARM-MSM sub-architecture
 help / color / mirror / Atom feed
* [PATCH v6] soc: qcom: apr: Add check for idr_alloc and of_property_read_string_index
@ 2022-11-07  1:44 Jiasheng Jiang
  2022-11-07  3:23 ` Bjorn Andersson
  2022-11-08  1:27 ` Bjorn Andersson
  0 siblings, 2 replies; 3+ messages in thread
From: Jiasheng Jiang @ 2022-11-07  1:44 UTC (permalink / raw)
  To: andersson
  Cc: quic_jjohnson, agross, bjorn.andersson, konrad.dybcio,
	linux-arm-msm, linux-kernel, Jiasheng Jiang

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>
---
Changelog:

v5 -> v6:

1. Remove the put_device.

v4 -> v5:

1. Change dev_err and goto statements.

v3 -> v4:

1. Change the title and remove the kfree.

v2 -> v3:

1. Change the title and use goto statement to deal with the exception.

v1 -> v2:

1. Add dev_err and put_device in order to maintain the code consistency.
---
 drivers/soc/qcom/apr.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/soc/qcom/apr.c b/drivers/soc/qcom/apr.c
index b4046f393575..cd44f17dad3d 100644
--- a/drivers/soc/qcom/apr.c
+++ b/drivers/soc/qcom/apr.c
@@ -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;
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v6] soc: qcom: apr: Add check for idr_alloc and of_property_read_string_index
  2022-11-07  1:44 [PATCH v6] soc: qcom: apr: Add check for idr_alloc and of_property_read_string_index Jiasheng Jiang
@ 2022-11-07  3:23 ` Bjorn Andersson
  2022-11-08  1:27 ` Bjorn Andersson
  1 sibling, 0 replies; 3+ messages in thread
From: Bjorn Andersson @ 2022-11-07  3:23 UTC (permalink / raw)
  To: Jiasheng Jiang
  Cc: quic_jjohnson, agross, bjorn.andersson, konrad.dybcio,
	linux-arm-msm, linux-kernel

On Mon, Nov 07, 2022 at 09:44:03AM +0800, Jiasheng Jiang wrote:
> 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>

Thanks,
Bjorn

> ---
> Changelog:
> 
> v5 -> v6:
> 
> 1. Remove the put_device.
> 
> v4 -> v5:
> 
> 1. Change dev_err and goto statements.
> 
> v3 -> v4:
> 
> 1. Change the title and remove the kfree.
> 
> v2 -> v3:
> 
> 1. Change the title and use goto statement to deal with the exception.
> 
> v1 -> v2:
> 
> 1. Add dev_err and put_device in order to maintain the code consistency.
> ---
>  drivers/soc/qcom/apr.c | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/soc/qcom/apr.c b/drivers/soc/qcom/apr.c
> index b4046f393575..cd44f17dad3d 100644
> --- a/drivers/soc/qcom/apr.c
> +++ b/drivers/soc/qcom/apr.c
> @@ -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;
>  }
>  
> -- 
> 2.25.1
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v6] soc: qcom: apr: Add check for idr_alloc and of_property_read_string_index
  2022-11-07  1:44 [PATCH v6] soc: qcom: apr: Add check for idr_alloc and of_property_read_string_index Jiasheng Jiang
  2022-11-07  3:23 ` Bjorn Andersson
@ 2022-11-08  1:27 ` Bjorn Andersson
  1 sibling, 0 replies; 3+ messages in thread
From: Bjorn Andersson @ 2022-11-08  1:27 UTC (permalink / raw)
  To: jiasheng
  Cc: quic_jjohnson, konrad.dybcio, agross, linux-kernel, linux-arm-msm

On Mon, 7 Nov 2022 09:44:03 +0800, Jiasheng Jiang wrote:
> 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.
> 
> 
> [...]

Applied, thanks!

[1/1] soc: qcom: apr: Add check for idr_alloc and of_property_read_string_index
      commit: 6d7860f5750d73da2fa1a1f6c9405058a593fa32

Best regards,
-- 
Bjorn Andersson <andersson@kernel.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-08  1:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-07  1:44 [PATCH v6] soc: qcom: apr: Add check for idr_alloc and of_property_read_string_index Jiasheng Jiang
2022-11-07  3:23 ` Bjorn Andersson
2022-11-08  1:27 ` Bjorn Andersson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox