Remove unnecessary null pointer checks?
Subsystems (270)
Hello,
I have tried the following short semantic patch out on a source file directory for Linux 3.13.1.
@Remove_unnecessary_pointer_checks@
expression x;
@@
-if (x)
kfree(x);
Some update candidates were found. I imagine that this search pattern can be extended a bit more.
How do think about the applicability of corresponding changes for current kernel source code?
What will be a good way to discuss such fixes on other mailing lists eventually?
Regards,
Markus
Quoted 9 lines · SF Markus Elfring
Hello,
I have tried the following short semantic patch out on a source file directory for Linux 3.13.1.
@Remove_unnecessary_pointer_checks@
expression x;
@@
-if (x)
Quoted 5 lines
kfree(x);Some update candidates were found. I imagine that this search pattern can be extended a bit more.
Not sure what you mean by extended. There are indeed some other functions in Linux that perform NULL tests before doing anything, and thus they don't really need a null test around them. Actually, it could be possible to find such functions using Coccinelle.
On the other hand, I think that one should study the code carefully before making such a change. There are several ways to make error handling code. One is to have one label at the end of the function, to have all error cases jump to there, and then to have if tests to decide what should be done. Another way is to have lots of labels, and jump directly to the right place, without any tests.
I think that the second way is nicer. So in removing such an if, one can consider whether the code could be further improved by adding more labels, and jumping to the right place directly, rather tha executing unnecessary code.
Quoted 3 lines
How do think about the applicability of corresponding changes for current kernel source code?
What will be a good way to discuss such fixes on other mailing lists eventually?
If you want to propose Linux related fixes, you may want to look at the kernel janitors mailing list.
http://vger.kernel.org/vger-lists.html#kernel-janitors
julia
Quoted 1 line
Not sure what you mean by extended.
I have tried the following search pattern.
@Show_functions_with_input_pointer_validation@
identifier fun, x;
type t;
@@
*fun(..., t* x, ...)
{
...
if (!x) return;
...
}
Will your current tool version "1.0.0-rc20" find also the kfree() functions?
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/mm/slab.c#n3641
Should I add any variant of "unlikely(ZERO_OR_NULL_PTR(...))" to my filter pattern eventually?
Quoted 2 lines
If you want to propose Linux related fixes, you may want to look at the kernel janitors mailing list.
Would it make sense to add the shown semantic patches to a specific script directory?
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/scripts/coccinelle
Regards,
Markus
Quoted 16 lines · SF Markus Elfring
Quoted 1 line
Not sure what you mean by extended.
I have tried the following search pattern.
@Show_functions_with_input_pointer_validation@
identifier fun, x;
type t;
@@
*fun(..., t* x, ...)
{
...
if (!x) return;
...
}
Quoted 5 lines
Will your current tool version "1.0.0-rc20" find also the
kfree()functions?
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/mm/slab.c#n3641Should I add any variant of "unlikely(ZERO_OR_NULL_PTR(...))" to my filter pattern eventually?
If you want to match a call to ZERO_OR_NULL_PTR, then you need to include that in the semantic patch. Coccinelle does not expand macros, so if doesn't see the relation to a NULL test.
Quoted 6 lines
Quoted 2 lines
If you want to propose Linux related fixes, you may want to look at the kernel janitors mailing list.
Would it make sense to add the shown semantic patches to a specific script directory?
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/scripts/coccinelle
Not sure to understand what the "shown semantic patches" refers to. What you have proposed is a semntic patch that finds functions that test their argument for NULL and return if the test is satisfied. That gives the user some information, but the rules in the Linux kernel are for finding bugs or making transformations.
Personally, I rather like null tests, if they are really needed, ie not implied to be always false by the context, because they give some information, eg that the value can be null at this point, and it is important to take that into account when considerin the following operation. So I'm not very eager to go around removing them.
julia
Quoted 3 lines
If you want to match a call to
ZERO_OR_NULL_PTR, then you need to include that in the semantic patch. Coccinelle does not expand macros, so if doesn't see the relation to a NULL test.
I have tried a command like the following a moment ago.
elfring at Sonne:~/Projekte/Coccinelle/janitor> MY_PATTERN=find_input_pointer_validation2.cocci && cat $MY_PATTERN && echo '-----' && spatch --version && spatch --sp-file $MY_PATTERN /usr/src/linux-stable/mm/slab.c --recursive-includes -I /usr/src/linux-stable/include/linux -I /usr/src/linux-stable/include/uapi -I /usr/src/linux-stable/arch/ia64/include -I /usr/src/linux-stable/include/asm-generic -I /usr/src/linux-stable/include/asm-generic/bitops -I /usr/local/include/c++/4.8.2 -I /usr/local/include/c++/4.8.2/x86_64-unknown-linux-gnu -I /usr/local/include -I /usr/include
@Show_functions_with_input_pointer_validation@
identifier fun, x;
type t;
@@
*void fun(..., t* x, ...)
{
...
if (unlikely(ZERO_OR_NULL_PTR(x)))
return;
...
}
-----
spatch version 1.0.0-rc20 with Python support and with PCRE supportinit_defs_builtins: ...
(ONCE) TYPE: header trace/events/kmem.h not found
previous modification:
MINUS
According to environment 2:
Show_functions_with_input_pointer_validation.t -> const
void
Show_functions_with_input_pointer_validation.fun -> id kfree
current modification:
MINUS
According to environment 2:
Show_functions_with_input_pointer_validation.t -> const void Show_functions_with_input_pointer_validation.fun -> id kfree
Fatal error: exception Failure("Show_functions_with_input_pointer_validation:
already tagged token:
C code context
File "/usr/src/linux-stable/mm/slab.c", line 3650, column 11, charpos = 94972
around = 'const', whole content = void kfree(const void *objp)")
How can I achieve a better result here?
Quoted 4 lines
What you have proposed is a semntic patch that finds functions that test their argument for NULL and return if the test is satisfied. That gives the user some information, but the rules in the Linux kernel are for finding bugs or making transformations.
I try to collect all names for functions which handle passed null pointers in a known way. I hope that such a function list can be converted into a constraint for a metavariable in another semantic patch variant.
Regards,
Markus
Quoted 1 line
Not sure what you mean by extended.
I would also like to try another source code search approach like the following.
elfring at Sonne:~/Projekte/Coccinelle/janitor> LINE='-----' && echo $LINE && PAT=list_input_parameter_validation1.cocci && cat $PAT && echo $LINE && SP=/usr/local/bin/spatch && $SP --version && $SP --sp-file $PAT /usr/src/linux-stable/fs/btrfs/extent_map.c
-----
@initialize:python@
@@
import sys
result = []
mark = ['"', '', '"']
delimiter = '|'
def store_positions(fun, typ, point, places):
"""Add source code positions to an internal list."""
for place in places:
fields = []
fields.append(fun)
mark[1] = typ
fields.append(''.join(mark))
fields.append(point)
mark[1] = place.file.replace('"', '""')
fields.append(''.join(mark))
fields.append(place.line)
fields.append(str(int(place.column) + 1))
result.append(delimiter.join(fields))@safety_check@
identifier work, input;
type data_type;
position pos;
@@
void work at pos(...,data_type input,...)
{
...
(
if (!input) return;
|
if (input) { ... }
|
if (input) { ... } else { ... }
|
switch (input) { case 0: return; ... }
)
...
}
@script:python collection depends on safety_check@ typ << safety_check.data_type;
fun << safety_check.work;
point << safety_check.input;
places << safety_check.pos;
@@store_positions(fun, typ, point, places)
@finalize:python@
@@
if result:
result.insert(0, delimiter.join(("function", '"data type"', '"parameter"',
'"source file"', "line", "column")))
print("\r\n".join(result))
else:
sys.stderr.write("No result for this analysis!\n")
-----
spatch version 1.0.0-rc20 with Python support and with PCRE supportinit_defs_builtins: /usr/local/share/coccinelle/standard.h
HANDLING: /usr/src/linux-stable/fs/btrfs/extent_map.c
No result for this analysis!
Why is the function "free_extent_map" not displayed here? Do I need to adjust my SmPL rule "safety_check" anyhow?
Regards,
Markus
Something goes wrong with the switch pattern. I would have to look into why. But I think that a switch is highly improbable for making such a test, so you could just drop it. You may also want to specify that input has pointer type, since you are actually looking for NULL tests, not zero tests.
julia
Quoted 83 lines · SF Markus Elfring
Quoted 1 line
Not sure what you mean by extended.
I would also like to try another source code search approach like the following.
elfring at Sonne:~/Projekte/Coccinelle/janitor> LINE='-----' && echo $LINE && PAT=list_input_parameter_validation1.cocci && cat $PAT && echo $LINE && SP=/usr/local/bin/spatch && $SP --version && $SP --sp-file $PAT
/usr/src/linux-stable/fs/btrfs/extent_map.c
-----
@initialize:python@
@@
import sys
result = []
mark = ['"', '', '"']
delimiter = '|'def
store_positions(fun, typ, point, places):"""Add source code positions to an internal list.""" for place in places: fields = [] fields.append(fun) mark[1] = typ fields.append(''.join(mark)) fields.append(point) mark[1] = place.file.replace('"', '""') fields.append(''.join(mark)) fields.append(place.line) fields.append(str(int(place.column) + 1)) result.append(delimiter.join(fields))@safety_check@
identifier work, input;
typedata_type;
position pos;
@@
void work atpos(...,data_type input,...)
{
...
(
if (!input) return;
|
if (input) { ... }
|
if (input) { ... } else { ... }
|
switch (input) { case 0: return; ... }
)
...
}@script:python collection depends on safety_check@ typ << safety_check.data_type;
fun << safety_check.work;
point << safety_check.input;
places << safety_check.pos;
@@store_positions(fun, typ, point, places)@finalize:python@
@@
if result:result.insert(0, delimiter.join(("function", '"data type"', '"parameter"','"source file"', "line", "column")))
print("\r\n".join(result))
else:
sys.stderr.write("No result for this analysis!\n")
-----
spatch version 1.0.0-rc20 with Python support and with PCRE supportinit_defs_builtins:/usr/local/share/coccinelle/standard.h
HANDLING:/usr/src/linux-stable/fs/btrfs/extent_map.c
No result for this analysis!Why is the function "
free_extent_map" not displayed here? Do I need to adjust my SmPL rule "safety_check" anyhow?Regards,
Markus
Quoted 1 line
Something goes wrong with the switch pattern. I would have to look into why.
Thanks for your quick feedback.
Quoted 2 lines
But I think that a switch is highly improbable for making such a test, so you could just drop it.
I just try to make the discussed filter patterns as complete as possible.
Quoted 2 lines
You may also want to specify that input has pointer type, since you are actually looking for NULL tests, not zero tests.
This is an important implementation detail which I would like to generalise so that also functions like "btrfsic_process_written_block" will be safely found by further source code searches.
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/fs/btrfs/check-integrity.c?id=878a876b2e10888afe53766dcca33f723ae20edc#n1835
This one was found by the previous simple pattern for example despite I expected it to handle primarily pointer data types instead of an "unsigned int" in this case.
Regards,
Markus
Quoted 10 lines
Quoted 2 lines
You may also want to specify that input has pointer type, since you are actually looking for NULL tests, not zero tests.
This is an important implementation detail which I would like to generalise so that also functions like "
btrfsic_process_written_block" will be safely found by further source code searches.
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/fs/btrfs/check-integrity.c?id=878a876b2e10888afe53766dcca33f723ae20edc#n1835This one was found by the previous simple pattern for example despite I expected it to handle primarily pointer data types instead of an "unsigned int" in this case.
As you like. As a general principle, I think it is better to work on fewer things at once. There are many reason why values may be null or 0, and if you lump too many of them together, you will end up with more information than is manageable. No bugs are involved here, you are only making the code simpler, and if you miss some possibilities for making the code simpler, it doesn't matter. You can just work on them later.
julia
Quoted 2 lines
But I think that a switch is highly improbable for making such a test, so you could just drop it.
I have got another idea for a bit of fine-tuning. I got the impression from the manual that the SmPL syntax element "singleton" might be applicable.
elfring at Sonne:~/Projekte/Coccinelle/janitor> LINE='-----' && echo $LINE && PAT=list_input_parameter_validation2.cocci && cat $PAT && echo $LINE && SP=/usr/local/bin/spatch && $SP --version && $SP --sp-file $PAT /usr/src/linux-stable/fs/btrfs/extent_map.c
-----
@initialize:python@
@@
import sys
result = []
mark = ['"', '', '"']
delimiter = '|'
def store_positions(fun, typ, point, places):
"""Add source code positions to an internal list."""
for place in places:
fields = []
fields.append(fun)
mark[1] = typ
fields.append(''.join(mark))
fields.append(point)
mark[1] = place.file.replace('"', '""')
fields.append(''.join(mark))
fields.append(place.line)
fields.append(str(int(place.column) + 1))
result.append(delimiter.join(fields))@safety_check@
identifier work, input;
type data_type;
position pos;
statement is, es;
@@
void work at pos(...,data_type input,...)
{
...
( if (!input) return;
| if (input) is
? else es
;
)
...
}
@script:python collection depends on safety_check@ typ << safety_check.data_type;
fun << safety_check.work;
point << safety_check.input;
places << safety_check.pos;
@@store_positions(fun, typ, point, places)
@finalize:python@
@@
if result:
result.insert(0, delimiter.join(("function", '"data type"', '"parameter"',
'"source file"', "line", "column")))
print("\r\n".join(result))
else:
sys.stderr.write("No result for this analysis!\n")
-----
spatch version 1.0.0-rc20 with Python support and with PCRE supportinit_defs_builtins: /usr/local/share/coccinelle/standard.h
warning: incompatible arity found on line 36
?safety_check:es
Fatal error: exception Failure("get_before_e: not supported")
Can this situation be improved?
Regards,
Markus
Quoted 10 lines · SF Markus Elfring
Quoted 2 lines
But I think that a switch is highly improbable for making such a test, so you could just drop it.
I have got another idea for a bit of fine-tuning. I got the impression from the manual that the SmPL syntax element "singleton" might be applicable.
elfring at Sonne:~/Projekte/Coccinelle/janitor> LINE='-----' && echo $LINE && PAT=list_input_parameter_validation2.cocci && cat $PAT && echo $LINE && SP=/usr/local/bin/spatch && $SP --version && $SP --sp-file $PAT
/usr/src/linux-stable/fs/btrfs/extent_map.c
Please don't put all of this noise in your messages. The only thing that is interesting is the file on which you have run Coccinelle.
Quoted 28 lines
-----
@initialize:python@
@@
import sys
result = []
mark = ['"', '', '"']
delimiter = '|'def
store_positions(fun, typ, point, places):"""Add source code positions to an internal list.""" for place in places: fields = [] fields.append(fun) mark[1] = typ fields.append(''.join(mark)) fields.append(point) mark[1] = place.file.replace('"', '""') fields.append(''.join(mark)) fields.append(place.line) fields.append(str(int(place.column) + 1)) result.append(delimiter.join(fields))
Quoted 13 lines
@safety_check@
identifier work, input;
typedata_type;
position pos;
statement is, es;
@@
void work atpos(...,data_type input,...)
{
...
( if (!input) return;
| if (input) is
? else es
;
There is no need to put the ? else es. If you put if (intput) is else es then an isomorphism will consider the case where else es is not there.
Also, the semicolon after is/es does not look right. Notmally one does not put an extra semicolon after an if.
julia
Quoted 34 lines
)
...
}@script:python collection depends on safety_check@ typ << safety_check.data_type;
fun << safety_check.work;
point << safety_check.input;
places << safety_check.pos;
@@store_positions(fun, typ, point, places)@finalize:python@
@@
if result:result.insert(0, delimiter.join(("function", '"data type"', '"parameter"','"source file"', "line", "column")))
print("\r\n".join(result))
else:
sys.stderr.write("No result for this analysis!\n")
-----
spatch version 1.0.0-rc20 with Python support and with PCRE supportinit_defs_builtins:/usr/local/share/coccinelle/standard.h
warning: incompatible arity found on line 36 ?safety_check:es
Fatal error: exceptionFailure("get_before_e: not supported")Can this situation be improved?
Regards,
Markus
Quoted 1 line
There is no need to put the ? else es.
Thanks for your explanation.
I get a "surprise" if I try out the following SmPL variant.
@safety_check@
identifier function, input;
type data_type;
position pos;
statement is, es;
@@
void function at pos(...,data_type input,...)
{
...
( if (!input) return;
| if (input) is else es
)
...
}
@script:python collection depends on safety_check@ typ << safety_check.data_type;
fun << safety_check.function;
point << safety_check.input;
places << safety_check.pos;
@@store_positions(fun, typ, point, places)
Response:
875 883
Fatal error: exception Failure("scriptmeta: parse error:
= File "list_input_parameter_validation3.cocci", line 43, column 20, charpos = 875
around = 'function', whole content = fun << safety_check.function;
Can such names be reused which are key words@other places?
Regards,
Markus
Quoted 30 lines · SF Markus Elfring
Quoted 1 line
There is no need to put the ? else es.
Thanks for your explanation.
I get a "surprise" if I try out the following SmPL variant.
@safety_check@
identifier function, input;
typedata_type;
position pos;
statement is, es;
@@
void function atpos(...,data_type input,...)
{
...
( if (!input) return;
| if (input) is else es
)
...
}@script:python collection depends on safety_check@ typ << safety_check.data_type;
fun << safety_check.function;
point << safety_check.input;
places << safety_check.pos;
@@store_positions(fun, typ, point, places)
Quoted 8 lines
Response:
875 883
Fatal error: exception Failure("scriptmeta: parse error:
= File "list_input_parameter_validation3.cocci", line 43, column 20, charpos = 875around = 'function', whole content = fun << safety_check.function;Can such names be reused which are key words at other places?
Apparently there is a problem in this case. I will make a note of it. In the meantime, just use another name.
julia
Quoted 1 line
There is no need to put the ? else es.
I get the following result for the adjusted search pattern.
void work at pos(...,data_type input,...)
{
...
( if (!input) return;
| if (input) is else es
)
...
}
elfring at Sonne:~/Projekte/Coccinelle/janitor> spatch --sp-file list_input_parameter_validation2.cocci /usr/src/linux-stable/arch/um/kernel/sysrq.c
...
function|"data type"|"parameter"|"source file"|line|column show_stack|"unsigned long *"|stack|"/usr/src/linux-stable/arch/um/kernel/sysrq.c"|67|6
This example does not fit to my expectation because it seems that the function implementation does not refer to the passed values.
Do you get any idea for this potential mismatch?
Regards,
Markus
Quoted 22 lines · SF Markus Elfring
Quoted 1 line
There is no need to put the ? else es.
I get the following result for the adjusted search pattern.
void work at
pos(...,data_type input,...)
{
...
( if (!input) return;
| if (input) is else es
)
...
}elfring at Sonne:~/Projekte/Coccinelle/janitor> spatch --sp-file
list_input_parameter_validation2.cocci/usr/src/linux-stable/arch/um/kernel/sysrq.c
...
function|"data type"|"parameter"|"source file"|line|column show_stack|"unsigned long *"|stack|"/usr/src/linux-stable/arch/um/kernel/sysrq.c"|67|6
Quoted 3 lines
This example does not fit to my expectation because it seems that the function implementation does not refer to the passed values.
Do you get any idea for this potential mismatch?
I'm not sure, but I think it has to do with the fact that the entire function is an if where both branches leave the function. It seems to be considering that to be error-handling code. It does not require to find the complete pattern on execution paths that correspond to error-handling code. So it doesn't require to find the pattern at all.
In your case, I think you want to be completely sure that regardless of the execution path chosen, the test is performed. So you should put when string after the first ... (ie the one after the first { ).
julia
Quoted 2 lines
Quoted 2 lines
This example does not fit to my expectation because it seems that the function implementation does not refer to the passed values.
I must correct my conclusion here. One function parameter is actually used in the condition "!stack" while the second parameter is forwarded to other function calls.
Is this source code line 83 handled by a SmPL isomorphism?
Quoted 3 lines
In your case, I think you want to be completely sure that regardless of the execution path chosen, the test is performed. So you should put when string after the first ... (ie the one after the first { ).
I'm sorry. I do not really understand your suggestion.
Regards,
Markus
Quoted 22 lines · SF Markus Elfring
Quoted 1 line
There is no need to put the ? else es.
I get the following result for the adjusted search pattern.
void work at
pos(...,data_type input,...)
{
...
( if (!input) return;
| if (input) is else es
)
...
}elfring at Sonne:~/Projekte/Coccinelle/janitor> spatch --sp-file
list_input_parameter_validation2.cocci/usr/src/linux-stable/arch/um/kernel/sysrq.c
...
function|"data type"|"parameter"|"source file"|line|column show_stack|"unsigned long *"|stack|"/usr/src/linux-stable/arch/um/kernel/sysrq.c"|67|6
Quoted 3 lines
This example does not fit to my expectation because it seems that the function implementation does not refer to the passed values.
Do you get any idea for this potential mismatch?
Sorry, I had been looking at the wrong function when I wrote my previous response.
Indeed, there are some uses of isomorphisms at work here. First the
if (input) is else es
is changed to
if (!input) es else is
and then that is changed to
if (!input) es
which matches the code at line 83.
I'm not sure what is the point of the if (input) is else es pattern. I would think you only want to find cases where the function does nothing until it tests input and aborts the function is the value is 0. So you only want the return case. Before it, you would want
... when != S
where S is a statement typed metavariable. That way the ... will only match declarations.
julia
Quoted 1 line
I'm not sure what is the point of the if (input) is else es pattern.
Now it seems that I added it because of too few considerations for isomorphisms.
Quoted 8 lines
I would think you only want to find cases where the function does nothing until it tests input and aborts the function is the value is 0. So you only want the return case. Before it, you would want
... when != S
where S is a statement typed metavariable. That way the ... will only match declarations.
We have got different expectations about the amount of source code before the statement "return". A bit more fine-tuning with the SmPL construct "when" might be needed to achieve further constraints.
Regards,
Markus
Quoted 2 lines
Quoted 2 lines
This example does not fit to my expectation because it seems that the function implementation does not refer to the passed values.
I'm sorry that I overlooked information somehow there.
The implementations of the function "show_stack" can be nice source code examples for further fine-tuning of proposed filter patterns.
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/arch/um/kernel/sysrq.c?id=8ed12fcc194d93c6a17714120a7027ee4d76a881#n67
Its interface contains two pointer parameters.
Quoted 1 line
I'm not sure what is the point of the if (input) is else es pattern.
I can also adjust the search approach like the following.
@safety_check@
identifier work, input;
type data_type;
position pos;
statement is, es;
@@
void work at pos(...,data_type input,...)
{
...
( if (input) is
| if (likely(input)) is
)
else es
...
}
Quoted 2 lines
I would think you only want to find cases where the function does nothing until it tests input and aborts the function is the value is 0.
I guess that the interpretation of "nothing relevant" will need further considerations, won't it?
Quoted 1 line
So you only want the return case.
Not "only" this one ...
I have got a feeling for a need to introspect the else branch for useful properties. I am unsure about better analysis of the metavariable "es" with the semantic patch language.
Regards,
Markus
Quoted 15 lines
I can also adjust the search approach like the following.
@safety_check@
identifier work, input;
typedata_type;
position pos;
statement is, es;
@@
void work atpos(...,data_type input,...)
{
...
( if (input) is
| if (likely(input)) is
)
else es
This is not allowed. Inside a disjunction you need to have complete terms.
Quoted 11 lines
...
}Quoted 2 lines
I would think you only want to find cases where the function does nothing until it tests input and aborts the function is the value is 0.
I guess that the interpretation of "nothing relevant" will need further considerations, won't it?
Quoted 7 lines
Quoted 1 line
So you only want the return case.
Not "only" this one ...
I have got a feeling for a need to introspect the else branch for useful properties. I am unsure about better analysis of the metavariable "es" with the semantic patch language.
I'm not sure to understand your goal. If the code currently has:
if (x != NULL)
call(x);
then the developer does not want to execute any of the code within call if x is NULL. If you just check that there is a NULL test on x somewhere within the definition of call, then that is not enough to ensure that nothing is executed within call. If you remove the NULL test, you could drastically change the behavior of the program.
julia
Quoted 1 line
This is not allowed. Inside a disjunction you need to have complete terms.
Thanks for your information. I guess that another adjustment will fit to the SmPL syntax then.
( if (input) is else es
| if (likely(input)) is else es
)
Quoted 7 lines
I'm not sure to understand your goal. If the code currently has:
if (x != NULL)
call(x);then the developer does not want to execute any of the code within call if x is NULL.
Yes. - This is one of the use cases I am trying to improve. It depends on the knowledge if something unwanted will happen if a null pointer (or zero) would be passed. If it is documented for example that an implementation of the function "call" checks the condition "!= NULL", I find the same check by the caller redundant.
Quoted 2 lines
If you just check that there is a NULL test on x somewhere within the definition of call, then that is not enough to ensure that nothing is executed within call.
Would you like to suggest any more fine-tuning?
Quoted 1 line
If you remove the NULL test, you could drastically change the behavior of the program.
I agree in principle.
But I would like to delete redundant checks from some source files.
Regards,
Markus
Quoted 1 line
I'm not sure to understand your goal.
I get an interesting result for example if I try the following source code search pattern out. Do you find it useful?
@Delete_unnecessary_checks@
expression x;
identifier release =~ "^(?x)
(?:
(?:kz?|slob_)free
|
(?:
abc
| xyz
)
)$";
@@
-if (x)
release(...,x,...);
elfring at Sonne:~/Projekte/Coccinelle/janitor> spatch --sp-file delete_unnecessary_checks1.cocci /usr/src/linux-stable/fs/btrfs/inode.cinit_defs_builtins: /usr/local/share/coccinelle/standard.h
HANDLING: /usr/src/linux-stable/fs/btrfs/inode.c
tmp/cocci-output-3740-5d95d8-inode.c renamed from usr/src/linux-stable/fs/btrfs/inode.c +1 -2
@@ -5137,8 +5137,7 @@ static int btrfs_dentry_delete(const strstatic void btrfs_dentry_release (struct dentry *dentry) { -if (dentry->d_fsdata) -kfree (dentry->d_fsdata); +kfree (dentry->d_fsdata); }
Quoted 2 lines
If you remove the NULL test, you could drastically change the behavior of the program.
But it seems that I stumble on a software debug challenge after I replaced the dummy alternation in the regular expression above by the real list of 5142 function names which were found by the other discussed pattern.
elfring at Sonne:~/Projekte/Coccinelle/janitor> spatch --sp-file delete_unnecessary_checks2.cocci /usr/src/linux-stable/fs/btrfs/inode.cinit_defs_builtins: /usr/local/share/coccinelle/standard.h Fatal error: exception Pcre.Error(_)
Regards,
Markus
Quoted 40 lines · SF Markus Elfring
Quoted 1 line
I'm not sure to understand your goal.
I get an interesting result for example if I try the following source code search pattern out. Do you find it useful?
@Delete_unnecessary_checks@
expression x;
identifier release =~ "^(?x)
(?:(?:kz?|slob_)free|
(?:
abc
| xyz
)
)$";
@@
-if (x)release(...,x,...);elfring at Sonne:~/Projekte/Coccinelle/janitor> spatch --sp-file
delete_unnecessary_checks1.cocci/usr/src/linux-stable/fs/btrfs/inode.cinit_defs_builtins:/usr/local/share/coccinelle/standard.h
HANDLING:/usr/src/linux-stable/fs/btrfs/inode.c
diff =tmp/cocci-output-3740-5d95d8-inode.c renamed from usr/src/linux-stable/fs/btrfs/inode.c +1
-2@@ -5137,8 +5137,7 @@ static int btrfs_dentry_delete(const strstatic void btrfs_dentry_release (struct dentry *dentry) { -if (dentry->d_fsdata) -kfree (dentry->d_fsdata); +kfree (dentry->d_fsdata); }Quoted 2 lines
If you remove the NULL test, you could drastically change the behavior of the program.
Quoted 8 lines
But it seems that I stumble on a software debug challenge after I replaced the dummy alternation in the regular expression above by the real list of 5142 function names which were found by the other discussed pattern.
elfring at Sonne:~/Projekte/Coccinelle/janitor> spatch --sp-file
delete_unnecessary_checks2.cocci/usr/src/linux-stable/fs/btrfs/inode.cinit_defs_builtins:/usr/local/share/coccinelle/standard.hFatal error: exceptionPcre.Error(_)
I don't think it is a good approach to do anything related to 5142 different functions at once. It would be better to pick a small set of functions, and work on them carefully.
julia
Quoted 2 lines
I don't think it is a good approach to do anything related to 5142 different functions at once.
A source code search with the following pattern found only six functions for further consideration.
@is_unnecessary_check@
expression data;
identifier work;
identifier release =~ "^kz?free$";
position pos;
type t;
@@
t work at pos(...)
{
...
( if (data) release(data);
| if (likely(data)) release(data);
)
...
}
I wonder a bit about this analysis result because the SmPL pattern I started this discussion thread with showed a few more update candidates.
Quoted 1 line
It would be better to pick a small set of functions, and work on them carefully.
I would prefer to handle a more complete fix pattern.
By the way: I read about corresponding software update approaches in an article "Best practices for a big patch series" by Wolfram Sang.
How are the chances to resolve the message "Fatal error: exception Pcre.Error(_)" with a proposed long alternation?
Regards,
Markus
Quoted 23 lines · SF Markus Elfring
Quoted 2 lines
I don't think it is a good approach to do anything related to 5142 different functions at once.
A source code search with the following pattern found only six functions for further consideration.
@is_unnecessary_check@
expression data;
identifier work;
identifier release =~ "^kz?free$";
position pos;
type t;
@@
t work at pos(...)
{
...
( if (data) release(data);
| if (likely(data)) release(data);
)
...
}
Quoted 2 lines
I wonder a bit about this analysis result because the SmPL pattern I started this discussion thread with showed a few more update candidates.
Remember that ... matches the shortest path between what is before and what is after. So if there is another if test on the same data in the function, that will cause a failure. If yo udon't care to have this constraint, you can put when any on a ...
Quoted 4 lines
Quoted 2 lines
It would be better to pick a small set of functions, and work on them carefully.
I would prefer to handle a more complete fix pattern.
As you like, but I think that no Linux maintainer will accept a patch that makes more than a few changes, so doing them all at once is a waste of time. Anyway, you would have to split up the patches according to maintainer.
Quoted 6 lines
By the way: I read about corresponding software update approaches in an article "Best practices for a big patch series" by Wolfram Sang.
How are the chances to resolve the message "Fatal error: exception
Pcre.Error(_)" with a proposed long alternation?
Pcre is a standard library. I know nothing about its implementation. But it is not surprising that a regular expression with over 5000 options exceeds its capacity.
julia
[Cocci] Source code analysis with big regular expressions?
Quoted 3 lines
Pcre is a standard library. I know nothing about its implementation. But it is not surprising that a regular expression with over 5000 options exceeds its capacity.
Are there any chances to find the source code place from which the exception "Pcre.Error(_)" was thrown?
Regards,
Markus
[Cocci] Source code analysis with big regular expressions?
Quoted 6 lines · SF Markus Elfring
Quoted 3 lines
Pcre is a standard library. I know nothing about its implementation. But it is not surprising that a regular expression with over 5000 options exceeds its capacity.
Are there any chances to find the source code place from which the exception "
Pcre.Error(_)" was thrown?
Set the OCAMLRUNPARAM environment variable to b in your shell. I don't know if it is necessary to recompile coccinelle. Then when it crashes you will get a backtrace.
julia
[Cocci] Source code analysis with big regular expressions?
Quoted 3 lines
Set the OCAMLRUNPARAM environment variable to b in your shell. I don't know if it is necessary to recompile coccinelle. Then when it crashes you will get a backtrace.
elfring at Sonne:~/Projekte/Coccinelle/janitor> export OCAMLRUNPARAM=b && spatch --sp-file delete_unnecessary_checks2.cocci /usr/src/linux-stable/fs/btrfs/inode.cinit_defs_builtins:/usr/local/share/coccinelle/standard.h
Fatal error: exception Pcre.Error(_)
Called from file "engine.ml", line 206, characters 1-27
Called from file "engine.ml", line 359, characters 23-36
How much can this information help us here?
Regards,
Markus
[Cocci] Source code analysis with big regular expressions?
Quoted 13 lines · SF Markus Elfring
Quoted 3 lines
Set the OCAMLRUNPARAM environment variable to b in your shell. I don't know if it is necessary to recompile coccinelle. Then when it crashes you will get a backtrace.
elfring at Sonne:~/Projekte/Coccinelle/janitor> export OCAMLRUNPARAM=b && spatch --sp-file
delete_unnecessary_checks2.cocci/usr/src/linux-stable/fs/btrfs/inode.cinit_defs_builtins:/usr/local/share/coccinelle/standard.h
Fatal error: exceptionPcre.Error(_)
Called from file "engine.ml", line 206, characters 1-27
Called from file "engine.ml", line 359, characters 23-36
Quoted 1 line
How much can this information help us here?
Those two lines at least are not from Coccinelle, so I guess that they are from the PCRE implementation. But I don't think there is anything to do. The regular expression engine is just not likely to be designed to support such a large regular expression.
If you like you can give each of the function names one by one as a command line argument. Eg
spatch file.cocci file.c -D fn=whatever
and then in your semantic patch
@@
identifier virtual.fn;
@@
... use fn as an identifier ...
julia
[Cocci] Source code analysis with big regular expressions?
Quoted 2 lines
Those two lines at least are not from Coccinelle, so I guess that they are from the PCRE implementation.
Are there any chances to retrieve a more detailed error information?
Quoted 2 lines
The regular expression engine is just not likely to be designed to support such a large regular expression.
I would try to compare the processing of big patterns with similar interfaces from other software.
Quoted 2 lines
If you like you can give each of the function names one by one as a command line argument.
I imagine that this approach will result also in different opinions about a useful patch granularity.
http://lwn.net/Articles/585782/
Regards,
Markus
[Cocci] Source code analysis with big regular expressions?
Quoted 13 lines · SF Markus Elfring
Quoted 2 lines
Those two lines at least are not from Coccinelle, so I guess that they are from the PCRE implementation.
Are there any chances to retrieve a more detailed error information?
Quoted 2 lines
The regular expression engine is just not likely to be designed to support such a large regular expression.
I would try to compare the processing of big patterns with similar interfaces from other software.
Quoted 6 lines
Quoted 2 lines
If you like you can give each of the function names one by one as a command line argument.
I imagine that this approach will result also in different opinions about a useful patch granularity.
http://lwn.net/Articles/585782/
In my opinion, the change you are proposing is controversial. Particular code instances may be corrected in a better way. If you try to do everything at once then the kernel maintainer will have a big block that he has to either accept or reject. If there is one change that is not made in the best way, then he will have to reject it.
On the other hand, if you do a few things at a time, then most of the individual things you do will perhaps be noncontroversial.
julia
Quoted 4 lines
Remember that ... matches the shortest path between what is before and what is after. So if there is another if test on the same data in the function, that will cause a failure. If yo udon't care to have this constraint, you can put when any on a ...
Which SmPL "when variant" would you recommend here?
Regards,
Markus
Quoted 6 lines · SF Markus Elfring
Quoted 4 lines
Remember that ... matches the shortest path between what is before and what is after. So if there is another if test on the same data in the function, that will cause a failure. If yo udon't care to have this constraint, you can put when any on a ...
Which SmPL "when variant" would you recommend here?
when any
[Cocci] Branch layout for if statements with SmPL disjunctions
In reply to Julia LawallQuoted 6 lines
Quoted 4 lines
( if (input) is
| if (likely(input)) is
)
else esThis is not allowed. Inside a disjunction you need to have complete terms.
I imagine that it would be nice if parts from an if statement could be written in the shown way. Would such an extension be useful for the semantic patch language?
I can easily adjust my simple pattern here because each if branch will be matched by a metavariable. I hope that the corresponding repetition of bigger subpatterns can be avoided in the future.
Regards,
Markus
Quoted 4 lines
Remember that ... matches the shortest path between what is before and what is after. So if there is another if test on the same data in the function, that will cause a failure. If yo udon't care to have this constraint, you can put when any on a ...
The following pattern variant does not show a different analysis result.
@is_unnecessary_check@
expression data;
identifier work;
identifier release =~ "^kz?free$";
position pos;
type t;
@@
t work at pos(...)
{
... when any
( if (data) release(data);
| if (likely(data)) release(data);
)
... when any
}
Regards,
Markus
[Cocci] Branch layout for if statements with SmPL disjunctions
In reply to SF Markus ElfringQuoted 10 lines · SF Markus Elfring
Quoted 6 lines
Quoted 4 lines
( if (input) is
| if (likely(input)) is
)
else esThis is not allowed. Inside a disjunction you need to have complete terms.
I imagine that it would be nice if parts from an if statement could be written in the shown way. Would such an extension be useful for the semantic patch language?
No, I think that simple rules are better. Always use complete terms is a simple rule.
julia
Quoted 7 lines
I can easily adjust my simple pattern here because each if branch will be matched by a metavariable. I hope that the corresponding repetition of bigger subpatterns can be avoided in the future.
Regards,
Markus
Quoted 2 lines
But it is not surprising that a regular expression with over 5000 options exceeds its capacity.
A source code search with the following pattern found 893 functions which check their single parameter.
@safety_check@
identifier work, input;
type data_type;
position pos;
statement is, es;
@@
void work at pos(data_type input)
{
... when any
( if (input) is else es
| if (likely(input)) is else es
)
... when any
}
Such a name list could be integrated into the following pattern variant.
@Delete_unnecessary_checks@
expression x;
identifier release =~ "^(?x)
(?:
(?:kz?|slob_)free
|
(?:
# alternation/disjunction of 893 strings ...
)
)$";
@@
-if (x)
release(x);I get an interesting result for example. Do you find it useful?
elfring at Sonne:~/Projekte/Coccinelle/janitor> spatch.opt --sp-file delete_unnecessary_checks3.cocci /usr/src/linux-stable/fs/btrfs/inode.cinit_defs_builtins: /usr/local/share/coccinelle/standard.h
HANDLING: /usr/src/linux-stable/fs/btrfs/inode.c
tmp/cocci-output-5030-250c49-inode.c renamed from usr/src/linux-stable/fs/btrfs/inode.c +3 -6
@@ -819,8 +819,7 @@ static u64 get_extent_allocation_hint(st em =search_extent_mapping (em_tree,0 ,0 );if (em && em->block_start <EXTENT_MAP_LAST_BYTE ) alloc_hint = em->block_start; -if (em) -free_extent_map (em); +free_extent_map (em); }else { alloc_hint = em->block_start;free_extent_map (em);
@@ -5137,8 +5136,7 @@ static int btrfs_dentry_delete(const strstatic void btrfs_dentry_release (struct dentry *dentry) { -if (dentry->d_fsdata) -kfree (dentry->d_fsdata); +kfree (dentry->d_fsdata); } static struct dentry *btrfs_lookup(struct inode *dir, struct dentry *dentry,
@@ -6362,8 +6360,7 @@ out:trace_btrfs_get_extent (root, em); -if (path) -btrfs_free_path (path); +btrfs_free_path (path);if (trans) { ret =btrfs_end_transaction (trans, root);if (!err)
Does the following pattern variant show also around 70 update candidates on your software development system?
@is_unnecessary_check@
expression data;
identifier work;
identifier release =~ "^(?x)
(?:
# Big regular expression for a metavariable constraint ...
)$";
position pos;
type t;
@@
t work at pos(...)
{
... when any
( if (data) release(data);
| if (likely(data)) release(data);
)
... when any
}
elfring at Sonne:~/Projekte/Coccinelle/janitor> date && spatch.opt --sp-file list_functions_with_unnecessary_checks1.cocci --dir /usr/src/linux-stable > list_functions_with_unnecessary_checks1.txt 2> list_functions_with_unnecessary_checks1-errors.txt && date
Mi 26. Feb 11:38:14 CET 2014
Mi 26. Feb 12:13:47 CET 2014
The log file contains messages like 'EXN:Invalid_argument("equal: abstract value")'. Do they need further considerations?
Is this intermediate source code analysis result good enough to expand the constructive discussion to a mailing list like "kernel janitors"?
Regards,
Markus
Quoted 1 line
I get an interesting result for example. Do you find it useful?
I checks on the three examples. They seem technically correct, in that the called function does immediately do a null test on the argument value. Personally, I still think that the null test at the call site conveys useful information, so I would rather have it there, but others may think differently.
On the other hand, you should not be using linux-stable when working on the Linux kernel. Patches should apply to linux-next, ie the very latest version of all of the code.
If you are convinced that dropping the null tests is a good idea, then you can submit the patch that makes the change to the relevant maintainers and mailing lists. Use scripts/get_maintainers.pl in the Linux kernel to find out who to sent it to. And study the documentation on submitting patches very carefully.
Quoted 2 lines
The log file contains messages like 'EXN:Invalid_argument("equal: abstract value")'. Do they need further considerations?
This is an unfortunate constraint on the use of PCRE regular expressions. I will try to track it down. Thanks for the report.
Quoted 2 lines
Is this intermediate source code analysis result good enough to expand the constructive discussion to a mailing list like "kernel janitors"?
I don't think people on the mailing list want to discuss the issue in a general sense. They just want patches, and may comment on them.
julia
Quoted 4 lines
On the other hand, you should not be using linux-stable when working on the Linux kernel. Patches should apply to linux-next, ie the very latest version of all of the code.
The discussed semantic patches can be tried out with every version a software developer or reviewer might be interested in. I am going to retry them with the newest source files as you suggest.
Quoted 2 lines
This is an unfortunate constraint on the use of PCRE regular expressions. I will try to track it down.
Thanks for your feedback.
- Do you need any excerpt from my log files?
- Does the message 'EXN:Invalid_argument("equal: abstractvalue")' indicate that the desired source code analysis is influenced in unwanted ways?
Regards,
Markus
Quoted 4 lines
- Do you need any excerpt from my log files?
- Does the message 'EXN:Invalid_argument("equal: abstractvalue")' indicate that the desired source code analysis is influenced in unwanted ways?
No, the semantic patch should be enough to reproduce the problem. If I need more information, I will ask. The problem has no impact on the quality of the answers actually obtained.
julia
[Cocci] Improvements for passing of big regular expressions in SmPL constraints?
In reply to SF Markus ElfringQuoted 4 lines
@Delete_unnecessary_checks@
expression x;
identifier release =~ "^(?x)
(?:
Quoted 9 lines
(?:kz?|slob_)free
|
(?:
# alternation/disjunction of 893 strings ...
)
)$";
@@
-if (x)
release(x);Would it be useful that the shown regular expression could be included from an other source file?
How do you think about an extension for the semantic patch language so that such a string could be assigned to a special metavariable with a type like "regex"? Can it be passed from a "virtual" parameter?
Regards,
Markus
[Cocci] Improvements for passing of big regular expressions in SmPL constraints?
Quoted 14 lines · SF Markus Elfring
Quoted 4 lines
@Delete_unnecessary_checks@
expression x;
identifier release =~ "^(?x)
(?:Quoted 9 lines
(?:kz?|slob_)free | (?: # alternation/disjunction of 893 strings ... ) )$"; @@ -if (x) release(x);
Quoted 5 lines
Would it be useful that the shown regular expression could be included from an other source file? How do you think about an extension for the semantic patch language so that such a string could be assigned to a special metavariable with a type like "regex"? Can it be passed from a "virtual" parameter?
A priori, I don't think regular expressions are a good idea at all. It reflects a lac of control over what is matched. Furthermore, Coccinelle doesn't do any optimizations based on regular expressions. If you put a regular expression match in your rule, Coccinelle is likely to have to try (parse etc) every file, because it doesn't know whether the regular expression matches or not. It would be better to use virtual identifiers. That way, if you also use some kind of indexing (glimpse or id-utils), then very little work will be done in most cases.
julia
[Cocci] Improvements for passing of big regular expressions in SmPL constraints?
Quoted 1 line
It would be better to use virtual identifiers.
Can this SmPL interface be marked and used in the way that an identifier does not contain "plain text" but should be handled as a long regular expression?
Regards,
Markus
[Cocci] Improvements for passing of big regular expressions in SmPL constraints?
Quoted 4 lines · SF Markus Elfring
Quoted 1 line
It would be better to use virtual identifiers.
Can this SmPL interface be marked and used in the way that an identifier does not contain "plain text" but should be handled as a long regular expression?
No.
julia
Re: [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls
In reply to Julia LawallQuoted 3 lines
If you are convinced that dropping the null tests is a good idea, then you can submit the patch that makes the change to the relevant maintainers and mailing lists.
Hello,
A couple of functions perform input parameter validation before their implementations will try further actions with side effects. Some calling functions perform similar safety checks.
Functions which release a system resource are often documented in the way that they tolerate the passing of a null pointer for example. I do not see a need because of this fact that a function caller repeats a corresponding check.
Now I would like to propose such a change again.
1. Extension of the infrastructure for the analysis tool "coccicheck" Semantic patch patterns can help to identify update candidates also in the
Linux source file hierarchy.
2. Clarification for some automated update suggestions
My source code search approach found seventy functions at least which might
need another review and corresponding corrections for Linux 3.14-rc5. Further software development will point out even more potentially open issues.
Regards,
Markus
Re: [coccicheck Linux 3.14-rc5 PATCH 1 of 5] Deletion of unnecessary checks before specific function calls
Quoted 5 lines
Quoted 3 lines
If you are convinced that dropping the null tests is a good idea, then you can submit the patch that makes the change to the relevant maintainers and mailing lists.
From
48c9c4f61a7d7ea98538e02631a981a429281005Mon Sep 17 00:00:00 2001
From: Markus Elfring <[email protected]>
Date: Wed, 5 Mar 2014 18:15:34 +0100
Subject: [PATCH 1/5] Addition of a semantic patch file for showing unnecessary
checks before a few known functions
This semantic patch pattern tries to find source code places where a check is performed for an expression that is passed to a function (like "kfree") which checks this single parameter itself for usability. Redundant value or pointer checks can be avoided here.
The pattern contains a special comment in a regular expression for a SmPL constraint which supports extensions.
--- .../deletions/delete_unnecessary_checks_template1.cocci | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644
scripts/coccinelle/deletions/delete_unnecessary_checks_template1.cocci
diff --git a/scripts/coccinelle/deletions/delete_unnecessary_checks_template1.cocci b/scripts/coccinelle/deletions/delete_unnecessary_checks_template1.cocci new file mode 100644
index 0000000..b092051
scripts/coccinelle/deletions/delete_unnecessary_checks_template1.cocci new file +13 -0
@@ -0,0 +1,13 @@ + at Delete_unnecessary_checks@ +expression x; +identifier release =~ "^(?x) +(?: + (?:kz?|slob_)free +| + (?: +# Alternation placeholder + ) +)$"; +@@ +-if (x) + release(x);
Signature · 1 line
1.9.0
Re: [coccicheck Linux 3.14-rc5 PATCH 2 of 5] Deletion of unnecessary checks before specific function calls
In reply to SF Markus ElfringQuoted 5 lines
Quoted 3 lines
If you are convinced that dropping the null tests is a good idea, then you can submit the patch that makes the change to the relevant maintainers and mailing lists.
From
1d2de3c3cfa43cc3c78a91200c41cef438b26a8fMon Sep 17 00:00:00 2001
From: Markus Elfring <[email protected]>
Date: Wed, 5 Mar 2014 18:38:43 +0100
Subject: [PATCH 2/5] Addition of a semantic patch file for listing of
functions that check their single parameter
This semantic patch pattern tries to find functions that check their single parameter for usability.
Example:
Null pointer checks are often performed as input parameter validation.
It uses Python statements to write information about the found source code places in a data format that is a variant of a CSV text file.
--- .../list_input_parameter_validation1.cocci | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644
scripts/coccinelle/deletions/list_input_parameter_validation1.cocci
(quoted diff) +0 -0
b/scripts/coccinelle/deletions/list_input_parameter_validation1.cocci new file mode 100644
index 0000000..b0a5a52
scripts/coccinelle/deletions/list_input_parameter_validation1.cocci new file +52 -0
52 lines not on this page · raw message
'"source file"', "line", "column")))
+ print("\r\n".join(result))
+else:
+ sys.stderr.write("No result for this analysis!\n")
Signature · 1 line
1.9.0
Re: [coccicheck Linux 3.14-rc5 PATCH 3 of 5] Deletion of unnecessary checks before specific function calls
In reply to SF Markus ElfringQuoted 5 lines
Quoted 3 lines
If you are convinced that dropping the null tests is a good idea, then you can submit the patch that makes the change to the relevant maintainers and mailing lists.
From
f4608fceec40b2b94aa9b4abe3bbb6d98ed5eed9Mon Sep 17 00:00:00 2001
From: Markus Elfring <[email protected]>
Date: Wed, 5 Mar 2014 18:58:30 +0100
Subject: [PATCH 3/5] Addition of a SQLite script for a text file import
A script was added so that a text file which was previously generated can be imported into a SQLite data base table.
http://sqlite.org/sqlite.html
The shown file name can be adjusted by a make file for example.
--- .../coccinelle/deletions/handle_function_list_template.sqlite | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644
scripts/coccinelle/deletions/handle_function_list_template.sqlite
(quoted diff) +0 -0
b/scripts/coccinelle/deletions/handle_function_list_template.sqlite new file mode 100644
index 0000000..bec366c
scripts/coccinelle/deletions/handle_function_list_template.sqlite new file +9 -0
@@ -0,0 +1,9 @@ +create table positions(function text, + data_type text, + parameter text, + source_file text, + line integer, + column integer); +.separator "|" +.import list_input_pointer_validation1.txt positions +.header OFF
Signature · 1 line
1.9.0
Re: [coccicheck Linux 3.14-rc5 PATCH 4 of 5] Deletion of unnecessary checks before specific function calls
In reply to SF Markus ElfringQuoted 5 lines
Quoted 3 lines
If you are convinced that dropping the null tests is a good idea, then you can submit the patch that makes the change to the relevant maintainers and mailing lists.
From
e6a21b920fcca2f6f01c9528909dc036a9b3bc41Mon Sep 17 00:00:00 2001
From: Markus Elfring <[email protected]>
Date: Wed, 5 Mar 2014 19:10:32 +0100
Subject: [PATCH 4/5] Addition of a semantic patch file for listing of
unnecessary checks before a few known functions
This semantic patch pattern tries to find source code places where a check is performed for an expression that is passed to a function (like "kfree") which checks this single parameter itself for usability. Redundant value or pointer checks can be avoided here.
The pattern contains a special comment in a regular expression for a SmPL constraint which supports extensions.
It uses Python statements to write information about the found places in a data format that is a variant of a CSV text file.
--- ...nctions_with_unnecessary_checks_template1.cocci | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644
scripts/coccinelle/deletions/list_functions_with_unnecessary_checks_template1.cocci
diff --git a/scripts/coccinelle/deletions/list_functions_with_unnecessary_checks_template1.cocci b/scripts/coccinelle/deletions/list_functions_with_unnecessary_checks_template1.cocci new file mode 100644
index 0000000..d2637e8
--- /dev/null
+++b/scripts/coccinelle/deletions/list_functions_with_unnecessary_checks_template1.cocci @@ -0,0 +1,59 @@
+ at initialize:python@
+@@
+import sys
+result = []
+mark = ['"', '', '"']
+delimiter = '|'
+
+def store_positions(fun, point, places):
+ """Add source code positions to an internal list."""
+ for place in places:
+ fields = []
+ fields.append(fun)
+
+ fields.append(point)
+
+ mark[1] = place.file.replace('"', '""')
+ fields.append(''.join(mark))
+
+ fields.append(place.line) + fields.append(str(int(place.column) + 1)) + result.append(delimiter.join(fields))
+
+ at is_unnecessary_check@
+expression data;
+identifier work;
+identifier release =~ "^(?x)
+(?:
+ (?:kz?|slob_)free
+|
+ (?:
+# Alternation placeholder
+ )
+)$";
+position pos;
+type t;
+@@
+ t work at pos(...)
+ {
+ ... when any
+( if (data) release(data);
+| if (likely(data)) release(data);
+)
+ ... when any
+ }
+
+ at script:python collection depends on is_unnecessary_check@ +fun << is_unnecessary_check.work;
+point << is_unnecessary_check.data;
+places << is_unnecessary_check.pos;
+@@
+store_positions(fun, point, places)
+
+@finalize:python@
+@@
+if result:
+ result.insert(0, delimiter.join(("function", '"parameter"', '"source file"',
"line", "column")))
+ print("\r\n".join(result))
+else:
+ sys.stderr.write("No result for this analysis!\n")
Signature · 1 line
1.9.0
Re: [coccicheck Linux 3.14-rc5 PATCH 5 of 5] Deletion of unnecessary checks before specific function calls
In reply to SF Markus ElfringQuoted 5 lines
Quoted 3 lines
If you are convinced that dropping the null tests is a good idea, then you can submit the patch that makes the change to the relevant maintainers and mailing lists.
From
bedf1cb3ddd162ee3b4c31cbb98d97431f70103dMon Sep 17 00:00:00 2001
From: Markus Elfring <[email protected]>
Date: Wed, 5 Mar 2014 19:40:43 +0100
Subject: [PATCH 5/5] Addition of a make file for build automation
This script can be used to combine some input files for the desired data output which will eventually show update candidates for further source code review. Some build targets were defined. Values for the used make variables can be adjusted by parameters on the command line as usual.
A few implementation details might need more fine-tuning.
- Automatic determination of the Linux source directory from a calling make process
- Setting of an extra output directory for the generated files
--- scripts/coccinelle/deletions/makefile | 126 ++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 scripts/coccinelle/deletions/makefile
(quoted diff) +0 -0
b/scripts/coccinelle/deletions/makefile
new file mode 100644
index 0000000..6464bae
scripts/coccinelle/deletions/makefile new file +39 -0
@@ -0,0 +1,126 @@ +SED=sed +SPATCH=spatch.opt --sp-file +RM=rm -f +LINUX_SOURCE_DIR=/usr/src/linux-stable +EXTRACT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER=list_input_parameter_validation1.cocci +SQLITE=sqlite3 +SQLITE_IMPORT_SCRIPT=handle_function_list.sqlite +SQLITE_IMPORT_SCRIPT_TEMPLATE=handle_function_list_template.sqlite +RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER=list_input_parameter_validation1.txt +RESULT_SQL_DATA_BASE=result.db +RESULT_FUNCTIONS_WITH_PREFIX=add_prefix-SQL.txt +RESULT_FUNCTIONS_WITH_UNNECESSARY_CHECKS_AS_LIST=list_functions_with_unnecessary_checks1.txt +RESULT_FUNCTIONS_WITH_UNNECESSARY_CHECKS_AS_PATCH=functions_with_unnecessary_checks1.diff +LOG_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER=list_input_parameter_validation1-errors.txt +LOG_LIST_FUNCTIONS_WITH_UNNECESSARY_CHECKS=list_functions_with_unnecessary_checks1-errors.txt +LOG_PATCH_FUNCTIONS_WITH_UNNECESSARY_CHECKS=functions_with_unnecessary_checks1-errors.txt +LIST_PATTERN_TEMPLATE=list_functions_with_unnecessary_checks_template1.cocci +LIST_PATTERN=list_functions_with_unnecessary_checks1.cocci +PATCH_PATTERN_TEMPLATE=delete_unnecessary_checks_template1.cocci +PATCH_PATTERN=delete_unnecessary_checks1.cocci +ESCAPING=XY=$$(< $(RESULT_FUNCTIONS_WITH_PREFIX)) \ + && XY=$${XY/|/ } \ + && XY=$${XY//%/\\%} \ + && $(SED) "s%\# Alternation placeholder%$${XY//$$'\n'/$$'\\\\\n'}%" +TEXT1=A pattern file was built from which a +TEXT2=was generated. Good luck with source code review! + +default: build_update_candidate_list + +$(RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER): \ +$(EXTRACT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) + $(SPATCH) $(EXTRACT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) \ +-dir $(LINUX_SOURCE_DIR) \ +> $@ 2> $(LOG_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) + +# This replacement action is needed for the use case that the corresponding +# variable was overridden. +$(SQLITE_IMPORT_SCRIPT): $(SQLITE_IMPORT_SCRIPT_TEMPLATE) + $(SED) "s%import list_input_pointer_validation1\.txt%import $(subst
%,\%,$(RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER))%" \
+$(SQLITE_IMPORT_SCRIPT_TEMPLATE) > $@
+
+$(RESULT_SQL_DATA_BASE) $(RESULT_FUNCTIONS_WITH_PREFIX): \
+$(RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) \
+$(SQLITE_IMPORT_SCRIPT)
+ @$(RM) $(RESULT_SQL_DATA_BASE)
+ $(SQLITE) -init $(SQLITE_IMPORT_SCRIPT) $(RESULT_SQL_DATA_BASE) \
+'select '\'' | '\'' || function from positions group by function order by
function desc;' \
+> $(RESULT_FUNCTIONS_WITH_PREFIX)
+
+$(LIST_PATTERN): $(RESULT_FUNCTIONS_WITH_PREFIX)
+ $(ESCAPING) $(LIST_PATTERN_TEMPLATE) > $@
+
+$(PATCH_PATTERN): $(RESULT_FUNCTIONS_WITH_PREFIX)
+ $(ESCAPING) $(PATCH_PATTERN_TEMPLATE) > $@
+
+$(RESULT_FUNCTIONS_WITH_UNNECESSARY_CHECKS_AS_LIST): $(LIST_PATTERN)
+ $(SPATCH) $(LIST_PATTERN) -dir $(LINUX_SOURCE_DIR) \
+> $@ 2> $(LOG_LIST_FUNCTIONS_WITH_UNNECESSARY_CHECKS)
+
+$(RESULT_FUNCTIONS_WITH_UNNECESSARY_CHECKS_AS_PATCH): $(PATCH_PATTERN)
+ $(SPATCH) $(PATCH_PATTERN) -dir $(LINUX_SOURCE_DIR) \
+> $@ 2> $(LOG_PATCH_FUNCTIONS_WITH_UNNECESSARY_CHECKS)
+
+build_check_list generate_list_of_functions_which_check_their_single_parameter: \
+$(RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER)
+ @echo 'The list of functions which check their single parameter was generated.'
+
+build_import_script: $(SQLITE_IMPORT_SCRIPT)
+ @echo 'A script was generated which should contain appropriate parameters for
a data base.'
+
+build_data_base: $(RESULT_SQL_DATA_BASE)
+ @echo 'A SQL data base was built.'
+
+build_alternation add_prefix_to_functions: build_data_base
+ @echo 'The function name list was converted to a component for a regular
expression.'
+
+build_list_pattern: $(LIST_PATTERN)
+ @echo '$(TEXT1) list can be generated.'
+
+build_patch_pattern: $(PATCH_PATTERN)
+ @echo '$(TEXT1) patch can be generated.'
+
+build_update_candidate_list show_list_of_update_candidates: build_list_pattern \
+$(RESULT_FUNCTIONS_WITH_UNNECESSARY_CHECKS_AS_LIST)
+ @echo 'The list of update candidates $(TEXT2)'
+
+build_patch show_update_suggestion: build_patch_pattern \
+$(RESULT_FUNCTIONS_WITH_UNNECESSARY_CHECKS_AS_PATCH)
+ @echo 'A patch file $(TEXT2)'
+
+all: build_update_candidate_list build_patch
+
+clean:
+ $(RM) *-errors.txt \
+$(LIST_PATTERN) \
+$(PATCH_PATTERN) \
+$(RESULT_FUNCTIONS_WITH_PREFIX) \
+$(RESULT_SQL_DATA_BASE) \
+$(RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) \
+$(SQLITE_IMPORT_SCRIPT)
+
+delete_data_base:
+ $(RM) $(RESULT_SQL_DATA_BASE) \
+$(RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER)
+
+.PHONY: all \
+build_check_list \
+build_data_base \
+build_import_script \
+build_list_pattern \
+build_patch \
+build_patch_pattern \
+build_update_candidate_list \
+clean \
+default \
+delete_data_base \
+generate_list_of_functions_which_check_their_single_parameter \
+show_list_of_update_candidates \
+show_update_suggestion
+
+
+# The following input files should not need further actions here. +$(EXTRACT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) \
+$(SQLITE_IMPORT_SCRIPT_TEMPLATE) \
+$(LIST_PATTERN_TEMPLATE) \
+$(PATCH_PATTERN_TEMPLATE): ;
Signature · 1 line
1.9.0
Quoted 6 lines
Quoted 3 lines
- Does the message 'EXN:Invalid_argument("equal: abstractvalue")' indicate that the desired source code analysis is influenced in unwanted ways?
No, the semantic patch should be enough to reproduce the problem. If I need more information, I will ask.
I have looked into my log files once more so that I can give you another feedback for a "regexp problem".
Quoted 1 line
The problem has no impact on the quality of the answers actually obtained.
Now I make a different observation for the processing of SmPL constraints with a long function name list in the regular expression.
elfring at Sonne:~/Projekte/Coccinelle/janitor> OCAMLRUNPARAM=b spatch.opt --sp-file delete_unnecessary_checks3.cocci /usr/src/linux-stable/fs/proc/proc_sysctl.cinit_defs_builtins: /usr/local/share/coccinelle/standard.h
HANDLING: /usr/src/linux-stable/fs/proc/proc_sysctl.c
tmp/cocci-output-5200-eacf04-proc_sysctl.c renamed from usr/src/linux-stable/fs/proc/proc_sysctl.c +1 -2
@@ -470,8 +470,7 @@ static struct dentry *proc_sys_lookup(std_add (dentry, inode); out: -if (h) -sysctl_head_finish (h); +sysctl_head_finish (h);sysctl_head_finish (head);return err; }
elfring at Sonne:~/Projekte/Coccinelle/janitor> OCAMLRUNPARAM=b spatch.opt --sp-file list_functions_with_unnecessary_checks1.cocci /usr/src/linux-stable/fs/proc/proc_sysctl.cinit_defs_builtins: /usr/local/share/coccinelle/standard.h
HANDLING: /usr/src/linux-stable/fs/proc/proc_sysctl.c
Fatal error: exception Invalid_argument("equal: abstract value") Called from file "list.ml", line 86, characters 24-34
Called from file "list.ml", line 86, characters 24-34
Called from file "list.ml", line 86, characters 24-34
Called from file "list.ml", line 57, characters 20-23
Regards,
Markus
Quoted 9 lines · SF Markus Elfring
Quoted 6 lines
Quoted 3 lines
- Does the message 'EXN:Invalid_argument("equal: abstractvalue")' indicate that the desired source code analysis is influenced in unwanted ways?
No, the semantic patch should be enough to reproduce the problem. If I need more information, I will ask.
I have looked into my log files once more so that I can give you another feedback for a "regexp problem".
I can't reproduce this. I need the semantic patch.
julia
Quoted 40 lines
Quoted 3 lines
The problem has no impact on the quality of the answers actually obtained.
Now I make a different observation for the processing of SmPL constraints with a long function name list in the regular expression.
elfring at Sonne:~/Projekte/Coccinelle/janitor> OCAMLRUNPARAM=b spatch.opt --sp-file
delete_unnecessary_checks3.cocci/usr/src/linux-stable/fs/proc/proc_sysctl.cinit_defs_builtins:/usr/local/share/coccinelle/standard.h
HANDLING:/usr/src/linux-stable/fs/proc/proc_sysctl.c
diff =tmp/cocci-output-5200-eacf04-proc_sysctl.c renamed from usr/src/linux-stable/fs/proc/proc_sysctl.c +1
-2@@ -470,8 +470,7 @@ static struct dentry *proc_sys_lookup(std_add (dentry, inode); out: -if (h) -sysctl_head_finish (h); +sysctl_head_finish (h);sysctl_head_finish (head);return err; }elfring at Sonne:~/Projekte/Coccinelle/janitor> OCAMLRUNPARAM=b spatch.opt --sp-file
list_functions_with_unnecessary_checks1.cocci/usr/src/linux-stable/fs/proc/proc_sysctl.cinit_defs_builtins:/usr/local/share/coccinelle/standard.h
HANDLING:/usr/src/linux-stable/fs/proc/proc_sysctl.c
Fatal error: exceptionInvalid_argument("equal: abstract value")Called from file "list.ml", line 86, characters 24-34
Called from file "list.ml", line 86, characters 24-34
Called from file "list.ml", line 86, characters 24-34
Called from file "list.ml", line 57, characters 20-23Regards,
Markus
Quoted 1 line
I can't reproduce this. I need the semantic patch.
How do you think about to try out the scripts which I published yesterday evening?
Regards,
Markus
[Cocci] Determination of the number for named function parameters
In reply to SF Markus ElfringQuoted 2 lines
A source code search with the following pattern found 893 functions which check their single parameter.
I am also interested to generate statistics for the declaration of function parameters and their use.
Is it possible to analyse the function parameter list by interfaces from the semantic patch language? Can any useful numbers be extracted at this place?
Regards,
Markus
[Cocci] Determination of the number for named function parameters
Quoted 7 lines · SF Markus Elfring
Quoted 2 lines
A source code search with the following pattern found 893 functions which check their single parameter.
I am also interested to generate statistics for the declaration of function parameters and their use.
Is it possible to analyse the function parameter list by interfaces from the semantic patch language? Can any useful numbers be extracted at this place?
The question is not very precise. I don't know what you mean by analyse, nor what you mean by interfaces, nor what you mean by useful. You can write things like:
f(...,T i,...) { ... }
where T is a type and i is an identifier
or
f(...,p,...) { ... }
where p is a parameter
or
f(ps,p,...) { ... }
where ps is a parameter list and p is a parameter.
In declaratin a parameter list, you can also say;
parameter list[n] ps;
and then n is the number of parameters that are matched.
julia
[Cocci] Determination of the number for named function parameters
Quoted 5 lines
In declaratin a parameter list, you can also say;
parameter list[n] ps;
and then n is the number of parameters that are matched.
Thanks for your interesting details.
I find the use of the element "n" (the name in square brackets) not obvious from the Coccinelle manual so far.
But I would like to try more analysis with the data that is passed by the metavariable type "parameter list". I have started to look a bit into it by the function "pickle.dumps". This kind of display is not so useful for me yet. I am missing documentation for corresponding data structures I can depend on in further reports.
Regards,
Markus
[Cocci] Determination of the number for named function parameters
Quoted 2 lines
I am missing documentation for corresponding data structures I can depend on in further reports.
The display from the function "pprint.pformat" shows another implementation detail in my simple script.
http://docs.python.org/2/library/pprint.html
Would you like to clarify data analysis according to the current situation around "coccilib.elems.TermList instance"?
Regards,
Markus
[Cocci] Determination of the number for named function parameters
Quoted 9 lines · SF Markus Elfring
Quoted 2 lines
I am missing documentation for corresponding data structures I can depend on in further reports.
The display from the function "pprint.pformat" shows another implementation detail in my simple script.
http://docs.python.org/2/library/pprint.htmlWould you like to clarify data analysis according to the current situation around "coccilib.elems.TermList instance"?
I know nothing about this. Maybe look at the python code and see what it does. But I am not sure that using it is the best way to do whjat you want, although I also don't know what you want to do.
julia
[Cocci] Determination of the number for named function parameters
In reply to SF Markus ElfringQuoted 10 lines · SF Markus Elfring
Quoted 5 lines
In declaratin a parameter list, you can also say;
parameter list[n] ps;
and then n is the number of parameters that are matched.
Thanks for your interesting details.
I find the use of the element "n" (the name in square brackets) not obvious from the Coccinelle manual so far.
It is the number of elements that have been matched. You can use it in python code (as a string, I think), in ocaml code (as an integer), or inherit it into another list-typed metavariable.
Quoted 5 lines
But I would like to try more analysis with the data that is passed by the metavariable type "parameter list". I have started to look a bit into it by the function "pickle.dumps". This kind of display is not so useful for me yet. I am missing documentation for corresponding data structures I can depend on in further reports.
What analysis do you want to do? If you write an ocaml script, you can have access to the comple abstract syntax trees. Python code only receives a string representation.
julia
[Cocci] Determination of the number for named function parameters
Quoted 4 lines
Quoted 2 lines
I find the use of the element "n" (the name in square brackets) not obvious from the Coccinelle manual so far.
It is the number of elements that have been matched.
A part of my difficulty with interpretation of the grammar for the semantic patch language came from this notation.
"metadecl ::= ...
| parameter [list] ids ;
| parameter list [ id ] ids ;..."
Do square brackets indicate in one line that an information is optional while in the other line they should be used as literals?
Quoted 1 line
What analysis do you want to do?
If I try out the following script ...
@initialize:python@
@@
import sys
result = []
mark = ['"', '', '"']
delimiter = '|'
def store_positions(fun, count, places):
"""Add source code positions to an internal list.""" for place in places:
fields = []
fields.append(fun)
fields.append(count)
mark[1] = place.file.replace('"', '""')
fields.append(''.join(mark))
fields.append(place.line)
fields.append(str(int(place.column) + 1))
result.append(delimiter.join(fields))
@skeleton@
identifier fun;
parameter list [count] pl;
position pos;
@@
fun at pos(pl)
{
...
}
@script:python collection depends on skeleton@
fun << skeleton.fun;
count << skeleton.count;
places << skeleton.pos;
@@store_positions(fun, count, places)
@finalize:python@
@@
if result:
result.insert(0, delimiter.join(("function", '"parameter count"', '"source
file"', "line", "column")))
print("\r\n".join(result))
else:
sys.stderr.write("No result for this analysis!\n")
... on this source code example, ...
void my_log(char const * text)
{
/* Write something ... */
}
int my_safe_log(char const * text)
{
if (!text)
return 1;
my_log(text);
return 0;
}
char const * const my_message(void)
{
return "Surprise!";
}
int my_status(void)
{
return 1;
}
int my_addition(char a, char b)
{
return a + b;
}
int main(void)
{
struct my_operations
{
void (*log)(char const * t);
int (*safe_log)(char const * t);
char const * const (*get_message)(void);
int (*is_ready)(void);
int (*add)(char a, char b); } mo = {my_log, my_safe_log, my_message, my_status, my_addition}, * mop = &mo;
char const * const x = mo.get_message();
int y = mop->is_ready();
y = mop->add(1, 2);
y = mo.add(3, 4);
mo.log(mo.get_message());
mo.is_ready();
my_safe_log(0);
mo.safe_log(0);
mop->safe_log(0);
}
... I get a result that is a bit interesting.
elfring at Sonne:~/Projekte/Coccinelle/janitor> spatch --sp-file list_function_parameters2.cocci ../Probe/f-ptr-test1.cinit_defs_builtins: /usr/local/share/coccinelle/standard.h
HANDLING: ../Probe/f-ptr-test1.c
function|"parameter count"|"source file"|line|column main|1|"../Probe/f-ptr-test1.c"|30|5 my_log|1|"../Probe/f-ptr-test1.c"|1|6 my_message|1|"../Probe/f-ptr-test1.c"|15|20
my_safe_log|1|"../Probe/f-ptr-test1.c"|6|5 my_status|1|"../Probe/f-ptr-test1.c"|20|5 my_addition|2|"../Probe/f-ptr-test1.c"|25|5
I guess that I want to exclude matches for my use case where where the parameter type is "void". I would like to show the distribution of parameter numbers in a source code base.
Regards,
Markus
[Cocci] Determination of the number for named function parameters
Quoted 8 lines · SF Markus Elfring
Quoted 4 lines
Quoted 2 lines
I find the use of the element "n" (the name in square brackets) not obvious from the Coccinelle manual so far.
It is the number of elements that have been matched.
A part of my difficulty with interpretation of the grammar for the semantic patch language came from this notation.
Quoted 8 lines
"metadecl ::= ...
| parameter [list] ids ; | parameter list [ id ] ids ;..."
Do square brackets indicate in one line that an information is optional while in the other line they should be used as literals?
Yes. The spaces around the [ ] means that they are tokens.
julia
[Cocci] Improvements for the SmPL grammar description?
Quoted 1 line
The spaces around the [ ] means that they are tokens.
I would appreciate if the distinction will become easier for such characters.
Regards,
Markus
[Cocci] Determination of the number for named function parameters
In reply to Julia LawallQuoted 4 lines
Quoted 2 lines
Would you like to clarify data analysis according to the current situation around "coccilib.elems.TermList instance"?
I know nothing about this.
I am surprised by this feedback.
I assume that a corresponding interface description would be nice if I look at "man 3cocci Coccilib". How are the chances to improve the mapping from the OCaml API to the Python binding?
Quoted 2 lines
But I am not sure that using it is the best way to do whjat you want, although I also don't know what you want to do.
The tool "spatch" counts all elements in a metavariable of the type "parameter list". I would like to treat list elements that have got the function parameter type "void" or no name differently.
- How can I assign the number "zero" (instead of "1") in this case?
- Should I generally exclude parameters without names from another report variant?
I am also interested a bit in run time optimisation. A passed list should be sufficient for further computations. I do not really need a count in another variable which was specified between square brackets of a SmPL rule.
Regards,
Markus
[Cocci] Determination of the number for named function parameters
Quoted 6 lines · SF Markus Elfring
Quoted 4 lines
Quoted 2 lines
Would you like to clarify data analysis according to the current situation around "coccilib.elems.TermList instance"?
I know nothing about this.
I am surprised by this feedback.
I didn't implement it, and I never use python. The thing you are citing was implemented by a masters student for his masters thesis project, and it contains whatever he found useful.
Quoted 3 lines
I assume that a corresponding interface description would be nice if I look at "man 3cocci Coccilib". How are the chances to improve the mapping from the OCaml API to the Python binding?
If you would like to have such a thing you are welcome to implement. In my experience the AST is very rarely useful.
Quoted 7 lines
Quoted 2 lines
But I am not sure that using it is the best way to do whjat you want, although I also don't know what you want to do.
The tool "spatch" counts all elements in a metavariable of the type "parameter list". I would like to treat list elements that have got the function parameter type "void" or no name differently.
- How can I assign the number "zero" (instead of "1") in this case?
Have a special rule for such functions and use position variables to prevent the rule that matches interesting parameter lists from matching functions that have satisfied this case:
@r@
position p;
identifier f;
@@
f at p(void} { ... }
@goodfunctions@
position p != r.p;
parameter list[n] ps;
identifier f;
@@
f at p(ps) { ... }
Or you can just use your python code to see if ps is just the string "void".
Quoted 3 lines
I am also interested a bit in run time optimisation. A passed list should be sufficient for further computations. I do not really need a count in another variable which was specified between square brackets of a SmPL rule.
It is hard to imagine why converting all the elements of a list to strings as is done in the interface to python would be more efficient than just passing a single number.
Anyway, the runtime cost is not here, in either case. The runtime cost will be that you have to parse every function of every file.
julia
[Cocci] Determination of the number for named function parameters
Quoted 1 line
I didn't implement it, and I never use python.
I would struggle with OCaml script development more so far.
Quoted 3 lines
Have a special rule for such functions and use position variables to prevent the rule that matches interesting parameter lists from matching functions that have satisfied this case:
Thanks for your SmPL pattern suggestion.
Quoted 7 lines
@r@
position p;
identifier f;
@@f at p(void} { ... }
Quoted 7 lines
@goodfunctions@
position p != r.p;
parameter list[n] ps;
identifier f;
@@f at p(ps) { ... }
I would prefer to specify a meaningful constraint for the metavariable "ps" somehow.
Quoted 2 lines
Or you can just use your python code to see if ps is just the string "void".
I thought also in a similar direction. But I would like to be sure about the passed data structures. I imagine that I would need to inspect the class "coccilib.elems.TermList" if the corresponding documentation is unclear.
Quoted 8 lines
Quoted 4 lines
I am also interested a bit in run time optimisation. A passed list should be sufficient for further computations. I do not really need a count in another variable which was specified between square brackets of a SmPL rule.
It is hard to imagine why converting all the elements of a list to strings as is done in the interface to python would be more efficient than just passing a single number.
I would like to try out two reports at least.
1. What is the maximum number of named function parameters in a source code base? I need only the value "n" (without the additional data from the related
metavariable).
2. Comparison for the incidence of unnamed function parameters to all of them The parameter count could be determined from the list of parameter names
alone, couldn't it?
Regards,
Markus
[Cocci] Determination of the number for named function parameters
In reply to Julia LawallQuoted 3 lines
Have a special rule for such functions and use position variables to prevent the rule that matches interesting parameter lists from matching functions that have satisfied this case:
I have adjusted your suggestion a little bit here.
@no_input@
identifier fun;
position pos;
@@
fun at pos(void) { ... }
@input depends on no_input@
identifier fun;
parameter list [count] pl;
position pos != no_input.pos;
@@
fun at pos(pl) { ... }
@script:python collection depends on input@
fun << input.fun;
count << input.count;
places << input.pos;
@@store_positions(fun, count, places)
This pattern variant works as expected for a source code example that was already mentioned before.
elfring@Sonne:~/Projekte/Coccinelle/janitor> spatch.opt --sp-file list_function_parameters2.cocci ../Probe/f-ptr-test1.cinit_defs_builtins: /usr/local/share/coccinelle/standard.h
HANDLING: ../Probe/f-ptr-test1.c
function|"parameter count"|"source file"|line|column my_log|1|"../Probe/f-ptr-test1.c"|1|6
my_safe_log|1|"../Probe/f-ptr-test1.c"|6|5 my_addition|2|"../Probe/f-ptr-test1.c"|25|5
But I wonder about the processing for the following small source file.
void my_log(char const * format, ...)
{
/* Write something ... */
}
elfring at Sonne:~/Projekte/Coccinelle/janitor> spatch.opt --sp-file list_function_parameters2.cocci ../Probe/ellipsis-test1.cinit_defs_builtins: /usr/local/share/coccinelle/standard.h
HANDLING: ../Probe/ellipsis-test1.c
No result for this analysis!
I would appreciate your advices.
Regards,
Markus
[Cocci] Determination of the number for named function parameters
Quoted 12 lines · SF Markus Elfring
Quoted 3 lines
Have a special rule for such functions and use position variables to prevent the rule that matches interesting parameter lists from matching functions that have satisfied this case:
I have adjusted your suggestion a little bit here.
@no_input@
identifier fun;
position pos;
@@
fun at pos(void) { ... }
Quoted 8 lines
@input depends on no_input@
identifier fun;
parameter list [count] pl;
position pos != no_input.pos;
@@
fun at pos(pl) { ... }@script:python collection depends on input@
No need for depends on input. For a python rule, all metavariables have to be bound before anything happens.
Quoted 27 lines
fun << input.fun;
count << input.count;
places << input.pos;
@@store_positions(fun, count, places)This pattern variant works as expected for a source code example that was already mentioned before.
elfring at Sonne:~/Projekte/Coccinelle/janitor> spatch.opt --sp-file
list_function_parameters2.cocci../Probe/f-ptr-test1.cinit_defs_builtins:/usr/local/share/coccinelle/standard.h
HANDLING:../Probe/f-ptr-test1.c
function|"parameter count"|"source file"|line|column my_log|1|"../Probe/f-ptr-test1.c"|1|6my_safe_log|1|"../Probe/f-ptr-test1.c"|6|5 my_addition|2|"../Probe/f-ptr-test1.c"|25|5But I wonder about the processing for the following small source file.
void
my_log(char const * format, ...)
{
/* Write something ... */
}
Quoted 8 lines
elfring at Sonne:~/Projekte/Coccinelle/janitor> spatch.opt --sp-file
list_function_parameters2.cocci../Probe/ellipsis-test1.cinit_defs_builtins:/usr/local/share/coccinelle/standard.h
HANDLING:../Probe/ellipsis-test1.c
No result for this analysis!I would appreciate your advices.
I have no idea. I would have sort of expected that it would return a length of 2, but I guess it is reasonable, and even desirable, that it does not. What answer would you like?
julia
[Cocci] Determination of the number for named function parameters
Quoted 3 lines
I have no idea. I would have sort of expected that it would return a length of 2, but I guess it is reasonable, and even desirable, that it does not. What answer would you like?
I would expect that it will be treated by the SmPL pattern as a function with a single named parameter at least. I am unsure how the "ellipsis" should be counted and matched in the signature eventually.
Does this small source file indicate that there might be further difficulties for data analysis of variadic functions?
Regards,
Markus
[Cocci] Determination of the number for named function parameters
Quoted 10 lines · SF Markus Elfring
Quoted 3 lines
I have no idea. I would have sort of expected that it would return a length of 2, but I guess it is reasonable, and even desirable, that it does not. What answer would you like?
I would expect that it will be treated by the SmPL pattern as a function with a single named parameter at least. I am unsure how the "ellipsis" should be counted and matched in the signature eventually.
Does this small source file indicate that there might be further difficulties for data analysis of variadic functions?
Without knowing what you mean by "data analysis" it is impossible to tell. It is clear that there is some problem with ... matching a parameter-typed metavariable. This could be considered reasonable, because ... is not a (single) parameter.
julia
[Cocci] Determination of the number for named function parameters
Quoted 1 line
Without knowing what you mean by "data analysis" it is impossible to tell.
I mean the existence check for a parameter like "format" or extraction of a position for the function signature.
Quoted 1 line
It is clear that there is some problem with ... matching a parameter-typed metavariable.
Thanks that you agree to this detail. Would you like to test the handling of variadic macros and functions also in other situations?
Quoted 1 line
This could be considered reasonable, because ... is not a (single) parameter.
Is there any special mapping of the "ellipsis" at this place in the semantic patch language needed?
Regards,
Markus
[Cocci] Selection of class libraries ...?
In reply to Julia LawallQuoted 1 line
I didn't implement it, and I never use python.
Would you like to suggest any references for class libraries which work in OCaml with popular data structures in a way I am used to from other programming languages? Is the "convenience" and software speed similar there?
Regards,
Markus
[Cocci] Selection of class libraries ...?
Quoted 5 lines · SF Markus Elfring
Quoted 1 line
I didn't implement it, and I never use python.
Would you like to suggest any references for class libraries which work in OCaml with popular data structures in a way I am used to from other programming languages? Is the "convenience" and software speed similar there?
I have no idea what you are asking for.
julia
[Cocci] Selection of class libraries ...?
Quoted 5 lines
Quoted 3 lines
Would you like to suggest any references for class libraries which work in OCaml with popular data structures in a way I am used to from other programming languages? Is the "convenience" and software speed similar there?
I have no idea what you are asking for.
The programming language "OCaml" has got the property that values from standard data types are immutable. Now I am looking for a well-known OCaml class library which supports the modification of data structures like strings and lists in place. I would prefer to reuse an existing one instead of developing another variation for my experiments.
Regards,
Markus
[Cocci] Selection of class libraries ...?
Quoted 11 lines · SF Markus Elfring
Quoted 5 lines
Quoted 3 lines
Would you like to suggest any references for class libraries which work in OCaml with popular data structures in a way I am used to from other programming languages? Is the "convenience" and software speed similar there?
I have no idea what you are asking for.
The programming language "OCaml" has got the property that values from standard data types are immutable. Now I am looking for a well-known OCaml class library which supports the modification of data structures like strings and lists in place. I would prefer to reuse an existing one instead of developing another variation for my experiments.
Why do you want to do this? There is a String.set function that allows you to modify a character of a string. For a list, if you need to modify an element then it should be a list of reference cells. But I think that in practice it would be strange for either operation to be necessary.
julia
[Cocci] Selection of class libraries ...?
Quoted 4 lines
Why do you want to do this? There is a String.set function that allows you to modify a character of a string. For a list, if you need to modify an element then it should be a list of reference cells. But I think that in practice it would be strange for either operation to be necessary.
I would like to avoid unwanted run time behaviour because of unnecessary data copying when I will append text lines to a growing list.
http://ocaml.org/learn/tutorials/comparison_of_standard_containers.html#Listsimmutablesinglylinkedlists
I imagine that in-place modification will be a more efficient approach for my use case. Is a kind of list buffer available?
Regards,
Markus
[Cocci] Selection of class libraries ...?
Quoted 11 lines · SF Markus Elfring
Quoted 4 lines
Why do you want to do this? There is a String.set function that allows you to modify a character of a string. For a list, if you need to modify an element then it should be a list of reference cells. But I think that in practice it would be strange for either operation to be necessary.
I would like to avoid unwanted run time behaviour because of unnecessary data copying when I will append text lines to a growing list.
http://ocaml.org/learn/tutorials/comparison_of_standard_containers.html#ListsimmutablesinglylinkedlistsI imagine that in-place modification will be a more efficient approach for my use case. Is a kind of list buffer available?
You can just add information to the front of the list, and then reverse it at the end if that is needed.
julia
[Cocci] Selection of class libraries ...?
Quoted 2 lines
You can just add information to the front of the list, and then reverse it at the end if that is needed.
I would like to avoid even insertion at some list heads and a corresponding element reordering because of software efficiency considerations. Is a data structure available for OCaml which is similar to a standard buffer?
http://ocaml.org/learn/tutorials/comparison_of_standard_containers.html#Bufferextensiblestrings
Regards,
Markus
[Cocci] Clarification for OCaml scripts in SmPL
In reply to Julia LawallQuoted 5 lines
Quoted 2 lines
I imagine that in-place modification will be a more efficient approach for my use case. Is a kind of list buffer available?
You can just add information to the front of the list, and then reverse it at the end if that is needed.
I am trying to convert Python statements into similar OCaml functionality for one of my semantic patch examples.
@initialize:ocaml@
@@
let result = Queue.create ()
let current_function = ref ""
let current_count = ref ""
let empty = ""
let delimiter = "|"
let quote = "\""
let quote2 = "\"\""
let mark text = String.concat empty [quote; text; quote]
let replace text =
let length = String.length text in
let part = Buffer.create length in
for x = 0 to length - 1 do
if text.[x] = '"' then
Buffer.add_string part quote2
else
Buffer.add_char part text.[x]
done;
Buffer.contents part
(* Add a source code position to an internal list. *) let append place =
Queue.add (String.concat delimiter [!current_function;
!current_count;
mark (replace place.file);
string_of_int place.line;
string_of_int (place.column + 1)]) resultlet store_positions fun count places =
current_function := fun;
current_count := string_of_int count;
List.iter append places@no_input@
identifier fun;
position pos;
@@
fun at pos(void) { ... }
@input depends on no_input@
identifier fun;
parameter list [count] pl;
position pos != no_input.pos;
@@
fun at pos(pl) { ... }
@script:ocaml collection@
fun << input.fun;
count << input.count;
places << input.pos;
@@store_positions fun count places
@finalize:ocaml@
@@
if Queue.is_empty result then
Printf.eprintf "No result for this analysis!\n"
else
let output text = Printf.printf "%s\r\n" text in
Printf.printf "%s\r\n" (String.concat delimiter ["function";
"\"parameter count\"";
"\"source file\"";
"line";
"column"]);Queue.iter output result
The source code from this SmPL finalisation rule works as expected in a OCaml command line interface. Now I wonder about the following error message.
elfring@Sonne:~/Projekte/Coccinelle/janitor> spatch.opt --sp-file list_function_parameters3.cocci ../Probe/f-ptr-test1.cinit_defs_builtins: /usr/local/share/coccinelle/standard.h
File "list_function_parameters3.cocci", line 69, column 27, charpos = 1914
around = '', whole content = Queue.iter output result
Fatal error: exception Failure("lexing: empty token")
I would appreciate your advices.
Regards,
Markus
[Cocci] Clarification for OCaml scripts in SmPL
Quoted 2 lines
let
store_positionsfun count places =current_function := fun;
Does OCaml not like my name selection here?
Do I accidentally stumble on another software development "surprise" with reserved key words?
http://ocaml.org/learn/faq.html
let store_positions fu count places =
current_fu := fu;
current_count := string_of_int count;
List.iter append placesRegards,
Markus
[Cocci] Clarification for OCaml scripts in SmPL
In reply to SF Markus ElfringQuoted 1 line
let output text = Printf.printf "%s\r\n" text in
It's not related to the problem, but I'm not sure to understand "let output text = ..." Normally the left hand side of a let has only one variable.
julia
[Cocci] Clarification for OCaml scripts in SmPL
Quoted 5 lines · Julia Lawall
Quoted 1 line
let output text = Printf.printf "%s\r\n" text in
It's not related to the problem, but I'm not sure to understand "let output text = ..." Normally the left hand side of a let has only one variable.
I'm sorry. That was a stupid comment :) It is the definition fo a function.
julia
[Cocci] Clarification for OCaml scripts in SmPL
In reply to SF Markus ElfringI think that the problem is in the use of \" and perhaps especially '"'. I'm not sure that what you are doing is the normal ocaml way to do what you want to do. Could you explain in words what replace is supposed to do, for example? I never use either for loops or Buffers.
julia
[Cocci] Clarification for OCaml scripts in SmPL
In reply to SF Markus ElfringQuoted 6 lines · SF Markus Elfring
Quoted 2 lines
let
store_positionsfun count places =current_function := fun;Does OCaml not like my name selection here?
Do I accidentally stumble on another software development "surprise" with reserved key words?
Well, it is not really a surprise. Fun is indeed a reserved keyword in ocaml.
julia
Quoted 14 lines
http://ocaml.org/learn/faq.html
let store_positions fu count places = current_fu := fu; current_count := string_of_int count; List.iter append placesRegards,
Markus
_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] Clarification for OCaml scripts in SmPL
In reply to Julia LawallQuoted 1 line
Could you explain in words what replace is supposed to do, for example?
Yes, of course.
It should replace each quotation mark in a string by two of this character. (Quotes should become duplicated.)
Quoted 1 line
I never use either for loops or Buffers.
Which elements would you prefer to reuse from the programming language "OCaml" for the shown use case?
Regards,
Markus
[Cocci] Clarification for OCaml scripts in SmPL
Quoted 6 lines · SF Markus Elfring
Quoted 1 line
Could you explain in words what replace is supposed to do, for example?
Yes, of course.
It should replace each quotation mark in a string by two of this character. (Quotes should become duplicated.)
The string in question is the file name from a position variable. A file name does not contain a quote character. When you print a string, it appears as eg "foo", but the only characters in the string are f o and o. If you want to put a quote character before and after, The simplest would
be: Printf.sprintf "\"%s\"" place.file.
julia
[Cocci] Clarification for OCaml scripts in SmPL
Quoted 2 lines
The string in question is the file name from a position variable. A file name does not contain a quote character.
I would prefer to handle also the general case that such strings contain quotation marks eventually.
It depends on the analysis area if corresponding safety checks for special characters will matter, doesn't it?
Other example:
https://github.com/coccinelle/coccinelle/issues/5
Regards,
Markus
[Cocci] Clarification for OCaml scripts in SmPL
Quoted 5 lines · SF Markus Elfring
Quoted 2 lines
The string in question is the file name from a position variable. A file name does not contain a quote character.
I would prefer to handle also the general case that such strings contain quotation marks eventually.
Why would a file name contain a quote character. And if it does, what good will adding exxtra ones do you. If the name is
foo\"bar
you will have
"foo\""bar"
and your string will be misparsed by your database.
julia
Quoted 9 lines
It depends on the analysis area if corresponding safety checks for special characters will matter, doesn't it?
Other example:
https://github.com/coccinelle/coccinelle/issues/5Regards,
Markus
[Cocci] Clarification for OCaml scripts in SmPL
Quoted 1 line
Why would a file name contain a quote character.
I do not really know how often this case happens in the world of detailed data processing.
Quoted 1 line
And if it does, what good will adding exxtra ones do you.
I hope to ensure constraints for the used data formats.
Quoted 1 line
... and your string will be misparsed by your database.
I do not think so. I try to achieve quoting by the discussed function implementation so that a column/field in a CSV file will be generally treated as a text string.
Regards,
Markus
[Cocci] Determination of the number for named function parameters
In reply to SF Markus ElfringQuoted 1 line
2. Comparison for the incidence of unnamed function parameters to all of them
I am trying out a bit more preparation with OCaml script development for this report variant.
@initialize:ocaml@
@@
module My_map = Map.Make(Int64)
let m = ref My_map.empty
let counting dir =
let d = Unix.opendir dir in
try while true do
let name = Unix.readdir d in
let length = Int64.of_int (String.length name) in
if My_map.mem length (! m) then
ignore (m := My_map.add length (Int64.add (My_map.find length (! m))
Int64.one) (! m))
else
ignore (m := My_map.add length Int64.one (! m))
done
with End_of_file -> Unix.closedir d@find@
identifier fu;
@@
*fu(...)
{ ... }
@script:ocaml collection@
area << virtual.folder;
@@
if area = "" then
counting "/"
else
counting area
@finalize:ocaml@
@@
if My_map.is_empty (! m) then
prerr_endline "No result for this analysis!"
else
let delimiter = '|' in
let output key count = Printf.printf "%Li%c%Li\r\n" key delimiter count in Printf.printf "length%cincidence\r\n" delimiter;
My_map.iter output (! m)
elfring@Sonne:~/Projekte/Coccinelle/janitor> spatch.opt --sp-file list_file_name_lengths1.cocci ../Probe/f-ptr-test1.cinit_defs_builtins: /usr/local/share/coccinelle/standard.h Using native version of ocamlc/ocamlopt/ocamldep ocamlopt.opt -shared -o /tmp/list_file_name_lengths1f3bae5.cmxs -g -I /usr/lib64/ocaml -I /usr/local/share/coccinelle/ocaml /tmp/list_file_name_lengths1f3bae5.ml
Compilation OK!
Loading ML code of the SP...
HANDLING: ../Probe/f-ptr-test1.c
...
No result for this analysis!
How do you think about such a semantic patch approach?
Regards,
Markus
[Cocci] How to exclude volatile data accesses in expressions with SmPL?
In reply to Julia LawallQuoted 3 lines
Not sure what you mean by extended. There are indeed some other functions in Linux that perform NULL tests before doing anything, and thus they don't really need a null test around them.
I have got another concern for a corresponding implementation detail. How can a constraint be specified for the filter in the semantic patch so that the expression refers only to non-volatile data?
Is it a software development challenge to exclude accesses on volatile data elements eventually from the suggested deletion of condition checks?
https://en.wikipedia.org/wiki/Volatile_variable#In_C_and_C.2B.2B
Regards,
Markus
[Cocci] How to exclude volatile data accesses in expressions with SmPL?
Quoted 10 lines · SF Markus Elfring
Quoted 3 lines
Not sure what you mean by extended. There are indeed some other functions in Linux that perform NULL tests before doing anything, and thus they don't really need a null test around them.
I have got another concern for a corresponding implementation detail. How can a constraint be specified for the filter in the semantic patch so that the expression refers only to non-volatile data?
Is it a software development challenge to exclude accesses on volatile data elements eventually from the suggested deletion of condition checks?
https://en.wikipedia.org/wiki/Volatile_variable#In_C_and_C.2B.2B
Perhaps it is possible to write:
@@
volatile x;
@@
* x == NULL
Or maybe
@@
type T;
volatile T x;
@@
* x == NULL
Or at worst:
@@
type T;
identifier i;
@@
volatile T i;
...
*i == NULL
I don't know if this would find much. Intuitively, one might expect such problems to be detected easily by testing or developers to know better in thw first place, but who knows.
julia
[Cocci] How to exclude volatile data accesses in expressions with SmPL?
Quoted 3 lines
I don't know if this would find much. Intuitively, one might expect such problems to be detected easily by testing or developers to know better in thw first place, but who knows.
I see the software development challenge in the analysis of the expression which is used in a condition check. Such an expression could be constructed out of several elements.
I am still unsure on how a data type property like "volatile" can be safely determined by the semantic patch language for each used element. I would be able to specify a filter for a single element as you suggest. But is the combination of some elements more interesting for the general use case?
Regards,
Markus
[Cocci] How to exclude volatile data accesses in expressions with SmPL?
Quoted 4 lines · SF Markus Elfring
Quoted 3 lines
I don't know if this would find much. Intuitively, one might expect such problems to be detected easily by testing or developers to know better in thw first place, but who knows.
Quoted 8 lines
I see the software development challenge in the analysis of the expression which is used in a condition check. Such an expression could be constructed out of several elements.
I am still unsure on how a data type property like "volatile" can be safely determined by the semantic patch language for each used element. I would be able to specify a filter for a single element as you suggest. But is the combination of some elements more interesting for the general use case?
Coccinelle makes an effort to infer types. YOu may need to use eg --recursive-includes and --relax-include-path to get the most possible type information.
julia
[Cocci] How to exclude volatile data accesses in expressions with SmPL?
Quoted 3 lines
Coccinelle makes an effort to infer types. YOu may need to use eg --recursive-includes and --relax-include-path to get the most possible type information.
It is nice when a simple filter pattern works in principle. A filter pattern which needs the knowledge about all data type details to consider relevant constraints will need more time for the data analysis. I hope that the corresponding execution speed can also be improved.
Regards,
Markus
[Cocci] How to exclude volatile data accesses in expressions with SmPL?
In reply to Julia LawallQuoted 3 lines
Coccinelle makes an effort to infer types. YOu may need to use eg --recursive-includes and --relax-include-path to get the most possible type information.
How do you think about to make it possible to check attributes for expressions in SmPL constraints?
Regards,
Markus
[Cocci] How to exclude volatile data accesses in expressions with SmPL?
Quoted 6 lines · SF Markus Elfring
Quoted 3 lines
Coccinelle makes an effort to infer types. YOu may need to use eg --recursive-includes and --relax-include-path to get the most possible type information.
How do you think about to make it possible to check attributes for expressions in SmPL constraints?
I tried to do this at one point, but it introduced a lot of parsing problems, because attributes can appear in a variety of places. The benefit didn't seem to be worth the risk.
julia
[Cocci] How to exclude volatile data accesses in expressions with SmPL?
Quoted 5 lines
Quoted 2 lines
How do you think about to make it possible to check attributes for expressions in SmPL constraints?
I tried to do this at one point, but it introduced a lot of parsing problems, because attributes can appear in a variety of places.
Which kind of syntax had you got in mind for such a functionality?
Is there a need to distinguish property checks from support for extensions from a popular compiler implementation?
http://gcc.gnu.org/onlinedocs/gcc-4.8.2/gcc/Type-Attributes.html
Quoted 1 line
The benefit didn't seem to be worth the risk.
Can we clarify your concerns a bit more here?
Regards,
Markus
[Cocci] How to exclude volatile data accesses in expressions with SmPL?
Quoted 8 lines · SF Markus Elfring
Quoted 5 lines
Quoted 2 lines
How do you think about to make it possible to check attributes for expressions in SmPL constraints?
I tried to do this at one point, but it introduced a lot of parsing problems, because attributes can appear in a variety of places.
Which kind of syntax had you got in mind for such a functionality?
Quoted 8 lines
Is there a need to distinguish property checks from support for extensions from a popular compiler implementation?
http://gcc.gnu.org/onlinedocs/gcc-4.8.2/gcc/Type-Attributes.htmlQuoted 1 line
The benefit didn't seem to be worth the risk.
Can we clarify your concerns a bit more here?
To my recollection, there were problems of ambiguity in the parser. Also, I think it made the abstract syntax tree unwieldy, because attributes had to be taken into account in many positions.
julia
[Cocci] How to exclude volatile data accesses in expressions with SmPL?
Quoted 3 lines
To my recollection, there were problems of ambiguity in the parser. Also, I think it made the abstract syntax tree unwieldy, because attributes had to be taken into account in many positions.
Would you like to give it another try?
Regards,
Markus
[Cocci] Fix for "lexing: empty token" needed?
In reply to Julia LawallQuoted 4 lines
Quoted 2 lines
I have looked into my log files once more so that I can give you another feedback for a "regexp problem".
I can't reproduce this. I need the semantic patch.
It seems that you could fix this issue with the software release "1.0.0-rc22".
I have tried out the discussed approach on the source files for the operating system "Linux 3.16.3" once more. Now I stumble on another error message.
elfring at Sonne:~/Projekte/Coccinelle/janitor> spatch.opt --version && OCAMLRUNPARAM=b spatch.opt --sp-file list_functions_with_unnecessary_checks1.cocci /usr/src/linux-stable/crypto/fcrypt.c spatch version 1.0.0-rc22 with Python support and with PCRE supportinit_defs_builtins: /usr/local/share/coccinelle/standard.h
HANDLING: /usr/src/linux-stable/crypto/fcrypt.c
Fatal error: exception Failure("lexing: empty token")
Raised at file "lexing.ml", line 65, characters 15-37
Can this detail also be improved?
Regards,
Markus
Re: [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls
In reply to SF Markus ElfringQuoted 3 lines
Quoted 3 lines
If you are convinced that dropping the null tests is a good idea, then you can submit the patch that makes the change to the relevant maintainers and mailing lists.
Hello,
A couple of functions perform input parameter validation before their implementations will try further actions with side effects. Some calling functions perform similar safety checks.
Functions which release a system resource are occasionally documented in the way that they tolerate the passing of a null pointer for example.
I do not see a need because of this fact that a function caller repeats a corresponding check.
Now I would like to propose such a change again.
1. Extension of the infrastructure for the analysis tool "coccicheck" Semantic patch patterns can help to identify update candidates also in the
Linux source file hierarchy.
Would you like to reconsider an approach which was discussed with a subject
like "scripts/coccinelle/free: Delete NULL test before freeing functions?" a while ago?
https://lkml.org/lkml/2014/8/9/36
https://groups.google.com/d/msg/linux.kernel/rIWfYsRRW6I/cTs6y0STf2cJ
2. Clarification for some automated update suggestions
My source code search approach found 227 functions with the help of the
software "Coccinelle 1.0.0-rc22" at least which might need another review and corresponding corrections for Linux 3.16.3. Further software development will point out even more potentially open issues.
Regards,
Markus
Re: [coccicheck PATCH 1/5] Deletion of unnecessary checks before specific function calls
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
If you are convinced that dropping the null tests is a good idea, then you can submit the patch that makes the change to the relevant maintainers and mailing lists.
From
48c9c4f61a7d7ea98538e02631a981a429281005Mon Sep 17 00:00:00 2001
From: Markus Elfring <[email protected]>
Date: Wed, 5 Mar 2014 18:15:34 +0100
Subject: [PATCH 1/5] Addition of a semantic patch file for showing unnecessary
checks before a few known functions
This semantic patch pattern tries to find source code places where a check is performed for an expression that is passed to a function (like "kfree") which checks this single parameter itself for usability. Redundant value or pointer checks can be avoided here.
The pattern contains a special comment in a regular expression for a SmPL constraint which supports extensions.
--- .../deletions/delete_unnecessary_checks_template1.cocci | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644
scripts/coccinelle/deletions/delete_unnecessary_checks_template1.cocci
diff --git a/scripts/coccinelle/deletions/delete_unnecessary_checks_template1.cocci b/scripts/coccinelle/deletions/delete_unnecessary_checks_template1.cocci new file mode 100644
index 0000000..b092051
scripts/coccinelle/deletions/delete_unnecessary_checks_template1.cocci new file +13 -0
@@ -0,0 +1,13 @@ + at Delete_unnecessary_checks@ +expression x; +identifier release =~ "^(?x) +(?: + (?:kz?|slob_)free +| + (?: +# Alternation placeholder + ) +)$"; +@@ +-if (x) + release(x);
Signature · 1 line
1.9.0
Re: [coccicheck PATCH 2/5] Deletion of unnecessary checks before specific function calls
In reply to SF Markus ElfringQuoted 5 lines
Quoted 3 lines
Quoted 3 lines
If you are convinced that dropping the null tests is a good idea, then you can submit the patch that makes the change to the relevant maintainers and mailing lists.
From
1d2de3c3cfa43cc3c78a91200c41cef438b26a8fMon Sep 17 00:00:00 2001
From: Markus Elfring <[email protected]>
Date: Wed, 5 Mar 2014 18:38:43 +0100
Subject: [PATCH 2/5] Addition of a semantic patch file for listing of
functions that check their single parameter
This semantic patch pattern tries to find functions that check their single parameter for usability.
Example:
Null pointer checks are often performed as input parameter validation.
It uses Python statements to write information about the found source code places in a data format that is a variant of a CSV text file.
--- .../list_input_parameter_validation1.cocci | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644
scripts/coccinelle/deletions/list_input_parameter_validation1.cocci
(quoted diff) +0 -0
b/scripts/coccinelle/deletions/list_input_parameter_validation1.cocci new file mode 100644
index 0000000..b0a5a52
scripts/coccinelle/deletions/list_input_parameter_validation1.cocci new file +52 -0
52 lines not on this page · raw message
'"source file"', "line", "column")))
+ print("\r\n".join(result))
+else:
+ sys.stderr.write("No result for this analysis!\n")
Signature · 1 line
1.9.0
Re: [coccicheck PATCH 3/5] Deletion of unnecessary checks before specific function calls
In reply to SF Markus ElfringQuoted 5 lines
Quoted 3 lines
Quoted 3 lines
If you are convinced that dropping the null tests is a good idea, then you can submit the patch that makes the change to the relevant maintainers and mailing lists.
From
f4608fceec40b2b94aa9b4abe3bbb6d98ed5eed9Mon Sep 17 00:00:00 2001
From: Markus Elfring <[email protected]>
Date: Wed, 5 Mar 2014 18:58:30 +0100
Subject: [PATCH 3/5] Addition of a SQLite script for a text file import
A script was added so that a text file which was previously generated can be imported into a SQLite data base table.
http://sqlite.org/sqlite.html
The shown file name can be adjusted by a make file for example.
--- .../coccinelle/deletions/handle_function_list_template.sqlite | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644
scripts/coccinelle/deletions/handle_function_list_template.sqlite
(quoted diff) +0 -0
b/scripts/coccinelle/deletions/handle_function_list_template.sqlite new file mode 100644
index 0000000..bec366c
scripts/coccinelle/deletions/handle_function_list_template.sqlite new file +9 -0
@@ -0,0 +1,9 @@ +create table positions(function text, + data_type text, + parameter text, + source_file text, + line integer, + column integer); +.separator "|" +.import list_input_pointer_validation1.txt positions +.header OFF
Signature · 1 line
1.9.0
Re: [coccicheck PATCH 4/5] Deletion of unnecessary checks before specific function calls
In reply to SF Markus ElfringQuoted 5 lines
Quoted 3 lines
Quoted 3 lines
If you are convinced that dropping the null tests is a good idea, then you can submit the patch that makes the change to the relevant maintainers and mailing lists.
From
e6a21b920fcca2f6f01c9528909dc036a9b3bc41Mon Sep 17 00:00:00 2001
From: Markus Elfring <[email protected]>
Date: Wed, 5 Mar 2014 19:10:32 +0100
Subject: [PATCH 4/5] Addition of a semantic patch file for listing of
unnecessary checks before a few known functions
This semantic patch pattern tries to find source code places where a check is performed for an expression that is passed to a function (like "kfree") which checks this single parameter itself for usability. Redundant value or pointer checks can be avoided here.
The pattern contains a special comment in a regular expression for a SmPL constraint which supports extensions.
It uses Python statements to write information about the found places in a data format that is a variant of a CSV text file.
--- ...nctions_with_unnecessary_checks_template1.cocci | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644
scripts/coccinelle/deletions/list_functions_with_unnecessary_checks_template1.cocci
diff --git a/scripts/coccinelle/deletions/list_functions_with_unnecessary_checks_template1.cocci b/scripts/coccinelle/deletions/list_functions_with_unnecessary_checks_template1.cocci new file mode 100644
index 0000000..d2637e8
--- /dev/null
+++b/scripts/coccinelle/deletions/list_functions_with_unnecessary_checks_template1.cocci @@ -0,0 +1,59 @@
+ at initialize:python@
+@@
+import sys
+result = []
+mark = ['"', '', '"']
+delimiter = '|'
+
+def store_positions(fun, point, places):
+ """Add source code positions to an internal list."""
+ for place in places:
+ fields = []
+ fields.append(fun)
+
+ fields.append(point)
+
+ mark[1] = place.file.replace('"', '""')
+ fields.append(''.join(mark))
+
+ fields.append(place.line) + fields.append(str(int(place.column) + 1)) + result.append(delimiter.join(fields))
+
+ at is_unnecessary_check@
+expression data;
+identifier work;
+identifier release =~ "^(?x)
+(?:
+ (?:kz?|slob_)free
+|
+ (?:
+# Alternation placeholder
+ )
+)$";
+position pos;
+type t;
+@@
+ t work at pos(...)
+ {
+ ... when any
+( if (data) release(data);
+| if (likely(data)) release(data);
+)
+ ... when any
+ }
+
+ at script:python collection depends on is_unnecessary_check@ +fun << is_unnecessary_check.work;
+point << is_unnecessary_check.data;
+places << is_unnecessary_check.pos;
+@@
+store_positions(fun, point, places)
+
+@finalize:python@
+@@
+if result:
+ result.insert(0, delimiter.join(("function", '"parameter"', '"source file"',
"line", "column")))
+ print("\r\n".join(result))
+else:
+ sys.stderr.write("No result for this analysis!\n")
Signature · 1 line
1.9.0
Re: [coccicheck PATCH 5/5] Deletion of unnecessary checks before specific function calls
In reply to SF Markus ElfringQuoted 5 lines
Quoted 3 lines
Quoted 3 lines
If you are convinced that dropping the null tests is a good idea, then you can submit the patch that makes the change to the relevant maintainers and mailing lists.
From
bedf1cb3ddd162ee3b4c31cbb98d97431f70103dMon Sep 17 00:00:00 2001
From: Markus Elfring <[email protected]>
Date: Wed, 5 Mar 2014 19:40:43 +0100
Subject: [PATCH 5/5] Addition of a make file for build automation
This script can be used to combine some input files for the desired data output which will eventually show update candidates for further source code review. Some build targets were defined. Values for the used make variables can be adjusted by parameters on the command line as usual.
A few implementation details might need more fine-tuning.
- Automatic determination of the Linux source directory from a calling make process
- Setting of an extra output directory for the generated files
--- scripts/coccinelle/deletions/makefile | 126 ++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 scripts/coccinelle/deletions/makefile
(quoted diff) +0 -0
b/scripts/coccinelle/deletions/makefile
new file mode 100644
index 0000000..6464bae
scripts/coccinelle/deletions/makefile new file +39 -0
@@ -0,0 +1,126 @@ +SED=sed +SPATCH=spatch.opt --sp-file +RM=rm -f +LINUX_SOURCE_DIR=/usr/src/linux-stable +EXTRACT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER=list_input_parameter_validation1.cocci +SQLITE=sqlite3 +SQLITE_IMPORT_SCRIPT=handle_function_list.sqlite +SQLITE_IMPORT_SCRIPT_TEMPLATE=handle_function_list_template.sqlite +RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER=list_input_parameter_validation1.txt +RESULT_SQL_DATA_BASE=result.db +RESULT_FUNCTIONS_WITH_PREFIX=add_prefix-SQL.txt +RESULT_FUNCTIONS_WITH_UNNECESSARY_CHECKS_AS_LIST=list_functions_with_unnecessary_checks1.txt +RESULT_FUNCTIONS_WITH_UNNECESSARY_CHECKS_AS_PATCH=functions_with_unnecessary_checks1.diff +LOG_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER=list_input_parameter_validation1-errors.txt +LOG_LIST_FUNCTIONS_WITH_UNNECESSARY_CHECKS=list_functions_with_unnecessary_checks1-errors.txt +LOG_PATCH_FUNCTIONS_WITH_UNNECESSARY_CHECKS=functions_with_unnecessary_checks1-errors.txt +LIST_PATTERN_TEMPLATE=list_functions_with_unnecessary_checks_template1.cocci +LIST_PATTERN=list_functions_with_unnecessary_checks1.cocci +PATCH_PATTERN_TEMPLATE=delete_unnecessary_checks_template1.cocci +PATCH_PATTERN=delete_unnecessary_checks1.cocci +ESCAPING=XY=$$(< $(RESULT_FUNCTIONS_WITH_PREFIX)) \ + && XY=$${XY/|/ } \ + && XY=$${XY//%/\\%} \ + && $(SED) "s%\# Alternation placeholder%$${XY//$$'\n'/$$'\\\\\n'}%" +TEXT1=A pattern file was built from which a +TEXT2=was generated. Good luck with source code review! + +default: build_update_candidate_list + +$(RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER): \ +$(EXTRACT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) + $(SPATCH) $(EXTRACT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) \ +-dir $(LINUX_SOURCE_DIR) \ +> $@ 2> $(LOG_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) + +# This replacement action is needed for the use case that the corresponding +# variable was overridden. +$(SQLITE_IMPORT_SCRIPT): $(SQLITE_IMPORT_SCRIPT_TEMPLATE) + $(SED) "s%import list_input_pointer_validation1\.txt%import $(subst
%,\%,$(RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER))%" \
+$(SQLITE_IMPORT_SCRIPT_TEMPLATE) > $@
+
+$(RESULT_SQL_DATA_BASE) $(RESULT_FUNCTIONS_WITH_PREFIX): \
+$(RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) \
+$(SQLITE_IMPORT_SCRIPT)
+ @$(RM) $(RESULT_SQL_DATA_BASE)
+ $(SQLITE) -init $(SQLITE_IMPORT_SCRIPT) $(RESULT_SQL_DATA_BASE) \
+'select '\'' | '\'' || function from positions group by function order by
function desc;' \
+> $(RESULT_FUNCTIONS_WITH_PREFIX)
+
+$(LIST_PATTERN): $(RESULT_FUNCTIONS_WITH_PREFIX)
+ $(ESCAPING) $(LIST_PATTERN_TEMPLATE) > $@
+
+$(PATCH_PATTERN): $(RESULT_FUNCTIONS_WITH_PREFIX)
+ $(ESCAPING) $(PATCH_PATTERN_TEMPLATE) > $@
+
+$(RESULT_FUNCTIONS_WITH_UNNECESSARY_CHECKS_AS_LIST): $(LIST_PATTERN)
+ $(SPATCH) $(LIST_PATTERN) -dir $(LINUX_SOURCE_DIR) \
+> $@ 2> $(LOG_LIST_FUNCTIONS_WITH_UNNECESSARY_CHECKS)
+
+$(RESULT_FUNCTIONS_WITH_UNNECESSARY_CHECKS_AS_PATCH): $(PATCH_PATTERN)
+ $(SPATCH) $(PATCH_PATTERN) -dir $(LINUX_SOURCE_DIR) \
+> $@ 2> $(LOG_PATCH_FUNCTIONS_WITH_UNNECESSARY_CHECKS)
+
+build_check_list generate_list_of_functions_which_check_their_single_parameter: \
+$(RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER)
+ @echo 'The list of functions which check their single parameter was generated.'
+
+build_import_script: $(SQLITE_IMPORT_SCRIPT)
+ @echo 'A script was generated which should contain appropriate parameters for
a data base.'
+
+build_data_base: $(RESULT_SQL_DATA_BASE)
+ @echo 'A SQL data base was built.'
+
+build_alternation add_prefix_to_functions: build_data_base
+ @echo 'The function name list was converted to a component for a regular
expression.'
+
+build_list_pattern: $(LIST_PATTERN)
+ @echo '$(TEXT1) list can be generated.'
+
+build_patch_pattern: $(PATCH_PATTERN)
+ @echo '$(TEXT1) patch can be generated.'
+
+build_update_candidate_list show_list_of_update_candidates: build_list_pattern \
+$(RESULT_FUNCTIONS_WITH_UNNECESSARY_CHECKS_AS_LIST)
+ @echo 'The list of update candidates $(TEXT2)'
+
+build_patch show_update_suggestion: build_patch_pattern \
+$(RESULT_FUNCTIONS_WITH_UNNECESSARY_CHECKS_AS_PATCH)
+ @echo 'A patch file $(TEXT2)'
+
+all: build_update_candidate_list build_patch
+
+clean:
+ $(RM) *-errors.txt \
+$(LIST_PATTERN) \
+$(PATCH_PATTERN) \
+$(RESULT_FUNCTIONS_WITH_PREFIX) \
+$(RESULT_SQL_DATA_BASE) \
+$(RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) \
+$(SQLITE_IMPORT_SCRIPT)
+
+delete_data_base:
+ $(RM) $(RESULT_SQL_DATA_BASE) \
+$(RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER)
+
+.PHONY: all \
+build_check_list \
+build_data_base \
+build_import_script \
+build_list_pattern \
+build_patch \
+build_patch_pattern \
+build_update_candidate_list \
+clean \
+default \
+delete_data_base \
+generate_list_of_functions_which_check_their_single_parameter \
+show_list_of_update_candidates \
+show_update_suggestion
+
+
+# The following input files should not need further actions here. +$(EXTRACT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) \
+$(SQLITE_IMPORT_SCRIPT_TEMPLATE) \
+$(LIST_PATTERN_TEMPLATE) \
+$(PATCH_PATTERN_TEMPLATE): ;
Signature · 1 line
1.9.0
Re: [PATCH 1/1] GPU-DRM-nouveau: Deletion of unnecessary checks before two function calls
In reply to SF Markus ElfringQuoted 3 lines
Quoted 3 lines
If you are convinced that dropping the null tests is a good idea, then you can submit the patch that makes the change to the relevant maintainers and mailing lists.
Would you like to integrate the following proposal into your source code repository?
Regards,
Markus
Quoted 1 line
From
29e61d5ccc44cd5e5961acff61b6938e0705044dMon Sep 17 00:00:00 2001
From: Markus Elfring <[email protected]>
Date: Wed, 22 Oct 2014 15:45:22 +0200
Subject: [PATCH] GPU-DRM-nouveau: Deletion of unnecessary checks before two
function calls
A semantic patch approach was proposed with the subject "[PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls" on 2014-03-05.
https://lkml.org/lkml/2014/3/5/344
http://article.gmane.org/gmane.comp.version-control.coccinelle/3513/
This patch pattern application was repeated with the help of the software "Coccinelle 1.0.0-rc22" on the source files for Linux 3.17.1. An extract of the automatically generated update suggestions is shown here.
It was determined that the affected source code places call functions which perform input parameter validation already. It is therefore not needed that a similar safety check is repeated at the call site.
--- drivers/gpu/drm/nouveau/core/core/handle.c | 3 +-- drivers/gpu/drm/nouveau/nouveau_drm.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)
(quoted diff) +0 -0
b/drivers/gpu/drm/nouveau/core/core/handle.c
index a490b80..75d0c2c 100644
drivers/gpu/drm/nouveau/core/core/handle.c +0 -0
@@ -219,8 +219,7 @@ nouveau_handle_get_cinst(struct nouveau_object *engctx, u32
cinst)
void
nouveau_handle_put(struct nouveau_handle *handle) {
- if (handle)
- nouveau_namedb_put(handle);
+ nouveau_namedb_put(handle);
}
int
(quoted diff) +0 -0
b/drivers/gpu/drm/nouveau/nouveau_drm.c
index 5723807..5c29079 100644
drivers/gpu/drm/nouveau/nouveau_drm.c +1 -2
@@ -512,8 +512,7 @@ nouveau_drm_unload(struct drm_device *dev)nouveau_vga_fini (drm);nvif_device_fini (&drm->device); -if (drm->hdmi_device) -pci_dev_put (drm->hdmi_device); +pci_dev_put (drm->hdmi_device);nouveau_cli_destroy (&drm->client);return 0 ; }
Signature · 1 line
2.1.2
Re: [PATCH 1/1] GPU-DRM-GMA500: Deletion of unnecessary checks before two function calls
In reply to SF Markus ElfringQuoted 3 lines
Quoted 3 lines
If you are convinced that dropping the null tests is a good idea, then you can submit the patch that makes the change to the relevant maintainers and mailing lists.
Would you like to integrate the following proposal into your source code repository?
Regards,
Markus
Quoted 1 line
From
e61965bbcb143a54696fbd468989110519e41497Mon Sep 17 00:00:00 2001
From: Markus Elfring <[email protected]>
Date: Wed, 22 Oct 2014 18:28:12 +0200
Subject: [PATCH] GPU-DRM-GMA500: Deletion of unnecessary checks before two
function calls
A semantic patch approach was proposed with the subject "[PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls" on 2014-03-05.
https://lkml.org/lkml/2014/3/5/344
http://article.gmane.org/gmane.comp.version-control.coccinelle/3513/
This patch pattern application was repeated with the help of the software "Coccinelle 1.0.0-rc22" on the source files for Linux 3.17.1. An extract of the automatically generated update suggestions is shown here.
It was determined that the affected source code places call functions which perform input parameter validation already. It is therefore not needed that a similar safety check is repeated at the call site.
--- drivers/gpu/drm/gma500/cdv_intel_hdmi.c | 3 +-- drivers/gpu/drm/gma500/cdv_intel_lvds.c | 9 +++------ drivers/gpu/drm/gma500/oaktrail_lvds.c | 3 +-- drivers/gpu/drm/gma500/psb_drv.c | 3 +-- drivers/gpu/drm/gma500/psb_intel_lvds.c | 9 +++------ 5 files changed, 9 insertions(+), 18 deletions(-)
(quoted diff) +0 -0
b/drivers/gpu/drm/gma500/cdv_intel_hdmi.c
index 4268bf2..0d69624 100644
drivers/gpu/drm/gma500/cdv_intel_hdmi.c +1 -2
@@ -246,8 +246,7 @@ static void cdv_hdmi_destroy(struct drm_connector *connector) {struct gma_encoder *gma_encoder =gma_attached_encoder (connector); -if (gma_encoder->i2c_bus) -psb_intel_i2c_destroy (gma_encoder->i2c_bus); +psb_intel_i2c_destroy (gma_encoder->i2c_bus);drm_connector_unregister (connector);drm_connector_cleanup (connector);kfree (connector);
(quoted diff) +0 -0
b/drivers/gpu/drm/gma500/cdv_intel_lvds.c
index 0b77039..8f24013 100644
drivers/gpu/drm/gma500/cdv_intel_lvds.c +0 -0
@@ -444,8 +444,7 @@ static void cdv_intel_lvds_destroy(struct drm_connector
*connector)
{
struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
- if (gma_encoder->i2c_bus)
- psb_intel_i2c_destroy(gma_encoder->i2c_bus);
+ psb_intel_i2c_destroy(gma_encoder->i2c_bus);
drm_connector_unregister(connector);
drm_connector_cleanup(connector);
kfree(connector);
@@ -780,12 +779,10 @@ out:
failed_find:
mutex_unlock(&dev->mode_config.mutex);
printk(KERN_ERR "Failed find\n");
- if (gma_encoder->ddc_bus)
- psb_intel_i2c_destroy(gma_encoder->ddc_bus);
+ psb_intel_i2c_destroy(gma_encoder->ddc_bus);
failed_ddc:
printk(KERN_ERR "Failed DDC\n");
- if (gma_encoder->i2c_bus)
- psb_intel_i2c_destroy(gma_encoder->i2c_bus);
+ psb_intel_i2c_destroy(gma_encoder->i2c_bus);
failed_blc_i2c:
printk(KERN_ERR "Failed BLC\n");
drm_encoder_cleanup(encoder);
(quoted diff) +0 -0
b/drivers/gpu/drm/gma500/oaktrail_lvds.c
index 0d39da6..49c5c415 100644
drivers/gpu/drm/gma500/oaktrail_lvds.c +1 -2
@@ -411,8 +411,7 @@ failed_find:mutex_unlock (&dev->mode_config.mutex);dev_dbg (dev->dev,"No LVDS modes found, disabling.\n" ); -if (gma_encoder->ddc_bus) -psb_intel_i2c_destroy (gma_encoder->ddc_bus); +psb_intel_i2c_destroy (gma_encoder->ddc_bus);/* failed_ddc: */
drivers/gpu/drm/gma500/psb_drv.c +1 -2
@@ -210,8 +210,7 @@ static int psb_driver_unload(struct drm_device *dev)iounmap (dev_priv->aux_reg); dev_priv->aux_reg =NULL ; } -if (dev_priv->aux_pdev) -pci_dev_put (dev_priv->aux_pdev); +pci_dev_put (dev_priv->aux_pdev);/* Destroy VBT data */ psb_intel_destroy_bios (dev);
(quoted diff) +0 -0
b/drivers/gpu/drm/gma500/psb_intel_lvds.c
index 88aad95..e73c3f9 100644
drivers/gpu/drm/gma500/psb_intel_lvds.c +3 -6
@@ -561,8 +561,7 @@ void psb_intel_lvds_destroy(struct drm_connector *connector)struct gma_encoder *gma_encoder =gma_attached_encoder (connector);struct psb_intel_lvds_priv *lvds_priv = gma_encoder->dev_priv; -if (lvds_priv->ddc_bus) -psb_intel_i2c_destroy (lvds_priv->ddc_bus); +psb_intel_i2c_destroy (lvds_priv->ddc_bus);drm_connector_unregister (connector);drm_connector_cleanup (connector);kfree (connector);
@@ -834,11 +833,9 @@ out: failed_find:mutex_unlock (&dev->mode_config.mutex); -if (lvds_priv->ddc_bus) -psb_intel_i2c_destroy (lvds_priv->ddc_bus); +psb_intel_i2c_destroy (lvds_priv->ddc_bus); failed_ddc: -if (lvds_priv->i2c_bus) -psb_intel_i2c_destroy (lvds_priv->i2c_bus); +psb_intel_i2c_destroy (lvds_priv->i2c_bus); failed_blc_i2c:drm_encoder_cleanup (encoder);drm_connector_cleanup (connector);
Signature · 1 line
2.1.2
Re: [PATCH 1/1] IOMMU-MSM: Deletion of unnecessary checks before the function call "clk_disable"
In reply to SF Markus ElfringQuoted 5 lines
Quoted 3 lines
If you are convinced that dropping the null tests is a good idea, then you can submit the patch that makes the change to the relevant maintainers and mailing lists.
From
af73fb59d5d4b2c2890000fb236d0752522b6b38Mon Sep 17 00:00:00 2001
From: Markus Elfring <[email protected]>
Date: Wed, 22 Oct 2014 19:39:21 +0200
Subject: [PATCH] IOMMU-MSM: Deletion of unnecessary checks before the function
call "clk_disable"
A semantic patch approach was proposed with the subject "[PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls" on 2014-03-05.
https://lkml.org/lkml/2014/3/5/344
http://article.gmane.org/gmane.comp.version-control.coccinelle/3513/
This patch pattern application was repeated with the help of the software "Coccinelle 1.0.0-rc22" on the source files for Linux 3.17.1. An extract of the automatically generated update suggestions is shown here.
It was determined that the affected source code places call functions which perform input parameter validation already. It is therefore not needed that a similar safety check is repeated at the call site.
--- drivers/iommu/msm_iommu.c | 3 +-- drivers/iommu/msm_iommu_dev.c | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-)
drivers/iommu/msm_iommu.c +1 -2
@@ -73,8 +73,7 @@ fail:static void __disable_clocks (struct msm_iommu_drvdata *drvdata) { -if (drvdata->clk) -clk_disable (drvdata->clk); +clk_disable (drvdata->clk);clk_disable (drvdata->pclk); }
drivers/iommu/msm_iommu_dev.c +2 -4
@@ -224,8 +224,7 @@ static int msm_iommu_probe(struct platform_device *pdev)platform_set_drvdata (pdev, drvdata); -if (iommu_clk) -clk_disable (iommu_clk); +clk_disable (iommu_clk);clk_disable (iommu_pclk);
@@ -323,8 +322,7 @@ static int msm_iommu_ctx_probe(struct platform_device *pdev)SET_NSCFG (drvdata->base, mid,3 ); } -if (drvdata->clk) -clk_disable (drvdata->clk); +clk_disable (drvdata->clk);clk_disable (drvdata->pclk);dev_info (&pdev->dev,"context %s using bank %d\n" , c->name, c->num);
Signature · 1 line
2.1.2
PATCH 1/1 SCSI-QLA2XXX: Deletion of unnecessary checks before the function call "vfree"
In reply to SF Markus ElfringQuoted 5 lines
Quoted 3 lines
If you are convinced that dropping the null tests is a good idea, then you can submit the patch that makes the change to the relevant maintainers and mailing lists.
From
ff44962f88ac2dae9324e30819629da4fb33f0ffMon Sep 17 00:00:00 2001
From: Markus Elfring <[email protected]>
Date: Wed, 22 Oct 2014 20:40:31 +0200
Subject: [PATCH] SCSI-QLA2XXX: Deletion of unnecessary checks before the
function call "vfree"
A semantic patch approach was proposed with the subject "[PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls" on 2014-03-05.
https://lkml.org/lkml/2014/3/5/344
http://article.gmane.org/gmane.comp.version-control.coccinelle/3513/
This patch pattern application was repeated with the help of the software "Coccinelle 1.0.0-rc22" on the source files for Linux 3.17.1. An extract of the automatically generated update suggestions is shown here.
It was determined that the affected source code places call functions which perform input parameter validation already. It is therefore not needed that a similar safety check is repeated at the call site.
--- drivers/scsi/qla2xxx/qla_attr.c | 6 ++---- drivers/scsi/qla2xxx/qla_init.c | 18 ++++++------------ drivers/scsi/qla2xxx/qla_os.c | 6 ++---- 3 files changed, 10 insertions(+), 20 deletions(-)
drivers/scsi/qla2xxx/qla_attr.c +0 -0
@@ -175,10 +175,8 @@ qla2x00_sysfs_write_fw_dump_template(struct file *filp,
struct kobject *kobj,
uint32_t size;
if (off == 0) {
- if (ha->fw_dump)
- vfree(ha->fw_dump);
- if (ha->fw_dump_template)
- vfree(ha->fw_dump_template);
+ vfree(ha->fw_dump);
+ vfree(ha->fw_dump_template);
ha->fw_dump = NULL;
ha->fw_dump_len = 0;
drivers/scsi/qla2xxx/qla_init.c +0 -0
@@ -5256,8 +5256,7 @@ qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t
*srisc_addr,
if (!IS_QLA27XX(ha))
return rval;
- if (ha->fw_dump_template)
- vfree(ha->fw_dump_template);
+ vfree(ha->fw_dump_template);
ha->fw_dump_template = NULL;
ha->fw_dump_template_len = 0;
@@ -5307,8 +5306,7 @@ qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
default_template:
ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
- if (ha->fw_dump_template)
- vfree(ha->fw_dump_template);
+ vfree(ha->fw_dump_template);
ha->fw_dump_template = NULL;
ha->fw_dump_template_len = 0;
@@ -5342,8 +5340,7 @@ default_template:
failed_template:
ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
- if (ha->fw_dump_template)
- vfree(ha->fw_dump_template);
+ vfree(ha->fw_dump_template);
ha->fw_dump_template = NULL;
ha->fw_dump_template_len = 0;
return rval;
@@ -5559,8 +5556,7 @@ qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
if (!IS_QLA27XX(ha))
return rval;
- if (ha->fw_dump_template)
- vfree(ha->fw_dump_template);
+ vfree(ha->fw_dump_template);
ha->fw_dump_template = NULL;
ha->fw_dump_template_len = 0;
@@ -5609,8 +5605,7 @@ qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
default_template:
ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
- if (ha->fw_dump_template)
- vfree(ha->fw_dump_template);
+ vfree(ha->fw_dump_template);
ha->fw_dump_template = NULL;
ha->fw_dump_template_len = 0;
@@ -5644,8 +5639,7 @@ default_template:
failed_template:
ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
- if (ha->fw_dump_template)
- vfree(ha->fw_dump_template);
+ vfree(ha->fw_dump_template);
ha->fw_dump_template = NULL;
ha->fw_dump_template_len = 0;
return rval;
drivers/scsi/qla2xxx/qla_os.c +2 -4
@@ -3676,10 +3676,8 @@ qla2x00_free_fw_dump(struct qla_hw_data *ha)dma_free_coherent (&ha->pdev->dev,EFT_SIZE , ha->eft, ha->eft_dma); -if (ha->fw_dump) -vfree (ha->fw_dump); -if (ha->fw_dump_template) -vfree (ha->fw_dump_template); +vfree (ha->fw_dump); +vfree (ha->fw_dump_template); ha->fce =NULL ; ha->fce_dma =0 ;
Signature · 1 line
2.1.2
Re: [PATCH 1/1] SCSI-QLA2...: Deletion of unnecessary checks before the function call "vfree"
In reply to SF Markus ElfringQuoted 3 lines
Quoted 3 lines
If you are convinced that dropping the null tests is a good idea, then you can submit the patch that makes the change to the relevant maintainers and mailing lists.
I resent the request once more because another "Triple-X" software development adventure might follow ...?
Regards,
Markus
Quoted 1 line
From
ff44962f88ac2dae9324e30819629da4fb33f0ffMon Sep 17 00:00:00 2001
From: Markus Elfring <[email protected]>
Date: Wed, 22 Oct 2014 20:40:31 +0200
Subject: [PATCH] SCSI-QLA2XXX: Deletion of unnecessary checks before the
function call "vfree"
A semantic patch approach was proposed with the subject "[PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls" on 2014-03-05.
https://lkml.org/lkml/2014/3/5/344
http://article.gmane.org/gmane.comp.version-control.coccinelle/3513/
This patch pattern application was repeated with the help of the software "Coccinelle 1.0.0-rc22" on the source files for Linux 3.17.1. An extract of the automatically generated update suggestions is shown here.
It was determined that the affected source code places call functions which perform input parameter validation already. It is therefore not needed that a similar safety check is repeated at the call site.
--- drivers/scsi/qla2xxx/qla_attr.c | 6 ++---- drivers/scsi/qla2xxx/qla_init.c | 18 ++++++------------ drivers/scsi/qla2xxx/qla_os.c | 6 ++---- 3 files changed, 10 insertions(+), 20 deletions(-)
drivers/scsi/qla2xxx/qla_attr.c +0 -0
@@ -175,10 +175,8 @@ qla2x00_sysfs_write_fw_dump_template(struct file *filp,
struct kobject *kobj,
uint32_t size;
if (off == 0) {
- if (ha->fw_dump)
- vfree(ha->fw_dump);
- if (ha->fw_dump_template)
- vfree(ha->fw_dump_template);
+ vfree(ha->fw_dump);
+ vfree(ha->fw_dump_template);
ha->fw_dump = NULL;
ha->fw_dump_len = 0;
drivers/scsi/qla2xxx/qla_init.c +0 -0
@@ -5256,8 +5256,7 @@ qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t
*srisc_addr,
if (!IS_QLA27XX(ha))
return rval;
- if (ha->fw_dump_template)
- vfree(ha->fw_dump_template);
+ vfree(ha->fw_dump_template);
ha->fw_dump_template = NULL;
ha->fw_dump_template_len = 0;
@@ -5307,8 +5306,7 @@ qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
default_template:
ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
- if (ha->fw_dump_template)
- vfree(ha->fw_dump_template);
+ vfree(ha->fw_dump_template);
ha->fw_dump_template = NULL;
ha->fw_dump_template_len = 0;
@@ -5342,8 +5340,7 @@ default_template:
failed_template:
ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
- if (ha->fw_dump_template)
- vfree(ha->fw_dump_template);
+ vfree(ha->fw_dump_template);
ha->fw_dump_template = NULL;
ha->fw_dump_template_len = 0;
return rval;
@@ -5559,8 +5556,7 @@ qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
if (!IS_QLA27XX(ha))
return rval;
- if (ha->fw_dump_template)
- vfree(ha->fw_dump_template);
+ vfree(ha->fw_dump_template);
ha->fw_dump_template = NULL;
ha->fw_dump_template_len = 0;
@@ -5609,8 +5605,7 @@ qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
default_template:
ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
- if (ha->fw_dump_template)
- vfree(ha->fw_dump_template);
+ vfree(ha->fw_dump_template);
ha->fw_dump_template = NULL;
ha->fw_dump_template_len = 0;
@@ -5644,8 +5639,7 @@ default_template:
failed_template:
ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
- if (ha->fw_dump_template)
- vfree(ha->fw_dump_template);
+ vfree(ha->fw_dump_template);
ha->fw_dump_template = NULL;
ha->fw_dump_template_len = 0;
return rval;
drivers/scsi/qla2xxx/qla_os.c +2 -4
@@ -3676,10 +3676,8 @@ qla2x00_free_fw_dump(struct qla_hw_data *ha)dma_free_coherent (&ha->pdev->dev,EFT_SIZE , ha->eft, ha->eft_dma); -if (ha->fw_dump) -vfree (ha->fw_dump); -if (ha->fw_dump_template) -vfree (ha->fw_dump_template); +vfree (ha->fw_dump); +vfree (ha->fw_dump_template); ha->fce =NULL ; ha->fce_dma =0 ;
Signature · 1 line
2.1.2
Re: [PATCH 1/1] GPU-DRM-GMA500: Deletion of unnecessary checks before two function calls
In reply to SF Markus ElfringQuoted 5 lines · On Wed, 22 Oct 2014 18:48:21 +0200 SF Markus Elfring…
Quoted 3 lines
Quoted 3 lines
If you are convinced that dropping the null tests is a good idea, then you can submit the patch that makes the change to the relevant maintainers and mailing lists.
Would you like to integrate the following proposal into your source code repository?
What platforms have you tested the code on at this point ?
Alan
Re: [PATCH 1/1] IOMMU-MSM: Deletion of unnecessary checks before the function call "clk_disable"
In reply to SF Markus ElfringQuoted 3 lines · SF Markus Elfring
drivers/iommu/msm_iommu.c | 3 +-- drivers/iommu/msm_iommu_dev.c | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-)
Applied to arm/msm, thanks.
Re: [PATCH 1/1] staging - rtl8188eu: Deletion of unnecessary checks before three function calls
In reply to SF Markus ElfringQuoted 1 line
From
45970693cad6c12da2d5ac7da3d2bd7a566170d7Mon Sep 17 00:00:00 2001
From: Markus Elfring <[email protected]>
Date: Thu, 23 Oct 2014 20:55:13 +0200
Subject: [PATCH] staging - rtl8188eu: Deletion of unnecessary checks before
three function calls
The functions kfree(), rtw_free_netdev() and vfree() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- drivers/staging/rtl8188eu/core/rtw_efuse.c | 3 +-- drivers/staging/rtl8188eu/core/rtw_mlme.c | 3 +-- drivers/staging/rtl8188eu/core/rtw_sta_mgt.c | 3 +-- drivers/staging/rtl8188eu/core/rtw_xmit.c | 6 ++---- drivers/staging/rtl8188eu/os_dep/usb_intf.c | 5 ++--- 5 files changed, 7 insertions(+), 13 deletions(-)
(quoted diff) +0 -0
b/drivers/staging/rtl8188eu/core/rtw_efuse.c
index 7006088..77f7552 100644
drivers/staging/rtl8188eu/core/rtw_efuse.c +0 -0
@@ -212,8 +212,7 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16
_size_byte, u8 *pbuf)
exit:
kfree(efuseTbl);
- if (eFuseWord)
- kfree(eFuseWord);
+ kfree(eFuseWord);
}
static void efuse_read_phymap_from_txpktbuf(
(quoted diff) +0 -0
b/drivers/staging/rtl8188eu/core/rtw_mlme.c
index 149c271..df54350 100644
drivers/staging/rtl8188eu/core/rtw_mlme.c +1 -2
@@ -122,8 +122,7 @@ void rtw_free_mlme_priv(struct mlme_priv *pmlmepriv)rtw_free_mlme_priv_ie_data (pmlmepriv);if (pmlmepriv) { -if (pmlmepriv->free_bss_buf) -vfree (pmlmepriv->free_bss_buf); +vfree (pmlmepriv->free_bss_buf); } }
(quoted diff) +0 -0
b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
index e1dc8fa..af1de9c 100644
drivers/staging/rtl8188eu/core/rtw_sta_mgt.c +1 -2
@@ -201,8 +201,7 @@ u32 _rtw_free_sta_priv(struct sta_priv *pstapriv)rtw_mfree_sta_priv_lock (pstapriv); -if (pstapriv->pallocated_stainfo_buf) -vfree (pstapriv->pallocated_stainfo_buf); +vfree (pstapriv->pallocated_stainfo_buf); }return _SUCCESS;
(quoted diff) +0 -0
b/drivers/staging/rtl8188eu/core/rtw_xmit.c
index 639ace0..011c9cf 100644
drivers/staging/rtl8188eu/core/rtw_xmit.c +2 -4
@@ -246,11 +246,9 @@ void _rtw_free_xmit_priv (struct xmit_priv *pxmitpriv) pxmitbuf++; } -if (pxmitpriv->pallocated_frame_buf) -vfree (pxmitpriv->pallocated_frame_buf); +vfree (pxmitpriv->pallocated_frame_buf); -if (pxmitpriv->pallocated_xmitbuf) -vfree (pxmitpriv->pallocated_xmitbuf); +vfree (pxmitpriv->pallocated_xmitbuf);/* free xmit extension buff */ pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmit_extbuf;
(quoted diff) +0 -0
b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
index 407a318..cdb70e4 100644
drivers/staging/rtl8188eu/os_dep/usb_intf.c +2 -3
@@ -456,7 +456,7 @@ free_adapter:if (status != _SUCCESS) {if (pnetdev)rtw_free_netdev (pnetdev); -else if (padapter) +else vfree (padapter); padapter =NULL ; }
@@ -487,8 +487,7 @@ static void rtw_usb_if1_deinit(struct adapter *if1)DBG_88E ("+r871xu_dev_remove, hw_init_completed=%d\n" , if1->hw_init_completed);rtw_free_drv_sw (if1); -if (pnetdev) -rtw_free_netdev (pnetdev); +rtw_free_netdev (pnetdev); } static int rtw_drv_init(struct usb_interface *pusb_intf, const struct
usb_device_id *pdid)
Signature · 1 line
2.1.2
Quoted 1 line
spatch version 1.0.0-rc20 with Python support and with PCRE support
[...]
Quoted 3 lines
Fatal error: exception Failure("Show_functions_with_input_pointer_validation:
already tagged token:
C code context
I tried this small source code search out again.
elfring at Sonne:~/Projekte/Coccinelle/janitor> date \
Quoted 15 lines
&& MY_PATTERN=find_input_pointer_validation2.cocci \
&& cat $MY_PATTERN \
&& echo '-----' \
&& spatch.opt --version \
&& spatch.opt --profile --include-headers-for-types --recursive-includes \(quoted diff) +0
-10-I /usr/src/linux-stable/include/linux \ -I /usr/src/linux-stable/include/uapi \ -I /usr/src/linux-stable/arch/ia64/include \ -I /usr/src/linux-stable/include/asm-generic \ -I /usr/src/linux-stable/include/asm-generic/bitops \ -I /usr/local/include/c++/4.8.2 \ -I /usr/local/include/c++/4.8.2/x86_64-unknown-linux-gnu \ -I /usr/local/include \ -I /usr/include \ --sp-file $MY_PATTERN /usr/src/linux-stable/mm/slab.c; \
Quoted 1 line
date
So 26. Okt 07:02:18 CET 2014
@Show_functions_with_input_pointer_validation@
identifier fun, x;
type t;
@@
*void fun(..., t* x, ...)
{
...
if (unlikely(ZERO_OR_NULL_PTR(x)))
return;
...
}
-----
spatch version 1.0.0-rc22 with Python support and with PCRE supportinit_defs_builtins: /usr/local/share/coccinelle/standard.h
HANDLING: /usr/src/linux-stable/mm/slab.c
(ONCE) TYPE: header process.h not found
[...]
(ONCE) TYPE: header trace/events/kmem.h not found
(ONCE) already tagged but only removed, so safe
diff =
--- /usr/src/linux-stable/mm/slab.c
@@ -3598,7 +3598,6 @@ EXPORT_SYMBOL(kmem_cache_free);
* Don't free memory not originally allocated by kmalloc()
* or you will run into trouble.
*/
-void kfree(const void *objp)
{
struct kmem_cache *c;
unsigned long flags;Note: processing took 43.5s: /usr/src/linux-stable/mm/slab.c
starting: Common.group_assoc_bykey_eff
ending: Common.group_assoc_bykey_eff, 0.000005s
---------------------
profiling result
---------------------
Main total : 43.552 sec 1 count Main.outfiles computation : 43.490 sec 1 count full_engine : 43.481 sec 1 count C parsing : 17.765 sec 866 count TOTAL : 17.763 sec 866 count HACK : 6.017 sec 2001 count C parsing.fix_cpp : 5.559 sec 1134 count C parsing.tokens : 3.528 sec 867 count LEXING : 3.506 sec 866 count Parsing: multi pass : 2.818 sec 2369 count Parsing: 1st pass : 2.258 sec 42256 count MACRO managment : 1.725 sec 2671 count YACC : 1.634 sec 40007 count TAC.annotate_program : 0.983 sec 433 count show_xxx : 0.855 sec 310 count C parsing.fix_define : 0.761 sec 1733 count MACRO mgmt prep 2 : 0.494 sec 866 count C consistencycheck : 0.461 sec 866 count C parsing.lookahead : 0.407 sec 455401 count Common.full_charpos_to_pos_large : 0.389 sec 867 count flow : 0.371 sec 20946 count C parsing.mk_info_item : 0.361 sec 42256 count C parsing.lex_ident : 0.314 sec 313227 count Type_c.type_of_s : 0.234 sec 10649 count fix_flow : 0.154 sec 15138 count TAC.add_binding : 0.075 sec 18856 count MACRO mgmt prep 1 : 0.064 sec 866 count pre_engine : 0.036 sec 1 count parse cocci : 0.032 sec 1 count bigloop : 0.026 sec 1 count Show_functions_with_input_pointer_validation : 0.023 sec 1 count process_a_ctl_a_env_a_toplevel : 0.023 sec 300 count mysat : 0.022 sec 300 count Common.info_from_charpos : 0.018 sec 82 count Common.=~ : 0.013 sec 9107 count worth_trying : 0.009 sec 1 count Common.full_charpos_to_pos : 0.005 sec 2 count TAC.typedef_fix : 0.005 sec 14621 count C unparsing : 0.005 sec 2 count asttoctl2 : 0.003 sec 1 count ctl : 0.000 sec 3 count Transformation3.transform : 0.000 sec 1 count get_glimpse_constants : 0.000 sec 1 count Main.result analysis : 0.000 sec 1 count check_duplicate : 0.000 sec 1 count Common.group_assoc_bykey_eff : 0.000 sec 1 count C_vs_c : 0.000 sec 1 count merge_env : 0.000 sec 1 count post_engine : 0.000 sec 1 count Main.infiles computation : 0.000 sec 1 count
So 26. Okt 07:03:01 CET 2014
Do you find this analysis result interesting?
Regards,
Markus
Re: [PATCH 1/1] GPU-DRM-GMA500: Deletion of unnecessary checks before two function calls
In reply to One Thousand GnomesQuoted 1 line
What platforms have you tested the code on at this point ?
None. - My "test computer" does not provide the corresponding hardware for the affected driver source files.
Regards,
Markus
I would like to show again that the version 1.0.0-rc22 works better than 1.0.0-rc20 for another use case.
Quoted 1 line
There is an isomorphism for unlikely, but it does not work well.
Interesting ...
Quoted 2 lines
You can disable it (look in standard.iso to find the name and then put disable name between the initial @@).
Does your feedback refer also to the message "(ONCE) already tagged but only removed, so safe" eventually?
I am curious how the shown profiling results will change over time because of software improvements.
Regards,
Markus
PATCH 1/1 GPU-DRM-GMA500: Deletion of unnecessary checks before two function calls
In reply to SF Markus ElfringI still have the hardware in use and I am willing to test.
If necessary, please send me a URL to the snapshot of the kernel with the modified code. I can compile this (takes about 8 hours ;-) on the high speed atom n2600) and run a couple of random tests, such as starting the WM, browsing some webpages, changing resolution, and run a 2D benchmark.
Greetings,
Arthur Borsboom
Quoted 9 lines · SF Markus Elfring
Quoted 1 line
What platforms have you tested the code on at this point ?
None. - My "test computer" does not provide the corresponding hardware for the
affected driver source files.Regards,
Markus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20141026/a28726a1/attachment-0001.html>
Greg Kroah-Hartman
maintainerRe: [PATCH 1/1] staging - rtl8188eu: Deletion of unnecessary checks before three function calls
In reply to SF Markus ElfringQuoted 5 lines · SF Markus Elfring
Quoted 1 line
From
45970693cad6c12da2d5ac7da3d2bd7a566170d7Mon Sep 17 00:00:00 2001From: Markus Elfring <[email protected]>
Date: Thu, 23 Oct 2014 20:55:13 +0200
Subject: [PATCH] staging - rtl8188eu: Deletion of unnecessary checks before
three function calls
Why is this here? Please use git send-email to send a patch, so I don't have to hand-edit the text in it.
Also, your Subject is a bit odd, it has a "Re:" in it for no reason, and your From: doesn't match the name you used here.
Please fix up and resend.
thanks,
greg k-h
Re: [PATCH 1/1] s390/net: Deletion of unnecessary checks before two function calls
In reply to SF Markus ElfringThe functions debug_unregister() and kfree_fsm() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- drivers/s390/net/claw.c | 6 ++---- drivers/s390/net/ctcm_main.c | 6 ++---- drivers/s390/net/lcs.c | 6 ++---- drivers/s390/net/netiucv.c | 12 ++++-------- 4 files changed, 10 insertions(+), 20 deletions(-)
drivers/s390/net/claw.c +2 -4
@@ -109,10 +109,8 @@ static debug_info_t *claw_dbf_trace;static void claw_unregister_debug_facility (void ) { -if (claw_dbf_setup) -debug_unregister (claw_dbf_setup); -if (claw_dbf_trace) -debug_unregister (claw_dbf_trace); +debug_unregister (claw_dbf_setup); +debug_unregister (claw_dbf_trace); } static int
drivers/s390/net/ctcm_main.c +2 -4
@@ -1074,8 +1074,7 @@ static void ctcm_free_netdevice(struct net_device *dev)if (priv) { grp = priv->mpcg;if (grp) { -if (grp->fsm) -kfree_fsm (grp->fsm); +kfree_fsm (grp->fsm);if (grp->xid_skb)dev_kfree_skb (grp->xid_skb);if (grp->rcvd_xid_skb)
@@ -1672,8 +1671,7 @@ static int ctcm_shutdown_device(struct ccwgroup_device *cgdev)ctcm_free_netdevice (dev); } -if (priv->fsm) -kfree_fsm (priv->fsm); +kfree_fsm (priv->fsm);ccw_device_set_offline (cgdev->cdev[1 ]);ccw_device_set_offline (cgdev->cdev[0 ]);
drivers/s390/net/lcs.c +2 -4
@@ -88,10 +88,8 @@ static debug_info_t *lcs_dbf_trace;static void lcs_unregister_debug_facility (void ) { -if (lcs_dbf_setup) -debug_unregister (lcs_dbf_setup); -if (lcs_dbf_trace) -debug_unregister (lcs_dbf_trace); +debug_unregister (lcs_dbf_setup); +debug_unregister (lcs_dbf_trace); } static int
drivers/s390/net/netiucv.c +4 -8
@@ -487,12 +487,9 @@ DEFINE_PER_CPU(char[256], iucv_dbf_txt_buf);static void iucv_unregister_dbf_views (void ) { -if (iucv_dbf_setup) -debug_unregister (iucv_dbf_setup); -if (iucv_dbf_data) -debug_unregister (iucv_dbf_data); -if (iucv_dbf_trace) -debug_unregister (iucv_dbf_trace); +debug_unregister (iucv_dbf_setup); +debug_unregister (iucv_dbf_data); +debug_unregister (iucv_dbf_trace); }static int iucv_register_dbf_views (void ) {
@@ -1975,8 +1972,7 @@ static void netiucv_free_netdevice(struct net_device *dev)if (privptr) {if (privptr->conn)netiucv_remove_connection (privptr->conn); -if (privptr->fsm) -kfree_fsm (privptr->fsm); +kfree_fsm (privptr->fsm); privptr->conn =NULL ; privptr->fsm =NULL ;/* privptr gets freed by free_netdev() */ }
Signature · 1 line
2.1.3
PATCH 1/1 staging: rtl8188eu: Deletion of unnecessary checks before three function calls
In reply to Greg Kroah-HartmanThe functions kfree(), rtw_free_netdev() and vfree() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- drivers/staging/rtl8188eu/core/rtw_efuse.c | 3 +-- drivers/staging/rtl8188eu/core/rtw_mlme.c | 3 +-- drivers/staging/rtl8188eu/core/rtw_sta_mgt.c | 3 +-- drivers/staging/rtl8188eu/core/rtw_xmit.c | 6 ++---- drivers/staging/rtl8188eu/os_dep/usb_intf.c | 5 ++--- 5 files changed, 7 insertions(+), 13 deletions(-)
(quoted diff) +0 -0
b/drivers/staging/rtl8188eu/core/rtw_efuse.c
index 7006088..77f7552 100644
drivers/staging/rtl8188eu/core/rtw_efuse.c +0 -0
@@ -212,8 +212,7 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16
_size_byte, u8 *pbuf)
exit:
kfree(efuseTbl);
- if (eFuseWord)
- kfree(eFuseWord);
+ kfree(eFuseWord);
}
static void efuse_read_phymap_from_txpktbuf(
(quoted diff) +0 -0
b/drivers/staging/rtl8188eu/core/rtw_mlme.c
index 149c271..df54350 100644
drivers/staging/rtl8188eu/core/rtw_mlme.c +1 -2
@@ -122,8 +122,7 @@ void rtw_free_mlme_priv(struct mlme_priv *pmlmepriv)rtw_free_mlme_priv_ie_data (pmlmepriv);if (pmlmepriv) { -if (pmlmepriv->free_bss_buf) -vfree (pmlmepriv->free_bss_buf); +vfree (pmlmepriv->free_bss_buf); } }
(quoted diff) +0 -0
b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
index e1dc8fa..af1de9c 100644
drivers/staging/rtl8188eu/core/rtw_sta_mgt.c +1 -2
@@ -201,8 +201,7 @@ u32 _rtw_free_sta_priv(struct sta_priv *pstapriv)rtw_mfree_sta_priv_lock (pstapriv); -if (pstapriv->pallocated_stainfo_buf) -vfree (pstapriv->pallocated_stainfo_buf); +vfree (pstapriv->pallocated_stainfo_buf); }return _SUCCESS;
(quoted diff) +0 -0
b/drivers/staging/rtl8188eu/core/rtw_xmit.c
index 639ace0..011c9cf 100644
drivers/staging/rtl8188eu/core/rtw_xmit.c +2 -4
@@ -246,11 +246,9 @@ void _rtw_free_xmit_priv (struct xmit_priv *pxmitpriv) pxmitbuf++; } -if (pxmitpriv->pallocated_frame_buf) -vfree (pxmitpriv->pallocated_frame_buf); +vfree (pxmitpriv->pallocated_frame_buf); -if (pxmitpriv->pallocated_xmitbuf) -vfree (pxmitpriv->pallocated_xmitbuf); +vfree (pxmitpriv->pallocated_xmitbuf);/* free xmit extension buff */ pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmit_extbuf;
(quoted diff) +0 -0
b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
index 407a318..cdb70e4 100644
drivers/staging/rtl8188eu/os_dep/usb_intf.c +2 -3
@@ -456,7 +456,7 @@ free_adapter:if (status != _SUCCESS) {if (pnetdev)rtw_free_netdev (pnetdev); -else if (padapter) +else vfree (padapter); padapter =NULL ; }
@@ -487,8 +487,7 @@ static void rtw_usb_if1_deinit(struct adapter *if1)DBG_88E ("+r871xu_dev_remove, hw_init_completed=%d\n" , if1->hw_init_completed);rtw_free_drv_sw (if1); -if (pnetdev) -rtw_free_netdev (pnetdev); +rtw_free_netdev (pnetdev); } static int rtw_drv_init(struct usb_interface *pusb_intf, const struct
usb_device_id *pdid)
Signature · 1 line
2.1.2
Re: [PATCH resent] staging: rtl8188eu: Deletion of unnecessary checks before three function calls
Quoted 21 lines · SF Markus Elfring
The functions
kfree(),rtw_free_netdev()andvfree()test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- drivers/staging/rtl8188eu/core/rtw_efuse.c | 3 +-- drivers/staging/rtl8188eu/core/rtw_mlme.c | 3 +-- drivers/staging/rtl8188eu/core/rtw_sta_mgt.c | 3 +-- drivers/staging/rtl8188eu/core/rtw_xmit.c | 6 ++---- drivers/staging/rtl8188eu/os_dep/usb_intf.c | 5 ++--- 5 files changed, 7 insertions(+), 13 deletions(-)drivers/staging/rtl8188eu/core/rtw_efuse.c +0
-0
drivers/staging/rtl8188eu/core/rtw_efuse.c efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 · line 216
Quoted 7 lines
drivers/staging/rtl8188eu/core/rtw_efuse.c +1
-2@@ -212,8 +212,7 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf) exit:kfree (efuseTbl); -if (eFuseWord) -kfree (eFuseWord); +kfree (eFuseWord);
I think that this code has been updated already. It would be better to add labels so that kfree is only executed when needed.
julia
Quoted 85 lines
drivers/staging/rtl8188eu/core/rtw_efuse.c +0
-0}static void efuse_read_phymap_from_txpktbuf(
drivers/staging/rtl8188eu/core/rtw_mlme.c +1
-2@@ -122,8 +122,7 @@ void rtw_free_mlme_priv(struct mlme_priv *pmlmepriv)rtw_free_mlme_priv_ie_data (pmlmepriv);if (pmlmepriv) { -if (pmlmepriv->free_bss_buf) -vfree (pmlmepriv->free_bss_buf); +vfree (pmlmepriv->free_bss_buf); } }drivers/staging/rtl8188eu/core/rtw_sta_mgt.c +1
-2@@ -201,8 +201,7 @@ u32 _rtw_free_sta_priv(struct sta_priv *pstapriv)rtw_mfree_sta_priv_lock (pstapriv); -if (pstapriv->pallocated_stainfo_buf) -vfree (pstapriv->pallocated_stainfo_buf); +vfree (pstapriv->pallocated_stainfo_buf); }return _SUCCESS;drivers/staging/rtl8188eu/core/rtw_xmit.c +2
-4@@ -246,11 +246,9 @@ void _rtw_free_xmit_priv (struct xmit_priv *pxmitpriv) pxmitbuf++; } -if (pxmitpriv->pallocated_frame_buf) -vfree (pxmitpriv->pallocated_frame_buf); +vfree (pxmitpriv->pallocated_frame_buf); -if (pxmitpriv->pallocated_xmitbuf) -vfree (pxmitpriv->pallocated_xmitbuf); +vfree (pxmitpriv->pallocated_xmitbuf);/* free xmit extension buff */ pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmit_extbuf;drivers/staging/rtl8188eu/os_dep/usb_intf.c +2
-3@@ -456,7 +456,7 @@ free_adapter:if (status != _SUCCESS) {if (pnetdev)rtw_free_netdev (pnetdev); -else if (padapter) +else vfree (padapter); padapter =NULL ; }@@ -487,8 +487,7 @@ static void rtw_usb_if1_deinit(struct adapter *if1)DBG_88E ("+r871xu_dev_remove, hw_init_completed=%d\n" , if1->hw_init_completed);rtw_free_drv_sw (if1); -if (pnetdev) -rtw_free_netdev (pnetdev); +rtw_free_netdev (pnetdev); } static int rtw_drv_init(struct usb_interface *pusb_intf, const struct
usb_device_id*pdid)
--
2.1.2--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH resent] staging: rtl8188eu: Deletion of unnecessary checks before three function calls
Quoted 25 lines
Quoted 25 lines
The functions
kfree(),rtw_free_netdev()andvfree()test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- drivers/staging/rtl8188eu/core/rtw_efuse.c | 3 +-- drivers/staging/rtl8188eu/core/rtw_mlme.c | 3 +-- drivers/staging/rtl8188eu/core/rtw_sta_mgt.c | 3 +-- drivers/staging/rtl8188eu/core/rtw_xmit.c | 6 ++---- drivers/staging/rtl8188eu/os_dep/usb_intf.c | 5 ++--- 5 files changed, 7 insertions(+), 13 deletions(-)drivers/staging/rtl8188eu/core/rtw_efuse.c +0
-0@@ -212,8 +212,7 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf) exit:kfree (efuseTbl);
Quoted 6 lines
drivers/staging/rtl8188eu/core/rtw_efuse.c efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 · line 216
Quoted 3 lines
drivers/staging/rtl8188eu/core/rtw_efuse.c +1
-2-if (eFuseWord) -kfree (eFuseWord); +kfree (eFuseWord);I think that this code has been updated already. It would be better to add labels so that kfree is only executed when needed.
Are there any chances to achieve the suggested fine-tuning for jump labels also with another semantic patch approach?
Regards,
Markus
Re: [PATCH resent] staging: rtl8188eu: Deletion of unnecessary checks before three function calls
Quoted 32 lines · SF Markus Elfring
Quoted 25 lines
Quoted 25 lines
The functions
kfree(),rtw_free_netdev()andvfree()test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- drivers/staging/rtl8188eu/core/rtw_efuse.c | 3 +-- drivers/staging/rtl8188eu/core/rtw_mlme.c | 3 +-- drivers/staging/rtl8188eu/core/rtw_sta_mgt.c | 3 +-- drivers/staging/rtl8188eu/core/rtw_xmit.c | 6 ++---- drivers/staging/rtl8188eu/os_dep/usb_intf.c | 5 ++--- 5 files changed, 7 insertions(+), 13 deletions(-)drivers/staging/rtl8188eu/core/rtw_efuse.c +0
-0@@ -212,8 +212,7 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf) exit:kfree (efuseTbl);Quoted 6 lines
drivers/staging/rtl8188eu/core/rtw_efuse.c efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 · line 216
Quoted 3 lines
drivers/staging/rtl8188eu/core/rtw_efuse.c +1
-2-if (eFuseWord) -kfree (eFuseWord); +kfree (eFuseWord);I think that this code has been updated already. It would be better to add labels so that kfree is only executed when needed.
Quoted 2 lines
Are there any chances to achieve the suggested fine-tuning for jump labels also with another semantic patch approach?
No, I don't think so. The pattern is not regular enough.
julia
PATCH 1/1 btrfs: Deletion of unnecessary checks before six function calls
In reply to SF Markus ElfringThe following functions test whether their argument is NULL and then return immediately.
* btrfs_free_path()
* free_extent_buffer()
* free_extent_map()
* free_extent_state()
* iput()
* kfree()
Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- fs/btrfs/dev-replace.c | 3 +-- fs/btrfs/extent_io.c | 12 ++++-------- fs/btrfs/file.c | 6 ++---- fs/btrfs/free-space-cache.c | 7 +++---- fs/btrfs/inode.c | 6 ++---- fs/btrfs/reada.c | 3 +-- fs/btrfs/relocation.c | 3 +-- fs/btrfs/tests/btrfs-tests.c | 3 +-- fs/btrfs/tree-defrag.c | 3 +-- fs/btrfs/tree-log.c | 6 ++---- 10 files changed, 18 insertions(+), 34 deletions(-)
fs/btrfs/dev-replace.c +1 -2
@@ -183,8 +183,7 @@ no_valid_dev_replace_entry_found: } out: -if (path) -btrfs_free_path (path); +btrfs_free_path (path);return ret; }
fs/btrfs/extent_io.c +4 -8
@@ -704,8 +704,7 @@ next: out:spin_unlock (&tree->lock); -if (prealloc) -free_extent_state (prealloc); +free_extent_state (prealloc);return 0 ;
@@ -1006,8 +1005,7 @@ hit_next: out:spin_unlock (&tree->lock); -if (prealloc) -free_extent_state (prealloc); +free_extent_state (prealloc);return err;
@@ -1223,8 +1221,7 @@ hit_next: out:spin_unlock (&tree->lock); -if (prealloc) -free_extent_state (prealloc); +free_extent_state (prealloc);return err;
@@ -4146,8 +4143,7 @@ int extent_readpages(struct extent_io_tree *tree,__extent_readpages (tree, pagepool, nr, get_extent, &em_cached, &bio,0 , &bio_flags,READ ); -if (em_cached) -free_extent_map (em_cached); +free_extent_map (em_cached);BUG_ON (!list_empty (pages));if (bio)
fs/btrfs/file.c +2 -4
@@ -677,10 +677,8 @@ next:/* once for the tree*/ free_extent_map (em); } -if (split) -free_extent_map (split); -if (split2) -free_extent_map (split2); +free_extent_map (split); +free_extent_map (split2); }/*
fs/btrfs/free-space-cache.c +3 -4
@@ -1943,8 +1943,7 @@ new_bitmap: out:if (info) { -if (info->bitmap) -kfree (info->bitmap); +kfree (info->bitmap);kmem_cache_free (btrfs_free_space_cachep, info); }
@@ -3322,8 +3321,8 @@ again:if (info)kmem_cache_free (btrfs_free_space_cachep, info); -if (map) -kfree (map); + +kfree (map);return 0 ; }
fs/btrfs/inode.c +0 -0
@@ -857,8 +857,7 @@ static u64 get_extent_allocation_hint(struct inode *inode,
u64 start,
em = search_extent_mapping(em_tree, 0, 0); if (em && em->block_start < EXTENT_MAP_LAST_BYTE)
alloc_hint = em->block_start;
- if (em)
- free_extent_map(em);
+ free_extent_map(em);
} else {
alloc_hint = em->block_start; free_extent_map(em);
@@ -6573,8 +6572,7 @@ out:
trace_btrfs_get_extent(root, em);
- if (path)
- btrfs_free_path(path);
+ btrfs_free_path(path);
if (trans) {
ret = btrfs_end_transaction(trans, root); if (!err)
fs/btrfs/reada.c +0 -0
@@ -731,8 +731,7 @@ static int reada_start_machine_dev(struct btrfs_fs_info
*fs_info,
else if (eb)
__readahead_hook(fs_info->extent_root, eb, eb->start, ret);
- if (eb)
- free_extent_buffer(eb);
+ free_extent_buffer(eb);
return 1;
fs/btrfs/relocation.c +1 -2
@@ -4158,8 +4158,7 @@ out:btrfs_end_transaction (trans, root);btrfs_btree_balance_dirty (root);if (err) { -if (inode) -iput (inode); +iput (inode); inode =ERR_PTR (err); }return inode;
fs/btrfs/tests/btrfs-tests.c +1 -2
@@ -162,8 +162,7 @@ void btrfs_free_dummy_root(struct btrfs_root *root) {if (!root)return ; -if (root->node) -free_extent_buffer (root->node); +free_extent_buffer (root->node);if (root->fs_info)btrfs_free_dummy_fs_info (root->fs_info);kfree (root);
fs/btrfs/tree-defrag.c +1 -2
@@ -118,8 +118,7 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, ret = -EAGAIN ; } out: -if (path) -btrfs_free_path (path); +btrfs_free_path (path);if (ret == -EAGAIN ) {if (root->defrag_max.objectid > root->defrag_progress.objectid) goto done;
fs/btrfs/tree-log.c +0 -0
@@ -736,8 +736,7 @@ static noinline int replay_one_extent(struct
btrfs_trans_handle *trans,
inode_add_bytes(inode, nbytes);
ret = btrfs_update_inode(trans, root, inode);
out:
- if (inode)
- iput(inode);
+ iput(inode);
return ret;
}
@@ -2210,8 +2209,7 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans,
}
WARN_ON(*level <= 0);
- if (path->nodes[*level-1])
- free_extent_buffer(path->nodes[*level-1]);
+ free_extent_buffer(path->nodes[*level-1]);
path->nodes[*level-1] = next; *level = btrfs_header_level(next); path->slots[*level] = 0;
Signature · 1 line
2.1.3
Re: [Cocci] [PATCH 1/1] btrfs: Deletion of unnecessary checks before six function calls
Quoted 32 lines · SF Markus Elfring
The following functions test whether their argument is NULL and then return immediately.
*btrfs_free_path()
*free_extent_buffer()
*free_extent_map()
*free_extent_state()
*iput()
*kfree()Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- fs/btrfs/dev-replace.c | 3 +-- fs/btrfs/extent_io.c | 12 ++++-------- fs/btrfs/file.c | 6 ++---- fs/btrfs/free-space-cache.c | 7 +++---- fs/btrfs/inode.c | 6 ++---- fs/btrfs/reada.c | 3 +-- fs/btrfs/relocation.c | 3 +-- fs/btrfs/tests/btrfs-tests.c | 3 +-- fs/btrfs/tree-defrag.c | 3 +-- fs/btrfs/tree-log.c | 6 ++---- 10 files changed, 18 insertions(+), 34 deletions(-)fs/btrfs/dev-replace.c +0
-0
fs/btrfs/dev-replace.c no_valid_dev_replace_entry_found: · line 186
Quoted 6 lines
fs/btrfs/dev-replace.c +1
-2@@ -183,8 +183,7 @@ no_valid_dev_replace_entry_found: } out: -if (path) -btrfs_free_path (path); +btrfs_free_path (path);
It appears to be statically apparent whether btrfs_free_path is needed or not. The code could be changed both not to have the test and not to have the jump and call to btrfs_free_path.
This is probably the case for the other occurrences next to labels.
julia
Quoted 206 lines
fs/btrfs/dev-replace.c +0
-0return ret; }fs/btrfs/extent_io.c +4
-8@@ -704,8 +704,7 @@ next: out:spin_unlock (&tree->lock); -if (prealloc) -free_extent_state (prealloc); +free_extent_state (prealloc);return 0 ;@@ -1006,8 +1005,7 @@ hit_next: out:spin_unlock (&tree->lock); -if (prealloc) -free_extent_state (prealloc); +free_extent_state (prealloc);return err;@@ -1223,8 +1221,7 @@ hit_next: out:spin_unlock (&tree->lock); -if (prealloc) -free_extent_state (prealloc); +free_extent_state (prealloc);return err;@@ -4146,8 +4143,7 @@ int extent_readpages(struct extent_io_tree *tree,__extent_readpages (tree, pagepool, nr, get_extent, &em_cached, &bio,0 , &bio_flags,READ ); -if (em_cached) -free_extent_map (em_cached); +free_extent_map (em_cached);BUG_ON (!list_empty (pages));if (bio)fs/btrfs/file.c +2
-4@@ -677,10 +677,8 @@ next:/* once for the tree*/ free_extent_map (em); } -if (split) -free_extent_map (split); -if (split2) -free_extent_map (split2); +free_extent_map (split); +free_extent_map (split2); }/* fs/btrfs/free-space-cache.c +3
-4@@ -1943,8 +1943,7 @@ new_bitmap: out:if (info) { -if (info->bitmap) -kfree (info->bitmap); +kfree (info->bitmap);kmem_cache_free (btrfs_free_space_cachep, info); }@@ -3322,8 +3321,8 @@ again:if (info)kmem_cache_free (btrfs_free_space_cachep, info); -if (map) -kfree (map); + +kfree (map);return 0 ; }fs/btrfs/inode.c +1
-2@@ -857,8 +857,7 @@ static u64 get_extent_allocation_hint(struct inode *inode,u64 start, em =search_extent_mapping (em_tree,0 ,0 );if (em && em->block_start <EXTENT_MAP_LAST_BYTE ) alloc_hint = em->block_start; -if (em) -free_extent_map (em); +free_extent_map (em); }else { alloc_hint = em->block_start;fs/btrfs/inode.c +1
-2free_extent_map (em);@@ -6573,8 +6572,7 @@ out:trace_btrfs_get_extent (root, em); -if (path) -btrfs_free_path (path); +btrfs_free_path (path);if (trans) { ret =btrfs_end_transaction (trans, root);if (!err)fs/btrfs/reada.c +1
-2@@ -731,8 +731,7 @@ static int reada_start_machine_dev(struct btrfs_fs_info *fs_info, else if (eb)__readahead_hook (fs_info->extent_root, eb, eb->start, ret); -if (eb) -free_extent_buffer (eb); +free_extent_buffer (eb);return 1 ;fs/btrfs/relocation.c +1
-2@@ -4158,8 +4158,7 @@ out:btrfs_end_transaction (trans, root);btrfs_btree_balance_dirty (root);if (err) { -if (inode) -iput (inode); +iput (inode); inode =ERR_PTR (err); }return inode;fs/btrfs/tests/btrfs-tests.c +1
-2@@ -162,8 +162,7 @@ void btrfs_free_dummy_root(struct btrfs_root *root) {if (!root)return ; -if (root->node) -free_extent_buffer (root->node); +free_extent_buffer (root->node);if (root->fs_info)btrfs_free_dummy_fs_info (root->fs_info);kfree (root);fs/btrfs/tree-defrag.c +1
-2@@ -118,8 +118,7 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, ret = -EAGAIN ; } out: -if (path) -btrfs_free_path (path); +btrfs_free_path (path);if (ret == -EAGAIN ) {if (root->defrag_max.objectid > root->defrag_progress.objectid) goto done;fs/btrfs/tree-log.c +2
-4@@ -736,8 +736,7 @@ static noinline int replay_one_extent(structbtrfs_trans_handle *trans,inode_add_bytes (inode ,nbytes ); ret =btrfs_update_inode (trans, root, inode); out: -if (inode) -iput (inode); +iput (inode);return ret; }@@ -2210,8 +2209,7 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans, }WARN_ON (*level <=0 ); -if (path->nodes[*level-1 ]) -free_extent_buffer (path->nodes[*level-1 ]); +free_extent_buffer (path->nodes[*level-1 ]); path->nodes[*level-1 ] = next; *level =btrfs_header_level (next);path->slots[*level] = 0;
Signature · 7 lines
2.1.3 _______________________________________________ Cocci mailing list Cocci at systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
PATCH 1/1 ocfs2: Deletion of unnecessary checks before two function calls
In reply to SF Markus ElfringThe functions iput() and ocfs2_free_path() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- fs/ocfs2/alloc.c | 15 +++++---------- fs/ocfs2/ioctl.c | 3 +-- fs/ocfs2/journal.c | 9 +++------ fs/ocfs2/localalloc.c | 9 +++------ fs/ocfs2/namei.c | 3 +-- fs/ocfs2/slot_map.c | 3 +-- fs/ocfs2/super.c | 3 +-- 7 files changed, 15 insertions(+), 30 deletions(-)
fs/ocfs2/alloc.c +5 -10
@@ -3453,8 +3453,7 @@ static int ocfs2_merge_rec_right(struct ocfs2_path *left_path, subtree_index); } out: -if (right_path) -ocfs2_free_path (right_path); +ocfs2_free_path (right_path);return ret; }
@@ -3647,8 +3646,7 @@ static int ocfs2_merge_rec_left(struct ocfs2_path *right_path, right_path, subtree_index); } out: -if (left_path) -ocfs2_free_path (left_path); +ocfs2_free_path (left_path);return ret; }
@@ -4431,10 +4429,8 @@ ocfs2_figure_merge_contig_type(struct ocfs2_extent_tree *et, } out: -if (left_path) -ocfs2_free_path (left_path); -if (right_path) -ocfs2_free_path (right_path); +ocfs2_free_path (left_path); +ocfs2_free_path (right_path);return ret; }
@@ -6157,8 +6153,7 @@ int ocfs2_begin_truncate_log_recovery(struct ocfs2_super *osb, } bail: -if (tl_inode) -iput (tl_inode); +iput (tl_inode);brelse (tl_bh);if (status <0 && (*tl_copy)) {
fs/ocfs2/ioctl.c +1 -2
@@ -606,8 +606,7 @@ bail:if (gb_inode)mutex_unlock (&gb_inode->i_mutex); -if (gb_inode) -iput (gb_inode); +iput (gb_inode);brelse (bh);
fs/ocfs2/journal.c +3 -6
@@ -1009,8 +1009,7 @@ void ocfs2_journal_shutdown(struct ocfs2_super *osb)// up_write(&journal->j_trans_barrier); done: -if (inode) -iput (inode); +iput (inode); } static void ocfs2_clear_journal_error(struct super_block *sb,
@@ -1646,8 +1645,7 @@ done:if (got_lock)ocfs2_inode_unlock (inode,1 ); -if (inode) -iput (inode); +iput (inode);brelse (bh);
@@ -1755,8 +1753,7 @@ static int ocfs2_trylock_journal(struct ocfs2_super *osb,ocfs2_inode_unlock (inode,1 ); bail: -if (inode) -iput (inode); +iput (inode);return status; }
fs/ocfs2/localalloc.c +3 -6
@@ -358,8 +358,7 @@ int ocfs2_load_local_alloc(struct ocfs2_super *osb) bail:if (status <0 )brelse (alloc_bh); -if (inode) -iput (inode); +iput (inode);trace_ocfs2_load_local_alloc (osb->local_alloc_bits);
@@ -473,8 +472,7 @@ out_mutex:iput (main_bm_inode); out: -if (local_alloc_inode) -iput (local_alloc_inode); +iput (local_alloc_inode);kfree (alloc_copy); }
@@ -1328,8 +1326,7 @@ bail:brelse (main_bm_bh); -if (main_bm_inode) -iput (main_bm_inode); +iput (main_bm_inode);kfree (alloc_copy);
fs/ocfs2/namei.c +1 -2
@@ -1607,8 +1607,7 @@ bail:if (new_inode)sync_mapping_buffers (old_inode->i_mapping); -if (new_inode) -iput (new_inode); +iput (new_inode);ocfs2_free_dir_lookup_result (&target_lookup_res);ocfs2_free_dir_lookup_result (&old_entry_lookup);
fs/ocfs2/slot_map.c +1 -2
@@ -322,8 +322,7 @@ static void __ocfs2_free_slot_info(struct ocfs2_slot_info *si)if (si ==NULL )return ; -if (si->si_inode) -iput (si->si_inode); +iput (si->si_inode);if (si->si_bh) {for (i =0 ; i < si->si_blocks; i++) {if (si->si_bh[i]) {
fs/ocfs2/super.c +0 -0
@@ -1723,8 +1723,7 @@ static int ocfs2_statfs(struct dentry *dentry, struct
kstatfs *buf)
ocfs2_inode_unlock(inode, 0);
status = 0;
bail:
- if (inode)
- iput(inode);
+ iput(inode);
if (status)
mlog_errno(status);
Signature · 1 line
2.1.3
Re: [PATCH 1/1] ocfs2: Deletion of unnecessary checks before two function calls
Quoted 3 lines · SF Markus Elfring
The functions
iput()andocfs2_free_path()test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.
Please check whether more labels could be added to avoid executing unnecessary code.
julia
Quoted 194 lines
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- fs/ocfs2/alloc.c | 15 +++++---------- fs/ocfs2/ioctl.c | 3 +-- fs/ocfs2/journal.c | 9 +++------ fs/ocfs2/localalloc.c | 9 +++------ fs/ocfs2/namei.c | 3 +-- fs/ocfs2/slot_map.c | 3 +-- fs/ocfs2/super.c | 3 +-- 7 files changed, 15 insertions(+), 30 deletions(-)fs/ocfs2/alloc.c +5
-10@@ -3453,8 +3453,7 @@ static int ocfs2_merge_rec_right(struct ocfs2_path *left_path, subtree_index); } out: -if (right_path) -ocfs2_free_path (right_path); +ocfs2_free_path (right_path);return ret; }@@ -3647,8 +3646,7 @@ static int ocfs2_merge_rec_left(struct ocfs2_path *right_path, right_path, subtree_index); } out: -if (left_path) -ocfs2_free_path (left_path); +ocfs2_free_path (left_path);return ret; }@@ -4431,10 +4429,8 @@ ocfs2_figure_merge_contig_type(struct ocfs2_extent_tree *et, } out: -if (left_path) -ocfs2_free_path (left_path); -if (right_path) -ocfs2_free_path (right_path); +ocfs2_free_path (left_path); +ocfs2_free_path (right_path);return ret; }@@ -6157,8 +6153,7 @@ int ocfs2_begin_truncate_log_recovery(struct ocfs2_super *osb, } bail: -if (tl_inode) -iput (tl_inode); +iput (tl_inode);brelse (tl_bh);if (status <0 && (*tl_copy)) {fs/ocfs2/ioctl.c +1
-2@@ -606,8 +606,7 @@ bail:if (gb_inode)mutex_unlock (&gb_inode->i_mutex); -if (gb_inode) -iput (gb_inode); +iput (gb_inode);brelse (bh);fs/ocfs2/journal.c +3
-6@@ -1009,8 +1009,7 @@ void ocfs2_journal_shutdown(struct ocfs2_super *osb)// up_write(&journal->j_trans_barrier); done: -if (inode) -iput (inode); +iput (inode); } static void ocfs2_clear_journal_error(struct super_block *sb,@@ -1646,8 +1645,7 @@ done:if (got_lock)ocfs2_inode_unlock (inode,1 ); -if (inode) -iput (inode); +iput (inode);brelse (bh);@@ -1755,8 +1753,7 @@ static int ocfs2_trylock_journal(struct ocfs2_super *osb,ocfs2_inode_unlock (inode,1 ); bail: -if (inode) -iput (inode); +iput (inode);return status; }fs/ocfs2/localalloc.c +3
-6@@ -358,8 +358,7 @@ int ocfs2_load_local_alloc(struct ocfs2_super *osb) bail:if (status <0 )brelse (alloc_bh); -if (inode) -iput (inode); +iput (inode);trace_ocfs2_load_local_alloc (osb->local_alloc_bits);@@ -473,8 +472,7 @@ out_mutex:iput (main_bm_inode); out: -if (local_alloc_inode) -iput (local_alloc_inode); +iput (local_alloc_inode);kfree (alloc_copy); }@@ -1328,8 +1326,7 @@ bail:brelse (main_bm_bh); -if (main_bm_inode) -iput (main_bm_inode); +iput (main_bm_inode);kfree (alloc_copy);fs/ocfs2/namei.c +1
-2@@ -1607,8 +1607,7 @@ bail:if (new_inode)sync_mapping_buffers (old_inode->i_mapping); -if (new_inode) -iput (new_inode); +iput (new_inode);ocfs2_free_dir_lookup_result (&target_lookup_res);ocfs2_free_dir_lookup_result (&old_entry_lookup);fs/ocfs2/slot_map.c +1
-2@@ -322,8 +322,7 @@ static void __ocfs2_free_slot_info(struct ocfs2_slot_info *si)if (si ==NULL )return ; -if (si->si_inode) -iput (si->si_inode); +iput (si->si_inode);if (si->si_bh) {for (i =0 ; i < si->si_blocks; i++) {if (si->si_bh[i]) {fs/ocfs2/super.c +1
-2@@ -1723,8 +1723,7 @@ static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf) ocfs2_inode_unlock(inode, 0); status =0 ; bail: -if (inode) -iput (inode); +iput (inode);if (status)
mlog_errno(status);Signature · 7 lines
2.1.3 -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/1 ceph: Deletion of unnecessary checks before two function calls
In reply to SF Markus ElfringThe functions ceph_put_snap_context() and iput() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- fs/ceph/caps.c | 3 +-- fs/ceph/mds_client.c | 6 ++---- fs/ceph/snap.c | 9 +++------ 3 files changed, 6 insertions(+), 12 deletions(-)
fs/ceph/caps.c +1 -2
@@ -3136,8 +3136,7 @@ flush_cap_releases: done:mutex_unlock (&session->s_mutex); done_unlocked: -if (inode) -iput (inode); +iput (inode);return ; bad:
fs/ceph/mds_client.c +2 -4
@@ -523,8 +523,7 @@ void ceph_mdsc_release_request(struct kref *kref) }if (req->r_locked_dir)ceph_put_cap_refs (ceph_inode (req->r_locked_dir),CEPH_CAP_PIN ); -if (req->r_target_inode) -iput (req->r_target_inode); +iput (req->r_target_inode);if (req->r_dentry)dput (req->r_dentry);if (req->r_old_dentry)
@@ -995,8 +994,7 @@ out: session->s_cap_iterator =NULL ;spin_unlock (&session->s_cap_lock); -if (last_inode) -iput (last_inode); +iput (last_inode);if (old_cap)ceph_put_cap (session->s_mdsc, old_cap);
fs/ceph/snap.c +1 -2
@@ -365,8 +365,7 @@ static int build_snap_context(struct ceph_snap_realm *realm) realm->ino, realm, snapc, snapc->seq, (unsigned int) snapc->num_snaps); -if (realm->cached_context) -ceph_put_snap_context (realm->cached_context); +ceph_put_snap_context (realm->cached_context); realm->cached_context = snapc;return 0 ;
@@ -590,15 +589,13 @@ static void queue_realm_cap_snaps(struct ceph_snap_realm
*realm)
if (!inode)
continue;
spin_unlock(&realm->inodes_with_caps_lock);
- if (lastinode)
- iput(lastinode);
+ iput(lastinode);
lastinode = inode; ceph_queue_cap_snap(ci); spin_lock(&realm->inodes_with_caps_lock);
} spin_unlock(&realm->inodes_with_caps_lock);
- if (lastinode)
- iput(lastinode);
+ iput(lastinode);
list_for_each_entry(child, &realm->children, child_item) {
dout("queue_realm_cap_snaps %p %llx queue child %p %llx\n",
Signature · 1 line
2.1.3
PATCH 1/1 PCI: Deletion of unnecessary checks before three function calls
In reply to SF Markus ElfringThe functions pci_dev_put(), pci_pme_wakeup_bus() and put_device() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- drivers/pci/pci-acpi.c | 3 +-- drivers/pci/probe.c | 3 +-- drivers/pci/search.c | 3 +-- drivers/pci/xen-pcifront.c | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-)
drivers/pci/pci-acpi.c +1 -2
@@ -60,8 +60,7 @@ static void pci_acpi_wake_dev(struct work_struct *work)pci_wakeup_event (pci_dev);pm_runtime_resume (&pci_dev->dev); -if (pci_dev->subordinate) -pci_pme_wakeup_bus (pci_dev->subordinate); +pci_pme_wakeup_bus (pci_dev->subordinate); }/**
drivers/pci/probe.c +1 -2
@@ -86,8 +86,7 @@ static void release_pcibus_dev(struct device *dev) {struct pci_bus *pci_bus =to_pci_bus (dev); -if (pci_bus->bridge) -put_device (pci_bus->bridge); +put_device (pci_bus->bridge);pci_bus_remove_resources (pci_bus);pci_release_bus_of_node (pci_bus);kfree (pci_bus);
drivers/pci/search.c +0 -0
@@ -305,8 +305,7 @@ static struct pci_dev *pci_get_dev_by_id(const struct
pci_device_id *id,
match_pci_dev_by_id);
if (dev)
pdev = to_pci_dev(dev);
- if (from)
- pci_dev_put(from);
+ pci_dev_put(from);
return pdev;
}
drivers/pci/xen-pcifront.c +1 -2
@@ -596,8 +596,7 @@ static pci_ers_result_t pcifront_common_process(int cmd, pcidev =pci_get_bus_and_slot (bus, devfn);if (!pcidev || !pcidev->driver) {dev_err (&pdev->xdev->dev,"device or AER driver is NULL\n" ); -if (pcidev) -pci_dev_put (pcidev); +pci_dev_put (pcidev);return result; } pdrv = pcidev->driver;
Signature · 1 line
2.1.3
PATCH 1/1 PCI: Deletion of unnecessary checks before three function calls
In reply to SF Markus ElfringThe functions pci_dev_put(), pci_pme_wakeup_bus() and put_device() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- drivers/pci/pci-acpi.c | 3 +-- drivers/pci/probe.c | 3 +-- drivers/pci/search.c | 3 +-- drivers/pci/xen-pcifront.c | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-)
drivers/pci/pci-acpi.c +1 -2
@@ -60,8 +60,7 @@ static void pci_acpi_wake_dev(struct work_struct *work)pci_wakeup_event (pci_dev);pm_runtime_resume (&pci_dev->dev); -if (pci_dev->subordinate) -pci_pme_wakeup_bus (pci_dev->subordinate); +pci_pme_wakeup_bus (pci_dev->subordinate); }/**
drivers/pci/probe.c +1 -2
@@ -86,8 +86,7 @@ static void release_pcibus_dev(struct device *dev) {struct pci_bus *pci_bus =to_pci_bus (dev); -if (pci_bus->bridge) -put_device (pci_bus->bridge); +put_device (pci_bus->bridge);pci_bus_remove_resources (pci_bus);pci_release_bus_of_node (pci_bus);kfree (pci_bus);
drivers/pci/search.c +0 -0
@@ -305,8 +305,7 @@ static struct pci_dev *pci_get_dev_by_id(const struct
pci_device_id *id,
match_pci_dev_by_id);
if (dev)
pdev = to_pci_dev(dev);
- if (from)
- pci_dev_put(from);
+ pci_dev_put(from);
return pdev;
}
drivers/pci/xen-pcifront.c +1 -2
@@ -596,8 +596,7 @@ static pci_ers_result_t pcifront_common_process(int cmd, pcidev =pci_get_bus_and_slot (bus, devfn);if (!pcidev || !pcidev->driver) {dev_err (&pdev->xdev->dev,"device or AER driver is NULL\n" ); -if (pcidev) -pci_dev_put (pcidev); +pci_dev_put (pcidev);return result; } pdrv = pcidev->driver;
Signature · 1 line
2.1.3
PATCH 1/1 PCI: EMU10K1: Deletion of unnecessary checks before three function calls
In reply to SF Markus ElfringThe functions kfree(), release_firmware() and snd_util_memhdr_free() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- sound/pci/emu10k1/emu10k1_main.c | 9 +++------ sound/pci/emu10k1/emufx.c | 3 +-- 2 files changed, 4 insertions(+), 8 deletions(-)
sound/pci/emu10k1/emu10k1_main.c +3 -6
@@ -1289,10 +1289,8 @@ static int snd_emu10k1_free(struct snd_emu10k1 *emu) }if (emu->emu1010.firmware_thread)kthread_stop (emu->emu1010.firmware_thread); -if (emu->firmware) -release_firmware (emu->firmware); -if (emu->dock_fw) -release_firmware (emu->dock_fw); +release_firmware (emu->firmware); +release_firmware (emu->dock_fw);if (emu->irq >=0 )free_irq (emu->irq, emu);/* remove reserved page */
@@ -1301,8 +1299,7 @@ static int snd_emu10k1_free(struct snd_emu10k1 *emu) (struct snd_util_memblk *)emu->reserved_page); emu->reserved_page =NULL ; } -if (emu->memhdr) -snd_util_memhdr_free (emu->memhdr); +snd_util_memhdr_free (emu->memhdr);if (emu->silent_page.area)snd_dma_free_pages (&emu->silent_page);if (emu->ptb_pages.area)
sound/pci/emu10k1/emufx.c +0 -0
@@ -777,8 +777,7 @@ static void snd_emu10k1_ctl_private_free(struct snd_kcontrol
*kctl)
kctl->private_value = 0;
list_del(&ctl->list);
kfree(ctl);
- if (kctl->tlv.p)
- kfree(kctl->tlv.p);
+ kfree(kctl->tlv.p);
}
static int snd_emu10k1_add_controls(struct snd_emu10k1 *emu,
Signature · 1 line
2.1.3
PATCH 1/1 kconfig: Deletion of unnecessary checks before the function call "sym_calc_value"
In reply to SF Markus ElfringThe sym_calc_value() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- scripts/kconfig/confdata.c | 6 ++---- scripts/kconfig/symbol.c | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-)
scripts/kconfig/confdata.c +2 -4
@@ -262,8 +262,7 @@ int conf_read_simple(const char *name, int def) goto load;sym_add_change_count (1 );if (!sym_defconfig_list) { -if (modules_sym) -sym_calc_value (modules_sym); +sym_calc_value (modules_sym);return 1 ; }
@@ -399,8 +398,7 @@ setsym:free (line);fclose (in); -if (modules_sym) -sym_calc_value (modules_sym); +sym_calc_value (modules_sym);return 0 ; }
scripts/kconfig/symbol.c +1 -2
@@ -447,8 +447,7 @@ void sym_clear_all_valid(void)for_all_symbols (i, sym) sym->flags &= ~SYMBOL_VALID;sym_add_change_count (1 ); -if (modules_sym) -sym_calc_value (modules_sym); +sym_calc_value (modules_sym); }void sym_set_changed (struct symbol *sym)
Signature · 1 line
2.1.3
Re: [PATCH 1/1] PCI: EMU10K1: Deletion of unnecessary checks before three function calls
In reply to SF Markus ElfringAt Sun, 02 Nov 2014 19:27:20 +0100,
Quoted 8 lines · SF Markus Elfring
The functions
kfree(),release_firmware()andsnd_util_memhdr_free()test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>
Your patch can't be applied cleanly due to your MUA breaking the lines. Please fix your MUA setup, or use an attachment if it's impossible, and resend the patch.
Also, try to align the subject line with the relevant commits. See "git log sound/pci/emu10k1"
thanks,
Takashi
Quoted 51 lines
--- sound/pci/emu10k1/emu10k1_main.c | 9 +++------ sound/pci/emu10k1/emufx.c | 3 +-- 2 files changed, 4 insertions(+), 8 deletions(-)sound/pci/emu10k1/emu10k1_main.c +3
-6@@ -1289,10 +1289,8 @@ static int snd_emu10k1_free(struct snd_emu10k1 *emu) }if (emu->emu1010.firmware_thread)kthread_stop (emu->emu1010.firmware_thread); -if (emu->firmware) -release_firmware (emu->firmware); -if (emu->dock_fw) -release_firmware (emu->dock_fw); +release_firmware (emu->firmware); +release_firmware (emu->dock_fw);if (emu->irq >=0 )free_irq (emu->irq, emu);/* remove reserved page */ @@ -1301,8 +1299,7 @@ static int snd_emu10k1_free(struct snd_emu10k1 *emu) (struct snd_util_memblk *)emu->reserved_page); emu->reserved_page =NULL ; } -if (emu->memhdr) -snd_util_memhdr_free (emu->memhdr); +snd_util_memhdr_free (emu->memhdr);if (emu->silent_page.area)snd_dma_free_pages (&emu->silent_page);if (emu->ptb_pages.area)sound/pci/emu10k1/emufx.c +1
-2@@ -777,8 +777,7 @@ static void snd_emu10k1_ctl_private_free(struct snd_kcontrol *kctl) kctl->private_value =0 ;list_del (&ctl->list);kfree (ctl); -if (kctl->tlv.p) -kfree (kctl->tlv.p); +kfree (kctl->tlv.p); }static int snd_emu10k1_add_controls(struct
snd_emu10k1*emu,Signature · 1 line
2.1.3
Re: [PATCH 1/1] s390/net: Deletion of unnecessary checks before two function calls
In reply to SF Markus ElfringThis one is buggy.
I'm sorry, but please stop sending these.
For kfree(), at least we all know that kfree() accepts NULL pointer. But for this one:
1) I don't know what the functions do so I have to look at the code.
2) It's in a arch that I don't compile so cscope isn't set up meaning it's hard to find the functions.
You're sending a lot of patches and they are all hard to review and some of them are buggy and none of them really add any value. It's a waste of your time and it's a waste of my time.
regards,
dan carpenter
Re: [PATCH 1/1] kconfig: Deletion of unnecessary checks before the function call "sym_calc_value"
In reply to SF Markus ElfringSince you use "SF Markus Elfring", this patch should start with:
From: Markus Elfring <[email protected]>
We don't care that you used a sourceforge.net address. Or has SF another meaning?
Quoted 4 lines · SF Markus Elfring
The
sym_calc_value()function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.This issue was detected by using the Coccinelle software.
Side note: I guess the coccinelle script you use just skips cases like
if (sym) {
sym_calc_value(sym);
do_foo_bar():
}Or did you filter those manually?
Quoted 35 lines
Signed-off-by Markus Elfring <[email protected]>--- scripts/kconfig/confdata.c | 6 ++---- scripts/kconfig/symbol.c | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-)scripts/kconfig/confdata.c +2
-4@@ -262,8 +262,7 @@ int conf_read_simple(const char *name, int def) goto load;sym_add_change_count (1 );if (!sym_defconfig_list) { -if (modules_sym) -sym_calc_value (modules_sym); +sym_calc_value (modules_sym);return 1 ; }@@ -399,8 +398,7 @@ setsym:free (line);fclose (in); -if (modules_sym) -sym_calc_value (modules_sym); +sym_calc_value (modules_sym);return 0 ; }scripts/kconfig/symbol.c +0
-0
scripts/kconfig/symbol.c void sym_clear_all_valid(void) · line 453
Quoted 9 lines
scripts/kconfig/symbol.c +1
-2@@ -447,8 +447,7 @@ void sym_clear_all_valid(void)for_all_symbols (i, sym) sym->flags &= ~SYMBOL_VALID;sym_add_change_count (1 ); -if (modules_sym) -sym_calc_value (modules_sym); +sym_calc_value (modules_sym); }void sym_set_changed (struct symbol *sym)
Please resend with
added.
Paul Bolle
Ilya Dryomov
AppliedRe: [PATCH 1/1] ceph: Deletion of unnecessary checks before two function calls
In reply to SF Markus ElfringQuoted 4 lines · SF Markus Elfring
The functions
ceph_put_snap_context()andiput()test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.
Quoted 8 lines
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- fs/ceph/caps.c | 3 +-- fs/ceph/mds_client.c | 6 ++---- fs/ceph/snap.c | 9 +++------ 3 files changed, 6 insertions(+), 12 deletions(-)
[CC'ed Zheng]
Applied, but see below.
Quoted 20 lines
fs/ceph/caps.c +1
-2@@ -3136,8 +3136,7 @@ flush_cap_releases: done:mutex_unlock (&session->s_mutex); done_unlocked: -if (inode) -iput (inode); +iput (inode);return ; bad:fs/ceph/mds_client.c +0
-0
fs/ceph/mds_client.c void ceph_mdsc_release_request(struct kref *kref) · line 528
Quoted 8 lines
fs/ceph/mds_client.c +1
-2@@ -523,8 +523,7 @@ void ceph_mdsc_release_request(struct kref *kref) }if (req->r_locked_dir)ceph_put_cap_refs (ceph_inode (req->r_locked_dir),CEPH_CAP_PIN ); -if (req->r_target_inode) -iput (req->r_target_inode); +iput (req->r_target_inode);if (req->r_dentry)dput (req->r_dentry);
dput() also checks for NULL argument, but the check is wrapped into unlikely(), which is why I presume it wasn't picked up. It would be great if you could improve your coccinelle script to handle {un,}likely() as well.
Quoted 26 lines
fs/ceph/mds_client.c +1
-2if (req->r_old_dentry)@@ -995,8 +994,7 @@ out: session->s_cap_iterator =NULL ;spin_unlock (&session->s_cap_lock); -if (last_inode) -iput (last_inode); +iput (last_inode);if (old_cap)ceph_put_cap (session->s_mdsc, old_cap);fs/ceph/snap.c +1
-2@@ -365,8 +365,7 @@ static int build_snap_context(struct ceph_snap_realm *realm) realm->ino, realm, snapc, snapc->seq, (unsigned int) snapc->num_snaps); -if (realm->cached_context) -ceph_put_snap_context (realm->cached_context); +ceph_put_snap_context (realm->cached_context); realm->cached_context = snapc;return 0 ;
fs/ceph/snap.c static void queue_realm_cap_snaps(struct ceph_snap_realm · line 589
Quoted 1 line
fs/ceph/snap.c +0
-0@@ -590,15 +589,13 @@ static void queue_realm_cap_snaps(struct ceph_snap_realm *realm)
The patch was corrupted, that should have been a single line. I fixed it up but you may want to look into your email client settings.
Thanks,
Ilya
Re: [PATCH 1/1] s390/net: Deletion of unnecessary checks before two function calls
In reply to SF Markus ElfringI agree with your proposed debug_unregister() changes, but not with your kfree_fsm() change.
Regards, Ursula Braun
Quoted 102 lines · SF Markus Elfring
The functions
debug_unregister()andkfree_fsm()test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- drivers/s390/net/claw.c | 6 ++---- drivers/s390/net/ctcm_main.c | 6 ++---- drivers/s390/net/lcs.c | 6 ++---- drivers/s390/net/netiucv.c | 12 ++++-------- 4 files changed, 10 insertions(+), 20 deletions(-)drivers/s390/net/claw.c +2
-4@@ -109,10 +109,8 @@ static debug_info_t *claw_dbf_trace;static void claw_unregister_debug_facility (void ) { -if (claw_dbf_setup) -debug_unregister (claw_dbf_setup); -if (claw_dbf_trace) -debug_unregister (claw_dbf_trace); +debug_unregister (claw_dbf_setup); +debug_unregister (claw_dbf_trace); } static intdrivers/s390/net/ctcm_main.c +2
-4@@ -1074,8 +1074,7 @@ static void ctcm_free_netdevice(struct net_device *dev)if (priv) { grp = priv->mpcg;if (grp) { -if (grp->fsm) -kfree_fsm (grp->fsm); +kfree_fsm (grp->fsm);if (grp->xid_skb)dev_kfree_skb (grp->xid_skb);if (grp->rcvd_xid_skb)@@ -1672,8 +1671,7 @@ static int ctcm_shutdown_device(struct ccwgroup_device *cgdev)ctcm_free_netdevice (dev); } -if (priv->fsm) -kfree_fsm (priv->fsm); +kfree_fsm (priv->fsm);ccw_device_set_offline (cgdev->cdev[1 ]);ccw_device_set_offline (cgdev->cdev[0 ]);drivers/s390/net/lcs.c +2
-4@@ -88,10 +88,8 @@ static debug_info_t *lcs_dbf_trace;static void lcs_unregister_debug_facility (void ) { -if (lcs_dbf_setup) -debug_unregister (lcs_dbf_setup); -if (lcs_dbf_trace) -debug_unregister (lcs_dbf_trace); +debug_unregister (lcs_dbf_setup); +debug_unregister (lcs_dbf_trace); } static intdrivers/s390/net/netiucv.c +4
-8@@ -487,12 +487,9 @@ DEFINE_PER_CPU(char[256], iucv_dbf_txt_buf);static void iucv_unregister_dbf_views (void ) { -if (iucv_dbf_setup) -debug_unregister (iucv_dbf_setup); -if (iucv_dbf_data) -debug_unregister (iucv_dbf_data); -if (iucv_dbf_trace) -debug_unregister (iucv_dbf_trace); +debug_unregister (iucv_dbf_setup); +debug_unregister (iucv_dbf_data); +debug_unregister (iucv_dbf_trace); }static int iucv_register_dbf_views (void ) {@@ -1975,8 +1972,7 @@ static void netiucv_free_netdevice(struct net_device *dev)if (privptr) {if (privptr->conn)netiucv_remove_connection (privptr->conn); -if (privptr->fsm) -kfree_fsm (privptr->fsm); +kfree_fsm (privptr->fsm); privptr->conn =NULL ; privptr->fsm =NULL ;/* privptr gets freed by free_netdev() */ }
Re: ceph: Deletion of unnecessary checks before two function calls
In reply to Ilya DryomovQuoted 4 lines
dput()also checks for NULL argument, but the check is wrapped intounlikely(), which is why I presume it wasn't picked up. It would be great if you could improve your coccinelle script to handle {un,}likely() as well.
Thanks for your suggestion.
Should I consider any more fine-tuning for the affected script "list_input_parameter_validation1.cocci" in the near future?
https://lkml.org/lkml/2014/3/5/362
http://article.gmane.org/gmane.comp.version-control.coccinelle/3514
Quoted 5 lines
Review static void queue_realm_cap_snaps(struct ceph_snap_realm · line 589
Quoted 2 lines
(quoted diff) +0
-0@@ -590,15 +589,13 @@ static void queue_realm_cap_snaps(struct ceph_snap_realm *realm)The patch was corrupted, that should have been a single line. I fixed it up but you may want to look into your email client settings.
Thanks for your feedback.
Does this example show a conflict between long comments after patch ranges and line length limitation for email eventually?
Regards,
Markus
Re: [PATCH resent] ALSA: emu10k1: Deletion of unnecessary checks before three function calls
In reply to Takashi IwaiQuoted 3 lines
Your patch can't be applied cleanly due to your MUA breaking the lines. Please fix your MUA setup, or use an attachment if it's impossible, and resend the patch.
Thanks for your feedback.
Does this example show a conflict between long comments like "snd_emu10k1_ctl_private_free( ... *kctl)" after patch ranges and line length limitation for email eventually?
Quoted 2 lines
Also, try to align the subject line with the relevant commits. See "git log
sound/pci/emu10k1"
I have attached my update suggestion with a slightly different commit title as before. Is this variant acceptable?
Regards,
Markus
Quoted 1 line
From
23bb7bd1325b7c9cc81761db3ebf3ea19f85338dMon Sep 17 00:00:00 2001
From: Markus Elfring <[email protected]>
Date: Mon, 3 Nov 2014 14:54:36 +0100
Subject: [PATCH] ALSA: emu10k1: Deletion of unnecessary checks before three
function calls
The functions kfree(), release_firmware() and snd_util_memhdr_free() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- sound/pci/emu10k1/emu10k1_main.c | 9 +++------ sound/pci/emu10k1/emufx.c | 3 +-- 2 files changed, 4 insertions(+), 8 deletions(-)
sound/pci/emu10k1/emu10k1_main.c +3 -6
@@ -1289,10 +1289,8 @@ static int snd_emu10k1_free(struct snd_emu10k1 *emu) }if (emu->emu1010.firmware_thread)kthread_stop (emu->emu1010.firmware_thread); -if (emu->firmware) -release_firmware (emu->firmware); -if (emu->dock_fw) -release_firmware (emu->dock_fw); +release_firmware (emu->firmware); +release_firmware (emu->dock_fw);if (emu->irq >=0 )free_irq (emu->irq, emu);/* remove reserved page */
@@ -1301,8 +1299,7 @@ static int snd_emu10k1_free(struct snd_emu10k1 *emu) (struct snd_util_memblk *)emu->reserved_page); emu->reserved_page =NULL ; } -if (emu->memhdr) -snd_util_memhdr_free (emu->memhdr); +snd_util_memhdr_free (emu->memhdr);if (emu->silent_page.area)snd_dma_free_pages (&emu->silent_page);if (emu->ptb_pages.area)
sound/pci/emu10k1/emufx.c +1 -2
@@ -777,8 +777,7 @@ static void snd_emu10k1_ctl_private_free(struct snd_kcontrol *kctl) kctl->private_value =0 ;list_del (&ctl->list);kfree (ctl); -if (kctl->tlv.p) -kfree (kctl->tlv.p); +kfree (kctl->tlv.p); } static int snd_emu10k1_add_controls(struct snd_emu10k1 *emu,
Signature · 1 line
2.1.3
Re: [PATCH resent] ALSA: emu10k1: Deletion of unnecessary checks before three function calls
At Mon, 03 Nov 2014 15:10:40 +0100,
Quoted 10 lines · SF Markus Elfring
Quoted 4 lines
Your patch can't be applied cleanly due to your MUA breaking the lines. Please fix your MUA setup, or use an attachment if it's impossible, and resend the patch.
Thanks for your feedback.
Does this example show a conflict between long comments like "snd_emu10k1_ctl_private_free( ... *kctl)" after patch ranges and line length limitation for email eventually?
Conflict? It's your MUA that is broken.
Quoted 5 lines
Quoted 2 lines
Also, try to align the subject line with the relevant commits. See "git log
sound/pci/emu10k1"I have attached my update suggestion with a slightly different commit title as before. Is this variant acceptable?
So, you couldn't fix your MUA? That's bad for you. Many maintainers dislike attachments and won't accept such patches.
Couldn't you simply send a patch via git-send-email?
In anyway, I applied the patch now. Thanks.
Takashi
Re: ceph: Deletion of unnecessary checks before two function calls
In reply to SF Markus ElfringQuoted 11 lines · SF Markus Elfring
Quoted 4 lines
dput()also checks for NULL argument, but the check is wrapped intounlikely(), which is why I presume it wasn't picked up. It would be great if you could improve your coccinelle script to handle {un,}likely() as well.Thanks for your suggestion.
Should I consider any more fine-tuning for the affected script "
list_input_parameter_validation1.cocci" in the near future?
https://lkml.org/lkml/2014/3/5/362
http://article.gmane.org/gmane.comp.version-control.coccinelle/3514
Make sure it at least catches stuff like:
{
if (input) {
}
}{
if (likely(input)) {
}
}{
if (!input)
return;
...
}{
if (unlikely(!input))
return;
...
}And of course each match then has to be validated manually.
Quoted 8 lines
Quoted 7 lines
Review static void queue_realm_cap_snaps(struct ceph_snap_realm · line 589
Quoted 4 lines
(quoted diff) +0
-0@@ -590,15 +589,13 @@ static void queue_realm_cap_snaps(struct ceph_snap_realm *realm)The patch was corrupted, that should have been a single line. I fixed it up but you may want to look into your email client settings.
Quoted 4 lines
Thanks for your feedback.
Does this example show a conflict between long comments after patch ranges and line length limitation for email eventually?
There is no line length limitation for email, at least one that would be relevant here. Patches should be sent verbatim, no line wrapping, expandtab, etc or they won't apply. I'd recommend git-send-email, but if you want to make thunderbird work for patches (which is what you seem to be using) have a look at the "Thunderbird (GUI)" section of Documentation/email-clients.txt in the kernel tree.
Thanks,
Ilya
Re: s390/net: Deletion of unnecessary checks before two function calls
In reply to Dan CarpenterQuoted 1 line
This one is buggy.
I am still interested to clarify this opinion a bit more.
Quoted 1 line
I'm sorry, but please stop sending these.
I am going to improve more implementation details in affected source files.
Quoted 2 lines
But for this one:
1) I don't know what the functions do so I have to look at the code.
I hope that static source code analysis can help here.
Quoted 2 lines
2) It's in a arch that I don't compile so cscope isn't set up meaning it's hard to find the functions.
Do you find the Coccinelle software also useful for your area?
Quoted 2 lines
You're sending a lot of patches and they are all hard to review and some of them are buggy and none of them really add any value.
Thanks for your feedback.
The suggested source code clean-up might result in a measurable effect depending on the call frequency for the changed functions. Can I help you in any ways to make corresponding review easier?
Quoted 1 line
It's a waste of your time and it's a waste of my time.
It can be your choice to reject my update suggestion.
Regards,
Markus
Re: s390/net: Deletion of unnecessary checks before two function calls
In reply to Ursula BraunQuoted 2 lines
I agree with your proposed
debug_unregister()changes, but not with yourkfree_fsm()change.
Why do you want to keep an additional null pointer check before the call of the kfree_fsm() function within the implementation of the netiucv_free_netdevice() function?
Regards,
Markus
Re: s390/net: Deletion of unnecessary checks before two function calls
In reply to SF Markus ElfringQuoted 4 lines · SF Markus Elfring
Quoted 1 line
This one is buggy.
I am still interested to clarify this opinion a bit more.
After your patch then it will print warning messages.
The truth is I think that all these patches are bad and they make the code harder to read.
Before: The code is clear and there is no NULL dereference.
After: You have to remember that rtw_free_netdev() accepts NULL
pointers but free_netdev() does not accept NULL pointers.
The if statements are there for *human* readers to understand and you are making it harder for humans to understand the code.
Even for kfree(), just removing the if statement is not really the right fix. We do it because everyone knows kfree(), but what Julia Lawall said is the real correct way change the code and make it simpler for people to understand:
https://lkml.org/lkml/2014/10/31/452
I know it's fun to send automated patches but these make the code worse and they waste reviewer time.
regards,
dan carpenter
Re: s390/net: Deletion of unnecessary checks before two function calls
In reply to SF Markus ElfringQuoted 6 lines · SF Markus Elfring
Quoted 2 lines
I agree with your proposed
debug_unregister()changes, but not with yourkfree_fsm()change.Why do you want to keep an additional null pointer check before the call of the
kfree_fsm()function within the implementation of thenetiucv_free_netdevice()function?
Think about how long it takes you to figure this out what the bug is and then remember that we have to spend that same amount of time multiplied by the number of patches you have sent.
regards,
dan carpenter
Re: s390/net: Deletion of unnecessary checks before two function calls
In reply to Dan CarpenterQuoted 1 line
After your patch then it will print warning messages.
To which messages do you refer to?
Quoted 4 lines
The truth is I think that all these patches are bad and they make the code harder to read.
Before: The code is clear and there is no NULL dereference.
Where do you stumble on a null pointer access?
Quoted 2 lines
After: You have to remember that
rtw_free_netdev()accepts NULL
pointers butfree_netdev()does not accept NULL pointers.
Are any improvements needed for the corresponding documentation to make it better accessible besides the source code?
Quoted 2 lines
The if statements are there for *human* readers to understand and you are making it harder for humans to understand the code.
Is there a target conflict between source code understandability and software efficiency?
Quoted 6 lines
Even for
kfree(), just removing the if statement is not really the right fix. We do it because everyone knowskfree(), but what Julia Lawall said is the real correct way change the code and make it simpler for people to understand:
You refer to another update suggestion for the software area "staging: rtl8188eu".
Do you find adjustments for jump labels easier to accept than the simple deletion of specific null pointer checks?
Quoted 2 lines
I know it's fun to send automated patches but these make the code worse and they waste reviewer time.
I hope that small automated changes can also help to improve affected source files.
Regards,
Markus
Re: s390/net: Deletion of unnecessary checks before two function calls
Quoted 6 lines
Quoted 3 lines
After your patch then it will print warning messages.
After: You have to remember thatrtw_free_netdev()accepts NULL
pointers butfree_netdev()does not accept NULL pointers.Are any improvements needed for the corresponding documentation to make it better accessible besides the source code?
When people are writing or reading code, they will not necessarily look at the documentation for every function that they use.
Quoted 5 lines
Quoted 2 lines
The if statements are there for *human* readers to understand and you are making it harder for humans to understand the code.
Is there a target conflict between source code understandability and software efficiency?
Efficiency is not an issue. This code is all in rare error handling paths or in service removal functions. None of it is in a critical path. What is important is to be able to easily check that what needs to be done is actually done. Removing null tests makes it more obscure what needs to be done, because it means that the conditions under which a function needs to be called (which may be different than the conditions under which it can be called) are less apparent.
julia
[Cocci] s390/net: Deletion of unnecessary checks before two function calls
In reply to Dan CarpenterDan
Quoted 2 lines
The truth is I think that all these patches are bad and they make the code harder to read.
I disagree, I think the code requires less effort to read without the if test.
A developer reading the code will wonder why kfree does not handle the case when its argument is NULL. This takes effort.
Now there might be a reason while kfree (or any other function) does not handle NULL, in which case the test is necessary for that reason. Or perhaps calling kfree has other consequences and this means it is good to minimise the number of calls, fair enough.
Quoted 2 lines
The if statements are there for *human* readers to understand and you are making it harder for humans to understand the code.
The reverse is true.
But if there are other reasons, then leave the test in.
Signature · 3 lines
Derek M. Jones tel: +44 (0) 1252 520 667 Knowledge Software Ltd blog:shape-of-code.coding-guidelines.com Software analysis http://www.knosof.co.uk
Re: s390/net: Deletion of unnecessary checks before two function calls
In reply to SF Markus ElfringQuoted 4 lines · SF Markus Elfring
Quoted 1 line
After your patch then it will print warning messages.
To which messages do you refer to?
Open your eyeballs up and read the code.
Quoted 8 lines
Quoted 5 lines
The truth is I think that all these patches are bad and they make the code harder to read.
Before: The code is clear and there is no NULL dereference.
Where do you stumble on a null pointer access?
I'm not talking about bugs, I'm talking about code clarity. Before is more clear than after.
Quoted 7 lines
Quoted 3 lines
After: You have to remember that
rtw_free_netdev()accepts NULL
pointers butfree_netdev()does not accept NULL pointers.Are any improvements needed for the corresponding documentation to make it better accessible besides the source code?
Documentation doesn't reduce the number of things to remember it just documents it. Meanwhile if we leave the code as-is there is no need for documentation because the code is clear.
Quoted 6 lines
Quoted 3 lines
The if statements are there for *human* readers to understand and you are making it harder for humans to understand the code.
Is there a target conflict between source code understandability and software efficiency?
If you can benchmark the code and the new code is faster then, yes, this patch is good and we will apply it. If you have no benchmarks then do not send the patch.
Quoted 6 lines
Quoted 6 lines
Even for
kfree(), just removing the if statement is not really the right fix. We do it because everyone knowskfree(), but what Julia Lawall said is the real correct way change the code and make it simpler for people to understand:
Quoted 6 lines
Quoted 1 line
You refer to another update suggestion for the software area "staging: rtl8188eu".
Do you find adjustments for jump labels easier to accept than the simple deletion of specific null pointer checks?
Yes.
Quoted 7 lines
Quoted 4 lines
I know it's fun to send automated patches but these make the code worse and they waste reviewer time.
I hope that small automated changes can also help to improve affected source files.
No. The changes make the code less clear.
regards,
dan carpenter
[Cocci] s390/net: Deletion of unnecessary checks before two function calls
In reply to Derek M JonesQuoted 8 lines · Derek M Jones
Dan
Quoted 2 lines
The truth is I think that all these patches are bad and they make the code harder to read.
I disagree, I think the code requires less effort to read without the if test.
Quoted 7 lines
A developer reading the code will wonder why kfree does not handle the case when its argument is NULL. This takes effort.
Now there might be a reason while kfree (or any other function) does not handle NULL, in which case the test is necessary for that reason. Or perhaps calling kfree has other consequences and this means it is good to minimise the number of calls, fair enough.
This may be true in general, but the standard assumption about kernel functions is that they are not defensive. Everything used in the kernel is defined in the kernel, and is normally written in a way to be optimal for in-kernel usage.
Quoted 6 lines
Quoted 2 lines
The if statements are there for *human* readers to understand and you are making it harder for humans to understand the code.
The reverse is true.
But if there are other reasons, then leave the test in.
The point about a null test is that it makes it apparent at the current point that the value can be null. The default assumption is that it cannot, ie that functions are only called when doing so is useful.
Actually, this assumption can be exploited by automatic tools for finding out what needs to be done when:
Suman Saha, Jean-Pierre Lozi, Ga?l Thomas, Julia L. Lawall, Gilles Muller:
Hector: Detecting Resource-Release Omission Faults in error-handling code for systems software. DSN 2013: 1-12
The point is that Linux code contains a huge number of alloc and free functions, many of which are not very well known. If free functions are only called when they are useful, then you can infer which free functions go with which alloc functions. If all free functions are just lumped together and called at random, then you lose a lot of information.
Similarly, as a human, when I look at code I don't know, it is very confusing to have functions called when as far as I can tell they don't need to be. A bunch of validity tests at the beginning of the called function doesn't really help, because as Dan points out the code is not always easy to find, and in the function definition itself one doesn't know in what contexts that code is intended to be used.
In separate cleanup functions (destroy_xxx) perhaps the tests are more or less noise. But in the error handling code of an initialization function, no test means to me that the call is needed at the current point, and a test means to me that for some reason it is not statically known whether a call is needed or not. This is information that is really useful for understanding the code, for both humans and for tools.
julia
Re: s390/net: Deletion of unnecessary checks before two function calls
In reply to Dan CarpenterQuoted 2 lines
If you can benchmark the code and the new code is faster then, yes, this patch is good and we will apply it.
I guess that I do not have enough resources myself to measure different run time effects in a S390 environment.
Quoted 1 line
If you have no benchmarks then do not send the patch.
Are other software developers and testers eventually interested to try a few pointer check adjustments out a bit more?
Regards,
Markus
PATCH v2 1/1 kconfig: Deletion of unnecessary checks before the function call "sym_calc_value"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
The sym_calc_value() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- scripts/kconfig/confdata.c | 6 ++---- scripts/kconfig/symbol.c | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-)
scripts/kconfig/confdata.c +2 -4
@@ -262,8 +262,7 @@ int conf_read_simple(const char *name, int def) goto load;sym_add_change_count (1 );if (!sym_defconfig_list) { -if (modules_sym) -sym_calc_value (modules_sym); +sym_calc_value (modules_sym);return 1 ; }
@@ -399,8 +398,7 @@ setsym:free (line);fclose (in); -if (modules_sym) -sym_calc_value (modules_sym); +sym_calc_value (modules_sym);return 0 ; }
scripts/kconfig/symbol.c +1 -2
@@ -447,8 +447,7 @@ void sym_clear_all_valid(void)for_all_symbols (i, sym) sym->flags &= ~SYMBOL_VALID;sym_add_change_count (1 ); -if (modules_sym) -sym_calc_value (modules_sym); +sym_calc_value (modules_sym); }void sym_set_changed (struct symbol *sym)
Signature · 1 line
2.1.3
[Cocci] Are defensive checks treated differently in specific areas?
In reply to Derek M JonesQuoted 8 lines
Quoted 2 lines
The truth is I think that all these patches are bad and they make the code harder to read.
I disagree, I think the code requires less effort to read without the if test.
A developer reading the code will wonder why kfree does not handle the case when its argument is NULL. This takes effort.
Does it make a difference for you where such safety checks should be finally placed in the source code?
Do you consider different assumptions for function implementations from an operating system in comparison to user applications?
How much will corresponding expectations need adjustments with the software evolution?
Regards,
Markus
Re: [PATCH 1/1] PCI: Deletion of unnecessary checks before three function calls
In reply to SF Markus ElfringQuoted 7 lines · SF Markus Elfring
The functions
pci_dev_put(),pci_pme_wakeup_bus()andput_device()test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>
Applied to pci/misc for v3.19, thanks!
Quoted 68 lines
--- drivers/pci/pci-acpi.c | 3 +-- drivers/pci/probe.c | 3 +-- drivers/pci/search.c | 3 +-- drivers/pci/xen-pcifront.c | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-)drivers/pci/pci-acpi.c +1
-2@@ -60,8 +60,7 @@ static void pci_acpi_wake_dev(struct work_struct *work)pci_wakeup_event (pci_dev);pm_runtime_resume (&pci_dev->dev); -if (pci_dev->subordinate) -pci_pme_wakeup_bus (pci_dev->subordinate); +pci_pme_wakeup_bus (pci_dev->subordinate); }/** drivers/pci/probe.c +1
-2@@ -86,8 +86,7 @@ static void release_pcibus_dev(struct device *dev) {struct pci_bus *pci_bus =to_pci_bus (dev); -if (pci_bus->bridge) -put_device (pci_bus->bridge); +put_device (pci_bus->bridge);pci_bus_remove_resources (pci_bus);pci_release_bus_of_node (pci_bus);kfree (pci_bus);drivers/pci/search.c +1
-2@@ -305,8 +305,7 @@ static struct pci_dev *pci_get_dev_by_id(const structpci_device_id *id, match_pci_dev_by_id);if (dev) pdev =to_pci_dev (dev); -if (from) -pci_dev_put (from); +pci_dev_put (from);return pdev; }drivers/pci/xen-pcifront.c +1
-2@@ -596,8 +596,7 @@ static pci_ers_result_t pcifront_common_process(int cmd, pcidev =pci_get_bus_and_slot (bus, devfn);if (!pcidev || !pcidev->driver) {dev_err (&pdev->xdev->dev,"device or AER driver is NULL\n" ); -if (pcidev) -pci_dev_put (pcidev); +pci_dev_put (pcidev);return result; } pdrv = pcidev->driver;Signature · 1 line
2.1.3
Re: [PATCH 1/1] PCI: Deletion of unnecessary checks before three function calls
In reply to SF Markus ElfringQuoted 7 lines · SF Markus Elfring
The functions
pci_dev_put(),pci_pme_wakeup_bus()andput_device()test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>
Applied to pci/misc for v3.19, thanks!
Quoted 68 lines
--- drivers/pci/pci-acpi.c | 3 +-- drivers/pci/probe.c | 3 +-- drivers/pci/search.c | 3 +-- drivers/pci/xen-pcifront.c | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-)drivers/pci/pci-acpi.c +1
-2@@ -60,8 +60,7 @@ static void pci_acpi_wake_dev(struct work_struct *work)pci_wakeup_event (pci_dev);pm_runtime_resume (&pci_dev->dev); -if (pci_dev->subordinate) -pci_pme_wakeup_bus (pci_dev->subordinate); +pci_pme_wakeup_bus (pci_dev->subordinate); }/** drivers/pci/probe.c +1
-2@@ -86,8 +86,7 @@ static void release_pcibus_dev(struct device *dev) {struct pci_bus *pci_bus =to_pci_bus (dev); -if (pci_bus->bridge) -put_device (pci_bus->bridge); +put_device (pci_bus->bridge);pci_bus_remove_resources (pci_bus);pci_release_bus_of_node (pci_bus);kfree (pci_bus);drivers/pci/search.c +1
-2@@ -305,8 +305,7 @@ static struct pci_dev *pci_get_dev_by_id(const structpci_device_id *id, match_pci_dev_by_id);if (dev) pdev =to_pci_dev (dev); -if (from) -pci_dev_put (from); +pci_dev_put (from);return pdev; }drivers/pci/xen-pcifront.c +1
-2@@ -596,8 +596,7 @@ static pci_ers_result_t pcifront_common_process(int cmd, pcidev =pci_get_bus_and_slot (bus, devfn);if (!pcidev || !pcidev->driver) {dev_err (&pdev->xdev->dev,"device or AER driver is NULL\n" ); -if (pcidev) -pci_dev_put (pcidev); +pci_dev_put (pcidev);return result; } pdrv = pcidev->driver;Signature · 1 line
2.1.3
Re: [PATCH with SmPL?] staging: rtl8188eu: Adjustments around jump labels
In reply to Julia LawallQuoted 12 lines
Quoted 12 lines
Quoted 11 lines
Review efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 · line 216
Quoted 8 lines
(quoted diff) +1
-2@@ -212,8 +212,7 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf) exit: kfree(efuseTbl); - if (eFuseWord) - kfree(eFuseWord); + kfree(eFuseWord);I think that this code has been updated already. It would be better to add labels so that kfree is only executed when needed.
Quoted 4 lines
Quoted 2 lines
Are there any chances to achieve the suggested fine-tuning for jump labels also with another semantic patch approach?
No, I don't think so. The pattern is not regular enough.
Now I have got a different impression for corresponding improvement possibilities.
elfring at Sonne:~/Projekte/Linux/stable-patched> spatch.opt -debug -sp-file ~/Projekte/Coccinelle/janitor/move_function_call_before_jump_label1.cocci drivers/staging/rtl8188eu/core/rtw_efuse.cinit_defs_builtins: /usr/local/share/coccinelle/standard.h
-----------------------------------------------------------------------
processing semantic patch file: /home/elfring/Projekte/Coccinelle/janitor/move_function_call_before_jump_label1.cocci
with isos from: /usr/local/share/coccinelle/standard.iso
-----------------------------------------------------------------------
@move_function_call_before_jump_label@
expression x;
identifier fu, label;
type t;
@@
t fu(...)
{
... when any
x = kzalloc(...);
if (x == NULL) {
...
goto label; }
... when any
+ kfree(x);
label:
- kfree(x);
...
}
HANDLING: drivers/staging/rtl8188eu/core/rtw_efuse.c
-----------------------------------------------------------------------
let's go
-----------------------------------------------------------------------
-----------------------------------------------------------------------
-----------------------------------------------------------------------move_function_call_before_jump_label =
-----------------------------------------------------------------------
dependencies for rule move_function_call_before_jump_label satisfied:
binding in = []
binding relevant in = []
(ONCE) USING optional_storage builtin isomorphism
transformation info returned:
transform state: 5
with rule_elem:
<<< kfree(move_function_call_before_jump_label:x);
move_function_call_before_jump_label:label:
with binding: [move_function_call_before_jump_label.x --> efuseTbl]
transform state: 204
with rule_elem: -kfree-(-move_function_call_before_jump_label:x-)-; with binding: [move_function_call_before_jump_label.x --> efuseTbl]
binding out = []
transform one node: 204
transform one node: 5
-----------------------------------------------------------------------
Finished
-----------------------------------------------------------------------
tmp/cocci-output-4498-349827-rtw_efuse.c renamed from staging/rtl8188eu/core/rtw_efuse.c +1 -1
@@ -209,8 +209,8 @@ efuse_phymap_to_logical(u8 *phymap, u16/* 5. Calculate Efuse utilization. */ /* */ +kfree (efuseTbl); exit: -kfree (efuseTbl);kfree (eFuseWord); }
Check duplication for 1 files
Can my update suggestion be generalised a bit more for the movement of specific jump labels towards the end of a function implementation like in the use case "efuse_phymap_to_logical()"?
Regards,
Markus
v2 cover staging: rtl8188eu: Deletion of a few unnecessary checks
In reply to Julia LawallFrom: Markus Elfring <[email protected]>
Date: Wed, 12 Nov 2014 20:42:18 +0100
Another update suggestion was taken into account after patches were applied from static source code analysis.
Markus Elfring (2):
staging: rtl8188eu: Deletion of unnecessary checks before three
function calls
staging: rtl8188eu: Better memory clean-up in efuse_phymap_to_logical()
drivers/staging/rtl8188eu/core/rtw_efuse.c | 13 ++++++++----- drivers/staging/rtl8188eu/core/rtw_mlme.c | 3 +-- drivers/staging/rtl8188eu/core/rtw_sta_mgt.c | 3 +-- drivers/staging/rtl8188eu/core/rtw_xmit.c | 6 ++---- drivers/staging/rtl8188eu/os_dep/usb_intf.c | 6 +++--- 5 files changed, 15 insertions(+), 16 deletions(-)
Signature · 1 line
2.1.3
PATCH v2 1/2 staging: rtl8188eu: Deletion of unnecessary checks before three function calls
From: Markus Elfring <[email protected]>
Date: Wed, 12 Nov 2014 20:25:49 +0100
The functions kfree(), rtw_free_netdev() and vfree() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- drivers/staging/rtl8188eu/core/rtw_efuse.c | 3 +-- drivers/staging/rtl8188eu/core/rtw_mlme.c | 3 +-- drivers/staging/rtl8188eu/core/rtw_sta_mgt.c | 3 +-- drivers/staging/rtl8188eu/core/rtw_xmit.c | 6 ++---- drivers/staging/rtl8188eu/os_dep/usb_intf.c | 6 +++--- 5 files changed, 8 insertions(+), 13 deletions(-)
drivers/staging/rtl8188eu/core/rtw_efuse.c +1 -2
@@ -212,8 +212,7 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf) exit:kfree (efuseTbl); -if (eFuseWord) -kfree (eFuseWord); +kfree (eFuseWord); } static void efuse_read_phymap_from_txpktbuf(
drivers/staging/rtl8188eu/core/rtw_mlme.c +1 -2
@@ -122,8 +122,7 @@ void rtw_free_mlme_priv(struct mlme_priv *pmlmepriv)rtw_free_mlme_priv_ie_data (pmlmepriv);if (pmlmepriv) { -if (pmlmepriv->free_bss_buf) -vfree (pmlmepriv->free_bss_buf); +vfree (pmlmepriv->free_bss_buf); } }
drivers/staging/rtl8188eu/core/rtw_sta_mgt.c +1 -2
@@ -201,8 +201,7 @@ u32 _rtw_free_sta_priv(struct sta_priv *pstapriv)rtw_mfree_sta_priv_lock (pstapriv); -if (pstapriv->pallocated_stainfo_buf) -vfree (pstapriv->pallocated_stainfo_buf); +vfree (pstapriv->pallocated_stainfo_buf); }return _SUCCESS;
drivers/staging/rtl8188eu/core/rtw_xmit.c +2 -4
@@ -246,11 +246,9 @@ void _rtw_free_xmit_priv (struct xmit_priv *pxmitpriv) pxmitbuf++; } -if (pxmitpriv->pallocated_frame_buf) -vfree (pxmitpriv->pallocated_frame_buf); +vfree (pxmitpriv->pallocated_frame_buf); -if (pxmitpriv->pallocated_xmitbuf) -vfree (pxmitpriv->pallocated_xmitbuf); +vfree (pxmitpriv->pallocated_xmitbuf);/* free xmit extension buff */ pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmit_extbuf;
drivers/staging/rtl8188eu/os_dep/usb_intf.c +3 -3
@@ -456,8 +456,9 @@ free_adapter:if (status != _SUCCESS) {if (pnetdev)rtw_free_netdev (pnetdev); -else if (padapter) +else vfree (padapter); + padapter =NULL ; } exit:
@@ -487,8 +488,7 @@ static void rtw_usb_if1_deinit(struct adapter *if1)DBG_88E ("+r871xu_dev_remove, hw_init_completed=%d\n" , if1->hw_init_completed);rtw_free_drv_sw (if1); -if (pnetdev) -rtw_free_netdev (pnetdev); +rtw_free_netdev (pnetdev); }static int rtw_drv_init (struct usb_interface *pusb_intf,const struct usb_device_id *pdid)
Signature · 1 line
2.1.3
PATCH v2 2/2 staging: rtl8188eu: Better memory clean-up in efuse_phymap_to_logical()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 12 Nov 2014 20:40:12 +0100
Memory releases were handled in an inefficient way by the implementation of the efuse_phymap_to_logical() function in case of an allocation failure. The corresponding clean-up was improved by reordering of kfree() calls and a few adjustments for jump labels.
--- drivers/staging/rtl8188eu/core/rtw_efuse.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/staging/rtl8188eu/core/rtw_efuse.c +8 -4
@@ -112,7 +112,7 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf) eFuseWord = (u16 **)rtw_malloc2d (EFUSE_MAX_SECTION_88E ,EFUSE_MAX_WORD_UNIT ,sizeof (u16));if (eFuseWord ==NULL ) {DBG_88E ("%s: alloc eFuseWord fail!\n" , __func__); - goto exit; + goto cleanup1; }/* 0. Refresh efuse init map as all oxFF. */
@@ -130,7 +130,7 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf) eFuse_Addr++; }else {DBG_88E ("EFUSE is empty efuse_Addr-%d efuse_data =%x\n" , eFuse_Addr, rtemp8); - goto exit; + goto cleanup2; }/* */
@@ -209,10 +209,14 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf)/* 5. Calculate Efuse utilization. */ /* */ -exit: +cleanup2: +kfree (eFuseWord); + +cleanup1:kfree (efuseTbl); -kfree (eFuseWord); +exit: + ; } static void efuse_read_phymap_from_txpktbuf(
Signature · 1 line
2.1.3
Re: [PATCH v2 2/2] staging: rtl8188eu: Better memory clean-up in efuse_phymap_to_logical()
Quoted 1 line · SF Markus Elfring
From: Markus Elfring <[email protected]>
Please fix your email client instead.
drivers/staging/rtl8188eu/core/rtw_efuse.c efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf) · line 115
Quoted 1 line
drivers/staging/rtl8188eu/core/rtw_efuse.c +1
-0+ goto cleanup1;
1) Don't use GW-BASIC label names. Label names should reflect what the label does such as free_fuse_word or free_fuse_tabel.
2) Don't use do-nothing labels. Just return directly.
regards,
dan carpenter
Re: [PATCH v2 1/2] staging: rtl8188eu: Deletion of unnecessary checks before three function calls
In reply to SF Markus Elfringdrivers/staging/rtl8188eu/os_dep/usb_intf.c static void rtw_usb_if1_deinit(struct adapter *if1) · line 491
Quoted 7 lines · SF Markus Elfring
drivers/staging/rtl8188eu/os_dep/usb_intf.c +1
-2@@ -487,8 +488,7 @@ static void rtw_usb_if1_deinit(struct adapter *if1)DBG_88E ("+r871xu_dev_remove, hw_init_completed=%d\n" , if1->hw_init_completed);rtw_free_drv_sw (if1); -if (pnetdev) -rtw_free_netdev (pnetdev); +rtw_free_netdev (pnetdev);
I still feel that hiding the if statement inside the function call makes the code more subtle and it is a bad harmful thing to do. This is especially true if you have trained yourself to know that free_netdev() can't accept NULL pointers.
regards,
dan carpenter
Re: [PATCH v2 1/2] staging: rtl8188eu: Deletion of unnecessary checks before three function calls
Quoted 10 lines
drivers/staging/rtl8188eu/os_dep/usb_intf.c static void rtw_usb_if1_deinit(struct adapter *if1) · line 491
Quoted 7 lines
drivers/staging/rtl8188eu/os_dep/usb_intf.c +1
-2@@ -487,8 +488,7 @@ static void rtw_usb_if1_deinit(struct adapter *if1)DBG_88E ("+r871xu_dev_remove, hw_init_completed=%d\n" , if1->hw_init_completed);rtw_free_drv_sw (if1); -if (pnetdev) -rtw_free_netdev (pnetdev); +rtw_free_netdev (pnetdev);I still feel that hiding the if statement inside the function call makes the code more subtle and it is a bad harmful thing to do.
I find your feedback interesting.
Quoted 2 lines
This is especially true if you have trained yourself to know that
free_netdev()can't accept NULL pointers.
Do you need to adjust your concerns a bit over time when function variants provide a corresponding safety check in their implementations?
Regards,
Markus
Re: [PATCH v2 1/2] staging: rtl8188eu: Deletion of unnecessary checks before three function calls
Quoted 5 lines
Quoted 2 lines
This is especially true if you have trained yourself to know that
free_netdev()can't accept NULL pointers.Do you need to adjust your concerns a bit over time when function variants provide a corresponding safety check in their implementations?
There would not seem to be any _need_ to do so. An unnecessary null test is always safe. The only real problem that I can see with an unnecessary null test in error handling code (intrinsically not critical performance wise) is if it gives the illusion that a value can be null when it cannot.
julia
Re: [PATCH v2 2/2] staging: rtl8188eu: Better memory clean-up in efuse_phymap_to_logical()
In reply to Dan CarpenterQuoted 6 lines
drivers/staging/rtl8188eu/core/rtw_efuse.c efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf) · line 115
Quoted 1 line
drivers/staging/rtl8188eu/core/rtw_efuse.c +1
-0+ goto cleanup1;1) Don't use GW-BASIC label names. Label names should reflect what the label does such as
free_fuse_wordorfree_fuse_tabel.2) Don't use do-nothing labels. Just return directly.
Does the document "CodingStyle" need any extensions for special cases? Are there any update candidates in the chapter "7: Centralized exiting of functions"?
Regards,
Markus
Re: [PATCH v2 2/2] staging: rtl8188eu: Better memory clean-up in efuse_phymap_to_logical()
Quoted 8 lines · SF Markus Elfring
Quoted 6 lines
drivers/staging/rtl8188eu/core/rtw_efuse.c efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf) · line 115
Quoted 1 line
drivers/staging/rtl8188eu/core/rtw_efuse.c +1
-0+ goto cleanup1;1) Don't use GW-BASIC label names. Label names should reflect what the label does such as
free_fuse_wordorfree_fuse_tabel.2) Don't use do-nothing labels. Just return directly.
Does the document "CodingStyle" need any extensions for special cases?
I don't understand.
Quoted 1 line
Are there any update candidates in the chapter "7: Centralized exiting of functions"?
CodingStyle says:
"If there is no cleanup needed then just return directly."
What is not clear about that?
regards,
dan carpenter
Re: [PATCH v2 1/2] staging: rtl8188eu: Deletion of unnecessary checks before three function calls
In reply to SF Markus ElfringQuoted 5 lines · SF Markus Elfring
Quoted 2 lines
This is especially true if you have trained yourself to know that
free_netdev()can't accept NULL pointers.Do you need to adjust your concerns a bit over time when function variants provide a corresponding safety check in their implementations?
No. Really, free_netdev vs rtw_free_netdev is just an example where it is really bad, but I feel that all of these patches are misguided and harmful.
We should have an if statement if the allocation is optional, we should not have an if statement if the allocation is required.
regards,
dan carpenter
Re: [PATCH v2 2/2] staging: rtl8188eu: Better memory clean-up in efuse_phymap_to_logical()
In reply to SF Markus ElfringQuoted 4 lines
drivers/staging/rtl8188eu/core/rtw_efuse.c +0
-0
[...]
drivers/staging/rtl8188eu/core/rtw_efuse.c efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf) · line 220
Quoted 11 lines
drivers/staging/rtl8188eu/core/rtw_efuse.c +6
-2-exit: +cleanup2: +kfree (eFuseWord); + +cleanup1:kfree (efuseTbl); -kfree (eFuseWord); +exit: + ; }
You are not using the most recent version of the code. The issue has already been fixed. Concretely, this part of the function now reads:
exit:
kfree(eFuseWord);
eFuseWord_failed:
kfree(efuseTbl);
julia
Re: [PATCH v2 1/2] staging: rtl8188eu: Deletion of unnecessary checks before three function calls
In reply to SF Markus ElfringQuoted 23 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Wed, 12 Nov 2014 20:25:49 +0100The functions
kfree(),rtw_free_netdev()andvfree()test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- drivers/staging/rtl8188eu/core/rtw_efuse.c | 3 +-- drivers/staging/rtl8188eu/core/rtw_mlme.c | 3 +-- drivers/staging/rtl8188eu/core/rtw_sta_mgt.c | 3 +-- drivers/staging/rtl8188eu/core/rtw_xmit.c | 6 ++---- drivers/staging/rtl8188eu/os_dep/usb_intf.c | 6 +++--- 5 files changed, 8 insertions(+), 13 deletions(-)drivers/staging/rtl8188eu/core/rtw_efuse.c +0
-0
drivers/staging/rtl8188eu/core/rtw_efuse.c efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf) · line 216
Quoted 7 lines
drivers/staging/rtl8188eu/core/rtw_efuse.c +1
-2@@ -212,8 +212,7 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf) exit:kfree (efuseTbl); -if (eFuseWord) -kfree (eFuseWord); +kfree (eFuseWord); }
As far as I can tell, the 2/2 patch in this series proposes a completely different fix for this code. When you send a series, patch n+1/m is supposed to apply to the result of patch n/m.
In any case, you can let this one go, because the problem has been fixed already.
julia
Re: [PATCH v2 2/2] staging: rtl8188eu: Better memory clean-up in efuse_phymap_to_logical()
In reply to Dan CarpenterQuoted 10 lines
Quoted 8 lines
Quoted 6 lines
drivers/staging/rtl8188eu/core/rtw_efuse.c efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf) · line 115
Quoted 1 line
drivers/staging/rtl8188eu/core/rtw_efuse.c +1
-0+ goto cleanup1;1) Don't use GW-BASIC label names. Label names should reflect what the label does such as
free_fuse_wordorfree_fuse_tabel.2) Don't use do-nothing labels. Just return directly.
Does the document "CodingStyle" need any extensions for special cases?
I don't understand.
Should the naming convention become more explicit for jump labels?
Quoted 3 lines
CodingStyle says:
"If there is no cleanup needed then just return directly."
Do you want that I send another update suggestion with other corrections for jump labels in the affected function implementation?
Regards,
Markus
Re: [PATCH v2 2/2] staging: rtl8188eu: Better memory clean-up in efuse_phymap_to_logical()
In reply to Julia LawallQuoted 2 lines
You are not using the most recent version of the code. The issue has already been fixed.
Thanks for your reminder.
Regards,
Markus
PATCH 1/1 fs-ext4: Deletion of an unnecessary check before the function call "iput"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 15 Nov 2014 19:04:06 +0100
The iput() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- fs/ext4/mballoc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/ext4/mballoc.c +1 -2
@@ -2712,8 +2712,7 @@ int ext4_mb_release(struct super_block *sb) }kfree (sbi->s_mb_offsets);kfree (sbi->s_mb_maxs); -if (sbi->s_buddy_cache) -iput (sbi->s_buddy_cache); +iput (sbi->s_buddy_cache);if (sbi->s_mb_stats) { ext4_msg(sb, KERN_INFO, "mballoc: %u blocks %u reqs (%u success)",
Signature · 1 line
2.1.3
PATCH 1/1 ntfs: Deletion of unnecessary checks before the function call "iput"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 15 Nov 2014 19:35:05 +0100
The iput() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- fs/ntfs/super.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-)
fs/ntfs/super.c +7 -14
@@ -2204,17 +2204,12 @@ get_ctx_vol_failed:return true;#ifdef NTFS_RW iput_usnjrnl_err_out: -if (vol->usnjrnl_j_ino) -iput (vol->usnjrnl_j_ino); -if (vol->usnjrnl_max_ino) -iput (vol->usnjrnl_max_ino); -if (vol->usnjrnl_ino) -iput (vol->usnjrnl_ino); +iput (vol->usnjrnl_j_ino); +iput (vol->usnjrnl_max_ino); +iput (vol->usnjrnl_ino); iput_quota_err_out: -if (vol->quota_q_ino) -iput (vol->quota_q_ino); -if (vol->quota_ino) -iput (vol->quota_ino); +iput (vol->quota_q_ino); +iput (vol->quota_ino);iput (vol->extend_ino);#endif /* NTFS_RW */ iput_sec_err_out:
@@ -2223,8 +2218,7 @@ iput_root_err_out:iput (vol->root_ino); iput_logfile_err_out:#ifdef NTFS_RW -if (vol->logfile_ino) -iput (vol->logfile_ino); +iput (vol->logfile_ino); iput_vol_err_out:#endif /* NTFS_RW */ iput (vol->vol_ino);
@@ -2254,8 +2248,7 @@ iput_mftbmp_err_out:iput (vol->mftbmp_ino); iput_mirr_err_out:#ifdef NTFS_RW -if (vol->mftmirr_ino) -iput (vol->mftmirr_ino); +iput (vol->mftmirr_ino);#endif /* NTFS_RW */ return false; }
Signature · 1 line
2.1.3
Re: [Cocci] [PATCH 1/1] ntfs: Deletion of unnecessary checks before the function call "iput"
Quoted 18 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 15 Nov 2014 19:35:05 +0100The
iput()function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- fs/ntfs/super.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-)fs/ntfs/super.c +0
-0
fs/ntfs/super.c get_ctx_vol_failed: · line 2206
Quoted 3 lines
fs/ntfs/super.c +0
-0@@ -2204,17 +2204,12 @@ get_ctx_vol_failed:return true;#ifdef NTFS_RW iput_usnjrnl_err_out:
I don't have time to look at the code now, but since there is an exit label here, have you checked whether you could improve the gotos in these cases?
julia
Quoted 48 lines
fs/ntfs/super.c +7
-14-if (vol->usnjrnl_j_ino) -iput (vol->usnjrnl_j_ino); -if (vol->usnjrnl_max_ino) -iput (vol->usnjrnl_max_ino); -if (vol->usnjrnl_ino) -iput (vol->usnjrnl_ino); +iput (vol->usnjrnl_j_ino); +iput (vol->usnjrnl_max_ino); +iput (vol->usnjrnl_ino); iput_quota_err_out: -if (vol->quota_q_ino) -iput (vol->quota_q_ino); -if (vol->quota_ino) -iput (vol->quota_ino); +iput (vol->quota_q_ino); +iput (vol->quota_ino);iput (vol->extend_ino);#endif /* NTFS_RW */ iput_sec_err_out:@@ -2223,8 +2218,7 @@ iput_root_err_out:iput (vol->root_ino); iput_logfile_err_out:#ifdef NTFS_RW -if (vol->logfile_ino) -iput (vol->logfile_ino); +iput (vol->logfile_ino); iput_vol_err_out:#endif /* NTFS_RW */ iput (vol->vol_ino);@@ -2254,8 +2248,7 @@ iput_mftbmp_err_out:iput (vol->mftbmp_ino); iput_mirr_err_out:#ifdef NTFS_RW -if (vol->mftmirr_ino) -iput (vol->mftmirr_ino); +iput (vol->mftmirr_ino);#endif /* NTFS_RW */ return false; }Signature · 7 lines
2.1.3 _______________________________________________ Cocci mailing list Cocci at systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
PATCH 1/1 fs-fat: Less function calls in fat_fill_super() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 15 Nov 2014 20:55:23 +0100
The iput() function was called in an inefficient way by the implementation of the fat_fill_super() function in case of an allocation failure. The corresponding source code was improved by deletion of two unnecessary null pointer checks and a few adjustments for jump labels.
--- fs/fat/inode.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
fs/fat/inode.c +10 -8
@@ -1716,20 +1716,20 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, fsinfo_inode =new_inode (sb);if (!fsinfo_inode) - goto out_fail; + goto fsinfo_inode_failure; fsinfo_inode->i_ino =MSDOS_FSINFO_INO ; sbi->fsinfo_inode = fsinfo_inode;insert_inode_hash (fsinfo_inode); root_inode =new_inode (sb);if (!root_inode) - goto out_fail; + goto other_failure; root_inode->i_ino =MSDOS_ROOT_INO ; root_inode->i_version =1 ; error =fat_read_root (root_inode);if (error <0 ) {iput (root_inode); - goto out_fail; + goto other_failure; } error = -ENOMEM ;insert_inode_hash (root_inode);
@@ -1737,7 +1737,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, sb->s_root =d_make_root (root_inode);if (!sb->s_root) {fat_msg (sb,KERN_ERR ,"get root inode failed" ); - goto out_fail; + goto other_failure; }if (sbi->options.discard) {
@@ -1756,11 +1756,13 @@ out_invalid:if (!silent)fat_msg (sb,KERN_INFO ,"Can't find a valid FAT filesystem" ); +other_failure: +iput (fsinfo_inode); + +fsinfo_inode_failure: +iput (fat_inode); + out_fail: -if (fsinfo_inode) -iput (fsinfo_inode); -if (fat_inode) -iput (fat_inode);unload_nls (sbi->nls_io);unload_nls (sbi->nls_disk);if (sbi->options.iocharset != fat_default_iocharset)
Signature · 1 line
2.1.3
Re: [PATCH 1/1] fs-fat: Less function calls in fat_fill_super() after error detection
Quoted 21 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 15 Nov 2014 20:55:23 +0100The
iput()function was called in an inefficient way by the implementation of thefat_fill_super()function in case of an allocation failure. The corresponding source code was improved by deletion of two unnecessary null pointer checks and a few adjustments for jump labels.Signed-off-by Markus Elfring <[email protected]>--- fs/fat/inode.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)fs/fat/inode.c +0
-0@@ -1716,20 +1716,20 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, fsinfo_inode =new_inode (sb);if (!fsinfo_inode)
fs/fat/inode.c int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, · line 1726
Quoted 10 lines
fs/fat/inode.c +2
-2- goto out_fail; + goto fsinfo_inode_failure; fsinfo_inode->i_ino =MSDOS_FSINFO_INO ; sbi->fsinfo_inode = fsinfo_inode;insert_inode_hash (fsinfo_inode); root_inode =new_inode (sb);if (!root_inode) - goto out_fail; + goto other_failure;
Other_failure is not such a good name. The one above is better.
julia
Quoted 46 lines
fs/fat/inode.c +8
-6root_inode->i_ino =MSDOS_ROOT_INO ; root_inode->i_version =1 ; error =fat_read_root (root_inode);if (error <0 ) {iput (root_inode); - goto out_fail; + goto other_failure; } error = -ENOMEM ;insert_inode_hash (root_inode);@@ -1737,7 +1737,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, sb->s_root =d_make_root (root_inode);if (!sb->s_root) {fat_msg (sb,KERN_ERR ,"get root inode failed" ); - goto out_fail; + goto other_failure; }if (sbi->options.discard) {@@ -1756,11 +1756,13 @@ out_invalid:if (!silent)fat_msg (sb,KERN_INFO ,"Can't find a valid FAT filesystem" ); +other_failure: +iput (fsinfo_inode); + +fsinfo_inode_failure: +iput (fat_inode); + out_fail: -if (fsinfo_inode) -iput (fsinfo_inode); -if (fat_inode) -iput (fat_inode);unload_nls (sbi->nls_io);unload_nls (sbi->nls_disk);if (sbi->options.iocharset != fat_default_iocharset)Signature · 7 lines
2.1.3 -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/1 lib/mpi: Deletion of unnecessary checks before the function call "mpi_free_limb_space"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 15 Nov 2014 21:33:26 +0100
The mpi_free_limb_space() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- lib/mpi/mpi-pow.c | 15 +++++---------- lib/mpi/mpih-mul.c | 21 +++++++-------------- 2 files changed, 12 insertions(+), 24 deletions(-)
lib/mpi/mpi-pow.c +5 -10
@@ -308,16 +308,11 @@ leave: enomem:if (assign_rp)mpi_assign_limb_space (res, rp, size); -if (mp_marker) -mpi_free_limb_space (mp_marker); -if (bp_marker) -mpi_free_limb_space (bp_marker); -if (ep_marker) -mpi_free_limb_space (ep_marker); -if (xp_marker) -mpi_free_limb_space (xp_marker); -if (tspace) -mpi_free_limb_space (tspace); +mpi_free_limb_space (mp_marker); +mpi_free_limb_space (bp_marker); +mpi_free_limb_space (ep_marker); +mpi_free_limb_space (xp_marker); +mpi_free_limb_space (tspace);return rc; }EXPORT_SYMBOL_GPL (mpi_powm);
lib/mpi/mpih-mul.c +7 -14
@@ -339,8 +339,7 @@ mpihelp_mul_karatsuba_case(mpi_ptr_t prodp,mpi_limb_t cy;if (!ctx->tspace || ctx->tspace_size < vsize) { -if (ctx->tspace) -mpi_free_limb_space (ctx->tspace); +mpi_free_limb_space (ctx->tspace); ctx->tspace =mpi_alloc_limb_space (2 * vsize);if (!ctx->tspace)return -ENOMEM ;
@@ -354,12 +353,10 @@ mpihelp_mul_karatsuba_case(mpi_ptr_t prodp, usize -= vsize;if (usize >= vsize) {if (!ctx->tp || ctx->tp_size < vsize) { -if (ctx->tp) -mpi_free_limb_space (ctx->tp); +mpi_free_limb_space (ctx->tp); ctx->tp =mpi_alloc_limb_space (2 * vsize);if (!ctx->tp) { -if (ctx->tspace) -mpi_free_limb_space (ctx->tspace); +mpi_free_limb_space (ctx->tspace); ctx->tspace =NULL ;return -ENOMEM ; }
@@ -407,16 +404,12 @@ void mpihelp_release_karatsuba_ctx(struct karatsuba_ctx *ctx) {struct karatsuba_ctx *ctx2; -if (ctx->tp) -mpi_free_limb_space (ctx->tp); -if (ctx->tspace) -mpi_free_limb_space (ctx->tspace); +mpi_free_limb_space (ctx->tp); +mpi_free_limb_space (ctx->tspace);for (ctx = ctx->next; ctx; ctx = ctx2) { ctx2 = ctx->next; -if (ctx->tp) -mpi_free_limb_space (ctx->tp); -if (ctx->tspace) -mpi_free_limb_space (ctx->tspace); +mpi_free_limb_space (ctx->tp); +mpi_free_limb_space (ctx->tspace);kfree (ctx); } }
Signature · 1 line
2.1.3
PATCH 1/1 kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 16 Nov 2014 11:27:43 +0100
The audit_log_end() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- kernel/auditsc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/auditsc.c +1 -2
@@ -1470,8 +1470,7 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts/* Send end of event record to help user space know we are finished */ ab =audit_log_start (context,GFP_KERNEL ,AUDIT_EOE ); -if (ab) -audit_log_end (ab); +audit_log_end (ab);if (call_panic)audit_panic ("error converting sid to string" ); }
Signature · 1 line
2.1.3
Re: [PATCH 1/1] kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end"
Please don't send these to trivial, because they can introduce bugs.
The make the code less clear and they are a layering violation. If the other maintainers want to take them that's fine, but don't send it to trivial.
regards,
dan carpenter
Re: [PATCH 1/1] kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end"
Quoted 1 line · Dan Carpenter
Please don't send these to trivial, because they can introduce bugs.
An example of a bug introduced is here:
https://lkml.org/lkml/2014/11/3/505
regards,
dan carpenter
Re: [PATCH 1/1] kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end"
In reply to SF Markus ElfringQuoted 5 lines · SF Markus Elfring
kernel/auditsc.c +0
-0
kernel/auditsc.c static void audit_log_exit(struct audit_context *context, struct task_struct *ts · line 1476
Quoted 9 lines
kernel/auditsc.c +1
-2@@ -1470,8 +1470,7 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts/* Send end of event record to help user space know we are finished */ ab =audit_log_start (context,GFP_KERNEL ,AUDIT_EOE ); -if (ab) -audit_log_end (ab); +audit_log_end (ab);if (call_panic)audit_panic ("error converting sid to string" ); }
I should have tried to explain this in my earlier message...
The original code is very clear, the new code works exactly the same but it's not clear if the author forgot about handling errors from audit_log_start(). So now someone will come along later and add:
if (!ab) return;
We get a lot of mindless "add error handling" patches like that. Even if no one adds that patch who ever is reading the code will think that the error handling is missing by mistake and have to read the git log to determine the original intention.
Instead of hiding the readable code in the git log, let's just leave it in the source file.
regards,
dan carpenter
Re: [PATCH 1/1] kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end"
In reply to Dan CarpenterQuoted 3 lines
An example of a bug introduced is here:
It seems that we try to clarify a different interpretation of "bugs", don't we?
It is an usual software development challenge to decide on the best source code places where to put input parameter validation (and when it can be omitted), isn't it?
Regards,
Markus
Re: [PATCH 1/1] kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end" (or improve error handling?)
In reply to Dan CarpenterQuoted 3 lines
The original code is very clear, the new code works exactly the same but it's not clear if the author forgot about handling errors from
audit_log_start().
We have got different expectations on source code clarity here.
Quoted 5 lines
So now someone will come along later and add:
if (!ab) return;We get a lot of mindless "add error handling" patches like that.
This is an interesting background information.
Do you eventually prefer to improve the affected error detection and corresponding exception handling?
Will a condition check become absolutely necessary there?
Regards,
Markus
PATCH 1/1 kprobes: Deletion of an unnecessary check before the function call "module_put"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 16 Nov 2014 12:20:31 +0100
The module_put() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- kernel/kprobes.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/kprobes.c +1 -2
@@ -1527,8 +1527,7 @@ int register_kprobe(struct kprobe *p) out:mutex_unlock (&kprobe_mutex); -if (probed_mod) -module_put (probed_mod); +module_put (probed_mod);return ret; }
Signature · 1 line
2.1.3
PATCH 1/1 kernel-power: Deletion of an unnecessary check before the function call "vfree"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 16 Nov 2014 14:18:28 +0100
The vfree() function performs also input parameter validation. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- kernel/power/swap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/power/swap.c +1 -1
@@ -1374,7 +1374,7 @@ out_clean:kthread_stop (data[thr].thr);vfree (data); } -if (page)vfree (page); +vfree (page);return ret; }
Signature · 1 line
2.1.3
Re: [Cocci] [PATCH 1/1] kprobes: Deletion of an unnecessary check before the function call "module_put"
In reply to SF Markus ElfringQuoted 18 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 16 Nov 2014 12:20:31 +0100The
module_put()function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- kernel/kprobes.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)kernel/kprobes.c +0
-0
kernel/kprobes.c int register_kprobe(struct kprobe *p) · line 1530
Quoted 6 lines
kernel/kprobes.c +1
-2@@ -1527,8 +1527,7 @@ int register_kprobe(struct kprobe *p) out:mutex_unlock (&kprobe_mutex); -if (probed_mod) -module_put (probed_mod); +module_put (probed_mod);
There is an out label, so please check whether the labels could not be better positioned to avoid calling module_put when it is not needed.
julia
Quoted 12 lines
kernel/kprobes.c +0
-1return ret; } --2.1.3
_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
PATCH 1/1 kernel-trace: Deletion of an unnecessary check before the function call "iput"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 16 Nov 2014 14:46:28 +0100
The iput() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- kernel/trace/trace_uprobe.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/trace/trace_uprobe.c +1 -2
@@ -552,8 +552,7 @@ error:return ret; fail_address_parse: -if (inode) -iput (inode); +iput (inode);pr_info ("Failed to parse address or file.\n" );
Signature · 1 line
2.1.3
Re: [Cocci] [PATCH 1/1] kprobes: Deletion of an unnecessary check before the function call "module_put"
In reply to Julia LawallQuoted 8 lines
Quoted 8 lines
kernel/kprobes.c +0
-0@@ -1527,8 +1527,7 @@ int register_kprobe(struct kprobe *p) out:mutex_unlock (&kprobe_mutex);
Quoted 6 lines
kernel/kprobes.c int register_kprobe(struct kprobe *p) · line 1530
Quoted 3 lines
kernel/kprobes.c +1
-2-if (probed_mod) -module_put (probed_mod); +module_put (probed_mod);There is an out label, so please check whether the labels could not be better positioned to avoid calling
module_putwhen it is not needed.
I do not see refactoring opportunities around jump labels in this use case for the implementation of the register_kprobe() function so far because the mutex_unlock() function must be called.
Would you like to suggest any other source code fine-tuning?
Regards,
Markus
Re: [Cocci] [PATCH 1/1] kprobes: Deletion of an unnecessary check before the function call "module_put"
Quoted 15 lines · SF Markus Elfring
Quoted 8 lines
Quoted 8 lines
kernel/kprobes.c +0
-0@@ -1527,8 +1527,7 @@ int register_kprobe(struct kprobe *p) out:mutex_unlock (&kprobe_mutex);Quoted 6 lines
kernel/kprobes.c int register_kprobe(struct kprobe *p) · line 1530
Quoted 3 lines
kernel/kprobes.c +1
-2-if (probed_mod) -module_put (probed_mod); +module_put (probed_mod);There is an out label, so please check whether the labels could not be better positioned to avoid calling
module_putwhen it is not needed.
Quoted 4 lines
I do not see refactoring opportunities around jump labels in this use case for the implementation of the
register_kprobe()function so far because themutex_unlock()function must be called.
Would you like to suggest any other source code fine-tuning?
OK. I don't think that removing the if is a good choice in this case. The code ret = check_kprobe_address_safe(p, &probed_mod); is unusual, in that it can fail to do anything in two ways. One is by setting ret, on detecting an error, and the other is by returning 0 but still putting a NULL value in probed_mod when there is nothing to do. Thus, in the successful execution of the rest of the function, a probed module might or might not exist. The if around the module_put is helpful to the reader to understand that this possibility exists.
julia
Re: [PATCH 1/1] kernel-trace: Deletion of an unnecessary check before the function call "iput"
In reply to SF Markus ElfringQuoted 18 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 16 Nov 2014 14:46:28 +0100The
iput()function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- kernel/trace/trace_uprobe.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)kernel/trace/trace_uprobe.c +0
-0
kernel/trace/trace_uprobe.c error: · line 555
Quoted 6 lines
kernel/trace/trace_uprobe.c +1
-2@@ -552,8 +552,7 @@ error:return ret; fail_address_parse: -if (inode) -iput (inode); +iput (inode);
There are jumps to fail_address_parse where the value of inode can only be NULL.
julia
Quoted 12 lines
kernel/trace/trace_uprobe.c +0
-1pr_info ("Failed to parse address or file.\n" ); --2.1.3
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [Cocci] [PATCH 1/1] kprobes: Deletion of an unnecessary check before the function call "module_put"
In reply to Julia LawallQuoted 2 lines
The if around the
module_putis helpful to the reader to understand that this possibility exists.
I have got a different opinion. I would still prefer a small code clean-up there.
Regards,
Markus
v2 cover kernel-trace: Fixes around the jump label "fail_address_parse"
In reply to Julia LawallFrom: Markus Elfring <[email protected]>
Date: Sun, 16 Nov 2014 19:56:15 +0100
Another update suggestion was taken into account after a patch was applied from static source code analysis.
Markus Elfring (2):
kernel-trace: Deletion of an unnecessary check before the function
call "iput"
kernel-trace: Less calls for iput() in create_trace_uprobe() after
error detection
kernel/trace/trace_uprobe.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
Signature · 1 line
2.1.3
PATCH v2 1/2 kernel-trace: Deletion of an unnecessary check before the function call "iput"
From: Markus Elfring <[email protected]>
Date: Sun, 16 Nov 2014 14:46:28 +0100
The iput() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- kernel/trace/trace_uprobe.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/trace/trace_uprobe.c +1 -2
@@ -552,8 +552,7 @@ error:return ret; fail_address_parse: -if (inode) -iput (inode); +iput (inode);pr_info ("Failed to parse address or file.\n" );
Signature · 1 line
2.1.3
PATCH v2 2/2 kernel-trace: Less calls for iput() in create_trace_uprobe() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 16 Nov 2014 19:49:39 +0100
The iput() function was called in three cases by the create_trace_uprobe() function during error handling even if the passed variable contained still a null pointer. This implementation detail could be improved by the introduction of another jump label.
--- kernel/trace/trace_uprobe.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
kernel/trace/trace_uprobe.c +9 -3
@@ -434,19 +434,24 @@ static int create_trace_uprobe(int argc, char **argv) arg =strchr (argv[1 ],':' );if (!arg) { ret = -EINVAL ; - goto fail_address_parse; + goto fail_address_parse2; } *arg++ ='\0' ; filename = argv[1 ]; ret =kern_path (filename,LOOKUP_FOLLOW , &path);if (ret) - goto fail_address_parse; + goto fail_address_parse2; inode =igrab (path.dentry->d_inode);path_put (&path); -if (!inode || !S_ISREG (inode->i_mode)) { +if (!inode) { + ret = -EINVAL ; + goto fail_address_parse2; + } + +if (!S_ISREG (inode->i_mode)) { ret = -EINVAL ; goto fail_address_parse; }
@@ -554,6 +559,7 @@ error: fail_address_parse:iput (inode); +fail_address_parse2:pr_info ("Failed to parse address or file.\n" );return ret;
Signature · 1 line
2.1.3
Steven Rostedt
maintainerRe: [PATCH v2 2/2] kernel-trace: Less calls for iput() in create_trace_uprobe() after error detection
Quoted 7 lines · On Sun, 16 Nov 2014 20:22:22 +0100 SF Markus Elfring…
From: Markus Elfring <[email protected]>
Date: Sun, 16 Nov 2014 19:49:39 +0100The
iput()function was called in three cases by thecreate_trace_uprobe()function during error handling even if the passed variable contained still a null pointer. This implementation detail could be improved by the introduction of another jump label.
The first patch is fine, and the only reason is to save the few bytes that the branch check might take. It's in a path that is unlikely to be hit so it is not a performance issue at all.
This patch is useless. I rather not apply any patch than to create another jump that skips over the freeing of iput() just because we know inode is null. That's why we had the if (inode) in the first place.
So Nack on this patch and I'll contemplate applying the first one. I probably will as it seems rather harmless.
Thanks,
-- Steve
Quoted 47 lines
Suggested-by Julia Lawall <[email protected]>Signed-off-by Markus Elfring <[email protected]>--- kernel/trace/trace_uprobe.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)kernel/trace/trace_uprobe.c +9
-3@@ -434,19 +434,24 @@ static int create_trace_uprobe(int argc, char **argv) arg =strchr (argv[1 ],':' );if (!arg) { ret = -EINVAL ; - goto fail_address_parse; + goto fail_address_parse2; } *arg++ ='\0' ; filename = argv[1 ]; ret =kern_path (filename,LOOKUP_FOLLOW , &path);if (ret) - goto fail_address_parse; + goto fail_address_parse2; inode =igrab (path.dentry->d_inode);path_put (&path); -if (!inode || !S_ISREG (inode->i_mode)) { +if (!inode) { + ret = -EINVAL ; + goto fail_address_parse2; + } + +if (!S_ISREG (inode->i_mode)) { ret = -EINVAL ; goto fail_address_parse; }@@ -554,6 +559,7 @@ error: fail_address_parse:iput (inode); +fail_address_parse2:pr_info ("Failed to parse address or file.\n" );return ret;
Re: [PATCH v2 2/2] kernel-trace: Less calls for iput() in create_trace_uprobe() after error detection
Quoted 15 lines · Steven Rostedt
Quoted 7 lines · On Sun, 16 Nov 2014 20:22:22 +0100 SF Markus Elfring…
From: Markus Elfring <[email protected]>
Date: Sun, 16 Nov 2014 19:49:39 +0100The
iput()function was called in three cases by thecreate_trace_uprobe()function during error handling even if the passed variable contained still a null pointer. This implementation detail could be improved by the introduction of another jump label.The first patch is fine, and the only reason is to save the few bytes that the branch check might take. It's in a path that is unlikely to be hit so it is not a performance issue at all.
Quoted 6 lines
This patch is useless. I rather not apply any patch than to create another jump that skips over the freeing of
iput()just because we know inode is null. That's why we had the if (inode) in the first place.So Nack on this patch and I'll contemplate applying the first one. I probably will as it seems rather harmless.
I wuold have thought that one could have just returned, like in the cases above... But maybe the printed message is useful.
julia
Steven Rostedt
maintainerRe: [PATCH v2 2/2] kernel-trace: Less calls for iput() in create_trace_uprobe() after error detection
Quoted 2 lines · On Sun, 16 Nov 2014 20:34:59 +0100 (CET) Julia Lawall <[email protected]>…
I wuold have thought that one could have just returned, like in the cases above... But maybe the printed message is useful.
Yes, it lets us know that the format string failed to parse.
-- Steve
PATCH 1/1 fs-jbd: Deletion of an unnecessary check before the function call "iput"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 16 Nov 2014 23:23:19 +0100
The iput() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- fs/jbd/journal.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/jbd/journal.c +1 -2
@@ -1373,8 +1373,7 @@ int journal_destroy(journal_t *journal) }mutex_unlock (&journal->j_checkpoint_mutex); -if (journal->j_inode) -iput (journal->j_inode); +iput (journal->j_inode);if (journal->j_revoke)journal_destroy_revoke (journal);kfree (journal->j_wbuf);
Signature · 1 line
2.1.3
Re: [PATCH 1/1] kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end"
In reply to SF Markus ElfringQuoted 6 lines · SF Markus Elfring
Quoted 3 lines
An example of a bug introduced is here:
It seems that we try to clarify a different interpretation of "bugs", don't we?
You removed the statement from "if (foo) kfree_fsm(foo);" so now it prints a warning.
drivers/s390/net/fsm.c
71 void
72 kfree_fsm(fsm_instance *this)
73 {
74 if (this) {
75 if (this->f) {
76 kfree(this->f->jumpmatrix);
77 kfree(this->f);
78 }
79 kfree(this);
80 } else
81 printk(KERN_WARNING
82 "fsm: kfree_fsm called with NULL argument\n");
83 }Quoted 2 lines
It is an usual software development challenge to decide on the best source code places where to put input parameter validation (and when it can be omitted), isn't it?
No, it's not. You should just try to write the most readable software you can instead of removing if statements because you can.
But that's not my point. My point is that these patches are not always welcome so we should not merge them through the trivial tree.
regards,
dan carpenter
Re: [PATCH 1/1] kprobes: Deletion of an unnecessary check before the function call "module_put"
In reply to SF Markus ElfringQuoted 18 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 16 Nov 2014 12:20:31 +0100The
module_put()function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- kernel/kprobes.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)kernel/kprobes.c +0
-0
kernel/kprobes.c int register_kprobe(struct kprobe *p) · line 1530
Quoted 6 lines
kernel/kprobes.c +1
-2@@ -1527,8 +1527,7 @@ int register_kprobe(struct kprobe *p) out:mutex_unlock (&kprobe_mutex); -if (probed_mod) -module_put (probed_mod); +module_put (probed_mod);
This is OK, but I you request a comment line over there so that code reader can understand it is safe to pass a NULL pointer to module_put().
# and of course don't touch jump label around that :)
Thank you,
Quoted 4 lines
kernel/kprobes.c +0
-0return ret; }
Signature · 4 lines
Masami HIRAMATSU Software Platform Research Dept. Linux Technology Research Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]
Re: [PATCH 1/1] kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end"
In reply to Dan CarpenterQuoted 4 lines
You removed the statement from "if (foo)
kfree_fsm(foo);" so now it prints a warning.
drivers/s390/net/fsm.c
Would it be better to continue the clarification of affected implementation details under the discussion topic "s390/net: Deletion of unnecessary checks before two function calls"?
Quoted 5 lines
Quoted 2 lines
It is an usual software development challenge to decide on the best source code places where to put input parameter validation (and when it can be omitted), isn't it?
No, it's not. You should just try to write the most readable software you can instead of removing if statements because you can.
Additional safety checks have also got an effect on source code readability, haven't they?
Regards,
Markus
PATCH 1/1 ALSA: hda: Deletion of unnecessary checks before two function calls
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 17 Nov 2014 10:44:33 +0100
The functions kfree() and release_firmware() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- sound/pci/hda/hda_codec.c | 3 +-- sound/pci/hda/hda_intel.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)
sound/pci/hda/hda_codec.c +1 -2
@@ -827,8 +827,7 @@ static void snd_hda_bus_free(struct hda_bus *bus)WARN_ON (!list_empty (&bus->codec_list));if (bus->workq)flush_workqueue (bus->workq); -if (bus->unsol) -kfree (bus->unsol); +kfree (bus->unsol);if (bus->ops.private_free) bus->ops.private_free (bus);if (bus->workq)
sound/pci/hda/hda_intel.c +1 -2
@@ -1129,8 +1129,7 @@ static int azx_free(struct azx *chip)pci_disable_device (chip->pci);kfree (chip->azx_dev);#ifdef CONFIG_SND_HDA_PATCH_LOADER -if (chip->fw) -release_firmware (chip->fw); +release_firmware (chip->fw);#endif if (chip->driver_caps &AZX_DCAPS_I915_POWERWELL ) {hda_display_power (false);
Signature · 1 line
2.1.3
PATCH 1/1 ALSA: ice17xx: Deletion of unnecessary checks before the function call "snd_ac97_resume"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 17 Nov 2014 11:28:02 +0100
The snd_ac97_resume() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- sound/pci/ice1712/ice1712.c | 3 +-- sound/pci/ice1712/ice1724.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)
sound/pci/ice1712/ice1712.c +1 -2
@@ -2905,8 +2905,7 @@ static int snd_ice1712_resume(struct device *dev)outw (ice->pm_saved_spdif_ctrl,ICEMT (ice,ROUTE_SPDOUT ));outw (ice->pm_saved_route,ICEMT (ice,ROUTE_PSDOUT03 )); -if (ice->ac97) -snd_ac97_resume (ice->ac97); +snd_ac97_resume (ice->ac97);snd_power_change_state (card,SNDRV_CTL_POWER_D0 );return 0 ;
sound/pci/ice1712/ice1724.c +1 -2
@@ -2884,8 +2884,7 @@ static int snd_vt1724_resume(struct device *dev)outb (ice->pm_saved_spdif_cfg,ICEREG1724 (ice,SPDIF_CFG ));outl (ice->pm_saved_route,ICEMT1724 (ice,ROUTE_PLAYBACK )); -if (ice->ac97) -snd_ac97_resume (ice->ac97); +snd_ac97_resume (ice->ac97);snd_power_change_state (card,SNDRV_CTL_POWER_D0 );return 0 ;
Signature · 1 line
2.1.3
PATCH 1/1 ALSA: lola: Deletion of an unnecessary check before the function call "vfree"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 17 Nov 2014 12:42:16 +0100
The vfree() function performs also input parameter validation. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- sound/pci/lola/lola_mixer.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
sound/pci/lola/lola_mixer.c +1 -2
@@ -108,8 +108,7 @@ int lola_init_pins(struct lola *chip, int dir, int *nidp)void lola_free_mixer (struct lola *chip) { -if (chip->mixer.array_saved) -vfree (chip->mixer.array_saved); +vfree (chip->mixer.array_saved); }int lola_init_mixer_widget (struct lola *chip,int nid)
Signature · 1 line
2.1.3
PATCH 1/1 ALSA: hdsp: Deletion of an unnecessary check before the function call "release_firmware"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 17 Nov 2014 13:04:14 +0100
The release_firmware() function tests whether its argument is NULL and then return immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- sound/pci/rme9652/hdsp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
sound/pci/rme9652/hdsp.c +1 -2
@@ -5368,8 +5368,7 @@ static int snd_hdsp_free(struct hdsp *hdsp)snd_hdsp_free_buffers (hdsp); -if (hdsp->firmware) -release_firmware (hdsp->firmware); +release_firmware (hdsp->firmware);vfree (hdsp->fw_uploaded);if (hdsp->iobase)
Signature · 1 line
2.1.3
PATCH 1/1 ALSA: powermac: Deletion of an unnecessary check before the function call "pci_dev_put"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 17 Nov 2014 13:35:54 +0100
The pci_dev_put() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- sound/ppc/pmac.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
sound/ppc/pmac.c +1 -2
@@ -887,8 +887,7 @@ static int snd_pmac_free(struct snd_pmac *chip) } } -if (chip->pdev) -pci_dev_put (chip->pdev); +pci_dev_put (chip->pdev);of_node_put (chip->node);kfree (chip);return 0 ;
Signature · 1 line
2.1.3
Takashi Iwai
AppliedRe: [PATCH 1/1] ALSA: hda: Deletion of unnecessary checks before two function calls
In reply to SF Markus ElfringAt Mon, 17 Nov 2014 11:07:04 +0100,
Quoted 11 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 17 Nov 2014 10:44:33 +0100The functions
kfree()andrelease_firmware()test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>
Applied, thanks.
Takashi
Quoted 37 lines
--- sound/pci/hda/hda_codec.c | 3 +-- sound/pci/hda/hda_intel.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)sound/pci/hda/hda_codec.c +1
-2@@ -827,8 +827,7 @@ static void snd_hda_bus_free(struct hda_bus *bus)WARN_ON (!list_empty (&bus->codec_list));if (bus->workq)flush_workqueue (bus->workq); -if (bus->unsol) -kfree (bus->unsol); +kfree (bus->unsol);if (bus->ops.private_free) bus->ops.private_free (bus);if (bus->workq)sound/pci/hda/hda_intel.c +1
-2@@ -1129,8 +1129,7 @@ static int azx_free(struct azx *chip)pci_disable_device (chip->pci);kfree (chip->azx_dev);#ifdef CONFIG_SND_HDA_PATCH_LOADER -if (chip->fw) -release_firmware (chip->fw); +release_firmware (chip->fw);#endif if (chip->driver_caps &AZX_DCAPS_I915_POWERWELL ) {hda_display_power (false);Signature · 1 line
2.1.3
Takashi Iwai
AppliedRe: [PATCH 1/1] ALSA: ice17xx: Deletion of unnecessary checks before the function call "snd_ac97_resume"
In reply to SF Markus ElfringAt Mon, 17 Nov 2014 11:34:22 +0100,
Quoted 10 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 17 Nov 2014 11:28:02 +0100The
snd_ac97_resume()function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>
Applied, thanks.
Takashi
Quoted 37 lines
--- sound/pci/ice1712/ice1712.c | 3 +-- sound/pci/ice1712/ice1724.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)sound/pci/ice1712/ice1712.c +1
-2@@ -2905,8 +2905,7 @@ static int snd_ice1712_resume(struct device *dev)outw (ice->pm_saved_spdif_ctrl,ICEMT (ice,ROUTE_SPDOUT ));outw (ice->pm_saved_route,ICEMT (ice,ROUTE_PSDOUT03 )); -if (ice->ac97) -snd_ac97_resume (ice->ac97); +snd_ac97_resume (ice->ac97);snd_power_change_state (card,SNDRV_CTL_POWER_D0 );return 0 ;sound/pci/ice1712/ice1724.c +1
-2@@ -2884,8 +2884,7 @@ static int snd_vt1724_resume(struct device *dev)outb (ice->pm_saved_spdif_cfg,ICEREG1724 (ice,SPDIF_CFG ));outl (ice->pm_saved_route,ICEMT1724 (ice,ROUTE_PLAYBACK )); -if (ice->ac97) -snd_ac97_resume (ice->ac97); +snd_ac97_resume (ice->ac97);snd_power_change_state (card,SNDRV_CTL_POWER_D0 );return 0 ;Signature · 1 line
2.1.3
Takashi Iwai
AppliedRe: [PATCH 1/1] ALSA: lola: Deletion of an unnecessary check before the function call "vfree"
In reply to SF Markus ElfringAt Mon, 17 Nov 2014 12:48:44 +0100,
Quoted 10 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 17 Nov 2014 12:42:16 +0100The
vfree()function performs also input parameter validation. Thus the test around the call is not needed.This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>
Applied, thanks.
Takashi
Quoted 22 lines
--- sound/pci/lola/lola_mixer.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)sound/pci/lola/lola_mixer.c +1
-2@@ -108,8 +108,7 @@ int lola_init_pins(struct lola *chip, int dir, int *nidp)void lola_free_mixer (struct lola *chip) { -if (chip->mixer.array_saved) -vfree (chip->mixer.array_saved); +vfree (chip->mixer.array_saved); }int lola_init_mixer_widget (struct lola *chip,int nid)Signature · 1 line
2.1.3
Takashi Iwai
AppliedRe: [PATCH 1/1] ALSA: hdsp: Deletion of an unnecessary check before the function call "release_firmware"
In reply to SF Markus ElfringAt Mon, 17 Nov 2014 13:12:15 +0100,
Quoted 10 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 17 Nov 2014 13:04:14 +0100The
release_firmware()function tests whether its argument is NULL and then return immediately. Thus the test around the call is not needed.This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>
Applied, thanks.
Takashi
Quoted 22 lines
--- sound/pci/rme9652/hdsp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)sound/pci/rme9652/hdsp.c +1
-2@@ -5368,8 +5368,7 @@ static int snd_hdsp_free(struct hdsp *hdsp)snd_hdsp_free_buffers (hdsp); -if (hdsp->firmware) -release_firmware (hdsp->firmware); +release_firmware (hdsp->firmware);vfree (hdsp->fw_uploaded);if (hdsp->iobase)Signature · 1 line
2.1.3
Takashi Iwai
AppliedRe: [PATCH 1/1] ALSA: powermac: Deletion of an unnecessary check before the function call "pci_dev_put"
In reply to SF Markus ElfringAt Mon, 17 Nov 2014 13:41:19 +0100,
Quoted 10 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 17 Nov 2014 13:35:54 +0100The
pci_dev_put()function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>
Applied, thanks.
Takashi
Quoted 22 lines
--- sound/ppc/pmac.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)sound/ppc/pmac.c +1
-2@@ -887,8 +887,7 @@ static int snd_pmac_free(struct snd_pmac *chip) } } -if (chip->pdev) -pci_dev_put (chip->pdev); +pci_dev_put (chip->pdev);of_node_put (chip->node);kfree (chip);return 0 ;Signature · 1 line
2.1.3
ASoC: omap-mcbsp: Deletion of an unnecessary check before the function call "kfree"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 17 Nov 2014 14:05:27 +0100
The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- sound/soc/omap/mcbsp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
sound/soc/omap/mcbsp.c +1 -2
@@ -621,8 +621,7 @@ void omap_mcbsp_free(struct omap_mcbsp *mcbsp) mcbsp->reg_cache =NULL ;spin_unlock (&mcbsp->lock); -if (reg_cache) -kfree (reg_cache); +kfree (reg_cache); }/*
Signature · 1 line
2.1.3
PATCH 1/1 tools lib traceevent: Deletion of an unnecessary check before the function call "free_arg"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 17 Nov 2014 14:38:14 +0100
The free_arg() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- tools/lib/traceevent/parse-filter.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
tools/lib/traceevent/parse-filter.c +1 -2
@@ -1237,8 +1237,7 @@ filter_event(struct event_filter *filter, struct event_format *event,if (filter_type ==NULL )return PEVENT_ERRNO__MEM_ALLOC_FAILED ; -if (filter_type->filter) -free_arg (filter_type->filter); +free_arg (filter_type->filter); filter_type->filter = arg;return 0 ;
Signature · 1 line
2.1.3
Re: [PATCH 1/1] kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end"
In reply to SF Markus ElfringQuoted 8 lines · SF Markus Elfring
Quoted 4 lines
You removed the statement from "if (foo)
kfree_fsm(foo);" so now it prints a warning.
drivers/s390/net/fsm.cWould it be better to continue the clarification of affected implementation details under the discussion topic "s390/net: Deletion of unnecessary checks before two function calls"?
What do you want me to clarify? Do you still not see the bug?
regards,
dan carpenter
Re: s390/net: Deletion of unnecessary checks before two function calls
Quoted 1 line
What do you want me to clarify? Do you still not see the bug?
Would you like to point out that you notice the warning message "fsm: kfree_fsm called with NULL argument" after my update suggestion?
How do you think about to share a bit more information about the corresponding function call graph from your test system?
Regards,
Markus
PATCH 1/1 perf tools: Deletion of unnecessary checks before two function calls
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 17 Nov 2014 18:05:57 +0100
The functions free_event_desc() and strfilter__delete() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- tools/perf/builtin-probe.c | 6 ++---- tools/perf/util/header.c | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-)
tools/perf/builtin-probe.c +2 -4
@@ -254,8 +254,7 @@ static int opt_set_filter(const struct option *opt __maybe_unused,if (str) {pr_debug2 ("Set filter: %s\n" , str); -if (params.filter) -strfilter__delete (params.filter); +strfilter__delete (params.filter); params.filter =strfilter__new (str, &err);if (!params.filter) {pr_err ("Filter parse error at %td.\n" , err - str +1 );
@@ -283,8 +282,7 @@ static void cleanup_params(void)strlist__delete (params.dellist);line_range__clear (¶ms.line_range);free (params.target); -if (params.filter) -strfilter__delete (params.filter); +strfilter__delete (params.filter);memset (¶ms,0 ,sizeof (params)); }
tools/perf/util/header.c +1 -2
@@ -1367,8 +1367,7 @@ out:free (buf);return events; error: -if (events) -free_event_desc (events); +free_event_desc (events); events =NULL ; goto out; }
Signature · 1 line
2.1.3
PATCH 1/1 mm/zswap: Deletion of an unnecessary check before the function call "free_percpu"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 17 Nov 2014 18:33:33 +0100
The free_percpu() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- mm/zswap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mm/zswap.c +1 -2
@@ -152,8 +152,7 @@ static int __init zswap_comp_init(void)static void zswap_comp_exit (void ) {/* free percpu transforms */ -if (zswap_comp_pcpu_tfms) -free_percpu (zswap_comp_pcpu_tfms); +free_percpu (zswap_comp_pcpu_tfms); }/*********************************
Signature · 1 line
2.1.3
PATCH 1/1 hfs/hfs+: Deletion of unnecessary checks before the function call "hfs_bnode_put"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 17 Nov 2014 19:13:56 +0100
The hfs_bnode_put() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- fs/hfs/bfind.c | 3 +-- fs/hfs/brec.c | 3 +-- fs/hfsplus/bfind.c | 3 +-- fs/hfsplus/brec.c | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-)
fs/hfs/bfind.c +1 -2
@@ -100,8 +100,7 @@ int hfs_brec_find(struct hfs_find_data *fd)int height, res; tree = fd->tree; -if (fd->bnode) -hfs_bnode_put (fd->bnode); +hfs_bnode_put (fd->bnode); fd->bnode =NULL ; nidx = tree->root;if (!nidx)
fs/hfs/brec.c +1 -2
@@ -272,8 +272,7 @@ static struct hfs_bnode *hfs_bnode_split(struct hfs_find_data *fd)/* panic? */ hfs_bnode_put (node);hfs_bnode_put (new_node); -if (next_node) -hfs_bnode_put (next_node); +hfs_bnode_put (next_node);return ERR_PTR (-ENOSPC ); }
fs/hfsplus/bfind.c +1 -2
@@ -171,8 +171,7 @@ int hfs_brec_find(struct hfs_find_data *fd, search_strategy_t do_key_compare)int height, res; tree = fd->tree; -if (fd->bnode) -hfs_bnode_put (fd->bnode); +hfs_bnode_put (fd->bnode); fd->bnode =NULL ; nidx = tree->root;if (!nidx)
fs/hfsplus/brec.c +1 -2
@@ -276,8 +276,7 @@ static struct hfs_bnode *hfs_bnode_split(struct hfs_find_data *fd)/* panic? */ hfs_bnode_put (node);hfs_bnode_put (new_node); -if (next_node) -hfs_bnode_put (next_node); +hfs_bnode_put (next_node);return ERR_PTR (-ENOSPC ); }
Signature · 1 line
2.1.3
PATCH 1/1 configfs: Deletion of unnecessary checks before the function call "config_item_put"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 17 Nov 2014 19:37:03 +0100
The config_item_put() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- fs/configfs/file.c | 3 +-- fs/configfs/item.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)
fs/configfs/file.c +1 -2
@@ -291,8 +291,7 @@ static int configfs_release(struct inode * inode, struct file * filp)struct module * owner = attr->ca_owner;struct configfs_buffer * buffer = filp->private_data; -if (item) -config_item_put (item); +config_item_put (item);/* After this point, attr should not be accessed. */ module_put (owner);
fs/configfs/item.c +1 -2
@@ -153,8 +153,7 @@ static void config_item_cleanup(struct config_item *item) t->ct_item_ops->release (item);if (s)config_group_put (s); -if (parent) -config_item_put (parent); +config_item_put (parent); }static void config_item_release (struct kref *kref)
Signature · 1 line
2.1.3
Jarkko Nikula
Acked-byRe: ASoC: omap-mcbsp: Deletion of an unnecessary check before the function call "kfree"
In reply to SF Markus ElfringQuoted 6 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 17 Nov 2014 14:05:27 +0100The
kfree()function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
Quoted 7 lines
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- sound/soc/omap/mcbsp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Re: [PATCH 1/1] hfs/hfs+: Deletion of unnecessary checks before the function call "hfs_bnode_put"
In reply to SF Markus ElfringQuoted 8 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 17 Nov 2014 19:13:56 +0100The
hfs_bnode_put()function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.This issue was detected by using the Coccinelle software.
Thank you. It's the reasonable correction. Looks good for me.
Thanks,
Vyacheslav Dubeyko.
Quoted 64 lines
Signed-off-by Markus Elfring <[email protected]>--- fs/hfs/bfind.c | 3 +-- fs/hfs/brec.c | 3 +-- fs/hfsplus/bfind.c | 3 +-- fs/hfsplus/brec.c | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-)fs/hfs/bfind.c +1
-2@@ -100,8 +100,7 @@ int hfs_brec_find(struct hfs_find_data *fd)int height, res; tree = fd->tree; -if (fd->bnode) -hfs_bnode_put (fd->bnode); +hfs_bnode_put (fd->bnode); fd->bnode =NULL ; nidx = tree->root;if (!nidx)fs/hfs/brec.c +1
-2@@ -272,8 +272,7 @@ static struct hfs_bnode *hfs_bnode_split(struct hfs_find_data *fd)/* panic? */ hfs_bnode_put (node);hfs_bnode_put (new_node); -if (next_node) -hfs_bnode_put (next_node); +hfs_bnode_put (next_node);return ERR_PTR (-ENOSPC ); }fs/hfsplus/bfind.c +1
-2@@ -171,8 +171,7 @@ int hfs_brec_find(struct hfs_find_data *fd, search_strategy_t do_key_compare)int height, res; tree = fd->tree; -if (fd->bnode) -hfs_bnode_put (fd->bnode); +hfs_bnode_put (fd->bnode); fd->bnode =NULL ; nidx = tree->root;if (!nidx)fs/hfsplus/brec.c +1
-2@@ -276,8 +276,7 @@ static struct hfs_bnode *hfs_bnode_split(struct hfs_find_data *fd)/* panic? */ hfs_bnode_put (node);hfs_bnode_put (new_node); -if (next_node) -hfs_bnode_put (next_node); +hfs_bnode_put (next_node);return ERR_PTR (-ENOSPC ); }
PATCH 1/1 fs-eventpoll: Deletion of unnecessary checks before the function call "__pm_stay_awake"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 09:27:16 +0100
The __pm_stay_awake() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- fs/eventpoll.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
fs/eventpoll.c +2 -4
@@ -555,8 +555,7 @@ static inline void ep_pm_stay_awake(struct epitem *epi) {struct wakeup_source *ws =ep_wakeup_source (epi); -if (ws) -__pm_stay_awake (ws); +__pm_stay_awake (ws); }static inline bool ep_has_wakeup_source (struct epitem *epi)
@@ -571,8 +570,7 @@ static inline void ep_pm_stay_awake_rcu(struct epitem *epi)rcu_read_lock (); ws =rcu_dereference (epi->ws); -if (ws) -__pm_stay_awake (ws); +__pm_stay_awake (ws);rcu_read_unlock (); }
Signature · 1 line
2.1.3
PATCH 1/1 exofs: Deletion of an unnecessary check before the function call "ore_put_io_state"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 10:05:19 +0100
The ore_put_io_state() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- fs/exofs/ore_raid.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/exofs/ore_raid.c +1 -2
@@ -716,6 +716,5 @@ void _ore_free_raid_stuff(struct ore_io_state *ios)if (ios->extra_part_alloc)kfree (ios->per_dev[0 ].sglist); } -if (ios->ios_read_4_write) -ore_put_io_state (ios->ios_read_4_write); +ore_put_io_state (ios->ios_read_4_write); }
Signature · 1 line
2.1.3
Re: [osd-dev] [PATCH 1/1] exofs: Deletion of an unnecessary check before the function call "ore_put_io_state"
Quoted 19 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 10:05:19 +0100The
ore_put_io_state()function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- fs/exofs/ore_raid.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)fs/exofs/ore_raid.c +0
-0
fs/exofs/ore_raid.c void _ore_free_raid_stuff(struct ore_io_state *ios) · line 720
Quoted 7 lines
fs/exofs/ore_raid.c +1
-2@@ -716,6 +716,5 @@ void _ore_free_raid_stuff(struct ore_io_state *ios)if (ios->extra_part_alloc)kfree (ios->per_dev[0 ].sglist); } -if (ios->ios_read_4_write) -ore_put_io_state (ios->ios_read_4_write); +ore_put_io_state (ios->ios_read_4_write); }
Thanks will submit for next Kernel
Boaz
Jan Kara
maintainerRe: [PATCH 1/1] fs-jbd: Deletion of an unnecessary check before the function call "iput"
In reply to SF Markus ElfringQuoted 6 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 16 Nov 2014 23:23:19 +0100The
iput()function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
Quoted 6 lines
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- fs/jbd/journal.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Thanks. Merged into my tree.
Honza
Quoted 19 lines
fs/jbd/journal.c +1
-2@@ -1373,8 +1373,7 @@ int journal_destroy(journal_t *journal) }mutex_unlock (&journal->j_checkpoint_mutex); -if (journal->j_inode) -iput (journal->j_inode); +iput (journal->j_inode);if (journal->j_revoke)journal_destroy_revoke (journal);kfree (journal->j_wbuf);Signature · 1 line
2.1.3
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: ASoC: omap-mcbsp: Deletion of an unnecessary check before the function call "kfree"
In reply to SF Markus ElfringQuoted 5 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 17 Nov 2014 14:05:27 +0100The
kfree()function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
Applied, thanks.
PATCH 1/1 GFS2: Deletion of unnecessary checks before two function calls
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 11:31:23 +0100
The functions iput() and put_pid() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- fs/gfs2/glock.c | 3 +-- fs/gfs2/ops_fstype.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)
fs/gfs2/glock.c +1 -2
@@ -836,8 +836,7 @@ void gfs2_holder_reinit(unsigned int state, unsigned flags, struct gfs2_holder * gh->gh_flags = flags; gh->gh_iflags =0 ; gh->gh_ip = (unsigned long )__builtin_return_address (0 ); -if (gh->gh_owner_pid) -put_pid (gh->gh_owner_pid); +put_pid (gh->gh_owner_pid); gh->gh_owner_pid =get_pid (task_pid (current)); }
fs/gfs2/ops_fstype.c +1 -2
@@ -918,8 +918,7 @@ fail_qc_i: fail_ut_i:iput (sdp->sd_sc_inode); fail: -if (pn) -iput (pn); +iput (pn);return error; }
Signature · 1 line
2.1.3
Re: [PATCH 1/1] GFS2: Deletion of unnecessary checks before two function calls
Hi,
Now in the GFS2 -nmw git tree. Thanks,
Steve.
Quoted 42 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 11:31:23 +0100The functions
iput()andput_pid()test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- fs/gfs2/glock.c | 3 +-- fs/gfs2/ops_fstype.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)fs/gfs2/glock.c +1
-2@@ -836,8 +836,7 @@ void gfs2_holder_reinit(unsigned int state, unsigned flags, struct gfs2_holder * gh->gh_flags = flags; gh->gh_iflags =0 ; gh->gh_ip = (unsigned long )__builtin_return_address (0 ); -if (gh->gh_owner_pid) -put_pid (gh->gh_owner_pid); +put_pid (gh->gh_owner_pid); gh->gh_owner_pid =get_pid (task_pid (current)); }fs/gfs2/ops_fstype.c +1
-2@@ -918,8 +918,7 @@ fail_qc_i: fail_ut_i:iput (sdp->sd_sc_inode); fail: -if (pn) -iput (pn); +iput (pn);return error; }
PATCH 1/1 fs-namespace: Deletion of unnecessary checks before the function call "mntput"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 12:10:43 +0100
The mntput() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- fs/namespace.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
fs/namespace.c +2 -4
@@ -2615,10 +2615,8 @@ struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns, }namespace_unlock (); -if (rootmnt) -mntput (rootmnt); -if (pwdmnt) -mntput (pwdmnt); +mntput (rootmnt); +mntput (pwdmnt);return new_ns; }
Signature · 1 line
2.1.3
PATCH 1/1 NFS: Deletion of unnecessary checks before the function call "nfs_put_client"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 13:23:43 +0100
The nfs_put_client() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- fs/nfs/filelayout/filelayoutdev.c | 3 +-- fs/nfs/nfs4client.c | 15 +++++---------- 2 files changed, 6 insertions(+), 12 deletions(-)
fs/nfs/filelayout/filelayoutdev.c +1 -2
@@ -204,8 +204,7 @@ destroy_ds(struct nfs4_pnfs_ds *ds)ifdebug (FACILITY)print_ds (ds); -if (ds->ds_clp) -nfs_put_client (ds->ds_clp); +nfs_put_client (ds->ds_clp);while (!list_empty (&ds->ds_addrs)) { da = list_first_entry(&ds->ds_addrs,
fs/nfs/nfs4client.c +5 -10
@@ -498,8 +498,7 @@ int nfs40_walk_client_list(struct nfs_client *new,atomic_inc (&pos->cl_count);spin_unlock (&nn->nfs_client_lock); -if (prev) -nfs_put_client (prev); +nfs_put_client (prev); prev = pos; status =nfs_wait_client_init_complete (pos);
@@ -517,8 +516,7 @@ int nfs40_walk_client_list(struct nfs_client *new,atomic_inc (&pos->cl_count);spin_unlock (&nn->nfs_client_lock); -if (prev) -nfs_put_client (prev); +nfs_put_client (prev); prev = pos; status =nfs4_proc_setclientid_confirm (pos, &clid, cred);
@@ -549,8 +547,7 @@ int nfs40_walk_client_list(struct nfs_client *new,/* No match found. The server lost our clientid */ out: -if (prev) -nfs_put_client (prev); +nfs_put_client (prev);dprintk ("NFS: <-- %s status = %d\n" , __func__, status);return status; }
@@ -641,8 +638,7 @@ int nfs41_walk_client_list(struct nfs_client *new,atomic_inc (&pos->cl_count);spin_unlock (&nn->nfs_client_lock); -if (prev) -nfs_put_client (prev); +nfs_put_client (prev); prev = pos; status =nfs_wait_client_init_complete (pos);
@@ -675,8 +671,7 @@ int nfs41_walk_client_list(struct nfs_client *new,/* No matching nfs_client found. */ spin_unlock (&nn->nfs_client_lock);dprintk ("NFS: <-- %s status = %d\n" , __func__, status); -if (prev) -nfs_put_client (prev); +nfs_put_client (prev); return status; }#endif /* CONFIG_NFS_V4_1 */
Signature · 1 line
2.1.3
PATCH 1/1 nilfs2: Deletion of an unnecessary check before the function call "iput"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 14:41:27 +0100
The iput() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- fs/nilfs2/the_nilfs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/nilfs2/the_nilfs.c +1 -2
@@ -808,8 +808,7 @@ void nilfs_put_root(struct nilfs_root *root)spin_lock (&nilfs->ns_cptree_lock);rb_erase (&root->rb_node, &nilfs->ns_cptree);spin_unlock (&nilfs->ns_cptree_lock); -if (root->ifile) -iput (root->ifile); +iput (root->ifile);kfree (root); }
Signature · 1 line
2.1.3
PATCH 1/1 fs-proc: One function call less in proc_sys_lookup() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 15:42:43 +0100
The sysctl_head_finish() function was called in an inefficient way by the implementation of the proc_sys_lookup() function in case of a lookup failure. The corresponding source code was improved by deletion of an unnecessary null pointer check and a few adjustments for jump labels.
--- fs/proc/proc_sysctl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/proc/proc_sysctl.c +4 -4
@@ -457,21 +457,21 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry, ret =sysctl_follow_link (&h, &p, current->nsproxy); err =ERR_PTR (ret);if (ret) - goto out; + goto inode_failure; } err =ERR_PTR (-ENOMEM ); inode =proc_sys_make_inode (dir->i_sb, h ? h : head, p);if (!inode) - goto out; + goto inode_failure; err =NULL ;d_set_d_op (dentry, &proc_sys_dentry_operations);d_add (dentry, inode); +inode_failure: +sysctl_head_finish (h); out: -if (h) -sysctl_head_finish (h);sysctl_head_finish (head);return err; }
Signature · 1 line
2.1.3
cover fs-udf: Deletion of two unnecessary checks
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 18:33:08 +0100
Another update suggestion was taken into account after a patch was applied from static source code analysis.
Markus Elfring (2):
Deletion of unnecessary checks before the function call "iput" One function call less in udf_fill_super() after error detection
fs/udf/super.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
Signature · 1 line
2.1.3
PATCH 1/2 fs-udf: Deletion of unnecessary checks before the function call "iput"
From: Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 17:17:46 +0100
The iput() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- fs/udf/super.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
fs/udf/super.c +2 -4
@@ -2237,8 +2237,7 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)return 0 ; error_out: -if (sbi->s_vat_inode) -iput (sbi->s_vat_inode); +iput (sbi->s_vat_inode);#ifdef CONFIG_UDF_NLS if (UDF_QUERY_FLAG (sb,UDF_FLAG_NLS_MAP ))unload_nls (sbi->s_nls_map);
@@ -2291,8 +2290,7 @@ static void udf_put_super(struct super_block *sb) sbi =UDF_SB (sb); -if (sbi->s_vat_inode) -iput (sbi->s_vat_inode); +iput (sbi->s_vat_inode);#ifdef CONFIG_UDF_NLS if (UDF_QUERY_FLAG (sb,UDF_FLAG_NLS_MAP ))unload_nls (sbi->s_nls_map);
Signature · 1 line
2.1.3
PATCH 2/2 fs-udf: One function call less in udf_fill_super() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 18:29:10 +0100
The iput() function was called in up to three cases by the udf_fill_super() function during error handling even if the passed data structure element contained still a null pointer. This implementation detail could be improved by the introduction of another jump label.
--- fs/udf/super.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/udf/super.c +3 -2
@@ -2082,12 +2082,12 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)mutex_init (&sbi->s_alloc_mutex);if (!udf_parse_options ((char *)options, &uopt, false)) - goto error_out; + goto parse_options_failure;if (uopt.flags & (1 <<UDF_FLAG_UTF8 ) && uopt.flags & (1 <<UDF_FLAG_NLS_MAP )) {udf_err (sb,"utf8 cannot be combined with iocharset\n" ); - goto error_out; + goto parse_options_failure; }#ifdef CONFIG_UDF_NLS if ((uopt.flags & (1 <<UDF_FLAG_NLS_MAP )) && !uopt.nls_map) {
@@ -2238,6 +2238,7 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent) error_out:iput (sbi->s_vat_inode); +parse_options_failure:#ifdef CONFIG_UDF_NLS if (UDF_QUERY_FLAG (sb,UDF_FLAG_NLS_MAP ))unload_nls (sbi->s_nls_map);
Signature · 1 line
2.1.3
PATCH 1/1 net: pktgen: Deletion of an unnecessary check before the function call "proc_remove"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 20:10:34 +0100
The proc_remove() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- net/core/pktgen.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
net/core/pktgen.c +1 -2
@@ -3698,8 +3698,7 @@ static int pktgen_remove_device(struct pktgen_thread *t,/* Remove proc before if_list entry, because add_device uses * list to determine if interface already exist, avoid race * with proc_create_data() */ -if (pkt_dev->entry) -proc_remove (pkt_dev->entry); +proc_remove (pkt_dev->entry);/* And update the thread if_list */ _rem_dev_from_if_list (t, pkt_dev);
Signature · 1 line
2.1.3
PATCH 1/1 netfilter: Deletion of unnecessary checks before two function calls
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 20:37:05 +0100
The functions free_percpu() and module_put() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- net/netfilter/ipvs/ip_vs_ctl.c | 3 +-- net/netfilter/ipvs/ip_vs_pe.c | 3 +-- net/netfilter/ipvs/ip_vs_sched.c | 3 +-- net/netfilter/ipvs/ip_vs_sync.c | 3 +-- net/netfilter/nf_tables_api.c | 3 +-- 5 files changed, 5 insertions(+), 10 deletions(-)
net/netfilter/ipvs/ip_vs_ctl.c +1 -2
@@ -465,8 +465,7 @@ __ip_vs_bind_svc(struct ip_vs_dest *dest, struct ip_vs_service *svc)static void ip_vs_service_free (struct ip_vs_service *svc) { -if (svc->stats.cpustats) -free_percpu (svc->stats.cpustats); +free_percpu (svc->stats.cpustats);kfree (svc); }
net/netfilter/ipvs/ip_vs_pe.c +1 -2
@@ -37,8 +37,7 @@ struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name)rcu_read_unlock ();return pe; } -if (pe->module) -module_put (pe->module); +module_put (pe->module); }rcu_read_unlock ();
net/netfilter/ipvs/ip_vs_sched.c +1 -2
@@ -104,8 +104,7 @@ static struct ip_vs_scheduler *ip_vs_sched_getbyname(const char *sched_name)mutex_unlock (&ip_vs_sched_mutex);return sched; } -if (sched->module) -module_put (sched->module); +module_put (sched->module); }mutex_unlock (&ip_vs_sched_mutex);
net/netfilter/ipvs/ip_vs_sync.c +1 -2
@@ -820,8 +820,7 @@ ip_vs_conn_fill_param_sync(struct net *net, int af, union ip_vs_sync_conn *sc, p->pe_data =kmemdup (pe_data, pe_data_len,GFP_ATOMIC );if (!p->pe_data) { -if (p->pe->module) -module_put (p->pe->module); +module_put (p->pe->module);return -ENOMEM ; } p->pe_data_len = pe_data_len;
net/netfilter/nf_tables_api.c +1 -2
@@ -3472,8 +3472,7 @@ static int nf_tables_abort(struct sk_buff *skb)break ;case NFT_MSG_NEWCHAIN :if (nft_trans_chain_update (trans)) { -if (nft_trans_chain_stats (trans)) -free_percpu (nft_trans_chain_stats (trans)); +free_percpu (nft_trans_chain_stats (trans));nft_trans_destroy (trans); }else {
Signature · 1 line
2.1.3
PATCH 1/1 netlink: Deletion of an unnecessary check before the function call "__module_get"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 21:03:13 +0100
The __module_get() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- net/netlink/af_netlink.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
net/netlink/af_netlink.c +1 -2
@@ -142,8 +142,7 @@ int netlink_add_tap(struct netlink_tap *nt)list_add_rcu (&nt->list, &netlink_tap_all);spin_unlock (&netlink_tap_lock); -if (nt->module) -__module_get (nt->module); +__module_get (nt->module);return 0 ; }
Signature · 1 line
2.1.3
PATCH 1/1 net: sched: Deletion of an unnecessary check before the function call "kfree"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 21:21:16 +0100
The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- net/sched/cls_bpf.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
net/sched/cls_bpf.c +1 -2
@@ -212,8 +212,7 @@ static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,if (fp_old)bpf_prog_destroy (fp_old); -if (bpf_old) -kfree (bpf_old); +kfree (bpf_old);return 0 ;
Signature · 1 line
2.1.3
PATCH 1/1 net: xfrm: Deletion of an unnecessary check before the function call "ipcomp_free_tfms"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 21:41:26 +0100
The ipcomp_free_tfms() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- net/xfrm/xfrm_ipcomp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
net/xfrm/xfrm_ipcomp.c +1 -2
@@ -320,8 +320,7 @@ error:static void ipcomp_free_data (struct ipcomp_data *ipcd) { -if (ipcd->tfms) -ipcomp_free_tfms (ipcd->tfms); +ipcomp_free_tfms (ipcd->tfms);ipcomp_free_scratches (); }
Signature · 1 line
2.1.3
PATCH 1/1 keys: Deletion of an unnecessary check before the function call "key_put"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 21:57:14 +0100
The key_put() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- security/keys/process_keys.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
security/keys/process_keys.c +1 -2
@@ -242,8 +242,7 @@ int install_session_keyring_to_cred(struct cred *cred, struct key *keyring) old = cred->session_keyring;rcu_assign_pointer (cred->session_keyring, keyring); -if (old) -key_put (old); +key_put (old);return 0 ; }
Signature · 1 line
2.1.3
Re: [PATCH 1/1] mm/zswap: Deletion of an unnecessary check before the function call "free_percpu"
In reply to SF Markus ElfringQuoted 7 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 17 Nov 2014 18:33:33 +0100The
free_percpu()function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.This issue was detected by using the Coccinelle software.
Thanks for the cleanup!
Quoted 23 lines
Signed-off-by Markus Elfring <[email protected]>--- mm/zswap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)mm/zswap.c +1
-2@@ -152,8 +152,7 @@ static int __init zswap_comp_init(void)static void zswap_comp_exit (void ) {/* free percpu transforms */ -if (zswap_comp_pcpu_tfms) -free_percpu (zswap_comp_pcpu_tfms); +free_percpu (zswap_comp_pcpu_tfms); }/********************************* Signature · 1 line
2.1.3
Rafael J. Wysocki
AppliedRe: [PATCH 1/1] kernel-power: Deletion of an unnecessary check before the function call "vfree"
In reply to SF Markus ElfringQuoted 9 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 16 Nov 2014 14:18:28 +0100The
vfree()function performs also input parameter validation. Thus the test around the call is not needed.This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>
Queued up for 3.19-rc1, thanks!
Quoted 18 lines
--- kernel/power/swap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/power/swap.c +1
-1@@ -1374,7 +1374,7 @@ out_clean:kthread_stop (data[thr].thr);vfree (data); } -if (page)vfree (page); +vfree (page);return ret; }
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Ryusuke Konishi
AppliedRe: [PATCH 1/1] nilfs2: Deletion of an unnecessary check before the function call "iput"
In reply to SF Markus ElfringQuoted 9 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 14:41:27 +0100The
iput()function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>
Applied to nilfs2 git tree. Thanks.
Ryusuke Konishi
Quoted 25 lines
--- fs/nilfs2/the_nilfs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)fs/nilfs2/the_nilfs.c +1
-2@@ -808,8 +808,7 @@ void nilfs_put_root(struct nilfs_root *root)spin_lock (&nilfs->ns_cptree_lock);rb_erase (&root->rb_node, &nilfs->ns_cptree);spin_unlock (&nilfs->ns_cptree_lock); -if (root->ifile) -iput (root->ifile); +iput (root->ifile);kfree (root); }Signature · 6 lines
2.1.3 -- To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/1] kprobes: Deletion of an unnecessary check before the function call "module_put"
In reply to Masami HiramatsuQuoted 7 lines
Quoted 7 lines
index 3995f54..f1e7d45 100644
kernel/kprobes.c +0
-0@@ -1527,8 +1527,7 @@ int register_kprobe(struct kprobe *p) out:mutex_unlock (&kprobe_mutex);
Quoted 7 lines
kernel/kprobes.c int register_kprobe(struct kprobe *p) · line 1530
Quoted 3 lines
kernel/kprobes.c +1
-2-if (probed_mod) -module_put (probed_mod); +module_put (probed_mod);This is OK, but I you request a comment line over there so that code reader can understand it is safe to pass a NULL pointer to
module_put().
Do you want that I replace the shown null pointer check by a short comment which repeats an expectation for the affected function call?
Regards,
Markus
Re: [PATCH 1/1] net: xfrm: Deletion of an unnecessary check before the function call "ipcomp_free_tfms"
In reply to SF Markus ElfringQuoted 6 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 21:41:26 +0100The
ipcomp_free_tfms()function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
It doesn't though...
regards,
dan carpenter
PATCH 1/1 crypto-drbg: Deletion of unnecessary checks before the function call "kzfree"
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 10:11:04 +0100
The kzfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- crypto/drbg.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
crypto/drbg.c +6 -12
@@ -1151,8 +1151,7 @@ static int drbg_seed(struct drbg_state *drbg, struct drbg_string *pers, drbg->reseed_ctr =1 ; out: -if (entropy) -kzfree (entropy); +kzfree (entropy);return ret; }
@@ -1161,19 +1160,15 @@ static inline void drbg_dealloc_state(struct drbg_state *drbg) {if (!drbg)return ; -if (drbg->V) -kzfree (drbg->V); +kzfree (drbg->V); drbg->V =NULL ; -if (drbg->C) -kzfree (drbg->C); +kzfree (drbg->C); drbg->C =NULL ; -if (drbg->scratchpad) -kzfree (drbg->scratchpad); +kzfree (drbg->scratchpad); drbg->scratchpad =NULL ; drbg->reseed_ctr =0 ;#ifdef CONFIG_CRYPTO_FIPS -if (drbg->prev) -kzfree (drbg->prev); +kzfree (drbg->prev); drbg->prev =NULL ; drbg->fips_primed = false;#endif
@@ -1293,8 +1288,7 @@ static int drbg_make_shadow(struct drbg_state *drbg, struct drbg_state **shadow)return 0 ; err: -if (tmp) -kzfree (tmp); +kzfree (tmp);return ret; }
Signature · 1 line
2.1.3
Re: net: xfrm: Deletion of an unnecessary check before the function call "ipcomp_free_tfms"
In reply to Dan CarpenterQuoted 4 lines
Quoted 2 lines
The
ipcomp_free_tfms()function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.It doesn't though...
You are right that this function implementation does a bit more before returning because of a detected null pointer.
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/net/xfrm/xfrm_ipcomp.c?id94efd19d5fcae936261bd48e5b33b21897aacf8#n247
Can you agree that input parameter validation is also performed there? Do you want that I resend my patch with a corrected commit message?
Regards,
Markus
Re: net: xfrm: Deletion of an unnecessary check before the function call "ipcomp_free_tfms"
Quoted 11 lines · SF Markus Elfring
Quoted 4 lines
Quoted 2 lines
The
ipcomp_free_tfms()function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.It doesn't though...
You are right that this function implementation does a bit more before returning because of a detected null pointer.
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/net/xfrm/xfrm_ipcomp.c?id94efd19d5fcae936261bd48e5b33b21897aacf8#n247Can you agree that input parameter validation is also performed there? Do you want that I resend my patch with a corrected commit message?
This is completely crazy. The function performs a side effect on a data structure. If the call site doesn't want that done in a certain case, then it should not be done.
julia
Re: net: xfrm: Deletion of an unnecessary check before the function call "ipcomp_free_tfms"
In reply to SF Markus ElfringI have come to view you as a very clever troll. You will say infuriating things like "That is an interesting background information but the function implementation update suggestion is correct" and pretend to not see the bug for nine emails. Then you'll say something "Ha ha, I audited all the call trees and it can't actually be NULL so you were getting angry for no reason." Except you'll say it in a more obfuscated way than that. This is what you did last time.
regards,
dan carpenter