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 <[email protected]>
---
drivers/soc/qcom/apr.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/soc/qcom/apr.c b/drivers/soc/qcom/apr.c
index b4046f393575..1b73ce9b4f9a 100644
--- a/drivers/soc/qcom/apr.c
+++ b/drivers/soc/qcom/apr.c
@@ -454,8 +454,12 @@ 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) {
+ kfree(adev);
+ return ret;
+ }
of_property_read_string_index(np, "qcom,protection-domain",
1, &adev->service_path);
--
2.25.1
On 9/12/2022 7:30 PM, Jiasheng Jiang wrote:
> 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 <[email protected]>
> ---
> drivers/soc/qcom/apr.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/soc/qcom/apr.c b/drivers/soc/qcom/apr.c
> index b4046f393575..1b73ce9b4f9a 100644
> --- a/drivers/soc/qcom/apr.c
> +++ b/drivers/soc/qcom/apr.c
> @@ -454,8 +454,12 @@ 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) {
> + kfree(adev);
> + return ret;
> + }
for consistency suggest you follow the same error logic as the
device_register() failure just below, call dev_err() and put_device()
On 9/12/2022 8:51 PM, Jeff Johnson wrote:
> On 9/12/2022 7:30 PM, Jiasheng Jiang wrote:
>> 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 <[email protected]>
>> ---
>> drivers/soc/qcom/apr.c | 6 +++++-
>> 1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/soc/qcom/apr.c b/drivers/soc/qcom/apr.c
>> index b4046f393575..1b73ce9b4f9a 100644
>> --- a/drivers/soc/qcom/apr.c
>> +++ b/drivers/soc/qcom/apr.c
>> @@ -454,8 +454,12 @@ 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) {
>> + kfree(adev);
>> + return ret;
>> + }
>
> for consistency suggest you follow the same error logic as the
> device_register() failure just below, call dev_err() and put_device()
>
in addition the of_property_read_string_index() that follows could also
use error checking