Skip to contentSkip to conversation

coccinelle: platform_get_irq: Add dev_err_probe() check

PATCH In review Li Zetao 3 participants 11 messages Aug 1, 2023 – Aug 4, 2023 1 message not in the archive Coccinelle/Semantic Patches (SmPL)

lore
Share & tools
lore

Li Zetao

author
#0 lore raw

PATCH 1/1 coccinelle: platform_get_irq: Add dev_err_probe() check

After the commit "2043727c2882" and "27446562a1d9", dev_err_probe() will be called to print error message when get device irq failed, so it is unnecessary for the caller to print error message. The platform_get_irq.cocci will check the "dev_err", but not the "dev_error_probe". Add the inspection of "dev_error_probe" to enhance the use case.

---
 scripts/coccinelle/api/platform_get_irq.cocci | 29 +++++++++++++++++++
 1 file changed, 29 insertions(+)
scripts/coccinelle/api/platform_get_irq.cocci +29 -0
index 06b6a95e2bfc..3621411bff92 100644
@@ -21,6 +21,7 @@ platform_get_irq
 platform_get_irq_byname
 )(E, ...);
 
+(
 if ( \( ret < 0 \| ret <= 0 \) )
 {
 (
@@ -34,6 +35,14 @@ if (ret != -EPROBE_DEFER)
 )
 ...
 }
+|
+if ( \( ret < 0 \| ret <= 0 \) )
+(
+*dev_err_probe(...);
+|
+*return dev_err_probe(...);
+)
+)
 
 @depends on patch@
 expression ret;
@@ -47,6 +56,7 @@ platform_get_irq
 platform_get_irq_byname
 )(E, ...);
 
+(
 if ( \( ret < 0 \| ret <= 0 \) )
 {
 (
@@ -60,6 +70,16 @@ if ( \( ret < 0 \| ret <= 0 \) )
 )
 ...
 }
+|
+if ( \( ret < 0 \| ret <= 0 \) )
+(
+-dev_err_probe(...);
++return ret;
+|
+-return dev_err_probe(...);
++return ret;
+)
+)
 
 @r depends on org || report@
 position p1;
@@ -74,6 +94,7 @@ platform_get_irq
 platform_get_irq_byname
 )(E, ...);
 
+(
 if ( \( ret < 0 \| ret <= 0 \) )
 {
 (
@@ -87,6 +108,14 @@ dev_err@p1(...);
 )
 ...
 }
+|
+if ( \( ret < 0 \| ret <= 0 \) )
+(
+dev_err_probe@p1(...);
+|
+return dev_err_probe@p1(...);
+)
+)
 
 @script:python depends on org@
 p1 << r.p1;
Signature · 1 line
2.34.1
#1 lore raw

…

Quoted 1 line

+++ b/scripts/coccinelle/api/platform_get_irq.cocci

…

Quoted 1 line
(quoted diff) +0 -0
@@ -60,6 +70,16 @@ if ( \( ret < 0 \| ret <= 0 \) )

…

scripts/coccinelle/api/platform_get_irq.cocci if ( \( ret < 0 \| ret <= 0 \) ) · line 82

Quoted 9 lines
scripts/coccinelle/api/platform_get_irq.cocci +9 -0
+if ( \( ret < 0 \| ret <= 0 \) )
+(
+-dev_err_probe(...);
++return ret;
+|
+-return dev_err_probe(...);
++return ret;
+)
+)

How do you think about to use the following code variant for the adjusted SmPL disjunctions in the patch operation mode?

if ( \( ret < 0 \| ret <= 0 \) )
(
-dev_err_probe(...)
|
-return dev_err_probe(...)
)
+return ret
;

Regards,
Markus

maintainer
#2 lore raw
Quoted 18 lines · Markus Elfring

…

Quoted 1 line

+++ b/scripts/coccinelle/api/platform_get_irq.cocci

…

Quoted 1 line
(quoted diff) +0 -0
@@ -60,6 +70,16 @@ if ( \( ret < 0 \| ret <= 0 \) )

…

scripts/coccinelle/api/platform_get_irq.cocci if ( \( ret < 0 \| ret <= 0 \) ) · line 82

Quoted 9 lines
scripts/coccinelle/api/platform_get_irq.cocci +9 -0
+if ( \( ret < 0 \| ret <= 0 \) )
+(
+-dev_err_probe(...);
++return ret;
+|
+-return dev_err_probe(...);
++return ret;
+)
+)

How do you think about to use the following code variant for the adjusted SmPL disjunctions in the patch operation mode?

Quoted 8 lines

if ( \( ret < 0 \| ret <= 0 \) )
(
-dev_err_probe(...)
|
-return dev_err_probe(...)
)
+return ret
;

If this style works here, it doesn't always work, so it is not desirable to put it in the Linux kernel.

julia

#3 lore raw
Quoted 18 lines
Quoted 18 lines

…

Quoted 1 line

+++ b/scripts/coccinelle/api/platform_get_irq.cocci

…

Quoted 1 line
(quoted diff) +0 -0
@@ -60,6 +70,16 @@ if ( \( ret < 0 \| ret <= 0 \) )

…

scripts/coccinelle/api/platform_get_irq.cocci if ( \( ret < 0 \| ret <= 0 \) ) · line 82

Quoted 9 lines
scripts/coccinelle/api/platform_get_irq.cocci +9 -0
+if ( \( ret < 0 \| ret <= 0 \) )
+(
+-dev_err_probe(...);
++return ret;
+|
+-return dev_err_probe(...);
++return ret;
+)
+)

How do you think about to use the following code variant for the adjusted SmPL disjunctions in the patch operation mode?

Quoted 10 lines
Quoted 8 lines

if ( \( ret < 0 \| ret <= 0 \) )
(
-dev_err_probe(...)
|
-return dev_err_probe(...)
)
+return ret
;

If this style works here, it doesn't always work,

I find this feedback not so clear.

Quoted 1 line

so it is not desirable to put it in the Linux kernel.

Can it be helpful to avoid a bit of duplicate SmPL code for the proposed transformation?

Regards,
Markus

maintainer
#4 lore raw
Quoted 29 lines · Markus Elfring
Quoted 18 lines
Quoted 18 lines

…

Quoted 1 line

+++ b/scripts/coccinelle/api/platform_get_irq.cocci

…

Quoted 1 line
(quoted diff) +0 -0
@@ -60,6 +70,16 @@ if ( \( ret < 0 \| ret <= 0 \) )

…

scripts/coccinelle/api/platform_get_irq.cocci if ( \( ret < 0 \| ret <= 0 \) ) · line 82

Quoted 9 lines
scripts/coccinelle/api/platform_get_irq.cocci +9 -0
+if ( \( ret < 0 \| ret <= 0 \) )
+(
+-dev_err_probe(...);
++return ret;
+|
+-return dev_err_probe(...);
++return ret;
+)
+)

How do you think about to use the following code variant for the adjusted SmPL disjunctions in the patch operation mode?

Quoted 10 lines
Quoted 8 lines

if ( \( ret < 0 \| ret <= 0 \) )
(
-dev_err_probe(...)
|
-return dev_err_probe(...)
)
+return ret
;

If this style works here, it doesn't always work,

Quoted 1 line

I find this feedback not so clear.

Normally, you can't put + code after a disjunction. Because the two branches of the disjunction might cause the matching process to end up in two different places.

The fact that you are suggesting to do this seems to suggest that you think that the Coccinelle semantic patch parser accepts this code. But I have no idea whether it does. It should not in any case.

julia

Quoted 10 lines
Quoted 3 lines

so it is not desirable to put it in the Linux kernel.

Can it be helpful to avoid a bit of duplicate SmPL code for the proposed transformation?

Regards,
Markus

#5 lore raw
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 11 lines

How do you think about to use the following code variant for the adjusted SmPL disjunctions in the patch operation mode?

if ( \( ret < 0 \| ret <= 0 \) )
(
-dev_err_probe(...)
|
-return dev_err_probe(...)
)
+return ret
;

If this style works here, it doesn't always work,

Quoted 8 lines
Quoted 1 line

I find this feedback not so clear.

Normally, you can't put + code after a disjunction. Because the two branches of the disjunction might cause the matching process to end up in two different places.

The fact that you are suggesting to do this seems to suggest that you think that the Coccinelle semantic patch parser accepts this code.

I would find it useful if a desired code deletion could be achieved by a corresponding SmPL disjunction (without duplicate SmPL code).

Quoted 1 line

But I have no idea whether it does. It should not in any case.

May it be expected that the matching process should determine appropriate source code places?

Regards,
Markus

#6 lore raw

Re: [cocci] Improving support for handling of optional items in deletion patterns

In reply to Julia Lawall
Quoted 7 lines

Normally, you can't put + code after a disjunction. Because the two branches of the disjunction might cause the matching process to end up in two different places.

The fact that you are suggesting to do this seems to suggest that you think that the Coccinelle semantic patch parser accepts this code. But I have no idea whether it does. It should not in any case.

Will the chances grow to reconsider involved application concerns any more?

An SmPL disjunction is used here to achieve the deletion of a statement which contains an optional item (like the key word “return” in the discussed case). Regular expressions support the quantifier “question mark” for such a purpose. Do you see possibilities that the semantic patch language can support such functionality also in a succinct way for SmPL deletion code?

Regards,
Markus

#7 lore raw
In reply to Li Zetao

…

Quoted 1 line

+++ b/scripts/coccinelle/api/platform_get_irq.cocci

…

Quoted 1 line
(quoted diff) +0 -0
@@ -60,6 +70,16 @@ if ( \( ret < 0 \| ret <= 0 \) )

…

scripts/coccinelle/api/platform_get_irq.cocci if ( \( ret < 0 \| ret <= 0 \) ) · line 82

Quoted 9 lines
scripts/coccinelle/api/platform_get_irq.cocci +9 -0
+if ( \( ret < 0 \| ret <= 0 \) )
+(
+-dev_err_probe(...);
++return ret;
+|
+-return dev_err_probe(...);
++return ret;
+)
+)

How do you think about to use the following code variant for the adjusted SmPL disjunctions in the patch operation mode (for a while)?

if ( \( ret < 0 \| ret <= 0 \) )
(
-dev_err_probe(...)
+return ret
;
|
return
- dev_err_probe(...)
+ ret
;
)

Regards,
Markus

A message that is not in the archive (sent off-list or not yet received): [email protected]

#9 lore raw

…

Quoted 3 lines

---
v1 -> v2: Modify the return statement for the adjusted SmPL disjunctions in the patch operation mode

Thanks that you would like to pick a part of my adjustment idea up.

…

Quoted 1 line

+++ b/scripts/coccinelle/api/platform_get_irq.cocci

…

Quoted 1 line
(quoted diff) +0 -0
@@ -60,6 +70,17 @@ if ( \( ret < 0 \| ret <= 0 \) )

…

scripts/coccinelle/api/platform_get_irq.cocci if ( \( ret < 0 \| ret <= 0 \) ) · line 81

Quoted 9 lines
scripts/coccinelle/api/platform_get_irq.cocci +9 -0
+if ( \( ret < 0 \| ret <= 0 \) )
+(
+-dev_err_probe(...);
++return ret;
+|
+return
+-	dev_err_probe(...);
++	ret;
+)

I tend to prefer a different SmPL coding style.

* Thus I imagine that unneeded deletion and addition of code (which affects also semicolons) should be avoided here.

* Space characters should be preserved in the first text column.

if ( \( ret < 0 \| ret <= 0 \) )
(
-dev_err_probe(...)
+return ret
;
|
return
- dev_err_probe(...)
+ ret
;
)

Regards,
Markus

maintainer
#10 lore raw
Quoted 40 lines · Markus Elfring

…

Quoted 3 lines

---
v1 -> v2: Modify the return statement for the adjusted SmPL disjunctions in the patch operation mode

Thanks that you would like to pick a part of my adjustment idea up.

…

Quoted 1 line

+++ b/scripts/coccinelle/api/platform_get_irq.cocci

…

Quoted 1 line
(quoted diff) +0 -0
@@ -60,6 +70,17 @@ if ( \( ret < 0 \| ret <= 0 \) )

…

scripts/coccinelle/api/platform_get_irq.cocci if ( \( ret < 0 \| ret <= 0 \) ) · line 81

Quoted 9 lines
scripts/coccinelle/api/platform_get_irq.cocci +9 -0
+if ( \( ret < 0 \| ret <= 0 \) )
+(
+-dev_err_probe(...);
++return ret;
+|
+return
+-	dev_err_probe(...);
++	ret;
+)

I tend to prefer a different SmPL coding style.

* Thus I imagine that unneeded deletion and addition of code (which affects also semicolons) should be avoided here.

* Space characters should be preserved in the first text column.

if ( \( ret < 0 \| ret <= 0 \) )
(

(quoted diff) +1 -1
-dev_err_probe(...)
+return ret
 ;

|
return

(quoted diff) +1 -1
-       dev_err_probe(...)
+       ret
 ;
Quoted 1 line

)

I see no purpose to any of this.

julia

#11 lore raw
Quoted 7 lines
Quoted 7 lines

I tend to prefer a different SmPL coding style.

* Thus I imagine that unneeded deletion and addition of code (which affects also semicolons) should be avoided here.

* Space characters should be preserved in the first text column.

Quoted 13 lines
Quoted 11 lines

if ( \( ret < 0 \| ret <= 0 \) )
(

(quoted diff) +1 -1
-dev_err_probe(...)
+return ret
 ;

|
return

(quoted diff) +1 -1
-       dev_err_probe(...)
+       ret
 ;

)

I see no purpose to any of this.

I suggest once more to increase the attention another bit for a potentially more desirable change granularity.

Regards,
Markus