diff mbox series

[v1] soc: qcom: pbs: Simplify with dev_err_probe()

Message ID 20240829124813.3264437-1-yujiaoliang@vivo.com
State New
Headers show
Series [v1] soc: qcom: pbs: Simplify with dev_err_probe() | expand

Commit Message

Yu Jiaoliang Aug. 29, 2024, 12:48 p.m. UTC
Error handling in probe() can be a bit simpler with dev_err_probe().

Signed-off-by: Yu Jiaoliang <yujiaoliang@vivo.com>
---
 drivers/soc/qcom/qcom-pbs.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Comments

Konrad Dybcio Aug. 30, 2024, 10:03 a.m. UTC | #1
On 30.08.2024 10:08 AM, Krzysztof Kozlowski wrote:
> On 29/08/2024 14:48, Yu Jiaoliang wrote:
>> Error handling in probe() can be a bit simpler with dev_err_probe().
>>
>> Signed-off-by: Yu Jiaoliang <yujiaoliang@vivo.com>
>> ---
>>  drivers/soc/qcom/qcom-pbs.c | 7 +++----
>>  1 file changed, 3 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/soc/qcom/qcom-pbs.c b/drivers/soc/qcom/qcom-pbs.c
>> index 77a70d3d0d0b..ab9de12ec901 100644
>> --- a/drivers/soc/qcom/qcom-pbs.c
>> +++ b/drivers/soc/qcom/qcom-pbs.c
>> @@ -201,10 +201,9 @@ static int qcom_pbs_probe(struct platform_device *pdev)
>>  	}
>>  
>>  	ret = device_property_read_u32(pbs->dev, "reg", &val);
>> -	if (ret < 0) {
>> -		dev_err(pbs->dev, "Couldn't find reg, ret = %d\n", ret);
>> -		return ret;
>> -	}
>> +	if (ret < 0)
>> +		return dev_err_probe(pbs->dev, ret, "Couldn't find reg\n");
> 
> This cannot defer, so not much benefits. And you ignore other place in
> the probe()... That's like a weird pattern with all your patches change
> something irrelevant, but leave other places unchanged.
> 
> That's pointless and churn.

Hm, that's a good point.. Maybe the static checker folks could come up
with a way that would find functions that call something that can defer
at one point or another and suggest (not) using dev_err_probe with W=1/2..
(although that is probably not going to be very high prio given all the
other static checker issues we're still yet to resolve)

Unless we have something like that already? +CC Dan

Konrad
Dan Carpenter Aug. 30, 2024, 3:19 p.m. UTC | #2
On Fri, Aug 30, 2024 at 12:03:20PM +0200, Konrad Dybcio wrote:
> On 30.08.2024 10:08 AM, Krzysztof Kozlowski wrote:
> > On 29/08/2024 14:48, Yu Jiaoliang wrote:
> >> Error handling in probe() can be a bit simpler with dev_err_probe().
> >>
> >> Signed-off-by: Yu Jiaoliang <yujiaoliang@vivo.com>
> >> ---
> >>  drivers/soc/qcom/qcom-pbs.c | 7 +++----
> >>  1 file changed, 3 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/drivers/soc/qcom/qcom-pbs.c b/drivers/soc/qcom/qcom-pbs.c
> >> index 77a70d3d0d0b..ab9de12ec901 100644
> >> --- a/drivers/soc/qcom/qcom-pbs.c
> >> +++ b/drivers/soc/qcom/qcom-pbs.c
> >> @@ -201,10 +201,9 @@ static int qcom_pbs_probe(struct platform_device *pdev)
> >>  	}
> >>  
> >>  	ret = device_property_read_u32(pbs->dev, "reg", &val);
> >> -	if (ret < 0) {
> >> -		dev_err(pbs->dev, "Couldn't find reg, ret = %d\n", ret);
> >> -		return ret;
> >> -	}
> >> +	if (ret < 0)
> >> +		return dev_err_probe(pbs->dev, ret, "Couldn't find reg\n");
> > 
> > This cannot defer, so not much benefits. And you ignore other place in
> > the probe()... That's like a weird pattern with all your patches change
> > something irrelevant, but leave other places unchanged.
> > 
> > That's pointless and churn.
> 
> Hm, that's a good point.. Maybe the static checker folks could come up
> with a way that would find functions that call something that can defer
> at one point or another and suggest (not) using dev_err_probe with W=1/2..
> (although that is probably not going to be very high prio given all the
> other static checker issues we're still yet to resolve)
> 
> Unless we have something like that already? +CC Dan

I believe these patches are from people writing their own Coccinelle scripts to
do the conversions.  There aren't any published scripts which care one way or
the other.

device_property_read_u32() can't return -EPROBE_DEFER.  It's documented in a
comment.  So this is just a question of preferred style.  There isn't a kernel
wide preferred style on this.  Some maintainers prefer to not use dev_err_probe()
where it "doesn't make sense because ret isn't -EPROBE_DEFER".  Other maintainers
use it all the time even for error code literals like:
	return dev_err_probe(pbs->dev, -EINVAL, "invalid input.\n");
Because "it's cleaner, more uniform and only takes one line".  I think Julia
said she didn't want to get involved with this debate and I definitely don't.

There are a few things which we could do:

1) Returning -EPROBE_DEFER to an ioctl or something besides a probe()
   This is a bug right?  -EPROBE_DEFER is basically kernel internal for probe()
   functions.  It tried to write this but it was complicated so I gave up.

2) Printing an error message for -EPROBE_DEFER warnings
   I've written this check and I can test it tonight.

3) Not propagating the -EPROBE_DEFER returns
   This shouldn't be too hard to write.

Let me add a KTODO in case anyone wants to do this before I get around to it.

KTODO: write Smatch EPROBE_DEFER warnings

regards,
dan carpenter
diff mbox series

Patch

diff --git a/drivers/soc/qcom/qcom-pbs.c b/drivers/soc/qcom/qcom-pbs.c
index 77a70d3d0d0b..ab9de12ec901 100644
--- a/drivers/soc/qcom/qcom-pbs.c
+++ b/drivers/soc/qcom/qcom-pbs.c
@@ -201,10 +201,9 @@  static int qcom_pbs_probe(struct platform_device *pdev)
 	}
 
 	ret = device_property_read_u32(pbs->dev, "reg", &val);
-	if (ret < 0) {
-		dev_err(pbs->dev, "Couldn't find reg, ret = %d\n", ret);
-		return ret;
-	}
+	if (ret < 0)
+		return dev_err_probe(pbs->dev, ret, "Couldn't find reg\n");
+
 	pbs->base = val;
 	mutex_init(&pbs->lock);