* Re: [Cocci] Reducing source code around return statements with SmPL?
2019-09-23 8:59 ` Julia Lawall
@ 2019-09-23 11:17 ` Markus Elfring
2019-09-24 15:27 ` Markus Elfring
` (3 subsequent siblings)
4 siblings, 0 replies; 31+ messages in thread
From: Markus Elfring @ 2019-09-23 11:17 UTC (permalink / raw)
To: Julia Lawall, Coccinelle; +Cc: kernel-janitors
>> The following small script for the semantic patch language
>> can point various source code places out for further considerations.
>>
>> @replacement@
>> expression x;
>> identifier rc;
>
> Add: local idexpression lrc;
>
>> @@
>> -rc = x;
>
> Replace by - lrc@rc = x;
>
> julia
>
>> return
>> - rc
>> + x
>> ;
Thanks for your advice.
>> Which adjustments should be taken better into account for this use case?
The shown metavariable combination is interesting, isn't it?
2064 Linux source files are pointed out by this transformation approach.
* Does this number need any additional thoughts?
* Will it become helpful to integrate such a SmPL script
into a corresponding Linux directory?
Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [Cocci] Reducing source code around return statements with SmPL?
2019-09-23 8:59 ` Julia Lawall
2019-09-23 11:17 ` Markus Elfring
@ 2019-09-24 15:27 ` Markus Elfring
2019-09-24 15:30 ` Julia Lawall
2019-09-24 18:20 ` Markus Elfring
` (2 subsequent siblings)
4 siblings, 1 reply; 31+ messages in thread
From: Markus Elfring @ 2019-09-24 15:27 UTC (permalink / raw)
To: Julia Lawall; +Cc: Coccinelle
>> @@
>> -rc = x;
>
> Replace by - lrc@rc = x;
I have constructed the following test script for the semantic patch language.
@check1@
expression x;
identifier rc;
local idexpression lrc;
position p;
@@
lrc@rc = x@p;
return lrc;
@check2@
identifier check1.rc;
position p;
type t;
@@
t rc@p;
... when != rc
@script:python to_do1@
p << check1.p;
@@
coccilib.org.print_todo(p[0],
"WARNING: An expression was assigned to a local variable before it will be returned by the subsequent statement.")
@script:python to_do2@
p << check2.p;
v << check2.rc;
@@
coccilib.org.print_todo(p[0],
"INFO: May the local variable \""
+ v
+ "\" be deleted?")
I wonder about a corresponding test result.
elfring@Sonne:~/Projekte/Coccinelle/janitor> spatch --parse-cocci move_code_to_return1.cocci
…
scriptmeta: semantic error: bad rule check2 or bad variable rc
File "move_code_to_return1.cocci", line 26, column 14, charpos = 474
around = ';',
whole content = v << check2.rc;
I imagine that it would be easier to understand that the content from
the inherited metavariable can be directly used.
The SmPL specification “v << check1.rc;” gets accepted by Coccinelle software
and seems to work then in the way I would expect it also for the other script variant.
Will any more adjustments become relevant for such a source code search approach?
Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [Cocci] Reducing source code around return statements with SmPL?
2019-09-24 15:27 ` Markus Elfring
@ 2019-09-24 15:30 ` Julia Lawall
2019-09-24 15:40 ` Markus Elfring
2019-09-24 19:24 ` Markus Elfring
0 siblings, 2 replies; 31+ messages in thread
From: Julia Lawall @ 2019-09-24 15:30 UTC (permalink / raw)
To: Markus Elfring; +Cc: Coccinelle
[-- Attachment #1: Type: text/plain, Size: 1654 bytes --]
On Tue, 24 Sep 2019, Markus Elfring wrote:
> >> @@
> >> -rc = x;
> >
> > Replace by - lrc@rc = x;
>
> I have constructed the following test script for the semantic patch language.
>
> @check1@
> expression x;
> identifier rc;
> local idexpression lrc;
> position p;
> @@
> lrc@rc = x@p;
> return lrc;
>
> @check2@
> identifier check1.rc;
> position p;
> type t;
> @@
> t rc@p;
> ... when != rc
>
> @script:python to_do1@
> p << check1.p;
> @@
> coccilib.org.print_todo(p[0],
> "WARNING: An expression was assigned to a local variable before it will be returned by the subsequent statement.")
>
> @script:python to_do2@
> p << check2.p;
> v << check2.rc;
> @@
> coccilib.org.print_todo(p[0],
> "INFO: May the local variable \""
> + v
> + "\" be deleted?")
>
>
> I wonder about a corresponding test result.
>
> elfring@Sonne:~/Projekte/Coccinelle/janitor> spatch --parse-cocci move_code_to_return1.cocci
> …
> scriptmeta: semantic error: bad rule check2 or bad variable rc
> File "move_code_to_return1.cocci", line 26, column 14, charpos = 474
> around = ';',
> whole content = v << check2.rc;
>
>
> I imagine that it would be easier to understand that the content from
> the inherited metavariable can be directly used.
> The SmPL specification “v << check1.rc;” gets accepted by Coccinelle software
> and seems to work then in the way I would expect it also for the other script variant.
> Will any more adjustments become relevant for such a source code search approach?
rc comes from check1 so it should be inherited from check1.
julia
[-- Attachment #2: Type: text/plain, Size: 136 bytes --]
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [Cocci] Reducing source code around return statements with SmPL?
2019-09-24 15:30 ` Julia Lawall
@ 2019-09-24 15:40 ` Markus Elfring
[not found] ` <alpine.DEB.2.21.1909241750490.2281@hadrien>
2019-09-24 19:24 ` Markus Elfring
1 sibling, 1 reply; 31+ messages in thread
From: Markus Elfring @ 2019-09-24 15:40 UTC (permalink / raw)
To: Julia Lawall; +Cc: Coccinelle
> rc comes from check1 so it should be inherited from check1.
* Did you get any other impression from the specification “identifier check1.rc;”
in the SmPL rule “check2” for this test case?
* Can a SmPL specification like “v << check2.rc;” look also reasonable here
(despite of the error message which is reported so far)?
Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [Cocci] Reducing source code around return statements with SmPL?
2019-09-24 15:30 ` Julia Lawall
2019-09-24 15:40 ` Markus Elfring
@ 2019-09-24 19:24 ` Markus Elfring
2019-09-24 20:16 ` Julia Lawall
1 sibling, 1 reply; 31+ messages in thread
From: Markus Elfring @ 2019-09-24 19:24 UTC (permalink / raw)
To: Julia Lawall; +Cc: Coccinelle
> rc comes from check1 so it should be inherited from check1.
I stumble on understanding difficulties for the currently supported
software functionality.
@check1@
expression x;
identifier rc;
local idexpression lrc;
position p;
@@
lrc@rc = x@p;
return lrc;
@check2@
identifier check1.rc;
position p;
type t;
@@
t rc@p;
... when != rc
@script:python to_do1@
p << check1.p;
@@
coccilib.org.print_todo(p[0],
"WARNING: An expression was assigned to a local variable before it will be returned by the subsequent statement.")
@script:python to_do2@
p << check2.p;
v << check1.rc;
@@
coccilib.org.print_todo(p[0],
"INFO: May the local variable \""
+ v
+ "\" be deleted?")
elfring@Sonne:~/Projekte/Linux/next-patched> spatch ~/Projekte/Coccinelle/janitor/move_code_to_return2.cocci arch/arm64/kernel/ptrace.c
Three source code places are pointed out by the SmPL rule “to_do1”
as it would be expected.
Unfortunately, I miss the message “INFO: May the local variable "err" be deleted?”
for the function “ptrace_hbp_set_addr” according to the SmPL rule “to_do2”.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/kernel/ptrace.c?id=08f103b9a9502974109fab47ea35ca8542c4e57a#n451
Which adjustments will become relevant here?
Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [Cocci] Reducing source code around return statements with SmPL?
2019-09-24 19:24 ` Markus Elfring
@ 2019-09-24 20:16 ` Julia Lawall
2019-09-24 20:35 ` Markus Elfring
0 siblings, 1 reply; 31+ messages in thread
From: Julia Lawall @ 2019-09-24 20:16 UTC (permalink / raw)
To: Markus Elfring; +Cc: Coccinelle
[-- Attachment #1: Type: text/plain, Size: 1593 bytes --]
On Tue, 24 Sep 2019, Markus Elfring wrote:
> > rc comes from check1 so it should be inherited from check1.
>
> I stumble on understanding difficulties for the currently supported
> software functionality.
>
> @check1@
> expression x;
> identifier rc;
> local idexpression lrc;
> position p;
> @@
> lrc@rc = x@p;
> return lrc;
>
> @check2@
> identifier check1.rc;
> position p;
> type t;
> @@
> t rc@p;
> ... when != rc
>
> @script:python to_do1@
> p << check1.p;
> @@
> coccilib.org.print_todo(p[0],
> "WARNING: An expression was assigned to a local variable before it will be returned by the subsequent statement.")
>
> @script:python to_do2@
> p << check2.p;
> v << check1.rc;
> @@
> coccilib.org.print_todo(p[0],
> "INFO: May the local variable \""
> + v
> + "\" be deleted?")
>
>
> elfring@Sonne:~/Projekte/Linux/next-patched> spatch ~/Projekte/Coccinelle/janitor/move_code_to_return2.cocci arch/arm64/kernel/ptrace.c
>
> Three source code places are pointed out by the SmPL rule “to_do1”
> as it would be expected.
> Unfortunately, I miss the message “INFO: May the local variable "err" be deleted?”
> for the function “ptrace_hbp_set_addr” according to the SmPL rule “to_do2”.
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/kernel/ptrace.c?id=08f103b9a9502974109fab47ea35ca8542c4e57a#n451
>
> Which adjustments will become relevant here?
In that function err is used elsewhere, so the second message should not
be printed.
julia
[-- Attachment #2: Type: text/plain, Size: 136 bytes --]
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [Cocci] Reducing source code around return statements with SmPL?
2019-09-24 20:16 ` Julia Lawall
@ 2019-09-24 20:35 ` Markus Elfring
2019-09-24 20:49 ` Julia Lawall
0 siblings, 1 reply; 31+ messages in thread
From: Markus Elfring @ 2019-09-24 20:35 UTC (permalink / raw)
To: Julia Lawall; +Cc: Coccinelle
>> elfring@Sonne:~/Projekte/Linux/next-patched> spatch ~/Projekte/Coccinelle/janitor/move_code_to_return2.cocci arch/arm64/kernel/ptrace.c
>>
>> Three source code places are pointed out by the SmPL rule “to_do1”
>> as it would be expected.
>> Unfortunately, I miss the message “INFO: May the local variable "err" be deleted?”
>> for the function “ptrace_hbp_set_addr” according to the SmPL rule “to_do2”.
>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/kernel/ptrace.c?id=08f103b9a9502974109fab47ea35ca8542c4e57a#n451
>>
>> Which adjustments will become relevant here?
>
> In that function err is used elsewhere, so the second message should not
> be printed.
I disagree to this view (after the removal of previous uses).
The following SmPL script variant can point also questionable variable declarations out.
@check1@
expression x;
identifier rc;
local idexpression lrc;
position p;
@@
lrc@rc = x@p;
return lrc;
@check2@
identifier check1.rc;
position check1.p;
type t;
@@
t rc@p;
... when != rc
@script:python to_do1@
p << check1.p;
@@
coccilib.org.print_todo(p[0],
"WARNING: An expression was assigned to a local variable before it will be returned by the subsequent statement.")
@script:python to_do2@
p << check1.p;
v << check1.rc;
@@
coccilib.org.print_todo(p[0],
"INFO: May the local variable \""
+ v
+ "\" be deleted?")
But how should be achieved that the notification for declarations
which can be omitted will be presented only once for each affected local variable?
Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [Cocci] Reducing source code around return statements with SmPL?
2019-09-24 20:35 ` Markus Elfring
@ 2019-09-24 20:49 ` Julia Lawall
2019-09-24 20:55 ` Markus Elfring
2019-09-25 6:13 ` Markus Elfring
0 siblings, 2 replies; 31+ messages in thread
From: Julia Lawall @ 2019-09-24 20:49 UTC (permalink / raw)
To: Markus Elfring; +Cc: Coccinelle
[-- Attachment #1: Type: text/plain, Size: 1863 bytes --]
On Tue, 24 Sep 2019, Markus Elfring wrote:
> >> elfring@Sonne:~/Projekte/Linux/next-patched> spatch ~/Projekte/Coccinelle/janitor/move_code_to_return2.cocci arch/arm64/kernel/ptrace.c
> >>
> >> Three source code places are pointed out by the SmPL rule “to_do1”
> >> as it would be expected.
> >> Unfortunately, I miss the message “INFO: May the local variable "err" be deleted?”
> >> for the function “ptrace_hbp_set_addr” according to the SmPL rule “to_do2”.
> >> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/kernel/ptrace.c?id=08f103b9a9502974109fab47ea35ca8542c4e57a#n451
> >>
> >> Which adjustments will become relevant here?
> >
> > In that function err is used elsewhere, so the second message should not
> > be printed.
>
> I disagree to this view (after the removal of previous uses).
What is causing the previous uses to be removed?
julia
>
> The following SmPL script variant can point also questionable variable declarations out.
>
> @check1@
> expression x;
> identifier rc;
> local idexpression lrc;
> position p;
> @@
> lrc@rc = x@p;
> return lrc;
>
> @check2@
> identifier check1.rc;
> position check1.p;
> type t;
> @@
> t rc@p;
> ... when != rc
>
> @script:python to_do1@
> p << check1.p;
> @@
> coccilib.org.print_todo(p[0],
> "WARNING: An expression was assigned to a local variable before it will be returned by the subsequent statement.")
>
> @script:python to_do2@
> p << check1.p;
> v << check1.rc;
> @@
> coccilib.org.print_todo(p[0],
> "INFO: May the local variable \""
> + v
> + "\" be deleted?")
>
>
> But how should be achieved that the notification for declarations
> which can be omitted will be presented only once for each affected local variable?
>
> Regards,
> Markus
>
[-- Attachment #2: Type: text/plain, Size: 136 bytes --]
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [Cocci] Reducing source code around return statements with SmPL?
2019-09-23 8:59 ` Julia Lawall
2019-09-23 11:17 ` Markus Elfring
2019-09-24 15:27 ` Markus Elfring
@ 2019-09-24 18:20 ` Markus Elfring
2019-09-24 20:21 ` Julia Lawall
2019-09-24 18:33 ` Markus Elfring
2019-09-25 11:33 ` [Cocci] [PATCH] Coccinelle: Add a SmPL script for the reconsideration of specific combinations of assignment and return statements Markus Elfring
4 siblings, 1 reply; 31+ messages in thread
From: Markus Elfring @ 2019-09-24 18:20 UTC (permalink / raw)
To: Julia Lawall; +Cc: Coccinelle
>> @@
>> -rc = x;
>
> Replace by - lrc@rc = x;
I have constructed further test scripts for the semantic patch language.
@display1@
expression x;
identifier rc;
local idexpression lrc;
@@
(
if (...)
*{
*lrc@rc = x;
*return lrc;
*}
|
*lrc@rc = x;
*return lrc;
)
@display2@
identifier display1.rc;
type t;
@@
*t rc;
... when != rc
The following test result is generated so far for an example.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/kernel/ptrace.c?id=08f103b9a9502974109fab47ea35ca8542c4e57a
elfring@Sonne:~/Projekte/Linux/next-patched> spatch ~/Projekte/Coccinelle/janitor/show_code_for_moving_to_return1.cocci arch/arm64/kernel/ptrace.c
…
(ONCE) already tagged but only removed, so safe
…
@@ -290,7 +290,6 @@ static struct perf_event *ptrace_hbp_cre
{
struct perf_event *bp;
struct perf_event_attr attr;
- int err, type;
switch (note_type) {
case NT_ARM_HW_BREAK:
@@ -329,7 +328,6 @@ static int ptrace_hbp_fill_attr_ctrl(uns
struct arch_hw_breakpoint_ctrl ctrl,
struct perf_event_attr *attr)
{
- int err, len, type, offset, disabled = !ctrl.enabled;
attr->disabled = disabled;
if (disabled)
@@ -434,10 +432,6 @@ static int ptrace_hbp_set_ctrl(unsigned
struct arch_hw_breakpoint_ctrl ctrl;
bp = ptrace_hbp_get_initialised_bp(note_type, tsk, idx);
- if (IS_ERR(bp)) {
- err = PTR_ERR(bp);
- return err;
- }
attr = bp->attr;
decode_ctrl_reg(uctrl, &ctrl);
@@ -458,15 +452,9 @@ static int ptrace_hbp_set_addr(unsigned
struct perf_event_attr attr;
bp = ptrace_hbp_get_initialised_bp(note_type, tsk, idx);
- if (IS_ERR(bp)) {
- err = PTR_ERR(bp);
- return err;
- }
attr = bp->attr;
attr.bp_addr = addr;
- err = modify_user_hw_breakpoint(bp, &attr);
- return err;
}
#define PTRACE_HBP_ADDR_SZ sizeof(u64)
I suggest to compare this output with the following source code transformation approach.
@replacement@
expression x;
identifier rc;
local idexpression lrc;
@@
-lrc@rc = x;
return
- rc
+ x
;
@deletion@
identifier replacement.rc;
type t;
@@
-t rc;
... when != rc
elfring@Sonne:~/Projekte/Linux/next-patched> spatch ~/Projekte/Coccinelle/janitor/simplify_return2.cocci arch/arm64/kernel/ptrace.c
…
@@ -435,8 +435,7 @@ static int ptrace_hbp_set_ctrl(unsigned
bp = ptrace_hbp_get_initialised_bp(note_type, tsk, idx);
if (IS_ERR(bp)) {
- err = PTR_ERR(bp);
- return err;
+ return PTR_ERR(bp);
}
attr = bp->attr;
@@ -453,20 +452,17 @@ static int ptrace_hbp_set_addr(unsigned
unsigned long idx,
u64 addr)
{
- int err;
struct perf_event *bp;
struct perf_event_attr attr;
bp = ptrace_hbp_get_initialised_bp(note_type, tsk, idx);
if (IS_ERR(bp)) {
- err = PTR_ERR(bp);
- return err;
+ return PTR_ERR(bp);
}
attr = bp->attr;
attr.bp_addr = addr;
- err = modify_user_hw_breakpoint(bp, &attr);
- return err;
+ return modify_user_hw_breakpoint(bp, &attr);
}
#define PTRACE_HBP_ADDR_SZ sizeof(u64)
* Why are the functions “ptrace_hbp_create” and “ptrace_hbp_fill_attr_ctrl”
presented here?
* Why is the first variable declaration from the function “ptrace_hbp_set_addr”
not marked by the SmPL asterisk functionality in this test example?
Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [Cocci] Reducing source code around return statements with SmPL?
2019-09-24 18:20 ` Markus Elfring
@ 2019-09-24 20:21 ` Julia Lawall
2019-09-24 20:48 ` Markus Elfring
0 siblings, 1 reply; 31+ messages in thread
From: Julia Lawall @ 2019-09-24 20:21 UTC (permalink / raw)
To: Markus Elfring; +Cc: Coccinelle
[-- Attachment #1: Type: text/plain, Size: 3913 bytes --]
On Tue, 24 Sep 2019, Markus Elfring wrote:
> >> @@
> >> -rc = x;
> >
> > Replace by - lrc@rc = x;
>
> I have constructed further test scripts for the semantic patch language.
>
> @display1@
> expression x;
> identifier rc;
> local idexpression lrc;
> @@
> (
> if (...)
> *{
> *lrc@rc = x;
> *return lrc;
> *}
> |
> *lrc@rc = x;
> *return lrc;
> )
>
> @display2@
> identifier display1.rc;
> type t;
> @@
> *t rc;
> ... when != rc
>
>
> The following test result is generated so far for an example.
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/kernel/ptrace.c?id=08f103b9a9502974109fab47ea35ca8542c4e57a
>
> elfring@Sonne:~/Projekte/Linux/next-patched> spatch ~/Projekte/Coccinelle/janitor/show_code_for_moving_to_return1.cocci arch/arm64/kernel/ptrace.c
> …
> (ONCE) already tagged but only removed, so safe
> …
> @@ -290,7 +290,6 @@ static struct perf_event *ptrace_hbp_cre
> {
> struct perf_event *bp;
> struct perf_event_attr attr;
> - int err, type;
>
> switch (note_type) {
> case NT_ARM_HW_BREAK:
> @@ -329,7 +328,6 @@ static int ptrace_hbp_fill_attr_ctrl(uns
> struct arch_hw_breakpoint_ctrl ctrl,
> struct perf_event_attr *attr)
> {
> - int err, len, type, offset, disabled = !ctrl.enabled;
>
> attr->disabled = disabled;
> if (disabled)
> @@ -434,10 +432,6 @@ static int ptrace_hbp_set_ctrl(unsigned
> struct arch_hw_breakpoint_ctrl ctrl;
>
> bp = ptrace_hbp_get_initialised_bp(note_type, tsk, idx);
> - if (IS_ERR(bp)) {
> - err = PTR_ERR(bp);
> - return err;
> - }
>
> attr = bp->attr;
> decode_ctrl_reg(uctrl, &ctrl);
> @@ -458,15 +452,9 @@ static int ptrace_hbp_set_addr(unsigned
> struct perf_event_attr attr;
>
> bp = ptrace_hbp_get_initialised_bp(note_type, tsk, idx);
> - if (IS_ERR(bp)) {
> - err = PTR_ERR(bp);
> - return err;
> - }
>
> attr = bp->attr;
> attr.bp_addr = addr;
> - err = modify_user_hw_breakpoint(bp, &attr);
> - return err;
> }
>
> #define PTRACE_HBP_ADDR_SZ sizeof(u64)
>
>
>
> I suggest to compare this output with the following source code transformation approach.
>
> @replacement@
> expression x;
> identifier rc;
> local idexpression lrc;
> @@
> -lrc@rc = x;
> return
> - rc
> + x
> ;
>
> @deletion@
> identifier replacement.rc;
> type t;
> @@
> -t rc;
> ... when != rc
>
>
> elfring@Sonne:~/Projekte/Linux/next-patched> spatch ~/Projekte/Coccinelle/janitor/simplify_return2.cocci arch/arm64/kernel/ptrace.c
> …
> @@ -435,8 +435,7 @@ static int ptrace_hbp_set_ctrl(unsigned
>
> bp = ptrace_hbp_get_initialised_bp(note_type, tsk, idx);
> if (IS_ERR(bp)) {
> - err = PTR_ERR(bp);
> - return err;
> + return PTR_ERR(bp);
> }
>
> attr = bp->attr;
> @@ -453,20 +452,17 @@ static int ptrace_hbp_set_addr(unsigned
> unsigned long idx,
> u64 addr)
> {
> - int err;
> struct perf_event *bp;
> struct perf_event_attr attr;
>
> bp = ptrace_hbp_get_initialised_bp(note_type, tsk, idx);
> if (IS_ERR(bp)) {
> - err = PTR_ERR(bp);
> - return err;
> + return PTR_ERR(bp);
> }
>
> attr = bp->attr;
> attr.bp_addr = addr;
> - err = modify_user_hw_breakpoint(bp, &attr);
> - return err;
> + return modify_user_hw_breakpoint(bp, &attr);
> }
>
> #define PTRACE_HBP_ADDR_SZ sizeof(u64)
>
>
> * Why are the functions “ptrace_hbp_create” and “ptrace_hbp_fill_attr_ctrl”
> presented here?
What does "here" mean. You give two semantic patches with two sets of
output. Which is here?
> * Why is the first variable declaration from the function “ptrace_hbp_set_addr”
> not marked by the SmPL asterisk functionality in this test example?
I don't know what you ae referring to so I can't answer precisely, but you
should know that the only connection between your first two rules with a *
is the name of an identifier. There is no guarantee that the two rules
match code in the same function.
julia
[-- Attachment #2: Type: text/plain, Size: 136 bytes --]
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [Cocci] Reducing source code around return statements with SmPL?
2019-09-24 20:21 ` Julia Lawall
@ 2019-09-24 20:48 ` Markus Elfring
2019-09-24 20:52 ` Julia Lawall
0 siblings, 1 reply; 31+ messages in thread
From: Markus Elfring @ 2019-09-24 20:48 UTC (permalink / raw)
To: Julia Lawall; +Cc: Coccinelle
>> I suggest to compare this output with the following source code transformation approach.
…
>> * Why are the functions “ptrace_hbp_create” and “ptrace_hbp_fill_attr_ctrl”
>> presented here?
>
> What does "here" mean. You give two semantic patches with two sets of
> output. Which is here?
Please check the relevance of the mentioned two function names once more.
>> * Why is the first variable declaration from the function “ptrace_hbp_set_addr”
>> not marked by the SmPL asterisk functionality in this test example?
>
> I don't know what you ae referring to so I can't answer precisely,
Do you find corresponding links clearer?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/kernel/ptrace.c?id=08f103b9a9502974109fab47ea35ca8542c4e57a#n451
https://elixir.bootlin.com/linux/v5.3.1/source/arch/arm64/kernel/ptrace.c#L451
> but you should know that the only connection between your first two rules with a *
> is the name of an identifier.
I would expect that the selected identifier should refer to the same scope
of the enclosing function implementation.
> There is no guarantee that the two rules match code in the same function.
Will any additional metavariables be needed to achieve this?
Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [Cocci] Reducing source code around return statements with SmPL?
2019-09-24 20:48 ` Markus Elfring
@ 2019-09-24 20:52 ` Julia Lawall
2019-09-24 21:00 ` Markus Elfring
0 siblings, 1 reply; 31+ messages in thread
From: Julia Lawall @ 2019-09-24 20:52 UTC (permalink / raw)
To: Markus Elfring; +Cc: Coccinelle
[-- Attachment #1: Type: text/plain, Size: 1541 bytes --]
On Tue, 24 Sep 2019, Markus Elfring wrote:
> >> I suggest to compare this output with the following source code transformation approach.
> …
> >> * Why are the functions “ptrace_hbp_create” and “ptrace_hbp_fill_attr_ctrl”
> >> presented here?
> >
> > What does "here" mean. You give two semantic patches with two sets of
> > output. Which is here?
>
> Please check the relevance of the mentioned two function names once more.
>
>
> >> * Why is the first variable declaration from the function “ptrace_hbp_set_addr”
> >> not marked by the SmPL asterisk functionality in this test example?
> >
> > I don't know what you ae referring to so I can't answer precisely,
>
> Do you find corresponding links clearer?
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/kernel/ptrace.c?id=08f103b9a9502974109fab47ea35ca8542c4e57a#n451
> https://elixir.bootlin.com/linux/v5.3.1/source/arch/arm64/kernel/ptrace.c#L451
>
>
> > but you should know that the only connection between your first two rules with a *
> > is the name of an identifier.
>
> I would expect that the selected identifier should refer to the same scope
> of the enclosing function implementation.
It doesn't. Identifier metavariables have no scope, and scope is only
taken into account within a rule, not beterrn rules.
>
>
> > There is no guarantee that the two rules match code in the same function.
>
> Will any additional metavariables be needed to achieve this?
Maybe you can match the whole function definition.
julia
[-- Attachment #2: Type: text/plain, Size: 136 bytes --]
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [Cocci] Reducing source code around return statements with SmPL?
2019-09-24 20:52 ` Julia Lawall
@ 2019-09-24 21:00 ` Markus Elfring
2019-09-24 21:03 ` Julia Lawall
0 siblings, 1 reply; 31+ messages in thread
From: Markus Elfring @ 2019-09-24 21:00 UTC (permalink / raw)
To: Julia Lawall; +Cc: Coccinelle
>> I would expect that the selected identifier should refer to the same scope
>> of the enclosing function implementation.
>
> It doesn't. Identifier metavariables have no scope, and scope is only
> taken into account within a rule, not beterrn rules.
Will this information become relevant also for further improvements
of the software documentation?
Which object references can refer to items in an unique way?
Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [Cocci] Reducing source code around return statements with SmPL?
2019-09-24 21:00 ` Markus Elfring
@ 2019-09-24 21:03 ` Julia Lawall
2019-09-25 6:04 ` Markus Elfring
` (2 more replies)
0 siblings, 3 replies; 31+ messages in thread
From: Julia Lawall @ 2019-09-24 21:03 UTC (permalink / raw)
To: Markus Elfring; +Cc: Coccinelle
On Tue, 24 Sep 2019, Markus Elfring wrote:
> >> I would expect that the selected identifier should refer to the same scope
> >> of the enclosing function implementation.
> >
> > It doesn't. Identifier metavariables have no scope, and scope is only
> > taken into account within a rule, not beterrn rules.
>
> Will this information become relevant also for further improvements
> of the software documentation?
>
> Which object references can refer to items in an unique way?
Only positions are unique.
julia
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [Cocci] Reducing source code around return statements with SmPL?
2019-09-23 8:59 ` Julia Lawall
` (2 preceding siblings ...)
2019-09-24 18:20 ` Markus Elfring
@ 2019-09-24 18:33 ` Markus Elfring
2019-09-25 11:33 ` [Cocci] [PATCH] Coccinelle: Add a SmPL script for the reconsideration of specific combinations of assignment and return statements Markus Elfring
4 siblings, 0 replies; 31+ messages in thread
From: Markus Elfring @ 2019-09-24 18:33 UTC (permalink / raw)
To: Julia Lawall; +Cc: Coccinelle
>> @@
>> -rc = x;
>
> Replace by - lrc@rc = x;
I have constructed another test script for the semantic patch language.
@replacement@
expression x;
identifier rc;
local idexpression lrc;
@@
(
if (...)
-{
-lrc@rc = x;
return
- rc
+ x
;
-}
|
-lrc@rc = x;
return
- rc
+ x
;
)
@deletion@
identifier replacement.rc;
type t;
@@
-t rc;
... when != rc
Test result:
elfring@Sonne:~/Projekte/Linux/next-patched> spatch ~/Projekte/Coccinelle/janitor/move_code_to_return3.cocci arch/arm64/kernel/ptrace.c
…
previous modification:
MINUS
>>> x
According to environment 2:
replacement.x -> PTR_ERR(bp)
replacement.rc -> id err
current modification:
MINUS
>>> x
According to environment 2:
replacement.x -> PTR_ERR(bp)
replacement.rc -> id err
exn while in timeout_function
replacement: already tagged token:
C code context
File "arch/arm64/kernel/ptrace.c", line 439, column 9, charpos = 10084
around = 'err',
whole content = return err;
Will any software improvements be needed around the application
of SmPL disjunctions for such a source code transformation approach?
Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] 31+ messages in thread
* [Cocci] [PATCH] Coccinelle: Add a SmPL script for the reconsideration of specific combinations of assignment and return statements
2019-09-23 8:59 ` Julia Lawall
` (3 preceding siblings ...)
2019-09-24 18:33 ` Markus Elfring
@ 2019-09-25 11:33 ` Markus Elfring
2019-10-01 14:30 ` [Cocci] [PATCH v2] " Markus Elfring
4 siblings, 1 reply; 31+ messages in thread
From: Markus Elfring @ 2019-09-25 11:33 UTC (permalink / raw)
To: Julia Lawall, Coccinelle, kernel-janitors, Gilles Muller,
Masahiro Yamada, Michal Marek, Nicolas Palix
Cc: Kate Stewart, Greg Kroah-Hartman, LKML, Allison Randal
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 25 Sep 2019 11:55:24 +0200
Values from expressions were occasionally assigned to local variables
before they will be returned by the subsequent statement.
Such expressions can be directly specified in the return statement instead.
Adjust affected source code by the means of the semantic patch language
(Coccinelle software).
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
.../coccinelle/misc/move_code_to_return.cocci | 67 +++++++++++++++++++
1 file changed, 67 insertions(+)
create mode 100644 scripts/coccinelle/misc/move_code_to_return.cocci
diff --git a/scripts/coccinelle/misc/move_code_to_return.cocci b/scripts/coccinelle/misc/move_code_to_return.cocci
new file mode 100644
index 000000000000..78cdf84f9aaa
--- /dev/null
+++ b/scripts/coccinelle/misc/move_code_to_return.cocci
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: GPL-2.0
+/// Return expressions directly instead of assigning them to
+/// local variables immediately before affected statements.
+//
+// Keywords: return statements variable assignments coding style
+// Confidence: Medium
+
+virtual patch
+
+@replacement1 depends on patch@
+expression x;
+identifier f, rc;
+local idexpression lrc;
+type rt;
+@@
+ rt f(...)
+ {
+ ... when any
+ if (...)
+-{
+-lrc@rc = x;
+ return
+- rc
++ x
+ ;
+-}
+ ... when any
+ }
+
+@replacement2 depends on patch@
+expression x;
+identifier f, rc;
+local idexpression lrc;
+type rt;
+@@
+ rt f(...)
+ {
+ ... when any
+-lrc@rc = x;
+ return
+- rc
++ x
+ ;
+ ... when any
+ }
+
+@deletion2 depends on patch@
+identifier replacement2.f, replacement2.rc;
+type replacement2.rt, t;
+@@
+ rt f(...)
+ {
+ ... when any
+-t rc;
+ ... when != rc
+ }
+
+@deletion1 depends on patch@
+identifier replacement1.f, replacement1.rc;
+type replacement1.rt, t;
+@@
+ rt f(...)
+ {
+ ... when any
+-t rc;
+ ... when != rc
+ }
--
2.23.0
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [Cocci] [PATCH v2] Coccinelle: Add a SmPL script for the reconsideration of specific combinations of assignment and return statements
2019-09-25 11:33 ` [Cocci] [PATCH] Coccinelle: Add a SmPL script for the reconsideration of specific combinations of assignment and return statements Markus Elfring
@ 2019-10-01 14:30 ` Markus Elfring
0 siblings, 0 replies; 31+ messages in thread
From: Markus Elfring @ 2019-10-01 14:30 UTC (permalink / raw)
To: Julia Lawall, Coccinelle, kernel-janitors, Gilles Muller,
Masahiro Yamada, Michal Marek, Nicolas Palix
Cc: Kate Stewart, Greg Kroah-Hartman, LKML, Allison Randal
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 1 Oct 2019 15:50:10 +0200
Values from expressions were occasionally assigned to local variables
before they will be returned by the subsequent statement.
Such expressions can be directly specified in the return statement instead.
Adjust affected source code by the means of the semantic patch language
(Coccinelle software).
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
v2:
* Application of the SmPL construct “<+... … ...+>”
* Addition of a hint for the supported coccicheck operation modes
.../coccinelle/misc/move_code_to_return.cocci | 73 +++++++++++++++++++
1 file changed, 73 insertions(+)
create mode 100644 scripts/coccinelle/misc/move_code_to_return.cocci
diff --git a/scripts/coccinelle/misc/move_code_to_return.cocci b/scripts/coccinelle/misc/move_code_to_return.cocci
new file mode 100644
index 000000000000..22ce7c9d0fd2
--- /dev/null
+++ b/scripts/coccinelle/misc/move_code_to_return.cocci
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0
+/// Return expressions directly instead of assigning them to
+/// local variables immediately before affected statements.
+//
+// Keywords: return statements variable assignments coding style
+// Confidence: Medium
+
+virtual patch
+virtual report
+
+@replacement1 depends on patch@
+expression x;
+identifier f, rc;
+local idexpression lrc;
+type rt;
+@@
+ rt f(...)
+ {
+ <+...
+ if (...)
+-{
+-lrc@rc = x;
+ return
+- rc
++ x
+ ;
+-}
+ ...+>
+ }
+
+@replacement2 depends on patch@
+expression x;
+identifier f, rc;
+local idexpression lrc;
+type rt;
+@@
+ rt f(...)
+ {
+ <+...
+-lrc@rc = x;
+ return
+- rc
++ x
+ ;
+ ...+>
+ }
+
+@deletion2 depends on patch@
+identifier replacement2.f, replacement2.rc;
+type replacement2.rt, t;
+@@
+ rt f(...)
+ {
+ ... when any
+-t rc;
+ ... when != rc
+ }
+
+@deletion1 depends on patch@
+identifier replacement1.f, replacement1.rc;
+type replacement1.rt, t;
+@@
+ rt f(...)
+ {
+ ... when any
+-t rc;
+ ... when != rc
+ }
+
+@script:python info depends on report@
+@@
+import sys
+sys.stderr.write("INFO: Unfortunately, specific software limitations have got the consequence that only the operation mode “patch” can be supported by this SmPL script so far as expected.\n")
--
2.23.0
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply related [flat|nested] 31+ messages in thread