Searching compound statements without “if” filter (by SmPL)?
Hello,
A function implementation like “free_one” was identified as another update candidate.
https://elixir.bootlin.com/linux/v6.11/source/kernel/bpf/memalloc.c#L253
Questionable source code can be pointed out by a script variant for the semantic patch language like the following.
@display2@
expression x;
@@
{
<+...
if (...)
{
...
* kfree(x);
* return;
}
...+>
kfree(x);
}
May I expect that such a search approach should also work without the extra SmPL filter “if (...)”?
Regards,
Markus
Quoted 25 lines · Markus Elfring
Hello,
A function implementation like “free_one” was identified as another update candidate.
https://elixir.bootlin.com/linux/v6.11/source/kernel/bpf/memalloc.c#L253Questionable source code can be pointed out by a script variant for the semantic patch language like the following.
@display2@
expression x;
@@
{
<+...
if (...)
{
...
* kfree(x);
* return;
}
...+>
kfree(x);
}
Quoted 2 lines
May I expect that such a search approach should also work without the extra SmPL filter “if (...)”?
I don't understand why you want to get rid of the if.
julia
Quoted 4 lines
Regards,
Markus
Quoted 4 lines
Quoted 2 lines
May I expect that such a search approach should also work without the extra SmPL filter “if (...)”?
I don't understand why you want to get rid of the if.
There are more control flow variations possible which do not begin with such a key word before compound statements (source code blocks with curly brackets).
Will the support grow for this general use case?
Regards,
Markus
Quoted 9 lines · Markus Elfring
Quoted 4 lines
Quoted 2 lines
May I expect that such a search approach should also work without the extra SmPL filter “if (...)”?
I don't understand why you want to get rid of the if.
There are more control flow variations possible which do not begin with such a key word before compound statements (source code blocks with curly brackets).
Will the support grow for this general use case?
What is a real semantic patch that fais, or a real example of C code that you are not able to match?
julia
Quoted 6 lines
Quoted 4 lines
There are more control flow variations possible which do not begin with such a key word before compound statements (source code blocks with curly brackets).
Will the support grow for this general use case?What is a real semantic patch that fais,
// See also:
// [PATCH] bpf: Call kfree(obj) only once in free_one()
// https://lore.kernel.org/kernel-janitors/[email protected]/
// https://lkml.org/lkml/2024/9/26/634
@display@
expression x;
@@
{
<+...
{
...
*kfree(x);
*return;
}
...+>
kfree(x);
}
Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> spatch …/Projekte/Coccinelle/janitor/show_kfree_candidates_for_reduction.cocci kernel/bpf/memalloc.c …
I miss the presentation of a known source code place.
Quoted 1 line
or a real example of C code that you are not able to match?
I would occasionally like to avoid the extra specification of control flow key words for special source code search patterns.
Regards,
Markus
Quoted 4 lines
I miss the presentation of a known source code place.
Quoted 1 line
or a real example of C code that you are not able to match?
Would you like to compare such a questionable test result with other helpful data?
Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> time spatch -timeout 45 -j4 --chunksize 1 --no-loops -dir . …/Projekte/Coccinelle/janitor/show_kfree_candidates_for_reduction2.cocci > …/Projekte/Bau/Linux/scripts/Coccinelle/show_kfree_candidates_for_reduction2-no_loops-20240927.diff 2> …/Projekte/Bau/Linux/scripts/Coccinelle/show_kfree_candidates_for_reduction2-no_loops-errors-20240927.txt
real 6m39,686s user 23m18,287s sys 0m23,439s
…
Markus_Elfring@Sonne:/home/altes_Heim2/elfring/Projekte/Linux/next-analyses> lsdiff …/Projekte/Bau/Linux/scripts/Coccinelle/show_kfree_candidates_for_reduction2-no_loops-20240927.diff | wc -l 325
Will such information trigger any further software development considerations?
Regards,
Markus
Quoted 4 lines
Would you like to compare such a questionable test result with other helpful data?
Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> time spatch -timeout 45 -j4 --chunksize 1 --no-loops -dir . …/Projekte/Coccinelle/janitor/show_kfree_candidates_for_reduction2.cocci > …/Projekte/Bau/Linux/scripts/Coccinelle/show_kfree_candidates_for_reduction2-no_loops-20240927.diff 2> …/Projekte/Bau/Linux/scripts/Coccinelle/show_kfree_candidates_for_reduction2-no_loops-errors-20240927.txt
…
Quoted 5 lines
Markus_Elfring@Sonne:/home/altes_Heim2/elfring/Projekte/Linux/next-analyses> lsdiff …/Projekte/Bau/Linux/scripts/Coccinelle/show_kfree_candidates_for_reduction2-no_loops-20240927.diff | wc -l 325
Will such information trigger any further software development considerations?
Probably, yes. ;-)
Can an isomorphism be disabled so that the combination of a kfree() call and return statement will actually be presented instead of the case where the kfree() call is only performed once just before the closing curly bracket in found function implementations?
By the way:
Are you still looking for opportunities to benefit more from the application of scope-based resource management?
Regards,
Markus