diff mbox series

[-next,2/8] soc: fsl: cpm1: Simplify with dev_err_probe()

Message ID 20240827114607.4019972-3-ruanjinjie@huawei.com (mailing list archive)
State New, archived
Headers show
Series soc: Simplify with scoped for each OF child loop and dev_err_probe() | expand

Commit Message

Jinjie Ruan Aug. 27, 2024, 11:46 a.m. UTC
Use the dev_err_probe() helper to simplify error handling during probe.
This also handle scenario, when EDEFER is returned and useless error
is printed.

Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
 drivers/soc/fsl/qe/tsa.c | 62 +++++++++++++++-------------------------
 1 file changed, 23 insertions(+), 39 deletions(-)

Comments

Krzysztof Kozlowski Aug. 27, 2024, 1:50 p.m. UTC | #1
On 27/08/2024 13:46, Jinjie Ruan wrote:
> Use the dev_err_probe() helper to simplify error handling during probe.
> This also handle scenario, when EDEFER is returned and useless error
> is printed.

? Sorry, this cannot happen. Please point to below code which can defer.

> 
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
> ---
>  drivers/soc/fsl/qe/tsa.c | 62 +++++++++++++++-------------------------
>  1 file changed, 23 insertions(+), 39 deletions(-)
> 
> diff --git a/drivers/soc/fsl/qe/tsa.c b/drivers/soc/fsl/qe/tsa.c
> index 7fa399b7a47c..fc37d23b746d 100644
> --- a/drivers/soc/fsl/qe/tsa.c
> +++ b/drivers/soc/fsl/qe/tsa.c
> @@ -453,10 +453,8 @@ static int tsa_of_parse_tdms(struct tsa *tsa, struct device_node *np)
>  
>  	for_each_available_child_of_node_scoped(np, tdm_np) {
>  		ret = of_property_read_u32(tdm_np, "reg", &tdm_id);
> -		if (ret) {
> -			dev_err(tsa->dev, "%pOF: failed to read reg\n", tdm_np);
> -			return ret;
> -		}
> +		if (ret)
> +			return dev_err_probe(tsa->dev, ret, "%pOF: failed to read reg\n", tdm_np);
>  		switch (tdm_id) {
>  		case 0:
>  			tsa->tdms |= BIT(TSA_TDMA);
> @@ -465,18 +463,15 @@ static int tsa_of_parse_tdms(struct tsa *tsa, struct device_node *np)
>  			tsa->tdms |= BIT(TSA_TDMB);
>  			break;
>  		default:
> -			dev_err(tsa->dev, "%pOF: Invalid tdm_id (%u)\n", tdm_np,
> -				tdm_id);
> -			return -EINVAL;
> +			return dev_err_probe(tsa->dev, -EINVAL, "%pOF: Invalid tdm_id (%u)\n",
> +					     tdm_np, tdm_id);
>  		}
>  	}
>  
>  	for_each_available_child_of_node_scoped(np, tdm_np) {
>  		ret = of_property_read_u32(tdm_np, "reg", &tdm_id);
> -		if (ret) {
> -			dev_err(tsa->dev, "%pOF: failed to read reg\n", tdm_np);
> -			return ret;
> -		}
> +		if (ret)
> +			return dev_err_probe(tsa->dev, ret, "%pOF: failed to read reg\n", tdm_np);
>  
>  		tdm = &tsa->tdm[tdm_id];
>  		tdm->simode_tdm = TSA_SIMODE_TDM_SDM_NORM;
> @@ -484,35 +479,26 @@ static int tsa_of_parse_tdms(struct tsa *tsa, struct device_node *np)
>  		val = 0;
>  		ret = of_property_read_u32(tdm_np, "fsl,rx-frame-sync-delay-bits",
>  					   &val);
> -		if (ret && ret != -EINVAL) {
> -			dev_err(tsa->dev,
> -				"%pOF: failed to read fsl,rx-frame-sync-delay-bits\n",
> -				tdm_np);
> -			return ret;
> -		}
> -		if (val > 3) {
> -			dev_err(tsa->dev,
> -				"%pOF: Invalid fsl,rx-frame-sync-delay-bits (%u)\n",
> -				tdm_np, val);
> -			return -EINVAL;
> -		}
> +		if (ret && ret != -EINVAL)
> +			return dev_err_probe(tsa->dev, ret,
> +					     "%pOF: failed to read fsl,rx-frame-sync-delay-bits\n",
> +					     tdm_np);
> +		if (val > 3)
> +			return dev_err_probe(tsa->dev, -EINVAL,
> +					     "%pOF: Invalid fsl,rx-frame-sync-delay-bits (%u)\n",
> +					     tdm_np, val);
>  		tdm->simode_tdm |= TSA_SIMODE_TDM_RFSD(val);
>  
>  		val = 0;
>  		ret = of_property_read_u32(tdm_np, "fsl,tx-frame-sync-delay-bits",
>  					   &val);
> -		if (ret && ret != -EINVAL) {
> -			dev_err(tsa->dev,
> -				"%pOF: failed to read fsl,tx-frame-sync-delay-bits\n",
> -				tdm_np);
> -			return ret;
> -		}
> -		if (val > 3) {
> -			dev_err(tsa->dev,
> -				"%pOF: Invalid fsl,tx-frame-sync-delay-bits (%u)\n",
> -				tdm_np, val);
> -			return -EINVAL;
> -		}
> +		if (ret && ret != -EINVAL)
> +			return dev_err_probe(tsa->dev, ret,
> +				"%pOF: failed to read fsl,tx-frame-sync-delay-bits\n", tdm_np);
> +		if (val > 3)
> +			return dev_err_probe(tsa->dev, -EINVAL,
> +					     "%pOF: Invalid fsl,tx-frame-sync-delay-bits (%u)\n",
> +					     tdm_np, val);
>  		tdm->simode_tdm |= TSA_SIMODE_TDM_TFSD(val);
>  
>  		if (of_property_read_bool(tdm_np, "fsl,common-rxtx-pins"))
> @@ -645,10 +631,8 @@ static int tsa_probe(struct platform_device *pdev)
>  		return PTR_ERR(tsa->si_regs);
>  
>  	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "si_ram");
> -	if (!res) {
> -		dev_err(tsa->dev, "si_ram resource missing\n");
> -		return -EINVAL;
> -	}
> +	if (!res)
> +		return dev_err_probe(tsa->dev, -EINVAL, "si_ram resource missing\n");
>  	tsa->si_ram_sz = resource_size(res);
>  	tsa->si_ram = devm_ioremap_resource(&pdev->dev, res);
>  	if (IS_ERR(tsa->si_ram))

Best regards,
Krzysztof
Jinjie Ruan Aug. 28, 2024, 1:58 a.m. UTC | #2
On 2024/8/27 21:50, Krzysztof Kozlowski wrote:
> On 27/08/2024 13:46, Jinjie Ruan wrote:
>> Use the dev_err_probe() helper to simplify error handling during probe.
>> This also handle scenario, when EDEFER is returned and useless error
>> is printed.
> 
> ? Sorry, this cannot happen. Please point to below code which can defer.
> 

Thank you!

This is not referring to a specific one, but rather the benefits it
offers,simplify code is the main purpose, if necessary, it will be
removed in next version.

>>
>> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
>> ---
>>  drivers/soc/fsl/qe/tsa.c | 62 +++++++++++++++-------------------------
>>  1 file changed, 23 insertions(+), 39 deletions(-)
>>
>> diff --git a/drivers/soc/fsl/qe/tsa.c b/drivers/soc/fsl/qe/tsa.c
>> index 7fa399b7a47c..fc37d23b746d 100644
>> --- a/drivers/soc/fsl/qe/tsa.c
>> +++ b/drivers/soc/fsl/qe/tsa.c
>> @@ -453,10 +453,8 @@ static int tsa_of_parse_tdms(struct tsa *tsa, struct device_node *np)
>>  
>>  	for_each_available_child_of_node_scoped(np, tdm_np) {
>>  		ret = of_property_read_u32(tdm_np, "reg", &tdm_id);
>> -		if (ret) {
>> -			dev_err(tsa->dev, "%pOF: failed to read reg\n", tdm_np);
>> -			return ret;
>> -		}
>> +		if (ret)
>> +			return dev_err_probe(tsa->dev, ret, "%pOF: failed to read reg\n", tdm_np);
>>  		switch (tdm_id) {
>>  		case 0:
>>  			tsa->tdms |= BIT(TSA_TDMA);
>> @@ -465,18 +463,15 @@ static int tsa_of_parse_tdms(struct tsa *tsa, struct device_node *np)
>>  			tsa->tdms |= BIT(TSA_TDMB);
>>  			break;
>>  		default:
>> -			dev_err(tsa->dev, "%pOF: Invalid tdm_id (%u)\n", tdm_np,
>> -				tdm_id);
>> -			return -EINVAL;
>> +			return dev_err_probe(tsa->dev, -EINVAL, "%pOF: Invalid tdm_id (%u)\n",
>> +					     tdm_np, tdm_id);
>>  		}
>>  	}
>>  
>>  	for_each_available_child_of_node_scoped(np, tdm_np) {
>>  		ret = of_property_read_u32(tdm_np, "reg", &tdm_id);
>> -		if (ret) {
>> -			dev_err(tsa->dev, "%pOF: failed to read reg\n", tdm_np);
>> -			return ret;
>> -		}
>> +		if (ret)
>> +			return dev_err_probe(tsa->dev, ret, "%pOF: failed to read reg\n", tdm_np);
>>  
>>  		tdm = &tsa->tdm[tdm_id];
>>  		tdm->simode_tdm = TSA_SIMODE_TDM_SDM_NORM;
>> @@ -484,35 +479,26 @@ static int tsa_of_parse_tdms(struct tsa *tsa, struct device_node *np)
>>  		val = 0;
>>  		ret = of_property_read_u32(tdm_np, "fsl,rx-frame-sync-delay-bits",
>>  					   &val);
>> -		if (ret && ret != -EINVAL) {
>> -			dev_err(tsa->dev,
>> -				"%pOF: failed to read fsl,rx-frame-sync-delay-bits\n",
>> -				tdm_np);
>> -			return ret;
>> -		}
>> -		if (val > 3) {
>> -			dev_err(tsa->dev,
>> -				"%pOF: Invalid fsl,rx-frame-sync-delay-bits (%u)\n",
>> -				tdm_np, val);
>> -			return -EINVAL;
>> -		}
>> +		if (ret && ret != -EINVAL)
>> +			return dev_err_probe(tsa->dev, ret,
>> +					     "%pOF: failed to read fsl,rx-frame-sync-delay-bits\n",
>> +					     tdm_np);
>> +		if (val > 3)
>> +			return dev_err_probe(tsa->dev, -EINVAL,
>> +					     "%pOF: Invalid fsl,rx-frame-sync-delay-bits (%u)\n",
>> +					     tdm_np, val);
>>  		tdm->simode_tdm |= TSA_SIMODE_TDM_RFSD(val);
>>  
>>  		val = 0;
>>  		ret = of_property_read_u32(tdm_np, "fsl,tx-frame-sync-delay-bits",
>>  					   &val);
>> -		if (ret && ret != -EINVAL) {
>> -			dev_err(tsa->dev,
>> -				"%pOF: failed to read fsl,tx-frame-sync-delay-bits\n",
>> -				tdm_np);
>> -			return ret;
>> -		}
>> -		if (val > 3) {
>> -			dev_err(tsa->dev,
>> -				"%pOF: Invalid fsl,tx-frame-sync-delay-bits (%u)\n",
>> -				tdm_np, val);
>> -			return -EINVAL;
>> -		}
>> +		if (ret && ret != -EINVAL)
>> +			return dev_err_probe(tsa->dev, ret,
>> +				"%pOF: failed to read fsl,tx-frame-sync-delay-bits\n", tdm_np);
>> +		if (val > 3)
>> +			return dev_err_probe(tsa->dev, -EINVAL,
>> +					     "%pOF: Invalid fsl,tx-frame-sync-delay-bits (%u)\n",
>> +					     tdm_np, val);
>>  		tdm->simode_tdm |= TSA_SIMODE_TDM_TFSD(val);
>>  
>>  		if (of_property_read_bool(tdm_np, "fsl,common-rxtx-pins"))
>> @@ -645,10 +631,8 @@ static int tsa_probe(struct platform_device *pdev)
>>  		return PTR_ERR(tsa->si_regs);
>>  
>>  	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "si_ram");
>> -	if (!res) {
>> -		dev_err(tsa->dev, "si_ram resource missing\n");
>> -		return -EINVAL;
>> -	}
>> +	if (!res)
>> +		return dev_err_probe(tsa->dev, -EINVAL, "si_ram resource missing\n");
>>  	tsa->si_ram_sz = resource_size(res);
>>  	tsa->si_ram = devm_ioremap_resource(&pdev->dev, res);
>>  	if (IS_ERR(tsa->si_ram))
> 
> Best regards,
> Krzysztof
>
Krzysztof Kozlowski Aug. 28, 2024, 1:08 p.m. UTC | #3
On 28/08/2024 03:58, Jinjie Ruan wrote:
> 
> 
> On 2024/8/27 21:50, Krzysztof Kozlowski wrote:
>> On 27/08/2024 13:46, Jinjie Ruan wrote:
>>> Use the dev_err_probe() helper to simplify error handling during probe.
>>> This also handle scenario, when EDEFER is returned and useless error
>>> is printed.
>>
>> ? Sorry, this cannot happen. Please point to below code which can defer.
>>
> 
> Thank you!
> 
> This is not referring to a specific one, but rather the benefits it
> offers,simplify code is the main purpose, if necessary, it will be
> removed in next version.

It just feels like you are doing these in machine way without actually
knowing concepts behind dev_err_probe().

Best regards,
Krzysztof
Jinjie Ruan Aug. 29, 2024, 2:25 a.m. UTC | #4
On 2024/8/28 21:08, Krzysztof Kozlowski wrote:
> On 28/08/2024 03:58, Jinjie Ruan wrote:
>>
>>
>> On 2024/8/27 21:50, Krzysztof Kozlowski wrote:
>>> On 27/08/2024 13:46, Jinjie Ruan wrote:
>>>> Use the dev_err_probe() helper to simplify error handling during probe.
>>>> This also handle scenario, when EDEFER is returned and useless error
>>>> is printed.
>>>
>>> ? Sorry, this cannot happen. Please point to below code which can defer.
>>>
>>
>> Thank you!
>>
>> This is not referring to a specific one, but rather the benefits it
>> offers,simplify code is the main purpose, if necessary, it will be
>> removed in next version.
> 
> It just feels like you are doing these in machine way without actually
> knowing concepts behind dev_err_probe().

Just try my best to make the code as clean as possible and do it by the way.

> 
> Best regards,
> Krzysztof
>
diff mbox series

Patch

diff --git a/drivers/soc/fsl/qe/tsa.c b/drivers/soc/fsl/qe/tsa.c
index 7fa399b7a47c..fc37d23b746d 100644
--- a/drivers/soc/fsl/qe/tsa.c
+++ b/drivers/soc/fsl/qe/tsa.c
@@ -453,10 +453,8 @@  static int tsa_of_parse_tdms(struct tsa *tsa, struct device_node *np)
 
 	for_each_available_child_of_node_scoped(np, tdm_np) {
 		ret = of_property_read_u32(tdm_np, "reg", &tdm_id);
-		if (ret) {
-			dev_err(tsa->dev, "%pOF: failed to read reg\n", tdm_np);
-			return ret;
-		}
+		if (ret)
+			return dev_err_probe(tsa->dev, ret, "%pOF: failed to read reg\n", tdm_np);
 		switch (tdm_id) {
 		case 0:
 			tsa->tdms |= BIT(TSA_TDMA);
@@ -465,18 +463,15 @@  static int tsa_of_parse_tdms(struct tsa *tsa, struct device_node *np)
 			tsa->tdms |= BIT(TSA_TDMB);
 			break;
 		default:
-			dev_err(tsa->dev, "%pOF: Invalid tdm_id (%u)\n", tdm_np,
-				tdm_id);
-			return -EINVAL;
+			return dev_err_probe(tsa->dev, -EINVAL, "%pOF: Invalid tdm_id (%u)\n",
+					     tdm_np, tdm_id);
 		}
 	}
 
 	for_each_available_child_of_node_scoped(np, tdm_np) {
 		ret = of_property_read_u32(tdm_np, "reg", &tdm_id);
-		if (ret) {
-			dev_err(tsa->dev, "%pOF: failed to read reg\n", tdm_np);
-			return ret;
-		}
+		if (ret)
+			return dev_err_probe(tsa->dev, ret, "%pOF: failed to read reg\n", tdm_np);
 
 		tdm = &tsa->tdm[tdm_id];
 		tdm->simode_tdm = TSA_SIMODE_TDM_SDM_NORM;
@@ -484,35 +479,26 @@  static int tsa_of_parse_tdms(struct tsa *tsa, struct device_node *np)
 		val = 0;
 		ret = of_property_read_u32(tdm_np, "fsl,rx-frame-sync-delay-bits",
 					   &val);
-		if (ret && ret != -EINVAL) {
-			dev_err(tsa->dev,
-				"%pOF: failed to read fsl,rx-frame-sync-delay-bits\n",
-				tdm_np);
-			return ret;
-		}
-		if (val > 3) {
-			dev_err(tsa->dev,
-				"%pOF: Invalid fsl,rx-frame-sync-delay-bits (%u)\n",
-				tdm_np, val);
-			return -EINVAL;
-		}
+		if (ret && ret != -EINVAL)
+			return dev_err_probe(tsa->dev, ret,
+					     "%pOF: failed to read fsl,rx-frame-sync-delay-bits\n",
+					     tdm_np);
+		if (val > 3)
+			return dev_err_probe(tsa->dev, -EINVAL,
+					     "%pOF: Invalid fsl,rx-frame-sync-delay-bits (%u)\n",
+					     tdm_np, val);
 		tdm->simode_tdm |= TSA_SIMODE_TDM_RFSD(val);
 
 		val = 0;
 		ret = of_property_read_u32(tdm_np, "fsl,tx-frame-sync-delay-bits",
 					   &val);
-		if (ret && ret != -EINVAL) {
-			dev_err(tsa->dev,
-				"%pOF: failed to read fsl,tx-frame-sync-delay-bits\n",
-				tdm_np);
-			return ret;
-		}
-		if (val > 3) {
-			dev_err(tsa->dev,
-				"%pOF: Invalid fsl,tx-frame-sync-delay-bits (%u)\n",
-				tdm_np, val);
-			return -EINVAL;
-		}
+		if (ret && ret != -EINVAL)
+			return dev_err_probe(tsa->dev, ret,
+				"%pOF: failed to read fsl,tx-frame-sync-delay-bits\n", tdm_np);
+		if (val > 3)
+			return dev_err_probe(tsa->dev, -EINVAL,
+					     "%pOF: Invalid fsl,tx-frame-sync-delay-bits (%u)\n",
+					     tdm_np, val);
 		tdm->simode_tdm |= TSA_SIMODE_TDM_TFSD(val);
 
 		if (of_property_read_bool(tdm_np, "fsl,common-rxtx-pins"))
@@ -645,10 +631,8 @@  static int tsa_probe(struct platform_device *pdev)
 		return PTR_ERR(tsa->si_regs);
 
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "si_ram");
-	if (!res) {
-		dev_err(tsa->dev, "si_ram resource missing\n");
-		return -EINVAL;
-	}
+	if (!res)
+		return dev_err_probe(tsa->dev, -EINVAL, "si_ram resource missing\n");
 	tsa->si_ram_sz = resource_size(res);
 	tsa->si_ram = devm_ioremap_resource(&pdev->dev, res);
 	if (IS_ERR(tsa->si_ram))