* [Cocci] Remove unnecessary null pointer checks?
@ 2014-02-21 21:52 SF Markus Elfring
2014-02-21 22:27 ` Julia Lawall
0 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-02-21 21:52 UTC (permalink / raw)
To: cocci
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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-21 21:52 [Cocci] Remove unnecessary null pointer checks? SF Markus Elfring
@ 2014-02-21 22:27 ` Julia Lawall
2014-02-22 8:09 ` SF Markus Elfring
` (2 more replies)
0 siblings, 3 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-02-21 22:27 UTC (permalink / raw)
To: cocci
On Fri, 21 Feb 2014, SF Markus Elfring wrote:
> 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.
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.
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-21 22:27 ` Julia Lawall
@ 2014-02-22 8:09 ` SF Markus Elfring
2014-02-22 12:36 ` Julia Lawall
2014-02-23 14:40 ` SF Markus Elfring
2014-03-27 13:41 ` [Cocci] How to exclude volatile data accesses in expressions with SmPL? SF Markus Elfring
2 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-02-22 8:09 UTC (permalink / raw)
To: cocci
> 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?
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-22 8:09 ` SF Markus Elfring
@ 2014-02-22 12:36 ` Julia Lawall
2014-02-22 18:01 ` SF Markus Elfring
0 siblings, 1 reply; 3619+ messages in thread
From: Julia Lawall @ 2014-02-22 12:36 UTC (permalink / raw)
To: cocci
On Sat, 22 Feb 2014, SF Markus Elfring wrote:
> > 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?
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.
> > 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-22 12:36 ` Julia Lawall
@ 2014-02-22 18:01 ` SF Markus Elfring
2014-10-26 6:07 ` SF Markus Elfring
0 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-02-22 18:01 UTC (permalink / raw)
To: cocci
> 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 support
init_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?
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-21 22:27 ` Julia Lawall
2014-02-22 8:09 ` SF Markus Elfring
@ 2014-02-23 14:40 ` SF Markus Elfring
2014-02-23 15:37 ` Julia Lawall
2014-03-27 13:41 ` [Cocci] How to exclude volatile data accesses in expressions with SmPL? SF Markus Elfring
2 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-02-23 14:40 UTC (permalink / raw)
To: cocci
> 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 support
init_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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-23 14:40 ` SF Markus Elfring
@ 2014-02-23 15:37 ` Julia Lawall
2014-02-23 16:33 ` SF Markus Elfring
` (2 more replies)
0 siblings, 3 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-02-23 15:37 UTC (permalink / raw)
To: cocci
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
On Sun, 23 Feb 2014, SF Markus Elfring wrote:
> > 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 support
> init_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
>
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-23 15:37 ` Julia Lawall
@ 2014-02-23 16:33 ` SF Markus Elfring
2014-02-23 16:42 ` Julia Lawall
2014-02-23 22:14 ` SF Markus Elfring
2014-11-28 16:00 ` [Cocci] Remove unnecessary null pointer checks? SF Markus Elfring
2 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-02-23 16:33 UTC (permalink / raw)
To: cocci
> Something goes wrong with the switch pattern. I would have to look into why.
Thanks for your quick feedback.
> 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.
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-23 16:33 ` SF Markus Elfring
@ 2014-02-23 16:42 ` Julia Lawall
0 siblings, 0 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-02-23 16:42 UTC (permalink / raw)
To: cocci
> > 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.
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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-23 15:37 ` Julia Lawall
2014-02-23 16:33 ` SF Markus Elfring
@ 2014-02-23 22:14 ` SF Markus Elfring
2014-02-24 6:00 ` Julia Lawall
2014-11-28 16:00 ` [Cocci] Remove unnecessary null pointer checks? SF Markus Elfring
2 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-02-23 22:14 UTC (permalink / raw)
To: cocci
> 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 support
init_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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-23 22:14 ` SF Markus Elfring
@ 2014-02-24 6:00 ` Julia Lawall
2014-02-24 10:55 ` SF Markus Elfring
2014-02-24 15:05 ` SF Markus Elfring
0 siblings, 2 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-02-24 6:00 UTC (permalink / raw)
To: cocci
On Sun, 23 Feb 2014, SF Markus Elfring wrote:
> > 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.
> -----
>
>
> @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
> ;
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
> )
> ...
> }
>
> @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 support
> init_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
>
>
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-24 6:00 ` Julia Lawall
@ 2014-02-24 10:55 ` SF Markus Elfring
2014-02-24 11:22 ` Julia Lawall
2014-02-24 15:05 ` SF Markus Elfring
1 sibling, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-02-24 10:55 UTC (permalink / raw)
To: cocci
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-24 10:55 ` SF Markus Elfring
@ 2014-02-24 11:22 ` Julia Lawall
0 siblings, 0 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-02-24 11:22 UTC (permalink / raw)
To: cocci
On Mon, 24 Feb 2014, SF Markus Elfring wrote:
> > 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 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-24 6:00 ` Julia Lawall
2014-02-24 10:55 ` SF Markus Elfring
@ 2014-02-24 15:05 ` SF Markus Elfring
2014-02-24 15:19 ` Julia Lawall
2014-02-24 16:14 ` Julia Lawall
1 sibling, 2 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-02-24 15:05 UTC (permalink / raw)
To: cocci
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-24 15:05 ` SF Markus Elfring
@ 2014-02-24 15:19 ` Julia Lawall
2014-02-24 15:58 ` SF Markus Elfring
2014-02-24 16:14 ` Julia Lawall
1 sibling, 1 reply; 3619+ messages in thread
From: Julia Lawall @ 2014-02-24 15:19 UTC (permalink / raw)
To: cocci
On Mon, 24 Feb 2014, SF Markus Elfring wrote:
> > 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?
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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-24 15:19 ` Julia Lawall
@ 2014-02-24 15:58 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-02-24 15:58 UTC (permalink / raw)
To: cocci
>> 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?
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-24 15:05 ` SF Markus Elfring
2014-02-24 15:19 ` Julia Lawall
@ 2014-02-24 16:14 ` Julia Lawall
2014-02-24 16:34 ` SF Markus Elfring
2014-02-25 9:10 ` SF Markus Elfring
1 sibling, 2 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-02-24 16:14 UTC (permalink / raw)
To: cocci
On Mon, 24 Feb 2014, SF Markus Elfring wrote:
> > 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?
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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-24 16:14 ` Julia Lawall
@ 2014-02-24 16:34 ` SF Markus Elfring
2014-02-25 9:10 ` SF Markus Elfring
1 sibling, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-02-24 16:34 UTC (permalink / raw)
To: cocci
> 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.
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-24 16:14 ` Julia Lawall
2014-02-24 16:34 ` SF Markus Elfring
@ 2014-02-25 9:10 ` SF Markus Elfring
2014-02-25 9:16 ` Julia Lawall
1 sibling, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-02-25 9:10 UTC (permalink / raw)
To: cocci
>> 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.
> 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
...
}
> 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?
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-25 9:10 ` SF Markus Elfring
@ 2014-02-25 9:16 ` Julia Lawall
2014-02-25 10:01 ` SF Markus Elfring
` (2 more replies)
0 siblings, 3 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-02-25 9:16 UTC (permalink / raw)
To: cocci
> 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
This is not allowed. Inside a disjunction you need to have complete
terms.
> ...
> }
>
>
> > 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?
>
>
> > 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-25 9:16 ` Julia Lawall
@ 2014-02-25 10:01 ` SF Markus Elfring
2014-02-25 17:28 ` SF Markus Elfring
2014-02-26 7:25 ` [Cocci] Branch layout for if statements with SmPL disjunctions SF Markus Elfring
2 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-02-25 10:01 UTC (permalink / raw)
To: cocci
> 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
)
> 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.
> 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?
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-25 9:16 ` Julia Lawall
2014-02-25 10:01 ` SF Markus Elfring
@ 2014-02-25 17:28 ` SF Markus Elfring
2014-02-25 17:42 ` Julia Lawall
2014-02-26 7:25 ` [Cocci] Branch layout for if statements with SmPL disjunctions SF Markus Elfring
2 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-02-25 17:28 UTC (permalink / raw)
To: cocci
> 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.c
init_defs_builtins: /usr/local/share/coccinelle/standard.h
HANDLING: /usr/src/linux-stable/fs/btrfs/inode.c
diff =
--- /usr/src/linux-stable/fs/btrfs/inode.c
+++ /tmp/cocci-output-3740-5d95d8-inode.c
@@ -5137,8 +5137,7 @@ static int btrfs_dentry_delete(const str
static void btrfs_dentry_release(struct dentry *dentry)
{
- if (dentry->d_fsdata)
- kfree(dentry->d_fsdata);
+ kfree(dentry->d_fsdata);
}
> 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.c
init_defs_builtins: /usr/local/share/coccinelle/standard.h
Fatal error: exception Pcre.Error(_)
Regards,
Markus
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-25 17:28 ` SF Markus Elfring
@ 2014-02-25 17:42 ` Julia Lawall
2014-02-25 20:11 ` SF Markus Elfring
0 siblings, 1 reply; 3619+ messages in thread
From: Julia Lawall @ 2014-02-25 17:42 UTC (permalink / raw)
To: cocci
On Tue, 25 Feb 2014, SF Markus Elfring wrote:
> > 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.c
> init_defs_builtins: /usr/local/share/coccinelle/standard.h
> HANDLING: /usr/src/linux-stable/fs/btrfs/inode.c
> diff =
> --- /usr/src/linux-stable/fs/btrfs/inode.c
> +++ /tmp/cocci-output-3740-5d95d8-inode.c
> @@ -5137,8 +5137,7 @@ static int btrfs_dentry_delete(const str
>
> static void btrfs_dentry_release(struct dentry *dentry)
> {
> - if (dentry->d_fsdata)
> - kfree(dentry->d_fsdata);
> + kfree(dentry->d_fsdata);
> }
>
>
> > 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.c
> init_defs_builtins: /usr/local/share/coccinelle/standard.h
> Fatal error: exception Pcre.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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-25 17:42 ` Julia Lawall
@ 2014-02-25 20:11 ` SF Markus Elfring
2014-02-25 20:20 ` Julia Lawall
0 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-02-25 20:11 UTC (permalink / raw)
To: cocci
> 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.
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-25 20:11 ` SF Markus Elfring
@ 2014-02-25 20:20 ` Julia Lawall
2014-02-25 20:37 ` [Cocci] Source code analysis with big regular expressions? SF Markus Elfring
` (3 more replies)
0 siblings, 4 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-02-25 20:20 UTC (permalink / raw)
To: cocci
On Tue, 25 Feb 2014, SF Markus Elfring wrote:
> > 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.
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 ...
> > 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.
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Source code analysis with big regular expressions?
2014-02-25 20:20 ` Julia Lawall
@ 2014-02-25 20:37 ` SF Markus Elfring
2014-02-25 20:44 ` Julia Lawall
2014-02-25 21:44 ` [Cocci] Remove unnecessary null pointer checks? SF Markus Elfring
` (2 subsequent siblings)
3 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-02-25 20:37 UTC (permalink / raw)
To: cocci
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Source code analysis with big regular expressions?
2014-02-25 20:37 ` [Cocci] Source code analysis with big regular expressions? SF Markus Elfring
@ 2014-02-25 20:44 ` Julia Lawall
2014-02-25 20:54 ` SF Markus Elfring
0 siblings, 1 reply; 3619+ messages in thread
From: Julia Lawall @ 2014-02-25 20:44 UTC (permalink / raw)
To: cocci
On Tue, 25 Feb 2014, SF Markus Elfring wrote:
> > 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Source code analysis with big regular expressions?
2014-02-25 20:44 ` Julia Lawall
@ 2014-02-25 20:54 ` SF Markus Elfring
2014-02-25 21:02 ` Julia Lawall
0 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-02-25 20:54 UTC (permalink / raw)
To: cocci
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Source code analysis with big regular expressions?
2014-02-25 20:54 ` SF Markus Elfring
@ 2014-02-25 21:02 ` Julia Lawall
2014-02-25 21:19 ` SF Markus Elfring
0 siblings, 1 reply; 3619+ messages in thread
From: Julia Lawall @ 2014-02-25 21:02 UTC (permalink / raw)
To: cocci
On Tue, 25 Feb 2014, SF Markus Elfring wrote:
> > 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?
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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Source code analysis with big regular expressions?
2014-02-25 21:02 ` Julia Lawall
@ 2014-02-25 21:19 ` SF Markus Elfring
2014-02-25 21:29 ` Julia Lawall
0 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-02-25 21:19 UTC (permalink / raw)
To: cocci
> 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?
> 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.
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Source code analysis with big regular expressions?
2014-02-25 21:19 ` SF Markus Elfring
@ 2014-02-25 21:29 ` Julia Lawall
0 siblings, 0 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-02-25 21:29 UTC (permalink / raw)
To: cocci
On Tue, 25 Feb 2014, SF Markus Elfring wrote:
> > 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?
>
>
> > 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.
>
>
> > 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-25 20:20 ` Julia Lawall
2014-02-25 20:37 ` [Cocci] Source code analysis with big regular expressions? SF Markus Elfring
@ 2014-02-25 21:44 ` SF Markus Elfring
2014-02-25 21:48 ` Julia Lawall
2014-02-26 8:04 ` SF Markus Elfring
2014-02-26 11:30 ` SF Markus Elfring
3 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-02-25 21:44 UTC (permalink / raw)
To: cocci
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-25 21:44 ` [Cocci] Remove unnecessary null pointer checks? SF Markus Elfring
@ 2014-02-25 21:48 ` Julia Lawall
0 siblings, 0 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-02-25 21:48 UTC (permalink / raw)
To: cocci
On Tue, 25 Feb 2014, SF Markus Elfring wrote:
> > 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Branch layout for if statements with SmPL disjunctions
2014-02-25 9:16 ` Julia Lawall
2014-02-25 10:01 ` SF Markus Elfring
2014-02-25 17:28 ` SF Markus Elfring
@ 2014-02-26 7:25 ` SF Markus Elfring
2014-02-26 9:39 ` Julia Lawall
2 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-02-26 7:25 UTC (permalink / raw)
To: cocci
>> ( if (input) is
>> | if (likely(input)) is
>> )
>> else es
>
> This 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-25 20:20 ` Julia Lawall
2014-02-25 20:37 ` [Cocci] Source code analysis with big regular expressions? SF Markus Elfring
2014-02-25 21:44 ` [Cocci] Remove unnecessary null pointer checks? SF Markus Elfring
@ 2014-02-26 8:04 ` SF Markus Elfring
2014-02-26 11:30 ` SF Markus Elfring
3 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-02-26 8:04 UTC (permalink / raw)
To: cocci
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Branch layout for if statements with SmPL disjunctions
2014-02-26 7:25 ` [Cocci] Branch layout for if statements with SmPL disjunctions SF Markus Elfring
@ 2014-02-26 9:39 ` Julia Lawall
0 siblings, 0 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-02-26 9:39 UTC (permalink / raw)
To: cocci
On Wed, 26 Feb 2014, SF Markus Elfring wrote:
> >> ( if (input) is
> >> | if (likely(input)) is
> >> )
> >> else es
> >
> > This 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
> 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
>
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-25 20:20 ` Julia Lawall
` (2 preceding siblings ...)
2014-02-26 8:04 ` SF Markus Elfring
@ 2014-02-26 11:30 ` SF Markus Elfring
2014-02-26 20:35 ` Julia Lawall
` (2 more replies)
3 siblings, 3 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-02-26 11:30 UTC (permalink / raw)
To: cocci
> 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.c
init_defs_builtins: /usr/local/share/coccinelle/standard.h
HANDLING: /usr/src/linux-stable/fs/btrfs/inode.c
diff =
--- /usr/src/linux-stable/fs/btrfs/inode.c
+++ /tmp/cocci-output-5030-250c49-inode.c
@@ -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 str
static 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-26 11:30 ` SF Markus Elfring
@ 2014-02-26 20:35 ` Julia Lawall
2014-02-26 21:01 ` SF Markus Elfring
` (2 more replies)
2014-03-01 8:16 ` [Cocci] Improvements for passing of big regular expressions in SmPL constraints? SF Markus Elfring
2014-03-08 12:30 ` [Cocci] Determination of the number for named function parameters SF Markus Elfring
2 siblings, 3 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-02-26 20:35 UTC (permalink / raw)
To: cocci
> 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.
> 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.
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-26 20:35 ` Julia Lawall
@ 2014-02-26 21:01 ` SF Markus Elfring
2014-02-26 21:09 ` Julia Lawall
2014-03-05 22:30 ` SF Markus Elfring
[not found] ` <5317A59D.4@users.so urceforge.net>
2 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-02-26 21:01 UTC (permalink / raw)
To: cocci
> 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.
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-26 21:01 ` SF Markus Elfring
@ 2014-02-26 21:09 ` Julia Lawall
2014-03-06 8:39 ` SF Markus Elfring
0 siblings, 1 reply; 3619+ messages in thread
From: Julia Lawall @ 2014-02-26 21:09 UTC (permalink / raw)
To: cocci
> - 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Improvements for passing of big regular expressions in SmPL constraints?
2014-02-26 11:30 ` SF Markus Elfring
2014-02-26 20:35 ` Julia Lawall
@ 2014-03-01 8:16 ` SF Markus Elfring
2014-03-01 13:15 ` Julia Lawall
2014-03-08 12:30 ` [Cocci] Determination of the number for named function parameters SF Markus Elfring
2 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-01 8:16 UTC (permalink / raw)
To: cocci
> @Delete_unnecessary_checks@
> expression x;
> identifier release =~ "^(?x)
> (?:
> (?: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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Improvements for passing of big regular expressions in SmPL constraints?
2014-03-01 8:16 ` [Cocci] Improvements for passing of big regular expressions in SmPL constraints? SF Markus Elfring
@ 2014-03-01 13:15 ` Julia Lawall
2014-03-01 13:34 ` SF Markus Elfring
0 siblings, 1 reply; 3619+ messages in thread
From: Julia Lawall @ 2014-03-01 13:15 UTC (permalink / raw)
To: cocci
On Sat, 1 Mar 2014, SF Markus Elfring wrote:
> > @Delete_unnecessary_checks@
> > expression x;
> > identifier release =~ "^(?x)
> > (?:
> > (?: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?
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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Improvements for passing of big regular expressions in SmPL constraints?
2014-03-01 13:15 ` Julia Lawall
@ 2014-03-01 13:34 ` SF Markus Elfring
2014-03-01 13:36 ` Julia Lawall
0 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-01 13:34 UTC (permalink / raw)
To: cocci
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Improvements for passing of big regular expressions in SmPL constraints?
2014-03-01 13:34 ` SF Markus Elfring
@ 2014-03-01 13:36 ` Julia Lawall
0 siblings, 0 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-03-01 13:36 UTC (permalink / raw)
To: cocci
On Sat, 1 Mar 2014, SF Markus Elfring wrote:
> > 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls
2014-02-26 20:35 ` Julia Lawall
2014-02-26 21:01 ` SF Markus Elfring
@ 2014-03-05 22:30 ` SF Markus Elfring
[not found] ` <5317A59D.4@users.so urceforge.net>
2 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-05 22:30 UTC (permalink / raw)
To: linux-kernel; +Cc: Coccinelle, kernel-janitors
> 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.
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/scripts/coccinelle?id=79f0345fefaafb7cde301a830471edd21a37989b
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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls
@ 2014-03-05 22:30 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-05 22:30 UTC (permalink / raw)
To: cocci
> 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.
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/scripts/coccinelle?idyf0345fefaafb7cde301a830471edd21a37989b
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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls
@ 2014-03-05 22:30 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-05 22:30 UTC (permalink / raw)
To: cocci
> 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.
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/scripts/coccinelle?id=79f0345fefaafb7cde301a830471edd21a37989b
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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [coccicheck Linux 3.14-rc5 PATCH 1 of 5] Deletion of unnecessary checks before specific function calls
2014-03-05 22:30 ` SF Markus Elfring
(?)
@ 2014-03-05 22:48 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-05 22:48 UTC (permalink / raw)
To: linux-kernel; +Cc: Coccinelle, kernel-janitors
>> 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 48c9c4f61a7d7ea98538e02631a981a429281005 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
.../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
--- /dev/null
+++ b/scripts/coccinelle/deletions/delete_unnecessary_checks_template1.cocci
@@ -0,0 +1,13 @@
+@Delete_unnecessary_checks@
+expression x;
+identifier release =~ "^(?x)
+(?:
+ (?:kz?|slob_)free
+|
+ (?:
+# Alternation placeholder
+ )
+)$";
+@@
+-if (x)
+ release(x);
--
1.9.0
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [coccicheck Linux 3.14-rc5 PATCH 1 of 5] Deletion of unnecessary checks before specific function
@ 2014-03-05 22:48 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-05 22:48 UTC (permalink / raw)
To: cocci
>> 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 48c9c4f61a7d7ea98538e02631a981a429281005 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
.../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
--- /dev/null
+++ b/scripts/coccinelle/deletions/delete_unnecessary_checks_template1.cocci
@@ -0,0 +1,13 @@
+@Delete_unnecessary_checks@
+expression x;
+identifier release =~ "^(?x)
+(?:
+ (?:kz?|slob_)free
+|
+ (?:
+# Alternation placeholder
+ )
+)$";
+@@
+-if (x)
+ release(x);
--
1.9.0
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Cocci] [coccicheck Linux 3.14-rc5 PATCH 1 of 5] Deletion of unnecessary checks before specific function calls
@ 2014-03-05 22:48 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-05 22:48 UTC (permalink / raw)
To: cocci
>> 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 48c9c4f61a7d7ea98538e02631a981a429281005 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
.../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
--- /dev/null
+++ b/scripts/coccinelle/deletions/delete_unnecessary_checks_template1.cocci
@@ -0,0 +1,13 @@
+ at Delete_unnecessary_checks@
+expression x;
+identifier release =~ "^(?x)
+(?:
+ (?:kz?|slob_)free
+|
+ (?:
+# Alternation placeholder
+ )
+)$";
+@@
+-if (x)
+ release(x);
--
1.9.0
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [coccicheck Linux 3.14-rc5 PATCH 2 of 5] Deletion of unnecessary checks before specific function calls
2014-03-05 22:30 ` SF Markus Elfring
(?)
@ 2014-03-05 22:50 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-05 22:50 UTC (permalink / raw)
To: linux-kernel; +Cc: Coccinelle, kernel-janitors
>> 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 1d2de3c3cfa43cc3c78a91200c41cef438b26a8f Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
.../list_input_parameter_validation1.cocci | 55 ++++++++++++++++++++++
1 file changed, 55 insertions(+)
create mode 100644
scripts/coccinelle/deletions/list_input_parameter_validation1.cocci
diff --git a/scripts/coccinelle/deletions/list_input_parameter_validation1.cocci
b/scripts/coccinelle/deletions/list_input_parameter_validation1.cocci
new file mode 100644
index 0000000..b0a5a52
--- /dev/null
+++ b/scripts/coccinelle/deletions/list_input_parameter_validation1.cocci
@@ -0,0 +1,55 @@
+@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@pos(data_type input)
+ {
+ ... when any
+( if (input) is else es
+| if (likely(input)) is else es
+)
+ ... when any
+ }
+
+@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")
--
1.9.0
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [coccicheck Linux 3.14-rc5 PATCH 2 of 5] Deletion of unnecessary checks before specific function
@ 2014-03-05 22:50 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-05 22:50 UTC (permalink / raw)
To: cocci
>> 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 1d2de3c3cfa43cc3c78a91200c41cef438b26a8f Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
.../list_input_parameter_validation1.cocci | 55 ++++++++++++++++++++++
1 file changed, 55 insertions(+)
create mode 100644
scripts/coccinelle/deletions/list_input_parameter_validation1.cocci
diff --git a/scripts/coccinelle/deletions/list_input_parameter_validation1.cocci
b/scripts/coccinelle/deletions/list_input_parameter_validation1.cocci
new file mode 100644
index 0000000..b0a5a52
--- /dev/null
+++ b/scripts/coccinelle/deletions/list_input_parameter_validation1.cocci
@@ -0,0 +1,55 @@
+@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@pos(data_type input)
+ {
+ ... when any
+( if (input) is else es
+| if (likely(input)) is else es
+)
+ ... when any
+ }
+
+@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")
--
1.9.0
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Cocci] [coccicheck Linux 3.14-rc5 PATCH 2 of 5] Deletion of unnecessary checks before specific function calls
@ 2014-03-05 22:50 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-05 22:50 UTC (permalink / raw)
To: cocci
>> 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 1d2de3c3cfa43cc3c78a91200c41cef438b26a8f Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
.../list_input_parameter_validation1.cocci | 55 ++++++++++++++++++++++
1 file changed, 55 insertions(+)
create mode 100644
scripts/coccinelle/deletions/list_input_parameter_validation1.cocci
diff --git a/scripts/coccinelle/deletions/list_input_parameter_validation1.cocci
b/scripts/coccinelle/deletions/list_input_parameter_validation1.cocci
new file mode 100644
index 0000000..b0a5a52
--- /dev/null
+++ b/scripts/coccinelle/deletions/list_input_parameter_validation1.cocci
@@ -0,0 +1,55 @@
+ at 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))
+
+ at 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
+ }
+
+ at 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")
--
1.9.0
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [coccicheck Linux 3.14-rc5 PATCH 3 of 5] Deletion of unnecessary checks before specific function calls
2014-03-05 22:30 ` SF Markus Elfring
(?)
@ 2014-03-05 22:52 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-05 22:52 UTC (permalink / raw)
To: linux-kernel; +Cc: Coccinelle, kernel-janitors
>> 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 f4608fceec40b2b94aa9b4abe3bbb6d98ed5eed9 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
.../coccinelle/deletions/handle_function_list_template.sqlite | 9 +++++++++
1 file changed, 9 insertions(+)
create mode 100644
scripts/coccinelle/deletions/handle_function_list_template.sqlite
diff --git a/scripts/coccinelle/deletions/handle_function_list_template.sqlite
b/scripts/coccinelle/deletions/handle_function_list_template.sqlite
new file mode 100644
index 0000000..bec366c
--- /dev/null
+++ b/scripts/coccinelle/deletions/handle_function_list_template.sqlite
@@ -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
--
1.9.0
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [coccicheck Linux 3.14-rc5 PATCH 3 of 5] Deletion of unnecessary checks before specific function
@ 2014-03-05 22:52 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-05 22:52 UTC (permalink / raw)
To: cocci
>> 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 f4608fceec40b2b94aa9b4abe3bbb6d98ed5eed9 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
.../coccinelle/deletions/handle_function_list_template.sqlite | 9 +++++++++
1 file changed, 9 insertions(+)
create mode 100644
scripts/coccinelle/deletions/handle_function_list_template.sqlite
diff --git a/scripts/coccinelle/deletions/handle_function_list_template.sqlite
b/scripts/coccinelle/deletions/handle_function_list_template.sqlite
new file mode 100644
index 0000000..bec366c
--- /dev/null
+++ b/scripts/coccinelle/deletions/handle_function_list_template.sqlite
@@ -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
--
1.9.0
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Cocci] [coccicheck Linux 3.14-rc5 PATCH 3 of 5] Deletion of unnecessary checks before specific function calls
@ 2014-03-05 22:52 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-05 22:52 UTC (permalink / raw)
To: cocci
>> 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 f4608fceec40b2b94aa9b4abe3bbb6d98ed5eed9 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
.../coccinelle/deletions/handle_function_list_template.sqlite | 9 +++++++++
1 file changed, 9 insertions(+)
create mode 100644
scripts/coccinelle/deletions/handle_function_list_template.sqlite
diff --git a/scripts/coccinelle/deletions/handle_function_list_template.sqlite
b/scripts/coccinelle/deletions/handle_function_list_template.sqlite
new file mode 100644
index 0000000..bec366c
--- /dev/null
+++ b/scripts/coccinelle/deletions/handle_function_list_template.sqlite
@@ -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
--
1.9.0
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [coccicheck Linux 3.14-rc5 PATCH 4 of 5] Deletion of unnecessary checks before specific function calls
2014-03-05 22:30 ` SF Markus Elfring
(?)
@ 2014-03-05 22:55 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-05 22:55 UTC (permalink / raw)
To: linux-kernel; +Cc: Coccinelle, kernel-janitors
>> 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 e6a21b920fcca2f6f01c9528909dc036a9b3bc41 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
...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 @@
+@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))
+
+@is_unnecessary_check@
+expression data;
+identifier work;
+identifier release =~ "^(?x)
+(?:
+ (?:kz?|slob_)free
+|
+ (?:
+# Alternation placeholder
+ )
+)$";
+position pos;
+type t;
+@@
+ t work@pos(...)
+ {
+ ... when any
+( if (data) release(data);
+| if (likely(data)) release(data);
+)
+ ... when any
+ }
+
+@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")
--
1.9.0
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [coccicheck Linux 3.14-rc5 PATCH 4 of 5] Deletion of unnecessary checks before specific function
@ 2014-03-05 22:55 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-05 22:55 UTC (permalink / raw)
To: cocci
>> 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 e6a21b920fcca2f6f01c9528909dc036a9b3bc41 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
...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 @@
+@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))
+
+@is_unnecessary_check@
+expression data;
+identifier work;
+identifier release =~ "^(?x)
+(?:
+ (?:kz?|slob_)free
+|
+ (?:
+# Alternation placeholder
+ )
+)$";
+position pos;
+type t;
+@@
+ t work@pos(...)
+ {
+ ... when any
+( if (data) release(data);
+| if (likely(data)) release(data);
+)
+ ... when any
+ }
+
+@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")
--
1.9.0
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] [coccicheck Linux 3.14-rc5 PATCH 4 of 5] Deletion of unnecessary checks before specific function calls
@ 2014-03-05 22:55 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-05 22:55 UTC (permalink / raw)
To: cocci
>> 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 e6a21b920fcca2f6f01c9528909dc036a9b3bc41 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
...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")
--
1.9.0
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [coccicheck Linux 3.14-rc5 PATCH 5 of 5] Deletion of unnecessary checks before specific function calls
2014-03-05 22:30 ` SF Markus Elfring
(?)
@ 2014-03-05 22:58 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-05 22:58 UTC (permalink / raw)
To: linux-kernel; +Cc: Coccinelle, kernel-janitors
>> 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 bedf1cb3ddd162ee3b4c31cbb98d97431f70103d Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
scripts/coccinelle/deletions/makefile | 126 ++++++++++++++++++++++++++++++++++
1 file changed, 126 insertions(+)
create mode 100644 scripts/coccinelle/deletions/makefile
diff --git a/scripts/coccinelle/deletions/makefile
b/scripts/coccinelle/deletions/makefile
new file mode 100644
index 0000000..6464bae
--- /dev/null
+++ b/scripts/coccinelle/deletions/makefile
@@ -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): ;
--
1.9.0
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [coccicheck Linux 3.14-rc5 PATCH 5 of 5] Deletion of unnecessary checks before specific function
@ 2014-03-05 22:58 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-05 22:58 UTC (permalink / raw)
To: cocci
>> 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 bedf1cb3ddd162ee3b4c31cbb98d97431f70103d Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
scripts/coccinelle/deletions/makefile | 126 ++++++++++++++++++++++++++++++++++
1 file changed, 126 insertions(+)
create mode 100644 scripts/coccinelle/deletions/makefile
diff --git a/scripts/coccinelle/deletions/makefile
b/scripts/coccinelle/deletions/makefile
new file mode 100644
index 0000000..6464bae
--- /dev/null
+++ b/scripts/coccinelle/deletions/makefile
@@ -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_PREFIXd_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Þlete_unnecessary_checks_template1.cocci
+PATCH_PATTERNÞlete_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): ;
--
1.9.0
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Cocci] [coccicheck Linux 3.14-rc5 PATCH 5 of 5] Deletion of unnecessary checks before specific function calls
@ 2014-03-05 22:58 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-05 22:58 UTC (permalink / raw)
To: cocci
>> 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 bedf1cb3ddd162ee3b4c31cbb98d97431f70103d Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
scripts/coccinelle/deletions/makefile | 126 ++++++++++++++++++++++++++++++++++
1 file changed, 126 insertions(+)
create mode 100644 scripts/coccinelle/deletions/makefile
diff --git a/scripts/coccinelle/deletions/makefile
b/scripts/coccinelle/deletions/makefile
new file mode 100644
index 0000000..6464bae
--- /dev/null
+++ b/scripts/coccinelle/deletions/makefile
@@ -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): ;
--
1.9.0
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-26 21:09 ` Julia Lawall
@ 2014-03-06 8:39 ` SF Markus Elfring
2014-03-06 16:24 ` Julia Lawall
0 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-06 8:39 UTC (permalink / raw)
To: cocci
>> - 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".
> 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.c
init_defs_builtins: /usr/local/share/coccinelle/standard.h
HANDLING: /usr/src/linux-stable/fs/proc/proc_sysctl.c
diff =
--- /usr/src/linux-stable/fs/proc/proc_sysctl.c
+++ /tmp/cocci-output-5200-eacf04-proc_sysctl.c
@@ -470,8 +470,7 @@ static struct dentry *proc_sys_lookup(st
d_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.c
init_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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-03-06 8:39 ` SF Markus Elfring
@ 2014-03-06 16:24 ` Julia Lawall
2014-03-06 17:04 ` SF Markus Elfring
2014-09-30 13:24 ` [Cocci] Fix for "lexing: empty token" needed? SF Markus Elfring
0 siblings, 2 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-03-06 16:24 UTC (permalink / raw)
To: cocci
On Thu, 6 Mar 2014, SF Markus Elfring wrote:
> >> - 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
>
>
> > 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.c
> init_defs_builtins: /usr/local/share/coccinelle/standard.h
> HANDLING: /usr/src/linux-stable/fs/proc/proc_sysctl.c
> diff =
> --- /usr/src/linux-stable/fs/proc/proc_sysctl.c
> +++ /tmp/cocci-output-5200-eacf04-proc_sysctl.c
> @@ -470,8 +470,7 @@ static struct dentry *proc_sys_lookup(st
> d_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.c
> init_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
>
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-03-06 16:24 ` Julia Lawall
@ 2014-03-06 17:04 ` SF Markus Elfring
2014-09-30 13:24 ` [Cocci] Fix for "lexing: empty token" needed? SF Markus Elfring
1 sibling, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-06 17:04 UTC (permalink / raw)
To: cocci
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Determination of the number for named function parameters
2014-02-26 11:30 ` SF Markus Elfring
2014-02-26 20:35 ` Julia Lawall
2014-03-01 8:16 ` [Cocci] Improvements for passing of big regular expressions in SmPL constraints? SF Markus Elfring
@ 2014-03-08 12:30 ` SF Markus Elfring
2014-03-08 14:16 ` Julia Lawall
2 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-08 12:30 UTC (permalink / raw)
To: cocci
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Determination of the number for named function parameters
2014-03-08 12:30 ` [Cocci] Determination of the number for named function parameters SF Markus Elfring
@ 2014-03-08 14:16 ` Julia Lawall
2014-03-08 15:10 ` SF Markus Elfring
0 siblings, 1 reply; 3619+ messages in thread
From: Julia Lawall @ 2014-03-08 14:16 UTC (permalink / raw)
To: cocci
On Sat, 8 Mar 2014, SF Markus Elfring wrote:
> > 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Determination of the number for named function parameters
2014-03-08 14:16 ` Julia Lawall
@ 2014-03-08 15:10 ` SF Markus Elfring
2014-03-08 20:01 ` SF Markus Elfring
2014-03-08 21:59 ` [Cocci] Determination of the number for named function parameters Julia Lawall
0 siblings, 2 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-08 15:10 UTC (permalink / raw)
To: cocci
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Determination of the number for named function parameters
2014-03-08 15:10 ` SF Markus Elfring
@ 2014-03-08 20:01 ` SF Markus Elfring
2014-03-08 21:41 ` Julia Lawall
2014-03-08 21:59 ` [Cocci] Determination of the number for named function parameters Julia Lawall
1 sibling, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-08 20:01 UTC (permalink / raw)
To: cocci
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Determination of the number for named function parameters
2014-03-08 20:01 ` SF Markus Elfring
@ 2014-03-08 21:41 ` Julia Lawall
2014-03-09 8:00 ` SF Markus Elfring
0 siblings, 1 reply; 3619+ messages in thread
From: Julia Lawall @ 2014-03-08 21:41 UTC (permalink / raw)
To: cocci
On Sat, 8 Mar 2014, SF Markus Elfring wrote:
> > 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"?
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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Determination of the number for named function parameters
2014-03-08 15:10 ` SF Markus Elfring
2014-03-08 20:01 ` SF Markus Elfring
@ 2014-03-08 21:59 ` Julia Lawall
2014-03-09 7:01 ` SF Markus Elfring
1 sibling, 1 reply; 3619+ messages in thread
From: Julia Lawall @ 2014-03-08 21:59 UTC (permalink / raw)
To: cocci
On Sat, 8 Mar 2014, SF Markus Elfring wrote:
> > 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.
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Determination of the number for named function parameters
2014-03-08 21:59 ` [Cocci] Determination of the number for named function parameters Julia Lawall
@ 2014-03-09 7:01 ` SF Markus Elfring
2014-03-09 7:13 ` Julia Lawall
0 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-09 7:01 UTC (permalink / raw)
To: cocci
>> 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?
> 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.c
init_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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Determination of the number for named function parameters
2014-03-09 7:01 ` SF Markus Elfring
@ 2014-03-09 7:13 ` Julia Lawall
2014-03-09 7:18 ` [Cocci] Improvements for the SmPL grammar description? SF Markus Elfring
0 siblings, 1 reply; 3619+ messages in thread
From: Julia Lawall @ 2014-03-09 7:13 UTC (permalink / raw)
To: cocci
On Sun, 9 Mar 2014, SF Markus Elfring wrote:
> >> 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?
Yes. The spaces around the [ ] means that they are tokens.
julia
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Improvements for the SmPL grammar description?
2014-03-09 7:13 ` Julia Lawall
@ 2014-03-09 7:18 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-09 7:18 UTC (permalink / raw)
To: cocci
> The spaces around the [ ] means that they are tokens.
I would appreciate if the distinction will become easier for such characters.
Regards,
Markus
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Determination of the number for named function parameters
2014-03-08 21:41 ` Julia Lawall
@ 2014-03-09 8:00 ` SF Markus Elfring
2014-03-09 8:12 ` Julia Lawall
0 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-09 8:00 UTC (permalink / raw)
To: cocci
>> 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?
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Determination of the number for named function parameters
2014-03-09 8:00 ` SF Markus Elfring
@ 2014-03-09 8:12 ` Julia Lawall
2014-03-09 8:50 ` SF Markus Elfring
` (2 more replies)
0 siblings, 3 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-03-09 8:12 UTC (permalink / raw)
To: cocci
On Sun, 9 Mar 2014, SF Markus Elfring wrote:
> >> 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.
> 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.
> > 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".
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Determination of the number for named function parameters
2014-03-09 8:12 ` Julia Lawall
@ 2014-03-09 8:50 ` SF Markus Elfring
2014-03-14 14:25 ` SF Markus Elfring
2014-03-09 12:51 ` SF Markus Elfring
2014-03-10 18:00 ` [Cocci] Selection of class libraries ...? SF Markus Elfring
2 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-09 8:50 UTC (permalink / raw)
To: cocci
> I didn't implement it, and I never use python.
I would struggle with OCaml script development more so far.
> 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.
> @r@
> position p;
> identifier f;
> @@
>
> f at p(void} { ... }
>
> @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.
> 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.
>
>> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Determination of the number for named function parameters
2014-03-09 8:12 ` Julia Lawall
2014-03-09 8:50 ` SF Markus Elfring
@ 2014-03-09 12:51 ` SF Markus Elfring
2014-03-09 13:06 ` Julia Lawall
2014-03-10 18:00 ` [Cocci] Selection of class libraries ...? SF Markus Elfring
2 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-09 12:51 UTC (permalink / raw)
To: cocci
> 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.c
init_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.c
init_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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Determination of the number for named function parameters
2014-03-09 12:51 ` SF Markus Elfring
@ 2014-03-09 13:06 ` Julia Lawall
2014-03-09 13:36 ` SF Markus Elfring
0 siblings, 1 reply; 3619+ messages in thread
From: Julia Lawall @ 2014-03-09 13:06 UTC (permalink / raw)
To: cocci
On Sun, 9 Mar 2014, SF Markus Elfring wrote:
> > 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@
No need for depends on input. For a python rule, all metavariables have
to be bound before anything happens.
> 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.c
> init_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.c
> init_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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Determination of the number for named function parameters
2014-03-09 13:06 ` Julia Lawall
@ 2014-03-09 13:36 ` SF Markus Elfring
2014-03-09 13:40 ` Julia Lawall
0 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-09 13:36 UTC (permalink / raw)
To: cocci
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Determination of the number for named function parameters
2014-03-09 13:36 ` SF Markus Elfring
@ 2014-03-09 13:40 ` Julia Lawall
2014-03-09 13:51 ` SF Markus Elfring
0 siblings, 1 reply; 3619+ messages in thread
From: Julia Lawall @ 2014-03-09 13:40 UTC (permalink / raw)
To: cocci
On Sun, 9 Mar 2014, SF Markus Elfring wrote:
> > 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Determination of the number for named function parameters
2014-03-09 13:40 ` Julia Lawall
@ 2014-03-09 13:51 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-09 13:51 UTC (permalink / raw)
To: cocci
> 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.
> 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?
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Selection of class libraries ...?
2014-03-09 8:12 ` Julia Lawall
2014-03-09 8:50 ` SF Markus Elfring
2014-03-09 12:51 ` SF Markus Elfring
@ 2014-03-10 18:00 ` SF Markus Elfring
2014-03-10 18:19 ` Julia Lawall
2 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-10 18:00 UTC (permalink / raw)
To: cocci
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Selection of class libraries ...?
2014-03-10 18:00 ` [Cocci] Selection of class libraries ...? SF Markus Elfring
@ 2014-03-10 18:19 ` Julia Lawall
2014-03-10 18:30 ` SF Markus Elfring
0 siblings, 1 reply; 3619+ messages in thread
From: Julia Lawall @ 2014-03-10 18:19 UTC (permalink / raw)
To: cocci
On Mon, 10 Mar 2014, SF Markus Elfring wrote:
> > 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Selection of class libraries ...?
2014-03-10 18:19 ` Julia Lawall
@ 2014-03-10 18:30 ` SF Markus Elfring
2014-03-10 19:24 ` Julia Lawall
0 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-10 18:30 UTC (permalink / raw)
To: cocci
>> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Selection of class libraries ...?
2014-03-10 18:30 ` SF Markus Elfring
@ 2014-03-10 19:24 ` Julia Lawall
2014-03-10 21:10 ` SF Markus Elfring
0 siblings, 1 reply; 3619+ messages in thread
From: Julia Lawall @ 2014-03-10 19:24 UTC (permalink / raw)
To: cocci
On Mon, 10 Mar 2014, SF Markus Elfring wrote:
> >> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Selection of class libraries ...?
2014-03-10 19:24 ` Julia Lawall
@ 2014-03-10 21:10 ` SF Markus Elfring
2014-03-10 21:15 ` Julia Lawall
0 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-10 21:10 UTC (permalink / raw)
To: cocci
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Selection of class libraries ...?
2014-03-10 21:10 ` SF Markus Elfring
@ 2014-03-10 21:15 ` Julia Lawall
2014-03-10 21:26 ` SF Markus Elfring
2014-03-12 10:10 ` [Cocci] Clarification for OCaml scripts in SmPL SF Markus Elfring
0 siblings, 2 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-03-10 21:15 UTC (permalink / raw)
To: cocci
On Mon, 10 Mar 2014, SF Markus Elfring wrote:
> > 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?
You can just add information to the front of the list, and then reverse it
at the end if that is needed.
julia
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Selection of class libraries ...?
2014-03-10 21:15 ` Julia Lawall
@ 2014-03-10 21:26 ` SF Markus Elfring
2014-03-12 10:10 ` [Cocci] Clarification for OCaml scripts in SmPL SF Markus Elfring
1 sibling, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-10 21:26 UTC (permalink / raw)
To: cocci
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Clarification for OCaml scripts in SmPL
2014-03-10 21:15 ` Julia Lawall
2014-03-10 21:26 ` SF Markus Elfring
@ 2014-03-12 10:10 ` SF Markus Elfring
2014-03-12 12:10 ` SF Markus Elfring
` (2 more replies)
1 sibling, 3 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-12 10:10 UTC (permalink / raw)
To: cocci
>> 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)]) result
let 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.c
init_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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Clarification for OCaml scripts in SmPL
2014-03-12 10:10 ` [Cocci] Clarification for OCaml scripts in SmPL SF Markus Elfring
@ 2014-03-12 12:10 ` SF Markus Elfring
2014-03-14 0:19 ` Julia Lawall
2014-03-13 23:56 ` Julia Lawall
2014-03-14 0:09 ` Julia Lawall
2 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-12 12:10 UTC (permalink / raw)
To: cocci
> let store_positions fun 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 places
Regards,
Markus
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Clarification for OCaml scripts in SmPL
2014-03-12 10:10 ` [Cocci] Clarification for OCaml scripts in SmPL SF Markus Elfring
2014-03-12 12:10 ` SF Markus Elfring
@ 2014-03-13 23:56 ` Julia Lawall
2014-03-13 23:58 ` Julia Lawall
2014-03-14 0:09 ` Julia Lawall
2 siblings, 1 reply; 3619+ messages in thread
From: Julia Lawall @ 2014-03-13 23:56 UTC (permalink / raw)
To: cocci
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Clarification for OCaml scripts in SmPL
2014-03-13 23:56 ` Julia Lawall
@ 2014-03-13 23:58 ` Julia Lawall
0 siblings, 0 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-03-13 23:58 UTC (permalink / raw)
To: cocci
On Thu, 13 Mar 2014, Julia Lawall wrote:
> > 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Clarification for OCaml scripts in SmPL
2014-03-12 10:10 ` [Cocci] Clarification for OCaml scripts in SmPL SF Markus Elfring
2014-03-12 12:10 ` SF Markus Elfring
2014-03-13 23:56 ` Julia Lawall
@ 2014-03-14 0:09 ` Julia Lawall
2014-03-14 7:14 ` SF Markus Elfring
2 siblings, 1 reply; 3619+ messages in thread
From: Julia Lawall @ 2014-03-14 0:09 UTC (permalink / raw)
To: cocci
I 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Clarification for OCaml scripts in SmPL
2014-03-12 12:10 ` SF Markus Elfring
@ 2014-03-14 0:19 ` Julia Lawall
0 siblings, 0 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-03-14 0:19 UTC (permalink / raw)
To: cocci
On Wed, 12 Mar 2014, SF Markus Elfring wrote:
> > let store_positions fun 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
> http://ocaml.org/learn/faq.html
>
> let store_positions fu count places =
> current_fu := fu;
> current_count := string_of_int count;
> List.iter append places
>
> Regards,
> Markus
> _______________________________________________
> Cocci mailing list
> Cocci at systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Clarification for OCaml scripts in SmPL
2014-03-14 0:09 ` Julia Lawall
@ 2014-03-14 7:14 ` SF Markus Elfring
2014-03-14 8:29 ` Julia Lawall
0 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-14 7:14 UTC (permalink / raw)
To: cocci
> 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.)
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Clarification for OCaml scripts in SmPL
2014-03-14 7:14 ` SF Markus Elfring
@ 2014-03-14 8:29 ` Julia Lawall
2014-03-14 8:39 ` SF Markus Elfring
0 siblings, 1 reply; 3619+ messages in thread
From: Julia Lawall @ 2014-03-14 8:29 UTC (permalink / raw)
To: cocci
On Fri, 14 Mar 2014, SF Markus Elfring wrote:
> > 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Clarification for OCaml scripts in SmPL
2014-03-14 8:29 ` Julia Lawall
@ 2014-03-14 8:39 ` SF Markus Elfring
2014-03-14 8:48 ` Julia Lawall
0 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-14 8:39 UTC (permalink / raw)
To: cocci
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Clarification for OCaml scripts in SmPL
2014-03-14 8:39 ` SF Markus Elfring
@ 2014-03-14 8:48 ` Julia Lawall
2014-03-14 9:01 ` SF Markus Elfring
0 siblings, 1 reply; 3619+ messages in thread
From: Julia Lawall @ 2014-03-14 8:48 UTC (permalink / raw)
To: cocci
On Fri, 14 Mar 2014, SF Markus Elfring wrote:
> > 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
> 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
>
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Clarification for OCaml scripts in SmPL
2014-03-14 8:48 ` Julia Lawall
@ 2014-03-14 9:01 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-14 9:01 UTC (permalink / raw)
To: cocci
> 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.
> And if it does, what good will adding exxtra ones do you.
I hope to ensure constraints for the used data formats.
> ... 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Determination of the number for named function parameters
2014-03-09 8:50 ` SF Markus Elfring
@ 2014-03-14 14:25 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-14 14:25 UTC (permalink / raw)
To: cocci
> 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.c
init_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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] How to exclude volatile data accesses in expressions with SmPL?
2014-02-21 22:27 ` Julia Lawall
2014-02-22 8:09 ` SF Markus Elfring
2014-02-23 14:40 ` SF Markus Elfring
@ 2014-03-27 13:41 ` SF Markus Elfring
2014-03-27 18:10 ` Julia Lawall
2 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-27 13:41 UTC (permalink / raw)
To: cocci
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] How to exclude volatile data accesses in expressions with SmPL?
2014-03-27 13:41 ` [Cocci] How to exclude volatile data accesses in expressions with SmPL? SF Markus Elfring
@ 2014-03-27 18:10 ` Julia Lawall
2014-03-27 18:39 ` SF Markus Elfring
0 siblings, 1 reply; 3619+ messages in thread
From: Julia Lawall @ 2014-03-27 18:10 UTC (permalink / raw)
To: cocci
On Thu, 27 Mar 2014, SF Markus Elfring wrote:
> > 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] How to exclude volatile data accesses in expressions with SmPL?
2014-03-27 18:10 ` Julia Lawall
@ 2014-03-27 18:39 ` SF Markus Elfring
2014-03-27 18:43 ` Julia Lawall
0 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-27 18:39 UTC (permalink / raw)
To: cocci
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] How to exclude volatile data accesses in expressions with SmPL?
2014-03-27 18:39 ` SF Markus Elfring
@ 2014-03-27 18:43 ` Julia Lawall
2014-03-27 18:59 ` SF Markus Elfring
2014-04-07 15:07 ` SF Markus Elfring
0 siblings, 2 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-03-27 18:43 UTC (permalink / raw)
To: cocci
On Thu, 27 Mar 2014, SF Markus Elfring wrote:
> > 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?
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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] How to exclude volatile data accesses in expressions with SmPL?
2014-03-27 18:43 ` Julia Lawall
@ 2014-03-27 18:59 ` SF Markus Elfring
2014-04-07 15:07 ` SF Markus Elfring
1 sibling, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-03-27 18:59 UTC (permalink / raw)
To: cocci
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] How to exclude volatile data accesses in expressions with SmPL?
2014-03-27 18:43 ` Julia Lawall
2014-03-27 18:59 ` SF Markus Elfring
@ 2014-04-07 15:07 ` SF Markus Elfring
2014-04-07 15:16 ` Julia Lawall
1 sibling, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-04-07 15:07 UTC (permalink / raw)
To: cocci
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] How to exclude volatile data accesses in expressions with SmPL?
2014-04-07 15:07 ` SF Markus Elfring
@ 2014-04-07 15:16 ` Julia Lawall
2014-04-07 15:28 ` SF Markus Elfring
0 siblings, 1 reply; 3619+ messages in thread
From: Julia Lawall @ 2014-04-07 15:16 UTC (permalink / raw)
To: cocci
On Mon, 7 Apr 2014, SF Markus Elfring wrote:
> > 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] How to exclude volatile data accesses in expressions with SmPL?
2014-04-07 15:16 ` Julia Lawall
@ 2014-04-07 15:28 ` SF Markus Elfring
2014-04-07 15:34 ` Julia Lawall
0 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-04-07 15:28 UTC (permalink / raw)
To: cocci
>> 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
> The benefit didn't seem to be worth the risk.
Can we clarify your concerns a bit more here?
Regards,
Markus
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] How to exclude volatile data accesses in expressions with SmPL?
2014-04-07 15:28 ` SF Markus Elfring
@ 2014-04-07 15:34 ` Julia Lawall
2014-04-07 15:40 ` SF Markus Elfring
0 siblings, 1 reply; 3619+ messages in thread
From: Julia Lawall @ 2014-04-07 15:34 UTC (permalink / raw)
To: cocci
On Mon, 7 Apr 2014, SF Markus Elfring wrote:
> >> 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
>
>
> > 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] How to exclude volatile data accesses in expressions with SmPL?
2014-04-07 15:34 ` Julia Lawall
@ 2014-04-07 15:40 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-04-07 15:40 UTC (permalink / raw)
To: cocci
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Fix for "lexing: empty token" needed?
2014-03-06 16:24 ` Julia Lawall
2014-03-06 17:04 ` SF Markus Elfring
@ 2014-09-30 13:24 ` SF Markus Elfring
1 sibling, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-09-30 13:24 UTC (permalink / raw)
To: cocci
>> 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 support
init_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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls
2014-03-05 22:30 ` SF Markus Elfring
(?)
@ 2014-10-01 13:01 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-01 13:01 UTC (permalink / raw)
To: linux-kernel, Andrew Morton, Stephen Rothwell
Cc: Coccinelle, kernel-janitors, Michal Marek, Chi Pham,
Fabian Frederick, Joe Perches
>> 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.
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/scripts/coccinelle?id=79f0345fefaafb7cde301a830471edd21a37989b
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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls
@ 2014-10-01 13:01 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-01 13:01 UTC (permalink / raw)
To: cocci
>> 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.
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/scripts/coccinelle?idyf0345fefaafb7cde301a830471edd21a37989b
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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls
@ 2014-10-01 13:01 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-01 13:01 UTC (permalink / raw)
To: cocci
>> 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.
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/scripts/coccinelle?id=79f0345fefaafb7cde301a830471edd21a37989b
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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [coccicheck PATCH 1/5] Deletion of unnecessary checks before specific function calls
2014-10-01 13:01 ` SF Markus Elfring
(?)
@ 2014-10-01 14:06 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-01 14:06 UTC (permalink / raw)
To: linux-kernel, Andrew Morton, Stephen Rothwell
Cc: Coccinelle, kernel-janitors, Michal Marek, Chi Pham,
Fabian Frederick, Joe Perches
>>> 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 48c9c4f61a7d7ea98538e02631a981a429281005 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
.../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
--- /dev/null
+++ b/scripts/coccinelle/deletions/delete_unnecessary_checks_template1.cocci
@@ -0,0 +1,13 @@
+@Delete_unnecessary_checks@
+expression x;
+identifier release =~ "^(?x)
+(?:
+ (?:kz?|slob_)free
+|
+ (?:
+# Alternation placeholder
+ )
+)$";
+@@
+-if (x)
+ release(x);
--
1.9.0
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [coccicheck PATCH 1/5] Deletion of unnecessary checks before specific function calls
@ 2014-10-01 14:06 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-01 14:06 UTC (permalink / raw)
To: cocci
>>> 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 48c9c4f61a7d7ea98538e02631a981a429281005 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
.../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
--- /dev/null
+++ b/scripts/coccinelle/deletions/delete_unnecessary_checks_template1.cocci
@@ -0,0 +1,13 @@
+@Delete_unnecessary_checks@
+expression x;
+identifier release =~ "^(?x)
+(?:
+ (?:kz?|slob_)free
+|
+ (?:
+# Alternation placeholder
+ )
+)$";
+@@
+-if (x)
+ release(x);
--
1.9.0
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Cocci] [coccicheck PATCH 1/5] Deletion of unnecessary checks before specific function calls
@ 2014-10-01 14:06 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-01 14:06 UTC (permalink / raw)
To: cocci
>>> 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 48c9c4f61a7d7ea98538e02631a981a429281005 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
.../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
--- /dev/null
+++ b/scripts/coccinelle/deletions/delete_unnecessary_checks_template1.cocci
@@ -0,0 +1,13 @@
+ at Delete_unnecessary_checks@
+expression x;
+identifier release =~ "^(?x)
+(?:
+ (?:kz?|slob_)free
+|
+ (?:
+# Alternation placeholder
+ )
+)$";
+@@
+-if (x)
+ release(x);
--
1.9.0
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [coccicheck PATCH 2/5] Deletion of unnecessary checks before specific function calls
2014-10-01 13:01 ` SF Markus Elfring
(?)
@ 2014-10-01 14:06 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-01 14:06 UTC (permalink / raw)
To: linux-kernel, Andrew Morton, Stephen Rothwell
Cc: Coccinelle, kernel-janitors, Michal Marek, Chi Pham,
Fabian Frederick, Joe Perches
>>> 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 1d2de3c3cfa43cc3c78a91200c41cef438b26a8f Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
.../list_input_parameter_validation1.cocci | 55 ++++++++++++++++++++++
1 file changed, 55 insertions(+)
create mode 100644
scripts/coccinelle/deletions/list_input_parameter_validation1.cocci
diff --git a/scripts/coccinelle/deletions/list_input_parameter_validation1.cocci
b/scripts/coccinelle/deletions/list_input_parameter_validation1.cocci
new file mode 100644
index 0000000..b0a5a52
--- /dev/null
+++ b/scripts/coccinelle/deletions/list_input_parameter_validation1.cocci
@@ -0,0 +1,55 @@
+@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@pos(data_type input)
+ {
+ ... when any
+( if (input) is else es
+| if (likely(input)) is else es
+)
+ ... when any
+ }
+
+@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")
--
1.9.0
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [coccicheck PATCH 2/5] Deletion of unnecessary checks before specific function calls
@ 2014-10-01 14:06 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-01 14:06 UTC (permalink / raw)
To: cocci
>>> 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 1d2de3c3cfa43cc3c78a91200c41cef438b26a8f Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
.../list_input_parameter_validation1.cocci | 55 ++++++++++++++++++++++
1 file changed, 55 insertions(+)
create mode 100644
scripts/coccinelle/deletions/list_input_parameter_validation1.cocci
diff --git a/scripts/coccinelle/deletions/list_input_parameter_validation1.cocci
b/scripts/coccinelle/deletions/list_input_parameter_validation1.cocci
new file mode 100644
index 0000000..b0a5a52
--- /dev/null
+++ b/scripts/coccinelle/deletions/list_input_parameter_validation1.cocci
@@ -0,0 +1,55 @@
+@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@pos(data_type input)
+ {
+ ... when any
+( if (input) is else es
+| if (likely(input)) is else es
+)
+ ... when any
+ }
+
+@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")
--
1.9.0
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Cocci] [coccicheck PATCH 2/5] Deletion of unnecessary checks before specific function calls
@ 2014-10-01 14:06 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-01 14:06 UTC (permalink / raw)
To: cocci
>>> 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 1d2de3c3cfa43cc3c78a91200c41cef438b26a8f Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
.../list_input_parameter_validation1.cocci | 55 ++++++++++++++++++++++
1 file changed, 55 insertions(+)
create mode 100644
scripts/coccinelle/deletions/list_input_parameter_validation1.cocci
diff --git a/scripts/coccinelle/deletions/list_input_parameter_validation1.cocci
b/scripts/coccinelle/deletions/list_input_parameter_validation1.cocci
new file mode 100644
index 0000000..b0a5a52
--- /dev/null
+++ b/scripts/coccinelle/deletions/list_input_parameter_validation1.cocci
@@ -0,0 +1,55 @@
+ at 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))
+
+ at 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
+ }
+
+ at 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")
--
1.9.0
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [coccicheck PATCH 3/5] Deletion of unnecessary checks before specific function calls
2014-10-01 13:01 ` SF Markus Elfring
(?)
@ 2014-10-01 14:06 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-01 14:06 UTC (permalink / raw)
To: linux-kernel, Andrew Morton, Stephen Rothwell
Cc: Coccinelle, kernel-janitors, Michal Marek, Chi Pham,
Fabian Frederick, Joe Perches
>>> 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 f4608fceec40b2b94aa9b4abe3bbb6d98ed5eed9 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
.../coccinelle/deletions/handle_function_list_template.sqlite | 9 +++++++++
1 file changed, 9 insertions(+)
create mode 100644
scripts/coccinelle/deletions/handle_function_list_template.sqlite
diff --git a/scripts/coccinelle/deletions/handle_function_list_template.sqlite
b/scripts/coccinelle/deletions/handle_function_list_template.sqlite
new file mode 100644
index 0000000..bec366c
--- /dev/null
+++ b/scripts/coccinelle/deletions/handle_function_list_template.sqlite
@@ -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
--
1.9.0
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [coccicheck PATCH 3/5] Deletion of unnecessary checks before specific function calls
@ 2014-10-01 14:06 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-01 14:06 UTC (permalink / raw)
To: cocci
>>> 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 f4608fceec40b2b94aa9b4abe3bbb6d98ed5eed9 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
.../coccinelle/deletions/handle_function_list_template.sqlite | 9 +++++++++
1 file changed, 9 insertions(+)
create mode 100644
scripts/coccinelle/deletions/handle_function_list_template.sqlite
diff --git a/scripts/coccinelle/deletions/handle_function_list_template.sqlite
b/scripts/coccinelle/deletions/handle_function_list_template.sqlite
new file mode 100644
index 0000000..bec366c
--- /dev/null
+++ b/scripts/coccinelle/deletions/handle_function_list_template.sqlite
@@ -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
--
1.9.0
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Cocci] [coccicheck PATCH 3/5] Deletion of unnecessary checks before specific function calls
@ 2014-10-01 14:06 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-01 14:06 UTC (permalink / raw)
To: cocci
>>> 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 f4608fceec40b2b94aa9b4abe3bbb6d98ed5eed9 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
.../coccinelle/deletions/handle_function_list_template.sqlite | 9 +++++++++
1 file changed, 9 insertions(+)
create mode 100644
scripts/coccinelle/deletions/handle_function_list_template.sqlite
diff --git a/scripts/coccinelle/deletions/handle_function_list_template.sqlite
b/scripts/coccinelle/deletions/handle_function_list_template.sqlite
new file mode 100644
index 0000000..bec366c
--- /dev/null
+++ b/scripts/coccinelle/deletions/handle_function_list_template.sqlite
@@ -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
--
1.9.0
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [coccicheck PATCH 4/5] Deletion of unnecessary checks before specific function calls
2014-10-01 13:01 ` SF Markus Elfring
(?)
@ 2014-10-01 14:07 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-01 14:07 UTC (permalink / raw)
To: linux-kernel, Andrew Morton, Stephen Rothwell
Cc: Coccinelle, kernel-janitors, Michal Marek, Chi Pham,
Fabian Frederick, Joe Perches
>>> 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 e6a21b920fcca2f6f01c9528909dc036a9b3bc41 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
...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 @@
+@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))
+
+@is_unnecessary_check@
+expression data;
+identifier work;
+identifier release =~ "^(?x)
+(?:
+ (?:kz?|slob_)free
+|
+ (?:
+# Alternation placeholder
+ )
+)$";
+position pos;
+type t;
+@@
+ t work@pos(...)
+ {
+ ... when any
+( if (data) release(data);
+| if (likely(data)) release(data);
+)
+ ... when any
+ }
+
+@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")
--
1.9.0
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [coccicheck PATCH 4/5] Deletion of unnecessary checks before specific function calls
@ 2014-10-01 14:07 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-01 14:07 UTC (permalink / raw)
To: cocci
>>> 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 e6a21b920fcca2f6f01c9528909dc036a9b3bc41 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
...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 @@
+@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))
+
+@is_unnecessary_check@
+expression data;
+identifier work;
+identifier release =~ "^(?x)
+(?:
+ (?:kz?|slob_)free
+|
+ (?:
+# Alternation placeholder
+ )
+)$";
+position pos;
+type t;
+@@
+ t work@pos(...)
+ {
+ ... when any
+( if (data) release(data);
+| if (likely(data)) release(data);
+)
+ ... when any
+ }
+
+@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")
--
1.9.0
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] [coccicheck PATCH 4/5] Deletion of unnecessary checks before specific function calls
@ 2014-10-01 14:07 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-01 14:07 UTC (permalink / raw)
To: cocci
>>> 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 e6a21b920fcca2f6f01c9528909dc036a9b3bc41 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
...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")
--
1.9.0
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [coccicheck PATCH 5/5] Deletion of unnecessary checks before specific function calls
2014-10-01 13:01 ` SF Markus Elfring
(?)
@ 2014-10-01 14:07 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-01 14:07 UTC (permalink / raw)
To: linux-kernel, Andrew Morton, Stephen Rothwell
Cc: Coccinelle, kernel-janitors, Michal Marek, Chi Pham,
Fabian Frederick, Joe Perches
>>> 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 bedf1cb3ddd162ee3b4c31cbb98d97431f70103d Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
scripts/coccinelle/deletions/makefile | 126 ++++++++++++++++++++++++++++++++++
1 file changed, 126 insertions(+)
create mode 100644 scripts/coccinelle/deletions/makefile
diff --git a/scripts/coccinelle/deletions/makefile
b/scripts/coccinelle/deletions/makefile
new file mode 100644
index 0000000..6464bae
--- /dev/null
+++ b/scripts/coccinelle/deletions/makefile
@@ -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): ;
--
1.9.0
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [coccicheck PATCH 5/5] Deletion of unnecessary checks before specific function calls
@ 2014-10-01 14:07 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-01 14:07 UTC (permalink / raw)
To: cocci
>>> 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 bedf1cb3ddd162ee3b4c31cbb98d97431f70103d Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
scripts/coccinelle/deletions/makefile | 126 ++++++++++++++++++++++++++++++++++
1 file changed, 126 insertions(+)
create mode 100644 scripts/coccinelle/deletions/makefile
diff --git a/scripts/coccinelle/deletions/makefile
b/scripts/coccinelle/deletions/makefile
new file mode 100644
index 0000000..6464bae
--- /dev/null
+++ b/scripts/coccinelle/deletions/makefile
@@ -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_PREFIXd_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Þlete_unnecessary_checks_template1.cocci
+PATCH_PATTERNÞlete_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): ;
--
1.9.0
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Cocci] [coccicheck PATCH 5/5] Deletion of unnecessary checks before specific function calls
@ 2014-10-01 14:07 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-01 14:07 UTC (permalink / raw)
To: cocci
>>> 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 bedf1cb3ddd162ee3b4c31cbb98d97431f70103d Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
scripts/coccinelle/deletions/makefile | 126 ++++++++++++++++++++++++++++++++++
1 file changed, 126 insertions(+)
create mode 100644 scripts/coccinelle/deletions/makefile
diff --git a/scripts/coccinelle/deletions/makefile
b/scripts/coccinelle/deletions/makefile
new file mode 100644
index 0000000..6464bae
--- /dev/null
+++ b/scripts/coccinelle/deletions/makefile
@@ -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): ;
--
1.9.0
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] GPU-DRM-nouveau: Deletion of unnecessary checks before two function calls
2014-03-05 22:30 ` SF Markus Elfring
(?)
(?)
@ 2014-10-22 14:30 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-22 14:30 UTC (permalink / raw)
To: David Airlie, dri-devel
Cc: Ben Skeggs, Ilia Mirkin, Alexandre Courbot, Thierry Reding,
linux-kernel, kernel-janitors, trivial, Coccinelle
>> 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
>From 29e61d5ccc44cd5e5961acff61b6938e0705044d Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/gpu/drm/nouveau/core/core/handle.c | 3 +--
drivers/gpu/drm/nouveau/nouveau_drm.c | 3 +--
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/nouveau/core/core/handle.c
b/drivers/gpu/drm/nouveau/core/core/handle.c
index a490b80..75d0c2c 100644
--- a/drivers/gpu/drm/nouveau/core/core/handle.c
+++ b/drivers/gpu/drm/nouveau/core/core/handle.c
@@ -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
diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c
b/drivers/gpu/drm/nouveau/nouveau_drm.c
index 5723807..5c29079 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_drm.c
@@ -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;
}
--
2.1.2
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] GPU-DRM-nouveau: Deletion of unnecessary checks before two function calls
@ 2014-10-22 14:30 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-22 14:30 UTC (permalink / raw)
To: cocci
>> 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
From 29e61d5ccc44cd5e5961acff61b6938e0705044d Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/gpu/drm/nouveau/core/core/handle.c | 3 +--
drivers/gpu/drm/nouveau/nouveau_drm.c | 3 +--
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/nouveau/core/core/handle.c
b/drivers/gpu/drm/nouveau/core/core/handle.c
index a490b80..75d0c2c 100644
--- a/drivers/gpu/drm/nouveau/core/core/handle.c
+++ b/drivers/gpu/drm/nouveau/core/core/handle.c
@@ -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
diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c
b/drivers/gpu/drm/nouveau/nouveau_drm.c
index 5723807..5c29079 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_drm.c
@@ -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;
}
--
2.1.2
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH 1/1] GPU-DRM-nouveau: Deletion of unnecessary checks before two function calls
@ 2014-10-22 14:30 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-22 14:30 UTC (permalink / raw)
To: cocci
>> 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
>From 29e61d5ccc44cd5e5961acff61b6938e0705044d Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/gpu/drm/nouveau/core/core/handle.c | 3 +--
drivers/gpu/drm/nouveau/nouveau_drm.c | 3 +--
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/nouveau/core/core/handle.c
b/drivers/gpu/drm/nouveau/core/core/handle.c
index a490b80..75d0c2c 100644
--- a/drivers/gpu/drm/nouveau/core/core/handle.c
+++ b/drivers/gpu/drm/nouveau/core/core/handle.c
@@ -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
diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c
b/drivers/gpu/drm/nouveau/nouveau_drm.c
index 5723807..5c29079 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_drm.c
@@ -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;
}
--
2.1.2
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] GPU-DRM-nouveau: Deletion of unnecessary checks before two function calls
@ 2014-10-22 14:30 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-22 14:30 UTC (permalink / raw)
To: David Airlie, dri-devel
Cc: Ben Skeggs, Ilia Mirkin, Alexandre Courbot, Thierry Reding,
linux-kernel, kernel-janitors, trivial, Coccinelle
>> 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
>From 29e61d5ccc44cd5e5961acff61b6938e0705044d Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/gpu/drm/nouveau/core/core/handle.c | 3 +--
drivers/gpu/drm/nouveau/nouveau_drm.c | 3 +--
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/nouveau/core/core/handle.c
b/drivers/gpu/drm/nouveau/core/core/handle.c
index a490b80..75d0c2c 100644
--- a/drivers/gpu/drm/nouveau/core/core/handle.c
+++ b/drivers/gpu/drm/nouveau/core/core/handle.c
@@ -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
diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c
b/drivers/gpu/drm/nouveau/nouveau_drm.c
index 5723807..5c29079 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_drm.c
@@ -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;
}
--
2.1.2
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] GPU-DRM-GMA500: Deletion of unnecessary checks before two function calls
2014-03-05 22:30 ` SF Markus Elfring
(?)
(?)
@ 2014-10-22 16:48 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-22 16:48 UTC (permalink / raw)
To: David Airlie, dri-devel
Cc: Daniel Vetter, Matt Roper, David Herrmann, Thomas Wood,
Rob Clark, Patrik Jakobsson, Arthur Borsboom, Thierry Reding,
Benoit Taine, linux-kernel, kernel-janitors, trivial, Coccinelle
>> 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
>From e61965bbcb143a54696fbd468989110519e41497 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/drivers/gpu/drm/gma500/cdv_intel_hdmi.c
b/drivers/gpu/drm/gma500/cdv_intel_hdmi.c
index 4268bf2..0d69624 100644
--- a/drivers/gpu/drm/gma500/cdv_intel_hdmi.c
+++ b/drivers/gpu/drm/gma500/cdv_intel_hdmi.c
@@ -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);
diff --git a/drivers/gpu/drm/gma500/cdv_intel_lvds.c
b/drivers/gpu/drm/gma500/cdv_intel_lvds.c
index 0b77039..8f24013 100644
--- a/drivers/gpu/drm/gma500/cdv_intel_lvds.c
+++ b/drivers/gpu/drm/gma500/cdv_intel_lvds.c
@@ -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);
diff --git a/drivers/gpu/drm/gma500/oaktrail_lvds.c
b/drivers/gpu/drm/gma500/oaktrail_lvds.c
index 0d39da6..49c5c415 100644
--- a/drivers/gpu/drm/gma500/oaktrail_lvds.c
+++ b/drivers/gpu/drm/gma500/oaktrail_lvds.c
@@ -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: */
diff --git a/drivers/gpu/drm/gma500/psb_drv.c b/drivers/gpu/drm/gma500/psb_drv.c
index 6ec3a90..0efe165 100644
--- a/drivers/gpu/drm/gma500/psb_drv.c
+++ b/drivers/gpu/drm/gma500/psb_drv.c
@@ -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);
diff --git a/drivers/gpu/drm/gma500/psb_intel_lvds.c
b/drivers/gpu/drm/gma500/psb_intel_lvds.c
index 88aad95..e73c3f9 100644
--- a/drivers/gpu/drm/gma500/psb_intel_lvds.c
+++ b/drivers/gpu/drm/gma500/psb_intel_lvds.c
@@ -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);
--
2.1.2
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] GPU-DRM-GMA500: Deletion of unnecessary checks before two function calls
@ 2014-10-22 16:48 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-22 16:48 UTC (permalink / raw)
To: cocci
>> 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
From e61965bbcb143a54696fbd468989110519e41497 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/drivers/gpu/drm/gma500/cdv_intel_hdmi.c
b/drivers/gpu/drm/gma500/cdv_intel_hdmi.c
index 4268bf2..0d69624 100644
--- a/drivers/gpu/drm/gma500/cdv_intel_hdmi.c
+++ b/drivers/gpu/drm/gma500/cdv_intel_hdmi.c
@@ -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);
diff --git a/drivers/gpu/drm/gma500/cdv_intel_lvds.c
b/drivers/gpu/drm/gma500/cdv_intel_lvds.c
index 0b77039..8f24013 100644
--- a/drivers/gpu/drm/gma500/cdv_intel_lvds.c
+++ b/drivers/gpu/drm/gma500/cdv_intel_lvds.c
@@ -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);
diff --git a/drivers/gpu/drm/gma500/oaktrail_lvds.c
b/drivers/gpu/drm/gma500/oaktrail_lvds.c
index 0d39da6..49c5c415 100644
--- a/drivers/gpu/drm/gma500/oaktrail_lvds.c
+++ b/drivers/gpu/drm/gma500/oaktrail_lvds.c
@@ -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: */
diff --git a/drivers/gpu/drm/gma500/psb_drv.c b/drivers/gpu/drm/gma500/psb_drv.c
index 6ec3a90..0efe165 100644
--- a/drivers/gpu/drm/gma500/psb_drv.c
+++ b/drivers/gpu/drm/gma500/psb_drv.c
@@ -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);
diff --git a/drivers/gpu/drm/gma500/psb_intel_lvds.c
b/drivers/gpu/drm/gma500/psb_intel_lvds.c
index 88aad95..e73c3f9 100644
--- a/drivers/gpu/drm/gma500/psb_intel_lvds.c
+++ b/drivers/gpu/drm/gma500/psb_intel_lvds.c
@@ -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);
--
2.1.2
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH 1/1] GPU-DRM-GMA500: Deletion of unnecessary checks before two function calls
@ 2014-10-22 16:48 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-22 16:48 UTC (permalink / raw)
To: cocci
>> 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
>From e61965bbcb143a54696fbd468989110519e41497 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/drivers/gpu/drm/gma500/cdv_intel_hdmi.c
b/drivers/gpu/drm/gma500/cdv_intel_hdmi.c
index 4268bf2..0d69624 100644
--- a/drivers/gpu/drm/gma500/cdv_intel_hdmi.c
+++ b/drivers/gpu/drm/gma500/cdv_intel_hdmi.c
@@ -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);
diff --git a/drivers/gpu/drm/gma500/cdv_intel_lvds.c
b/drivers/gpu/drm/gma500/cdv_intel_lvds.c
index 0b77039..8f24013 100644
--- a/drivers/gpu/drm/gma500/cdv_intel_lvds.c
+++ b/drivers/gpu/drm/gma500/cdv_intel_lvds.c
@@ -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);
diff --git a/drivers/gpu/drm/gma500/oaktrail_lvds.c
b/drivers/gpu/drm/gma500/oaktrail_lvds.c
index 0d39da6..49c5c415 100644
--- a/drivers/gpu/drm/gma500/oaktrail_lvds.c
+++ b/drivers/gpu/drm/gma500/oaktrail_lvds.c
@@ -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: */
diff --git a/drivers/gpu/drm/gma500/psb_drv.c b/drivers/gpu/drm/gma500/psb_drv.c
index 6ec3a90..0efe165 100644
--- a/drivers/gpu/drm/gma500/psb_drv.c
+++ b/drivers/gpu/drm/gma500/psb_drv.c
@@ -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);
diff --git a/drivers/gpu/drm/gma500/psb_intel_lvds.c
b/drivers/gpu/drm/gma500/psb_intel_lvds.c
index 88aad95..e73c3f9 100644
--- a/drivers/gpu/drm/gma500/psb_intel_lvds.c
+++ b/drivers/gpu/drm/gma500/psb_intel_lvds.c
@@ -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);
--
2.1.2
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] GPU-DRM-GMA500: Deletion of unnecessary checks before two function calls
@ 2014-10-22 16:48 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-22 16:48 UTC (permalink / raw)
To: David Airlie, dri-devel
Cc: Daniel Vetter, Matt Roper, David Herrmann, Thomas Wood,
Rob Clark, Patrik Jakobsson, Arthur Borsboom, Thierry Reding,
Benoit Taine, linux-kernel, kernel-janitors, trivial, Coccinelle
>> 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
>From e61965bbcb143a54696fbd468989110519e41497 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/drivers/gpu/drm/gma500/cdv_intel_hdmi.c
b/drivers/gpu/drm/gma500/cdv_intel_hdmi.c
index 4268bf2..0d69624 100644
--- a/drivers/gpu/drm/gma500/cdv_intel_hdmi.c
+++ b/drivers/gpu/drm/gma500/cdv_intel_hdmi.c
@@ -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);
diff --git a/drivers/gpu/drm/gma500/cdv_intel_lvds.c
b/drivers/gpu/drm/gma500/cdv_intel_lvds.c
index 0b77039..8f24013 100644
--- a/drivers/gpu/drm/gma500/cdv_intel_lvds.c
+++ b/drivers/gpu/drm/gma500/cdv_intel_lvds.c
@@ -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);
diff --git a/drivers/gpu/drm/gma500/oaktrail_lvds.c
b/drivers/gpu/drm/gma500/oaktrail_lvds.c
index 0d39da6..49c5c415 100644
--- a/drivers/gpu/drm/gma500/oaktrail_lvds.c
+++ b/drivers/gpu/drm/gma500/oaktrail_lvds.c
@@ -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: */
diff --git a/drivers/gpu/drm/gma500/psb_drv.c b/drivers/gpu/drm/gma500/psb_drv.c
index 6ec3a90..0efe165 100644
--- a/drivers/gpu/drm/gma500/psb_drv.c
+++ b/drivers/gpu/drm/gma500/psb_drv.c
@@ -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);
diff --git a/drivers/gpu/drm/gma500/psb_intel_lvds.c
b/drivers/gpu/drm/gma500/psb_intel_lvds.c
index 88aad95..e73c3f9 100644
--- a/drivers/gpu/drm/gma500/psb_intel_lvds.c
+++ b/drivers/gpu/drm/gma500/psb_intel_lvds.c
@@ -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);
--
2.1.2
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] IOMMU-MSM: Deletion of unnecessary checks before the function call "clk_disable"
2014-03-05 22:30 ` SF Markus Elfring
(?)
(?)
@ 2014-10-22 18:00 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-22 18:00 UTC (permalink / raw)
To: Jörg Rödel, iommu
Cc: linux-kernel, kernel-janitors, trivial, Coccinelle
>> 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 af73fb59d5d4b2c2890000fb236d0752522b6b38 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/iommu/msm_iommu.c | 3 +--
drivers/iommu/msm_iommu_dev.c | 6 ++----
2 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/iommu/msm_iommu.c b/drivers/iommu/msm_iommu.c
index 6e3dcc28..3e4d888 100644
--- a/drivers/iommu/msm_iommu.c
+++ b/drivers/iommu/msm_iommu.c
@@ -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);
}
diff --git a/drivers/iommu/msm_iommu_dev.c b/drivers/iommu/msm_iommu_dev.c
index 61def7cb..9574d21 100644
--- a/drivers/iommu/msm_iommu_dev.c
+++ b/drivers/iommu/msm_iommu_dev.c
@@ -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);
--
2.1.2
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] IOMMU-MSM: Deletion of unnecessary checks before the function call "clk_disable"
@ 2014-10-22 18:00 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-22 18:00 UTC (permalink / raw)
To: cocci
>> 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 af73fb59d5d4b2c2890000fb236d0752522b6b38 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/iommu/msm_iommu.c | 3 +--
drivers/iommu/msm_iommu_dev.c | 6 ++----
2 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/iommu/msm_iommu.c b/drivers/iommu/msm_iommu.c
index 6e3dcc28..3e4d888 100644
--- a/drivers/iommu/msm_iommu.c
+++ b/drivers/iommu/msm_iommu.c
@@ -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);
}
diff --git a/drivers/iommu/msm_iommu_dev.c b/drivers/iommu/msm_iommu_dev.c
index 61def7cb..9574d21 100644
--- a/drivers/iommu/msm_iommu_dev.c
+++ b/drivers/iommu/msm_iommu_dev.c
@@ -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);
--
2.1.2
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] IOMMU-MSM: Deletion of unnecessary checks before the function call "clk_disable"
@ 2014-10-22 18:00 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-22 18:00 UTC (permalink / raw)
To: Jörg Rödel, iommu
Cc: linux-kernel, kernel-janitors, trivial, Coccinelle
>> 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 af73fb59d5d4b2c2890000fb236d0752522b6b38 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/iommu/msm_iommu.c | 3 +--
drivers/iommu/msm_iommu_dev.c | 6 ++----
2 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/iommu/msm_iommu.c b/drivers/iommu/msm_iommu.c
index 6e3dcc28..3e4d888 100644
--- a/drivers/iommu/msm_iommu.c
+++ b/drivers/iommu/msm_iommu.c
@@ -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);
}
diff --git a/drivers/iommu/msm_iommu_dev.c b/drivers/iommu/msm_iommu_dev.c
index 61def7cb..9574d21 100644
--- a/drivers/iommu/msm_iommu_dev.c
+++ b/drivers/iommu/msm_iommu_dev.c
@@ -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);
--
2.1.2
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH 1/1] IOMMU-MSM: Deletion of unnecessary checks before the function call "clk_disable"
@ 2014-10-22 18:00 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-22 18:00 UTC (permalink / raw)
To: cocci
>> 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 af73fb59d5d4b2c2890000fb236d0752522b6b38 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/iommu/msm_iommu.c | 3 +--
drivers/iommu/msm_iommu_dev.c | 6 ++----
2 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/iommu/msm_iommu.c b/drivers/iommu/msm_iommu.c
index 6e3dcc28..3e4d888 100644
--- a/drivers/iommu/msm_iommu.c
+++ b/drivers/iommu/msm_iommu.c
@@ -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);
}
diff --git a/drivers/iommu/msm_iommu_dev.c b/drivers/iommu/msm_iommu_dev.c
index 61def7cb..9574d21 100644
--- a/drivers/iommu/msm_iommu_dev.c
+++ b/drivers/iommu/msm_iommu_dev.c
@@ -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);
--
2.1.2
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] SCSI-QLA2XXX: Deletion of unnecessary checks before the function call "vfree"
2014-03-05 22:30 ` SF Markus Elfring
@ 2014-10-22 18:55 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-22 18:55 UTC (permalink / raw)
To: James E. J. Bottomley, qla2xxx-upstream, linux-scsi
Cc: trivial, kernel-janitors, linux-kernel, Coccinelle
>> 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 ff44962f88ac2dae9324e30819629da4fb33f0ff Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index 82b92c4..95c4c09 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -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;
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index a4dde7e..8da3d4f 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -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;
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index db3dbd9..0f9c378 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -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;
--
2.1.2
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH 1/1] SCSI-QLA2XXX: Deletion of unnecessary checks before the function call "vfree"
@ 2014-10-22 18:55 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-22 18:55 UTC (permalink / raw)
To: cocci
>> 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 ff44962f88ac2dae9324e30819629da4fb33f0ff Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index 82b92c4..95c4c09 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -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;
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index a4dde7e..8da3d4f 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -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;
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index db3dbd9..0f9c378 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -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;
--
2.1.2
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] SCSI-QLA2...: Deletion of unnecessary checks before the function call "vfree"
2014-03-05 22:30 ` SF Markus Elfring
(?)
(?)
@ 2014-10-22 19:10 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-22 19:10 UTC (permalink / raw)
To: James E. J. Bottomley, qla2xxx-upstream, linux-scsi
Cc: linux-kernel, kernel-janitors, trivial, Coccinelle
>> 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
>From ff44962f88ac2dae9324e30819629da4fb33f0ff Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index 82b92c4..95c4c09 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -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;
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index a4dde7e..8da3d4f 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -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;
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index db3dbd9..0f9c378 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -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;
--
2.1.2
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] SCSI-QLA2...: Deletion of unnecessary checks before the function call "vfree"
@ 2014-10-22 19:10 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-22 19:10 UTC (permalink / raw)
To: cocci
>> 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
From ff44962f88ac2dae9324e30819629da4fb33f0ff Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index 82b92c4..95c4c09 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -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;
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index a4dde7e..8da3d4f 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -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;
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index db3dbd9..0f9c378 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -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;
--
2.1.2
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] SCSI-QLA2...: Deletion of unnecessary checks before the function call "vfree"
@ 2014-10-22 19:10 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-22 19:10 UTC (permalink / raw)
To: James E. J. Bottomley, qla2xxx-upstream, linux-scsi
Cc: linux-kernel, kernel-janitors, trivial, Coccinelle
>> 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
>From ff44962f88ac2dae9324e30819629da4fb33f0ff Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index 82b92c4..95c4c09 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -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;
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index a4dde7e..8da3d4f 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -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;
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index db3dbd9..0f9c378 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -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;
--
2.1.2
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH 1/1] SCSI-QLA2...: Deletion of unnecessary checks before the function call "vfree"
@ 2014-10-22 19:10 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-22 19:10 UTC (permalink / raw)
To: cocci
>> 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
>From ff44962f88ac2dae9324e30819629da4fb33f0ff Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index 82b92c4..95c4c09 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -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;
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index a4dde7e..8da3d4f 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -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;
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index db3dbd9..0f9c378 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -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;
--
2.1.2
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] GPU-DRM-GMA500: Deletion of unnecessary checks before two function calls
2014-10-22 16:48 ` SF Markus Elfring
(?)
@ 2014-10-23 11:26 ` One Thousand Gnomes
-1 siblings, 0 replies; 3619+ messages in thread
From: One Thousand Gnomes @ 2014-10-23 11:26 UTC (permalink / raw)
To: SF Markus Elfring
Cc: David Airlie, dri-devel, Daniel Vetter, Matt Roper,
David Herrmann, Thomas Wood, Rob Clark, Patrik Jakobsson,
Arthur Borsboom, Thierry Reding, Benoit Taine, linux-kernel,
kernel-janitors, trivial, Coccinelle
On Wed, 22 Oct 2014 18:48:21 +0200
SF Markus Elfring <elfring@users.sourceforge.net> wrote:
> >> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] GPU-DRM-GMA500: Deletion of unnecessary checks before two function calls
@ 2014-10-23 11:26 ` One Thousand Gnomes
0 siblings, 0 replies; 3619+ messages in thread
From: One Thousand Gnomes @ 2014-10-23 11:26 UTC (permalink / raw)
To: cocci
On Wed, 22 Oct 2014 18:48:21 +0200
SF Markus Elfring <elfring@users.sourceforge.net> wrote:
> >> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH 1/1] GPU-DRM-GMA500: Deletion of unnecessary checks before two function calls
@ 2014-10-23 11:26 ` One Thousand Gnomes
0 siblings, 0 replies; 3619+ messages in thread
From: One Thousand Gnomes @ 2014-10-23 11:26 UTC (permalink / raw)
To: cocci
On Wed, 22 Oct 2014 18:48:21 +0200
SF Markus Elfring <elfring@users.sourceforge.net> wrote:
> >> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] IOMMU-MSM: Deletion of unnecessary checks before the function call "clk_disable"
2014-10-22 18:00 ` SF Markus Elfring
(?)
(?)
@ 2014-10-23 12:51 ` Jörg Rödel
-1 siblings, 0 replies; 3619+ messages in thread
From: Jörg Rödel @ 2014-10-23 12:51 UTC (permalink / raw)
To: SF Markus Elfring
Cc: iommu, linux-kernel, kernel-janitors, trivial, Coccinelle
On Wed, Oct 22, 2014 at 08:00:17PM +0200, SF Markus Elfring wrote:
> 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.
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] IOMMU-MSM: Deletion of unnecessary checks before the function call "clk_disable"
@ 2014-10-23 12:51 ` Jörg Rödel
0 siblings, 0 replies; 3619+ messages in thread
From: Jörg Rödel @ 2014-10-23 12:51 UTC (permalink / raw)
To: cocci
On Wed, Oct 22, 2014 at 08:00:17PM +0200, SF Markus Elfring wrote:
> 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.
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] IOMMU-MSM: Deletion of unnecessary checks before the function call "clk_disable"
@ 2014-10-23 12:51 ` Jörg Rödel
0 siblings, 0 replies; 3619+ messages in thread
From: Jörg Rödel @ 2014-10-23 12:51 UTC (permalink / raw)
To: SF Markus Elfring
Cc: trivial-DgEjT+Ai2ygdnm+yROfE0A,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
kernel-janitors-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Coccinelle
On Wed, Oct 22, 2014 at 08:00:17PM +0200, SF Markus Elfring wrote:
> 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.
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH 1/1] IOMMU-MSM: Deletion of unnecessary checks before the function call "clk_disable"
@ 2014-10-23 12:51 ` Jörg Rödel
0 siblings, 0 replies; 3619+ messages in thread
From: Jörg Rödel @ 2014-10-23 12:51 UTC (permalink / raw)
To: cocci
On Wed, Oct 22, 2014 at 08:00:17PM +0200, SF Markus Elfring wrote:
> 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.
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] staging - rtl8188eu: Deletion of unnecessary checks before three function calls
2014-03-05 22:30 ` SF Markus Elfring
(?)
@ 2014-10-23 19:20 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-23 19:20 UTC (permalink / raw)
To: Greg Kroah-Hartman, devel
Cc: linux-kernel, kernel-janitors, trivial, Coccinelle
>From 45970693cad6c12da2d5ac7da3d2bd7a566170d7 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c
b/drivers/staging/rtl8188eu/core/rtw_efuse.c
index 7006088..77f7552 100644
--- a/drivers/staging/rtl8188eu/core/rtw_efuse.c
+++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c
@@ -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(
diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme.c
b/drivers/staging/rtl8188eu/core/rtw_mlme.c
index 149c271..df54350 100644
--- a/drivers/staging/rtl8188eu/core/rtw_mlme.c
+++ b/drivers/staging/rtl8188eu/core/rtw_mlme.c
@@ -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);
}
}
diff --git a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
index e1dc8fa..af1de9c 100644
--- a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
+++ b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
@@ -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;
diff --git a/drivers/staging/rtl8188eu/core/rtw_xmit.c
b/drivers/staging/rtl8188eu/core/rtw_xmit.c
index 639ace0..011c9cf 100644
--- a/drivers/staging/rtl8188eu/core/rtw_xmit.c
+++ b/drivers/staging/rtl8188eu/core/rtw_xmit.c
@@ -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;
diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
index 407a318..cdb70e4 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
@@ -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
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] staging - rtl8188eu: Deletion of unnecessary checks before three function calls
@ 2014-10-23 19:20 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-23 19:20 UTC (permalink / raw)
To: cocci
From 45970693cad6c12da2d5ac7da3d2bd7a566170d7 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c
b/drivers/staging/rtl8188eu/core/rtw_efuse.c
index 7006088..77f7552 100644
--- a/drivers/staging/rtl8188eu/core/rtw_efuse.c
+++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c
@@ -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(
diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme.c
b/drivers/staging/rtl8188eu/core/rtw_mlme.c
index 149c271..df54350 100644
--- a/drivers/staging/rtl8188eu/core/rtw_mlme.c
+++ b/drivers/staging/rtl8188eu/core/rtw_mlme.c
@@ -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);
}
}
diff --git a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
index e1dc8fa..af1de9c 100644
--- a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
+++ b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
@@ -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;
diff --git a/drivers/staging/rtl8188eu/core/rtw_xmit.c
b/drivers/staging/rtl8188eu/core/rtw_xmit.c
index 639ace0..011c9cf 100644
--- a/drivers/staging/rtl8188eu/core/rtw_xmit.c
+++ b/drivers/staging/rtl8188eu/core/rtw_xmit.c
@@ -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;
diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
index 407a318..cdb70e4 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
@@ -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
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH 1/1] staging - rtl8188eu: Deletion of unnecessary checks before three function calls
@ 2014-10-23 19:20 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-23 19:20 UTC (permalink / raw)
To: cocci
>From 45970693cad6c12da2d5ac7da3d2bd7a566170d7 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c
b/drivers/staging/rtl8188eu/core/rtw_efuse.c
index 7006088..77f7552 100644
--- a/drivers/staging/rtl8188eu/core/rtw_efuse.c
+++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c
@@ -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(
diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme.c
b/drivers/staging/rtl8188eu/core/rtw_mlme.c
index 149c271..df54350 100644
--- a/drivers/staging/rtl8188eu/core/rtw_mlme.c
+++ b/drivers/staging/rtl8188eu/core/rtw_mlme.c
@@ -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);
}
}
diff --git a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
index e1dc8fa..af1de9c 100644
--- a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
+++ b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
@@ -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;
diff --git a/drivers/staging/rtl8188eu/core/rtw_xmit.c
b/drivers/staging/rtl8188eu/core/rtw_xmit.c
index 639ace0..011c9cf 100644
--- a/drivers/staging/rtl8188eu/core/rtw_xmit.c
+++ b/drivers/staging/rtl8188eu/core/rtw_xmit.c
@@ -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;
diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
index 407a318..cdb70e4 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
@@ -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
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
2014-02-22 18:01 ` SF Markus Elfring
@ 2014-10-26 6:07 ` SF Markus Elfring
[not found] ` <alpine.DEB.2.10.1410260614460.2563@hadrien>
0 siblings, 1 reply; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-26 6:07 UTC (permalink / raw)
To: cocci
> spatch version 1.0.0-rc20 with Python support and with PCRE support
[...]
> 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 \
> && MY_PATTERN=find_input_pointer_validation2.cocci \
> && cat $MY_PATTERN \
> && echo '-----' \
> && spatch.opt --version \
> && spatch.opt --profile --include-headers-for-types --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 \
> --sp-file $MY_PATTERN /usr/src/linux-stable/mm/slab.c; \
> 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 support
init_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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] GPU-DRM-GMA500: Deletion of unnecessary checks before two function calls
2014-10-23 11:26 ` One Thousand Gnomes
(?)
(?)
@ 2014-10-26 12:10 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-26 12:10 UTC (permalink / raw)
To: One Thousand Gnomes
Cc: David Airlie, dri-devel, Daniel Vetter, Matt Roper,
David Herrmann, Thomas Wood, Rob Clark, Patrik Jakobsson,
Arthur Borsboom, Thierry Reding, Benoit Taine, linux-kernel,
kernel-janitors, trivial, Coccinelle
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] GPU-DRM-GMA500: Deletion of unnecessary checks before two function calls
@ 2014-10-26 12:10 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-26 12:10 UTC (permalink / raw)
To: cocci
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH 1/1] GPU-DRM-GMA500: Deletion of unnecessary checks before two function calls
@ 2014-10-26 12:10 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-26 12:10 UTC (permalink / raw)
To: cocci
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] GPU-DRM-GMA500: Deletion of unnecessary checks before two function calls
@ 2014-10-26 12:10 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-26 12:10 UTC (permalink / raw)
To: One Thousand Gnomes
Cc: David Airlie, dri-devel, Daniel Vetter, Matt Roper,
David Herrmann, Thomas Wood, Rob Clark, Patrik Jakobsson,
Arthur Borsboom, Thierry Reding, Benoit Taine, linux-kernel,
kernel-janitors, trivial, Coccinelle
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] Remove unnecessary null pointer checks?
[not found] ` <alpine.DEB.2.10.1410260614460.2563@hadrien>
@ 2014-10-26 13:54 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-26 13:54 UTC (permalink / raw)
To: cocci
I would like to show again that the version 1.0.0-rc22 works better than
1.0.0-rc20 for another use case.
> There is an isomorphism for unlikely, but it does not work well.
Interesting ...
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH 1/1] GPU-DRM-GMA500: Deletion of unnecessary checks before two function calls
2014-10-26 12:10 ` SF Markus Elfring
@ 2014-10-26 14:56 ` Arthur Borsboom
-1 siblings, 0 replies; 3619+ messages in thread
From: Arthur Borsboom @ 2014-10-26 14:56 UTC (permalink / raw)
To: cocci
I 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
On 26 Oct 2014 13:10, "SF Markus Elfring" <elfring@users.sourceforge.net>
wrote:
> > 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>
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] GPU-DRM-GMA500: Deletion of unnecessary checks before two function calls
@ 2014-10-26 14:56 ` Arthur Borsboom
0 siblings, 0 replies; 3619+ messages in thread
From: Arthur Borsboom @ 2014-10-26 14:56 UTC (permalink / raw)
To: SF Markus Elfring
Cc: One Thousand Gnomes, trivial, Daniel Vetter, kernel-janitors,
linux-kernel, dri-devel, Benoit Taine, Thierry Reding,
Coccinelle, Thomas Wood
[-- Attachment #1.1: Type: text/plain, Size: 665 bytes --]
I 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
On 26 Oct 2014 13:10, "SF Markus Elfring" <elfring@users.sourceforge.net>
wrote:
> > 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
>
[-- Attachment #1.2: Type: text/html, Size: 990 bytes --]
[-- Attachment #2: Type: text/plain, Size: 159 bytes --]
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] staging - rtl8188eu: Deletion of unnecessary checks before three function calls
2014-10-23 19:20 ` SF Markus Elfring
(?)
@ 2014-10-29 8:47 ` Greg Kroah-Hartman
-1 siblings, 0 replies; 3619+ messages in thread
From: Greg Kroah-Hartman @ 2014-10-29 8:47 UTC (permalink / raw)
To: SF Markus Elfring
Cc: devel, linux-kernel, kernel-janitors, trivial, Coccinelle
On Thu, Oct 23, 2014 at 09:20:29PM +0200, SF Markus Elfring wrote:
> >From 45970693cad6c12da2d5ac7da3d2bd7a566170d7 Mon Sep 17 00:00:00 2001
> From: Markus Elfring <elfring@users.sourceforge.net>
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] staging - rtl8188eu: Deletion of unnecessary checks before three function calls
@ 2014-10-29 8:47 ` Greg Kroah-Hartman
0 siblings, 0 replies; 3619+ messages in thread
From: Greg Kroah-Hartman @ 2014-10-29 8:47 UTC (permalink / raw)
To: cocci
On Thu, Oct 23, 2014 at 09:20:29PM +0200, SF Markus Elfring wrote:
> >From 45970693cad6c12da2d5ac7da3d2bd7a566170d7 Mon Sep 17 00:00:00 2001
> From: Markus Elfring <elfring@users.sourceforge.net>
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH 1/1] staging - rtl8188eu: Deletion of unnecessary checks before three function calls
@ 2014-10-29 8:47 ` Greg Kroah-Hartman
0 siblings, 0 replies; 3619+ messages in thread
From: Greg Kroah-Hartman @ 2014-10-29 8:47 UTC (permalink / raw)
To: cocci
On Thu, Oct 23, 2014 at 09:20:29PM +0200, SF Markus Elfring wrote:
> >From 45970693cad6c12da2d5ac7da3d2bd7a566170d7 Mon Sep 17 00:00:00 2001
> From: Markus Elfring <elfring@users.sourceforge.net>
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] s390/net: Deletion of unnecessary checks before two function calls
2014-03-05 22:30 ` SF Markus Elfring
(?)
@ 2014-10-31 17:40 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-31 17:40 UTC (permalink / raw)
To: Ursula Braun, Martin Schwidefsky, Heiko Carstens, Frank Blaschka,
linux390, linux-s390
Cc: linux-kernel, kernel-janitors, trivial, Coccinelle
The 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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/drivers/s390/net/claw.c b/drivers/s390/net/claw.c
index 213e54e..d609ca0 100644
--- a/drivers/s390/net/claw.c
+++ b/drivers/s390/net/claw.c
@@ -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
diff --git a/drivers/s390/net/ctcm_main.c b/drivers/s390/net/ctcm_main.c
index e056dd4..34dc0f3 100644
--- a/drivers/s390/net/ctcm_main.c
+++ b/drivers/s390/net/ctcm_main.c
@@ -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]);
diff --git a/drivers/s390/net/lcs.c b/drivers/s390/net/lcs.c
index 0a7d87c..5dfa7dd 100644
--- a/drivers/s390/net/lcs.c
+++ b/drivers/s390/net/lcs.c
@@ -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
diff --git a/drivers/s390/net/netiucv.c b/drivers/s390/net/netiucv.c
index 0a87809..bdcc3fe 100644
--- a/drivers/s390/net/netiucv.c
+++ b/drivers/s390/net/netiucv.c
@@ -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() */
}
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] s390/net: Deletion of unnecessary checks before two function calls
@ 2014-10-31 17:40 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-31 17:40 UTC (permalink / raw)
To: cocci
The 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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/drivers/s390/net/claw.c b/drivers/s390/net/claw.c
index 213e54e..d609ca0 100644
--- a/drivers/s390/net/claw.c
+++ b/drivers/s390/net/claw.c
@@ -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
diff --git a/drivers/s390/net/ctcm_main.c b/drivers/s390/net/ctcm_main.c
index e056dd4..34dc0f3 100644
--- a/drivers/s390/net/ctcm_main.c
+++ b/drivers/s390/net/ctcm_main.c
@@ -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]);
diff --git a/drivers/s390/net/lcs.c b/drivers/s390/net/lcs.c
index 0a7d87c..5dfa7dd 100644
--- a/drivers/s390/net/lcs.c
+++ b/drivers/s390/net/lcs.c
@@ -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
diff --git a/drivers/s390/net/netiucv.c b/drivers/s390/net/netiucv.c
index 0a87809..bdcc3fe 100644
--- a/drivers/s390/net/netiucv.c
+++ b/drivers/s390/net/netiucv.c
@@ -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() */
}
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH 1/1] s390/net: Deletion of unnecessary checks before two function calls
@ 2014-10-31 17:40 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-31 17:40 UTC (permalink / raw)
To: cocci
The 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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/drivers/s390/net/claw.c b/drivers/s390/net/claw.c
index 213e54e..d609ca0 100644
--- a/drivers/s390/net/claw.c
+++ b/drivers/s390/net/claw.c
@@ -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
diff --git a/drivers/s390/net/ctcm_main.c b/drivers/s390/net/ctcm_main.c
index e056dd4..34dc0f3 100644
--- a/drivers/s390/net/ctcm_main.c
+++ b/drivers/s390/net/ctcm_main.c
@@ -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]);
diff --git a/drivers/s390/net/lcs.c b/drivers/s390/net/lcs.c
index 0a7d87c..5dfa7dd 100644
--- a/drivers/s390/net/lcs.c
+++ b/drivers/s390/net/lcs.c
@@ -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
diff --git a/drivers/s390/net/netiucv.c b/drivers/s390/net/netiucv.c
index 0a87809..bdcc3fe 100644
--- a/drivers/s390/net/netiucv.c
+++ b/drivers/s390/net/netiucv.c
@@ -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() */
}
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [PATCH resent] staging: rtl8188eu: Deletion of unnecessary checks before three function calls
2014-10-29 8:47 ` Greg Kroah-Hartman
(?)
@ 2014-10-31 17:55 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-31 17:55 UTC (permalink / raw)
To: Greg Kroah-Hartman, devel
Cc: linux-kernel, kernel-janitors, trivial, Coccinelle
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c
b/drivers/staging/rtl8188eu/core/rtw_efuse.c
index 7006088..77f7552 100644
--- a/drivers/staging/rtl8188eu/core/rtw_efuse.c
+++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c
@@ -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(
diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme.c
b/drivers/staging/rtl8188eu/core/rtw_mlme.c
index 149c271..df54350 100644
--- a/drivers/staging/rtl8188eu/core/rtw_mlme.c
+++ b/drivers/staging/rtl8188eu/core/rtw_mlme.c
@@ -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);
}
}
diff --git a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
index e1dc8fa..af1de9c 100644
--- a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
+++ b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
@@ -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;
diff --git a/drivers/staging/rtl8188eu/core/rtw_xmit.c
b/drivers/staging/rtl8188eu/core/rtw_xmit.c
index 639ace0..011c9cf 100644
--- a/drivers/staging/rtl8188eu/core/rtw_xmit.c
+++ b/drivers/staging/rtl8188eu/core/rtw_xmit.c
@@ -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;
diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
index 407a318..cdb70e4 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
@@ -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
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [PATCH resent] staging: rtl8188eu: Deletion of unnecessary checks before three function calls
@ 2014-10-31 17:55 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-31 17:55 UTC (permalink / raw)
To: cocci
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c
b/drivers/staging/rtl8188eu/core/rtw_efuse.c
index 7006088..77f7552 100644
--- a/drivers/staging/rtl8188eu/core/rtw_efuse.c
+++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c
@@ -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(
diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme.c
b/drivers/staging/rtl8188eu/core/rtw_mlme.c
index 149c271..df54350 100644
--- a/drivers/staging/rtl8188eu/core/rtw_mlme.c
+++ b/drivers/staging/rtl8188eu/core/rtw_mlme.c
@@ -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);
}
}
diff --git a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
index e1dc8fa..af1de9c 100644
--- a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
+++ b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
@@ -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;
diff --git a/drivers/staging/rtl8188eu/core/rtw_xmit.c
b/drivers/staging/rtl8188eu/core/rtw_xmit.c
index 639ace0..011c9cf 100644
--- a/drivers/staging/rtl8188eu/core/rtw_xmit.c
+++ b/drivers/staging/rtl8188eu/core/rtw_xmit.c
@@ -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;
diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
index 407a318..cdb70e4 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
@@ -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
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH resent] staging: rtl8188eu: Deletion of unnecessary checks before three function calls
@ 2014-10-31 17:55 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-31 17:55 UTC (permalink / raw)
To: cocci
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c
b/drivers/staging/rtl8188eu/core/rtw_efuse.c
index 7006088..77f7552 100644
--- a/drivers/staging/rtl8188eu/core/rtw_efuse.c
+++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c
@@ -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(
diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme.c
b/drivers/staging/rtl8188eu/core/rtw_mlme.c
index 149c271..df54350 100644
--- a/drivers/staging/rtl8188eu/core/rtw_mlme.c
+++ b/drivers/staging/rtl8188eu/core/rtw_mlme.c
@@ -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);
}
}
diff --git a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
index e1dc8fa..af1de9c 100644
--- a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
+++ b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
@@ -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;
diff --git a/drivers/staging/rtl8188eu/core/rtw_xmit.c
b/drivers/staging/rtl8188eu/core/rtw_xmit.c
index 639ace0..011c9cf 100644
--- a/drivers/staging/rtl8188eu/core/rtw_xmit.c
+++ b/drivers/staging/rtl8188eu/core/rtw_xmit.c
@@ -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;
diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
index 407a318..cdb70e4 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
@@ -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
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [PATCH resent] staging: rtl8188eu: Deletion of unnecessary checks before three function calls
2014-10-31 17:55 ` SF Markus Elfring
(?)
@ 2014-10-31 18:01 ` Julia Lawall
-1 siblings, 0 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-10-31 18:01 UTC (permalink / raw)
To: SF Markus Elfring
Cc: Greg Kroah-Hartman, devel, linux-kernel, kernel-janitors,
trivial, Coccinelle
On Fri, 31 Oct 2014, SF Markus Elfring wrote:
> 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.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> 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(-)
>
> diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c
> b/drivers/staging/rtl8188eu/core/rtw_efuse.c
> index 7006088..77f7552 100644
> --- a/drivers/staging/rtl8188eu/core/rtw_efuse.c
> +++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c
> @@ -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
> }
>
> static void efuse_read_phymap_from_txpktbuf(
> diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme.c
> b/drivers/staging/rtl8188eu/core/rtw_mlme.c
> index 149c271..df54350 100644
> --- a/drivers/staging/rtl8188eu/core/rtw_mlme.c
> +++ b/drivers/staging/rtl8188eu/core/rtw_mlme.c
> @@ -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);
> }
> }
>
> diff --git a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
> b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
> index e1dc8fa..af1de9c 100644
> --- a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
> +++ b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
> @@ -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;
> diff --git a/drivers/staging/rtl8188eu/core/rtw_xmit.c
> b/drivers/staging/rtl8188eu/core/rtw_xmit.c
> index 639ace0..011c9cf 100644
> --- a/drivers/staging/rtl8188eu/core/rtw_xmit.c
> +++ b/drivers/staging/rtl8188eu/core/rtw_xmit.c
> @@ -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;
> diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
> b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
> index 407a318..cdb70e4 100644
> --- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
> +++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
> @@ -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@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH resent] staging: rtl8188eu: Deletion of unnecessary checks before three function calls
@ 2014-10-31 18:01 ` Julia Lawall
0 siblings, 0 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-10-31 18:01 UTC (permalink / raw)
To: cocci
On Fri, 31 Oct 2014, SF Markus Elfring wrote:
> 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.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> 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(-)
>
> diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c
> b/drivers/staging/rtl8188eu/core/rtw_efuse.c
> index 7006088..77f7552 100644
> --- a/drivers/staging/rtl8188eu/core/rtw_efuse.c
> +++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c
> @@ -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
> }
>
> static void efuse_read_phymap_from_txpktbuf(
> diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme.c
> b/drivers/staging/rtl8188eu/core/rtw_mlme.c
> index 149c271..df54350 100644
> --- a/drivers/staging/rtl8188eu/core/rtw_mlme.c
> +++ b/drivers/staging/rtl8188eu/core/rtw_mlme.c
> @@ -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);
> }
> }
>
> diff --git a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
> b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
> index e1dc8fa..af1de9c 100644
> --- a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
> +++ b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
> @@ -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;
> diff --git a/drivers/staging/rtl8188eu/core/rtw_xmit.c
> b/drivers/staging/rtl8188eu/core/rtw_xmit.c
> index 639ace0..011c9cf 100644
> --- a/drivers/staging/rtl8188eu/core/rtw_xmit.c
> +++ b/drivers/staging/rtl8188eu/core/rtw_xmit.c
> @@ -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;
> diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
> b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
> index 407a318..cdb70e4 100644
> --- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
> +++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
> @@ -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@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH resent] staging: rtl8188eu: Deletion of unnecessary checks before three function calls
@ 2014-10-31 18:01 ` Julia Lawall
0 siblings, 0 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-10-31 18:01 UTC (permalink / raw)
To: cocci
On Fri, 31 Oct 2014, SF Markus Elfring wrote:
> 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.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> 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(-)
>
> diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c
> b/drivers/staging/rtl8188eu/core/rtw_efuse.c
> index 7006088..77f7552 100644
> --- a/drivers/staging/rtl8188eu/core/rtw_efuse.c
> +++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c
> @@ -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
> }
>
> static void efuse_read_phymap_from_txpktbuf(
> diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme.c
> b/drivers/staging/rtl8188eu/core/rtw_mlme.c
> index 149c271..df54350 100644
> --- a/drivers/staging/rtl8188eu/core/rtw_mlme.c
> +++ b/drivers/staging/rtl8188eu/core/rtw_mlme.c
> @@ -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);
> }
> }
>
> diff --git a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
> b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
> index e1dc8fa..af1de9c 100644
> --- a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
> +++ b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
> @@ -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;
> diff --git a/drivers/staging/rtl8188eu/core/rtw_xmit.c
> b/drivers/staging/rtl8188eu/core/rtw_xmit.c
> index 639ace0..011c9cf 100644
> --- a/drivers/staging/rtl8188eu/core/rtw_xmit.c
> +++ b/drivers/staging/rtl8188eu/core/rtw_xmit.c
> @@ -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;
> diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
> b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
> index 407a318..cdb70e4 100644
> --- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
> +++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
> @@ -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
>
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH resent] staging: rtl8188eu: Deletion of unnecessary checks before three function calls
2014-10-31 18:01 ` Julia Lawall
(?)
@ 2014-10-31 18:08 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-31 18:08 UTC (permalink / raw)
To: Julia Lawall
Cc: Greg Kroah-Hartman, devel, linux-kernel, kernel-janitors,
trivial, Coccinelle
>> 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.
>>
>> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
>> ---
>> 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(-)
>>
>> diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c
>> b/drivers/staging/rtl8188eu/core/rtw_efuse.c
>> index 7006088..77f7552 100644
>> --- a/drivers/staging/rtl8188eu/core/rtw_efuse.c
>> +++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c
>> @@ -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.
Are there any chances to achieve the suggested fine-tuning for jump labels
also with another semantic patch approach?
Regards,
Markus
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH resent] staging: rtl8188eu: Deletion of unnecessary checks before three function calls
@ 2014-10-31 18:08 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-31 18:08 UTC (permalink / raw)
To: cocci
>> 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.
>>
>> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
>> ---
>> 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(-)
>>
>> diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c
>> b/drivers/staging/rtl8188eu/core/rtw_efuse.c
>> index 7006088..77f7552 100644
>> --- a/drivers/staging/rtl8188eu/core/rtw_efuse.c
>> +++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c
>> @@ -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.
Are there any chances to achieve the suggested fine-tuning for jump labels
also with another semantic patch approach?
Regards,
Markus
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH resent] staging: rtl8188eu: Deletion of unnecessary checks before three function calls
@ 2014-10-31 18:08 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-31 18:08 UTC (permalink / raw)
To: cocci
>> 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.
>>
>> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
>> ---
>> 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(-)
>>
>> diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c
>> b/drivers/staging/rtl8188eu/core/rtw_efuse.c
>> index 7006088..77f7552 100644
>> --- a/drivers/staging/rtl8188eu/core/rtw_efuse.c
>> +++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c
>> @@ -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.
Are there any chances to achieve the suggested fine-tuning for jump labels
also with another semantic patch approach?
Regards,
Markus
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH resent] staging: rtl8188eu: Deletion of unnecessary checks before three function calls
2014-10-31 18:08 ` SF Markus Elfring
(?)
@ 2014-10-31 18:11 ` Julia Lawall
-1 siblings, 0 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-10-31 18:11 UTC (permalink / raw)
To: SF Markus Elfring
Cc: Greg Kroah-Hartman, devel, linux-kernel, kernel-janitors,
trivial, Coccinelle
On Fri, 31 Oct 2014, SF Markus Elfring wrote:
> >> 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.
> >>
> >> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> >> ---
> >> 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(-)
> >>
> >> diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c
> >> b/drivers/staging/rtl8188eu/core/rtw_efuse.c
> >> index 7006088..77f7552 100644
> >> --- a/drivers/staging/rtl8188eu/core/rtw_efuse.c
> >> +++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c
> >> @@ -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.
>
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH resent] staging: rtl8188eu: Deletion of unnecessary checks before three function calls
@ 2014-10-31 18:11 ` Julia Lawall
0 siblings, 0 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-10-31 18:11 UTC (permalink / raw)
To: cocci
On Fri, 31 Oct 2014, SF Markus Elfring wrote:
> >> 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.
> >>
> >> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> >> ---
> >> 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(-)
> >>
> >> diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c
> >> b/drivers/staging/rtl8188eu/core/rtw_efuse.c
> >> index 7006088..77f7552 100644
> >> --- a/drivers/staging/rtl8188eu/core/rtw_efuse.c
> >> +++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c
> >> @@ -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.
>
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH resent] staging: rtl8188eu: Deletion of unnecessary checks before three function calls
@ 2014-10-31 18:11 ` Julia Lawall
0 siblings, 0 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-10-31 18:11 UTC (permalink / raw)
To: cocci
On Fri, 31 Oct 2014, SF Markus Elfring wrote:
> >> 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.
> >>
> >> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> >> ---
> >> 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(-)
> >>
> >> diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c
> >> b/drivers/staging/rtl8188eu/core/rtw_efuse.c
> >> index 7006088..77f7552 100644
> >> --- a/drivers/staging/rtl8188eu/core/rtw_efuse.c
> >> +++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c
> >> @@ -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.
>
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [PATCH 1/1] btrfs: Deletion of unnecessary checks before six function calls
2014-03-05 22:30 ` SF Markus Elfring
(?)
@ 2014-10-31 21:52 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-31 21:52 UTC (permalink / raw)
To: Chris Mason, Josef Bacik, linux-btrfs
Cc: linux-kernel, kernel-janitors, trivial, Coccinelle
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 <elfring@users.sourceforge.net>
---
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(-)
diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index 6f662b3..3465029 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -183,8 +183,7 @@ no_valid_dev_replace_entry_found:
}
out:
- if (path)
- btrfs_free_path(path);
+ btrfs_free_path(path);
return ret;
}
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index bf3f424..cfbf00a 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -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)
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index a18ceab..add07ce8 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -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);
}
/*
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index 3384819..11883e2 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -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;
}
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index d23362f..7301b99 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -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)
diff --git a/fs/btrfs/reada.c b/fs/btrfs/reada.c
index b63ae20..ec8eb49 100644
--- a/fs/btrfs/reada.c
+++ b/fs/btrfs/reada.c
@@ -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;
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 74257d6..f87a5ee 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -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;
diff --git a/fs/btrfs/tests/btrfs-tests.c b/fs/btrfs/tests/btrfs-tests.c
index 9626252..7fb123f 100644
--- a/fs/btrfs/tests/btrfs-tests.c
+++ b/fs/btrfs/tests/btrfs-tests.c
@@ -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);
diff --git a/fs/btrfs/tree-defrag.c b/fs/btrfs/tree-defrag.c
index a63719c..c74f106 100644
--- a/fs/btrfs/tree-defrag.c
+++ b/fs/btrfs/tree-defrag.c
@@ -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;
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 1475979..70926a9 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -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;
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [PATCH 1/1] btrfs: Deletion of unnecessary checks before six function calls
@ 2014-10-31 21:52 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-31 21:52 UTC (permalink / raw)
To: cocci
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 <elfring@users.sourceforge.net>
---
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(-)
diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index 6f662b3..3465029 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -183,8 +183,7 @@ no_valid_dev_replace_entry_found:
}
out:
- if (path)
- btrfs_free_path(path);
+ btrfs_free_path(path);
return ret;
}
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index bf3f424..cfbf00a 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -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)
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index a18ceab..add07ce8 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -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);
}
/*
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index 3384819..11883e2 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -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;
}
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index d23362f..7301b99 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -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)
diff --git a/fs/btrfs/reada.c b/fs/btrfs/reada.c
index b63ae20..ec8eb49 100644
--- a/fs/btrfs/reada.c
+++ b/fs/btrfs/reada.c
@@ -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;
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 74257d6..f87a5ee 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -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;
diff --git a/fs/btrfs/tests/btrfs-tests.c b/fs/btrfs/tests/btrfs-tests.c
index 9626252..7fb123f 100644
--- a/fs/btrfs/tests/btrfs-tests.c
+++ b/fs/btrfs/tests/btrfs-tests.c
@@ -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);
diff --git a/fs/btrfs/tree-defrag.c b/fs/btrfs/tree-defrag.c
index a63719c..c74f106 100644
--- a/fs/btrfs/tree-defrag.c
+++ b/fs/btrfs/tree-defrag.c
@@ -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;
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 1475979..70926a9 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -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;
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH 1/1] btrfs: Deletion of unnecessary checks before six function calls
@ 2014-10-31 21:52 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-10-31 21:52 UTC (permalink / raw)
To: cocci
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 <elfring@users.sourceforge.net>
---
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(-)
diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index 6f662b3..3465029 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -183,8 +183,7 @@ no_valid_dev_replace_entry_found:
}
out:
- if (path)
- btrfs_free_path(path);
+ btrfs_free_path(path);
return ret;
}
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index bf3f424..cfbf00a 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -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)
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index a18ceab..add07ce8 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -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);
}
/*
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index 3384819..11883e2 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -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;
}
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index d23362f..7301b99 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -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)
diff --git a/fs/btrfs/reada.c b/fs/btrfs/reada.c
index b63ae20..ec8eb49 100644
--- a/fs/btrfs/reada.c
+++ b/fs/btrfs/reada.c
@@ -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;
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 74257d6..f87a5ee 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -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;
diff --git a/fs/btrfs/tests/btrfs-tests.c b/fs/btrfs/tests/btrfs-tests.c
index 9626252..7fb123f 100644
--- a/fs/btrfs/tests/btrfs-tests.c
+++ b/fs/btrfs/tests/btrfs-tests.c
@@ -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);
diff --git a/fs/btrfs/tree-defrag.c b/fs/btrfs/tree-defrag.c
index a63719c..c74f106 100644
--- a/fs/btrfs/tree-defrag.c
+++ b/fs/btrfs/tree-defrag.c
@@ -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;
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 1475979..70926a9 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -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;
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [Cocci] [PATCH 1/1] btrfs: Deletion of unnecessary checks before six function calls
2014-10-31 21:52 ` SF Markus Elfring
(?)
@ 2014-10-31 21:59 ` Julia Lawall
-1 siblings, 0 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-10-31 21:59 UTC (permalink / raw)
To: SF Markus Elfring
Cc: Chris Mason, Josef Bacik, linux-btrfs, trivial, kernel-janitors,
linux-kernel, Coccinelle
On Fri, 31 Oct 2014, SF Markus Elfring wrote:
> 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 <elfring@users.sourceforge.net>
> ---
> 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(-)
>
> diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
> index 6f662b3..3465029 100644
> --- a/fs/btrfs/dev-replace.c
> +++ b/fs/btrfs/dev-replace.c
> @@ -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
> return ret;
> }
>
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index bf3f424..cfbf00a 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -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)
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
> index a18ceab..add07ce8 100644
> --- a/fs/btrfs/file.c
> +++ b/fs/btrfs/file.c
> @@ -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);
> }
>
> /*
> diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
> index 3384819..11883e2 100644
> --- a/fs/btrfs/free-space-cache.c
> +++ b/fs/btrfs/free-space-cache.c
> @@ -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;
> }
>
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index d23362f..7301b99 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -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)
> diff --git a/fs/btrfs/reada.c b/fs/btrfs/reada.c
> index b63ae20..ec8eb49 100644
> --- a/fs/btrfs/reada.c
> +++ b/fs/btrfs/reada.c
> @@ -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;
>
> diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
> index 74257d6..f87a5ee 100644
> --- a/fs/btrfs/relocation.c
> +++ b/fs/btrfs/relocation.c
> @@ -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;
> diff --git a/fs/btrfs/tests/btrfs-tests.c b/fs/btrfs/tests/btrfs-tests.c
> index 9626252..7fb123f 100644
> --- a/fs/btrfs/tests/btrfs-tests.c
> +++ b/fs/btrfs/tests/btrfs-tests.c
> @@ -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);
> diff --git a/fs/btrfs/tree-defrag.c b/fs/btrfs/tree-defrag.c
> index a63719c..c74f106 100644
> --- a/fs/btrfs/tree-defrag.c
> +++ b/fs/btrfs/tree-defrag.c
> @@ -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;
> diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
> index 1475979..70926a9 100644
> --- a/fs/btrfs/tree-log.c
> +++ b/fs/btrfs/tree-log.c
> @@ -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;
> --
> 2.1.3
>
>
> _______________________________________________
> Cocci mailing list
> Cocci@systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [Cocci] [PATCH 1/1] btrfs: Deletion of unnecessary checks before six function calls
@ 2014-10-31 21:59 ` Julia Lawall
0 siblings, 0 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-10-31 21:59 UTC (permalink / raw)
To: cocci
On Fri, 31 Oct 2014, SF Markus Elfring wrote:
> 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 <elfring@users.sourceforge.net>
> ---
> 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(-)
>
> diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
> index 6f662b3..3465029 100644
> --- a/fs/btrfs/dev-replace.c
> +++ b/fs/btrfs/dev-replace.c
> @@ -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
> return ret;
> }
>
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index bf3f424..cfbf00a 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -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)
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
> index a18ceab..add07ce8 100644
> --- a/fs/btrfs/file.c
> +++ b/fs/btrfs/file.c
> @@ -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);
> }
>
> /*
> diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
> index 3384819..11883e2 100644
> --- a/fs/btrfs/free-space-cache.c
> +++ b/fs/btrfs/free-space-cache.c
> @@ -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;
> }
>
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index d23362f..7301b99 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -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)
> diff --git a/fs/btrfs/reada.c b/fs/btrfs/reada.c
> index b63ae20..ec8eb49 100644
> --- a/fs/btrfs/reada.c
> +++ b/fs/btrfs/reada.c
> @@ -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;
>
> diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
> index 74257d6..f87a5ee 100644
> --- a/fs/btrfs/relocation.c
> +++ b/fs/btrfs/relocation.c
> @@ -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;
> diff --git a/fs/btrfs/tests/btrfs-tests.c b/fs/btrfs/tests/btrfs-tests.c
> index 9626252..7fb123f 100644
> --- a/fs/btrfs/tests/btrfs-tests.c
> +++ b/fs/btrfs/tests/btrfs-tests.c
> @@ -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);
> diff --git a/fs/btrfs/tree-defrag.c b/fs/btrfs/tree-defrag.c
> index a63719c..c74f106 100644
> --- a/fs/btrfs/tree-defrag.c
> +++ b/fs/btrfs/tree-defrag.c
> @@ -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;
> diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
> index 1475979..70926a9 100644
> --- a/fs/btrfs/tree-log.c
> +++ b/fs/btrfs/tree-log.c
> @@ -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;
> --
> 2.1.3
>
>
> _______________________________________________
> Cocci mailing list
> Cocci@systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH 1/1] btrfs: Deletion of unnecessary checks before six function calls
@ 2014-10-31 21:59 ` Julia Lawall
0 siblings, 0 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-10-31 21:59 UTC (permalink / raw)
To: cocci
On Fri, 31 Oct 2014, SF Markus Elfring wrote:
> 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 <elfring@users.sourceforge.net>
> ---
> 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(-)
>
> diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
> index 6f662b3..3465029 100644
> --- a/fs/btrfs/dev-replace.c
> +++ b/fs/btrfs/dev-replace.c
> @@ -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
> return ret;
> }
>
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index bf3f424..cfbf00a 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -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)
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
> index a18ceab..add07ce8 100644
> --- a/fs/btrfs/file.c
> +++ b/fs/btrfs/file.c
> @@ -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);
> }
>
> /*
> diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
> index 3384819..11883e2 100644
> --- a/fs/btrfs/free-space-cache.c
> +++ b/fs/btrfs/free-space-cache.c
> @@ -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;
> }
>
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index d23362f..7301b99 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -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)
> diff --git a/fs/btrfs/reada.c b/fs/btrfs/reada.c
> index b63ae20..ec8eb49 100644
> --- a/fs/btrfs/reada.c
> +++ b/fs/btrfs/reada.c
> @@ -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;
>
> diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
> index 74257d6..f87a5ee 100644
> --- a/fs/btrfs/relocation.c
> +++ b/fs/btrfs/relocation.c
> @@ -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;
> diff --git a/fs/btrfs/tests/btrfs-tests.c b/fs/btrfs/tests/btrfs-tests.c
> index 9626252..7fb123f 100644
> --- a/fs/btrfs/tests/btrfs-tests.c
> +++ b/fs/btrfs/tests/btrfs-tests.c
> @@ -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);
> diff --git a/fs/btrfs/tree-defrag.c b/fs/btrfs/tree-defrag.c
> index a63719c..c74f106 100644
> --- a/fs/btrfs/tree-defrag.c
> +++ b/fs/btrfs/tree-defrag.c
> @@ -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;
> diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
> index 1475979..70926a9 100644
> --- a/fs/btrfs/tree-log.c
> +++ b/fs/btrfs/tree-log.c
> @@ -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;
> --
> 2.1.3
>
>
> _______________________________________________
> Cocci mailing list
> Cocci at systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [PATCH 1/1] ocfs2: Deletion of unnecessary checks before two function calls
2014-03-05 22:30 ` SF Markus Elfring
(?)
(?)
@ 2014-11-02 9:40 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-02 9:40 UTC (permalink / raw)
To: Mark Fasheh, Joel Becker, ocfs2-devel
Cc: linux-kernel, kernel-janitors, trivial, Coccinelle
The 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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
index a93bf98..2e0ab63 100644
--- a/fs/ocfs2/alloc.c
+++ b/fs/ocfs2/alloc.c
@@ -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)) {
diff --git a/fs/ocfs2/ioctl.c b/fs/ocfs2/ioctl.c
index 53e6c40..28afb56 100644
--- a/fs/ocfs2/ioctl.c
+++ b/fs/ocfs2/ioctl.c
@@ -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);
diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c
index 4b0c688..f94be68 100644
--- a/fs/ocfs2/journal.c
+++ b/fs/ocfs2/journal.c
@@ -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;
}
diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
index 0440134..7eca277 100644
--- a/fs/ocfs2/localalloc.c
+++ b/fs/ocfs2/localalloc.c
@@ -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);
diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
index 8add6f1..a02593d 100644
--- a/fs/ocfs2/namei.c
+++ b/fs/ocfs2/namei.c
@@ -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);
diff --git a/fs/ocfs2/slot_map.c b/fs/ocfs2/slot_map.c
index a88b2a4..c5c6eb0 100644
--- a/fs/ocfs2/slot_map.c
+++ b/fs/ocfs2/slot_map.c
@@ -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]) {
diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
index 4142546..5860f0f 100644
--- a/fs/ocfs2/super.c
+++ b/fs/ocfs2/super.c
@@ -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);
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [PATCH 1/1] ocfs2: Deletion of unnecessary checks before two function calls
@ 2014-11-02 9:40 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-02 9:40 UTC (permalink / raw)
To: cocci
The 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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
index a93bf98..2e0ab63 100644
--- a/fs/ocfs2/alloc.c
+++ b/fs/ocfs2/alloc.c
@@ -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)) {
diff --git a/fs/ocfs2/ioctl.c b/fs/ocfs2/ioctl.c
index 53e6c40..28afb56 100644
--- a/fs/ocfs2/ioctl.c
+++ b/fs/ocfs2/ioctl.c
@@ -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);
diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c
index 4b0c688..f94be68 100644
--- a/fs/ocfs2/journal.c
+++ b/fs/ocfs2/journal.c
@@ -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;
}
diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
index 0440134..7eca277 100644
--- a/fs/ocfs2/localalloc.c
+++ b/fs/ocfs2/localalloc.c
@@ -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);
diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
index 8add6f1..a02593d 100644
--- a/fs/ocfs2/namei.c
+++ b/fs/ocfs2/namei.c
@@ -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);
diff --git a/fs/ocfs2/slot_map.c b/fs/ocfs2/slot_map.c
index a88b2a4..c5c6eb0 100644
--- a/fs/ocfs2/slot_map.c
+++ b/fs/ocfs2/slot_map.c
@@ -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]) {
diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
index 4142546..5860f0f 100644
--- a/fs/ocfs2/super.c
+++ b/fs/ocfs2/super.c
@@ -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);
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Ocfs2-devel] [PATCH 1/1] ocfs2: Deletion of unnecessary checks before two function calls
@ 2014-11-02 9:40 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-02 9:40 UTC (permalink / raw)
To: cocci
The 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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
index a93bf98..2e0ab63 100644
--- a/fs/ocfs2/alloc.c
+++ b/fs/ocfs2/alloc.c
@@ -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)) {
diff --git a/fs/ocfs2/ioctl.c b/fs/ocfs2/ioctl.c
index 53e6c40..28afb56 100644
--- a/fs/ocfs2/ioctl.c
+++ b/fs/ocfs2/ioctl.c
@@ -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);
diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c
index 4b0c688..f94be68 100644
--- a/fs/ocfs2/journal.c
+++ b/fs/ocfs2/journal.c
@@ -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;
}
diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
index 0440134..7eca277 100644
--- a/fs/ocfs2/localalloc.c
+++ b/fs/ocfs2/localalloc.c
@@ -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);
diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
index 8add6f1..a02593d 100644
--- a/fs/ocfs2/namei.c
+++ b/fs/ocfs2/namei.c
@@ -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);
diff --git a/fs/ocfs2/slot_map.c b/fs/ocfs2/slot_map.c
index a88b2a4..c5c6eb0 100644
--- a/fs/ocfs2/slot_map.c
+++ b/fs/ocfs2/slot_map.c
@@ -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]) {
diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
index 4142546..5860f0f 100644
--- a/fs/ocfs2/super.c
+++ b/fs/ocfs2/super.c
@@ -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);
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH 1/1] ocfs2: Deletion of unnecessary checks before two function calls
@ 2014-11-02 9:40 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-02 9:40 UTC (permalink / raw)
To: cocci
The 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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
index a93bf98..2e0ab63 100644
--- a/fs/ocfs2/alloc.c
+++ b/fs/ocfs2/alloc.c
@@ -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)) {
diff --git a/fs/ocfs2/ioctl.c b/fs/ocfs2/ioctl.c
index 53e6c40..28afb56 100644
--- a/fs/ocfs2/ioctl.c
+++ b/fs/ocfs2/ioctl.c
@@ -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);
diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c
index 4b0c688..f94be68 100644
--- a/fs/ocfs2/journal.c
+++ b/fs/ocfs2/journal.c
@@ -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;
}
diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
index 0440134..7eca277 100644
--- a/fs/ocfs2/localalloc.c
+++ b/fs/ocfs2/localalloc.c
@@ -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);
diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
index 8add6f1..a02593d 100644
--- a/fs/ocfs2/namei.c
+++ b/fs/ocfs2/namei.c
@@ -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);
diff --git a/fs/ocfs2/slot_map.c b/fs/ocfs2/slot_map.c
index a88b2a4..c5c6eb0 100644
--- a/fs/ocfs2/slot_map.c
+++ b/fs/ocfs2/slot_map.c
@@ -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]) {
diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
index 4142546..5860f0f 100644
--- a/fs/ocfs2/super.c
+++ b/fs/ocfs2/super.c
@@ -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);
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] ocfs2: Deletion of unnecessary checks before two function calls
2014-11-02 9:40 ` SF Markus Elfring
(?)
(?)
@ 2014-11-02 10:51 ` Julia Lawall
-1 siblings, 0 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-11-02 10:51 UTC (permalink / raw)
To: SF Markus Elfring
Cc: Mark Fasheh, Joel Becker, ocfs2-devel, linux-kernel,
kernel-janitors, trivial, Coccinelle
On Sun, 2 Nov 2014, SF Markus Elfring wrote:
> The 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.
Please check whether more labels could be added to avoid executing
unnecessary code.
julia
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> 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(-)
>
> diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
> index a93bf98..2e0ab63 100644
> --- a/fs/ocfs2/alloc.c
> +++ b/fs/ocfs2/alloc.c
> @@ -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)) {
> diff --git a/fs/ocfs2/ioctl.c b/fs/ocfs2/ioctl.c
> index 53e6c40..28afb56 100644
> --- a/fs/ocfs2/ioctl.c
> +++ b/fs/ocfs2/ioctl.c
> @@ -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);
>
> diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c
> index 4b0c688..f94be68 100644
> --- a/fs/ocfs2/journal.c
> +++ b/fs/ocfs2/journal.c
> @@ -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;
> }
> diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
> index 0440134..7eca277 100644
> --- a/fs/ocfs2/localalloc.c
> +++ b/fs/ocfs2/localalloc.c
> @@ -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);
>
> diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
> index 8add6f1..a02593d 100644
> --- a/fs/ocfs2/namei.c
> +++ b/fs/ocfs2/namei.c
> @@ -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);
> diff --git a/fs/ocfs2/slot_map.c b/fs/ocfs2/slot_map.c
> index a88b2a4..c5c6eb0 100644
> --- a/fs/ocfs2/slot_map.c
> +++ b/fs/ocfs2/slot_map.c
> @@ -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]) {
> diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
> index 4142546..5860f0f 100644
> --- a/fs/ocfs2/super.c
> +++ b/fs/ocfs2/super.c
> @@ -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);
> --
> 2.1.3
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] ocfs2: Deletion of unnecessary checks before two function calls
@ 2014-11-02 10:51 ` Julia Lawall
0 siblings, 0 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-11-02 10:51 UTC (permalink / raw)
To: cocci
On Sun, 2 Nov 2014, SF Markus Elfring wrote:
> The 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.
Please check whether more labels could be added to avoid executing
unnecessary code.
julia
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> 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(-)
>
> diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
> index a93bf98..2e0ab63 100644
> --- a/fs/ocfs2/alloc.c
> +++ b/fs/ocfs2/alloc.c
> @@ -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)) {
> diff --git a/fs/ocfs2/ioctl.c b/fs/ocfs2/ioctl.c
> index 53e6c40..28afb56 100644
> --- a/fs/ocfs2/ioctl.c
> +++ b/fs/ocfs2/ioctl.c
> @@ -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);
>
> diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c
> index 4b0c688..f94be68 100644
> --- a/fs/ocfs2/journal.c
> +++ b/fs/ocfs2/journal.c
> @@ -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;
> }
> diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
> index 0440134..7eca277 100644
> --- a/fs/ocfs2/localalloc.c
> +++ b/fs/ocfs2/localalloc.c
> @@ -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);
>
> diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
> index 8add6f1..a02593d 100644
> --- a/fs/ocfs2/namei.c
> +++ b/fs/ocfs2/namei.c
> @@ -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);
> diff --git a/fs/ocfs2/slot_map.c b/fs/ocfs2/slot_map.c
> index a88b2a4..c5c6eb0 100644
> --- a/fs/ocfs2/slot_map.c
> +++ b/fs/ocfs2/slot_map.c
> @@ -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]) {
> diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
> index 4142546..5860f0f 100644
> --- a/fs/ocfs2/super.c
> +++ b/fs/ocfs2/super.c
> @@ -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);
> --
> 2.1.3
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Ocfs2-devel] [PATCH 1/1] ocfs2: Deletion of unnecessary checks before two function calls
@ 2014-11-02 10:51 ` Julia Lawall
0 siblings, 0 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-11-02 10:51 UTC (permalink / raw)
To: cocci
On Sun, 2 Nov 2014, SF Markus Elfring wrote:
> The 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.
Please check whether more labels could be added to avoid executing
unnecessary code.
julia
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> 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(-)
>
> diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
> index a93bf98..2e0ab63 100644
> --- a/fs/ocfs2/alloc.c
> +++ b/fs/ocfs2/alloc.c
> @@ -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)) {
> diff --git a/fs/ocfs2/ioctl.c b/fs/ocfs2/ioctl.c
> index 53e6c40..28afb56 100644
> --- a/fs/ocfs2/ioctl.c
> +++ b/fs/ocfs2/ioctl.c
> @@ -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);
>
> diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c
> index 4b0c688..f94be68 100644
> --- a/fs/ocfs2/journal.c
> +++ b/fs/ocfs2/journal.c
> @@ -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;
> }
> diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
> index 0440134..7eca277 100644
> --- a/fs/ocfs2/localalloc.c
> +++ b/fs/ocfs2/localalloc.c
> @@ -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);
>
> diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
> index 8add6f1..a02593d 100644
> --- a/fs/ocfs2/namei.c
> +++ b/fs/ocfs2/namei.c
> @@ -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);
> diff --git a/fs/ocfs2/slot_map.c b/fs/ocfs2/slot_map.c
> index a88b2a4..c5c6eb0 100644
> --- a/fs/ocfs2/slot_map.c
> +++ b/fs/ocfs2/slot_map.c
> @@ -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]) {
> diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
> index 4142546..5860f0f 100644
> --- a/fs/ocfs2/super.c
> +++ b/fs/ocfs2/super.c
> @@ -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);
> --
> 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
>
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH 1/1] ocfs2: Deletion of unnecessary checks before two function calls
@ 2014-11-02 10:51 ` Julia Lawall
0 siblings, 0 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-11-02 10:51 UTC (permalink / raw)
To: cocci
On Sun, 2 Nov 2014, SF Markus Elfring wrote:
> The 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.
Please check whether more labels could be added to avoid executing
unnecessary code.
julia
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> 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(-)
>
> diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
> index a93bf98..2e0ab63 100644
> --- a/fs/ocfs2/alloc.c
> +++ b/fs/ocfs2/alloc.c
> @@ -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)) {
> diff --git a/fs/ocfs2/ioctl.c b/fs/ocfs2/ioctl.c
> index 53e6c40..28afb56 100644
> --- a/fs/ocfs2/ioctl.c
> +++ b/fs/ocfs2/ioctl.c
> @@ -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);
>
> diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c
> index 4b0c688..f94be68 100644
> --- a/fs/ocfs2/journal.c
> +++ b/fs/ocfs2/journal.c
> @@ -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;
> }
> diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
> index 0440134..7eca277 100644
> --- a/fs/ocfs2/localalloc.c
> +++ b/fs/ocfs2/localalloc.c
> @@ -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);
>
> diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
> index 8add6f1..a02593d 100644
> --- a/fs/ocfs2/namei.c
> +++ b/fs/ocfs2/namei.c
> @@ -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);
> diff --git a/fs/ocfs2/slot_map.c b/fs/ocfs2/slot_map.c
> index a88b2a4..c5c6eb0 100644
> --- a/fs/ocfs2/slot_map.c
> +++ b/fs/ocfs2/slot_map.c
> @@ -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]) {
> diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
> index 4142546..5860f0f 100644
> --- a/fs/ocfs2/super.c
> +++ b/fs/ocfs2/super.c
> @@ -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);
> --
> 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
>
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [PATCH 1/1] ceph: Deletion of unnecessary checks before two function calls
2014-03-05 22:30 ` SF Markus Elfring
(?)
(?)
@ 2014-11-02 14:20 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-02 14:20 UTC (permalink / raw)
To: Sage Weil, ceph-devel; +Cc: linux-kernel, kernel-janitors, trivial, Coccinelle
The 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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
fs/ceph/caps.c | 3 +--
fs/ceph/mds_client.c | 6 ++----
fs/ceph/snap.c | 9 +++------
3 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
index 6d1cd45..7d99fc8 100644
--- a/fs/ceph/caps.c
+++ b/fs/ceph/caps.c
@@ -3136,8 +3136,7 @@ flush_cap_releases:
done:
mutex_unlock(&session->s_mutex);
done_unlocked:
- if (inode)
- iput(inode);
+ iput(inode);
return;
bad:
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index bad07c0..3b0ab05 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -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);
diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c
index f01645a..c1cc993 100644
--- a/fs/ceph/snap.c
+++ b/fs/ceph/snap.c
@@ -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",
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [PATCH 1/1] ceph: Deletion of unnecessary checks before two function calls
@ 2014-11-02 14:20 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-02 14:20 UTC (permalink / raw)
To: Sage Weil, ceph-devel; +Cc: linux-kernel, kernel-janitors, trivial, Coccinelle
The 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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
fs/ceph/caps.c | 3 +--
fs/ceph/mds_client.c | 6 ++----
fs/ceph/snap.c | 9 +++------
3 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
index 6d1cd45..7d99fc8 100644
--- a/fs/ceph/caps.c
+++ b/fs/ceph/caps.c
@@ -3136,8 +3136,7 @@ flush_cap_releases:
done:
mutex_unlock(&session->s_mutex);
done_unlocked:
- if (inode)
- iput(inode);
+ iput(inode);
return;
bad:
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index bad07c0..3b0ab05 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -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);
diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c
index f01645a..c1cc993 100644
--- a/fs/ceph/snap.c
+++ b/fs/ceph/snap.c
@@ -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",
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [PATCH 1/1] ceph: Deletion of unnecessary checks before two function calls
@ 2014-11-02 14:20 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-02 14:20 UTC (permalink / raw)
To: Sage Weil, ceph-devel; +Cc: linux-kernel, kernel-janitors, trivial, Coccinelle
The 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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
fs/ceph/caps.c | 3 +--
fs/ceph/mds_client.c | 6 ++----
fs/ceph/snap.c | 9 +++------
3 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
index 6d1cd45..7d99fc8 100644
--- a/fs/ceph/caps.c
+++ b/fs/ceph/caps.c
@@ -3136,8 +3136,7 @@ flush_cap_releases:
done:
mutex_unlock(&session->s_mutex);
done_unlocked:
- if (inode)
- iput(inode);
+ iput(inode);
return;
bad:
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index bad07c0..3b0ab05 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -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);
diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c
index f01645a..c1cc993 100644
--- a/fs/ceph/snap.c
+++ b/fs/ceph/snap.c
@@ -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",
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH 1/1] ceph: Deletion of unnecessary checks before two function calls
@ 2014-11-02 14:20 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-02 14:20 UTC (permalink / raw)
To: cocci
The 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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
fs/ceph/caps.c | 3 +--
fs/ceph/mds_client.c | 6 ++----
fs/ceph/snap.c | 9 +++------
3 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
index 6d1cd45..7d99fc8 100644
--- a/fs/ceph/caps.c
+++ b/fs/ceph/caps.c
@@ -3136,8 +3136,7 @@ flush_cap_releases:
done:
mutex_unlock(&session->s_mutex);
done_unlocked:
- if (inode)
- iput(inode);
+ iput(inode);
return;
bad:
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index bad07c0..3b0ab05 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -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);
diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c
index f01645a..c1cc993 100644
--- a/fs/ceph/snap.c
+++ b/fs/ceph/snap.c
@@ -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",
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [PATCH 1/1] PCI: Deletion of unnecessary checks before three function calls
2014-03-05 22:30 ` SF Markus Elfring
(?)
(?)
@ 2014-11-02 15:12 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-02 15:12 UTC (permalink / raw)
To: Bjorn Helgaas, Boris Ostrovsky, David Vrabel,
Konrad Rzeszutek Wilk, Len Brown, Rafael J. Wysocki, linux-pci
Cc: linux-acpi, linux-kernel, xen-devel, kernel-janitors, trivial,
Coccinelle
The 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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index 37263b0..a8fe5de 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -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);
}
/**
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 4170113..e93f16e 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -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);
diff --git a/drivers/pci/search.c b/drivers/pci/search.c
index 827ad83..2d806bd 100644
--- a/drivers/pci/search.c
+++ b/drivers/pci/search.c
@@ -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;
}
diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c
index 53df39a..46664cc 100644
--- a/drivers/pci/xen-pcifront.c
+++ b/drivers/pci/xen-pcifront.c
@@ -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;
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [PATCH 1/1] PCI: Deletion of unnecessary checks before three function calls
@ 2014-11-02 15:12 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-02 15:12 UTC (permalink / raw)
To: Bjorn Helgaas, Boris Ostrovsky, David Vrabel,
Konrad Rzeszutek Wilk, Len Brown, Rafael J. Wysocki, linux-pci
Cc: linux-acpi, linux-kernel, xen-devel, kernel-janitors, trivial,
Coccinelle
The 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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index 37263b0..a8fe5de 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -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);
}
/**
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 4170113..e93f16e 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -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);
diff --git a/drivers/pci/search.c b/drivers/pci/search.c
index 827ad83..2d806bd 100644
--- a/drivers/pci/search.c
+++ b/drivers/pci/search.c
@@ -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;
}
diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c
index 53df39a..46664cc 100644
--- a/drivers/pci/xen-pcifront.c
+++ b/drivers/pci/xen-pcifront.c
@@ -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;
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [PATCH 1/1] PCI: Deletion of unnecessary checks before three function calls
@ 2014-11-02 15:12 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-02 15:12 UTC (permalink / raw)
To: cocci
The 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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index 37263b0..a8fe5de 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -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);
}
/**
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 4170113..e93f16e 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -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);
diff --git a/drivers/pci/search.c b/drivers/pci/search.c
index 827ad83..2d806bd 100644
--- a/drivers/pci/search.c
+++ b/drivers/pci/search.c
@@ -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;
}
diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c
index 53df39a..46664cc 100644
--- a/drivers/pci/xen-pcifront.c
+++ b/drivers/pci/xen-pcifront.c
@@ -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;
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH 1/1] PCI: Deletion of unnecessary checks before three function calls
@ 2014-11-02 15:12 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-02 15:12 UTC (permalink / raw)
To: cocci
The 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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index 37263b0..a8fe5de 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -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);
}
/**
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 4170113..e93f16e 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -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);
diff --git a/drivers/pci/search.c b/drivers/pci/search.c
index 827ad83..2d806bd 100644
--- a/drivers/pci/search.c
+++ b/drivers/pci/search.c
@@ -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;
}
diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c
index 53df39a..46664cc 100644
--- a/drivers/pci/xen-pcifront.c
+++ b/drivers/pci/xen-pcifront.c
@@ -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;
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [PATCH 1/1] PCI: Deletion of unnecessary checks before three function calls
2014-03-05 22:30 ` SF Markus Elfring
` (17 preceding siblings ...)
(?)
@ 2014-11-02 15:12 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-02 15:12 UTC (permalink / raw)
To: Bjorn Helgaas, Boris Ostrovsky, David Vrabel,
Konrad Rzeszutek Wilk, Len Brown, Rafael J. Wysocki, linux-pci
Cc: trivial, kernel-janitors, linux-kernel, linux-acpi, xen-devel,
Coccinelle
The 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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
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(-)
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index 37263b0..a8fe5de 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -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);
}
/**
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 4170113..e93f16e 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -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);
diff --git a/drivers/pci/search.c b/drivers/pci/search.c
index 827ad83..2d806bd 100644
--- a/drivers/pci/search.c
+++ b/drivers/pci/search.c
@@ -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;
}
diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c
index 53df39a..46664cc 100644
--- a/drivers/pci/xen-pcifront.c
+++ b/drivers/pci/xen-pcifront.c
@@ -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;
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [PATCH 1/1] PCI: EMU10K1: Deletion of unnecessary checks before three function calls
2014-03-05 22:30 ` SF Markus Elfring
(?)
(?)
@ 2014-11-02 18:27 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-02 18:27 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai, alsa-devel
Cc: linux-kernel, kernel-janitors, trivial, Coccinelle
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
sound/pci/emu10k1/emu10k1_main.c | 9 +++------
sound/pci/emu10k1/emufx.c | 3 +--
2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c
index 2292697..b4458a6 100644
--- a/sound/pci/emu10k1/emu10k1_main.c
+++ b/sound/pci/emu10k1/emu10k1_main.c
@@ -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)
diff --git a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c
index 745f062..eb5c0ab 100644
--- a/sound/pci/emu10k1/emufx.c
+++ b/sound/pci/emu10k1/emufx.c
@@ -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,
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [PATCH 1/1] PCI: EMU10K1: Deletion of unnecessary checks before three function calls
@ 2014-11-02 18:27 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-02 18:27 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai, alsa-devel
Cc: linux-kernel, kernel-janitors, trivial, Coccinelle
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
sound/pci/emu10k1/emu10k1_main.c | 9 +++------
sound/pci/emu10k1/emufx.c | 3 +--
2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c
index 2292697..b4458a6 100644
--- a/sound/pci/emu10k1/emu10k1_main.c
+++ b/sound/pci/emu10k1/emu10k1_main.c
@@ -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)
diff --git a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c
index 745f062..eb5c0ab 100644
--- a/sound/pci/emu10k1/emufx.c
+++ b/sound/pci/emu10k1/emufx.c
@@ -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,
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [PATCH 1/1] PCI: EMU10K1: Deletion of unnecessary checks before three function calls
@ 2014-11-02 18:27 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-02 18:27 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai, alsa-devel
Cc: linux-kernel, kernel-janitors, trivial, Coccinelle
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
sound/pci/emu10k1/emu10k1_main.c | 9 +++------
sound/pci/emu10k1/emufx.c | 3 +--
2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c
index 2292697..b4458a6 100644
--- a/sound/pci/emu10k1/emu10k1_main.c
+++ b/sound/pci/emu10k1/emu10k1_main.c
@@ -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)
diff --git a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c
index 745f062..eb5c0ab 100644
--- a/sound/pci/emu10k1/emufx.c
+++ b/sound/pci/emu10k1/emufx.c
@@ -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,
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH 1/1] PCI: EMU10K1: Deletion of unnecessary checks before three function calls
@ 2014-11-02 18:27 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-02 18:27 UTC (permalink / raw)
To: cocci
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
sound/pci/emu10k1/emu10k1_main.c | 9 +++------
sound/pci/emu10k1/emufx.c | 3 +--
2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c
index 2292697..b4458a6 100644
--- a/sound/pci/emu10k1/emu10k1_main.c
+++ b/sound/pci/emu10k1/emu10k1_main.c
@@ -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)
diff --git a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c
index 745f062..eb5c0ab 100644
--- a/sound/pci/emu10k1/emufx.c
+++ b/sound/pci/emu10k1/emufx.c
@@ -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,
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [PATCH 1/1] kconfig: Deletion of unnecessary checks before the function call "sym_calc_value"
2014-03-05 22:30 ` SF Markus Elfring
(?)
@ 2014-11-02 19:42 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-02 19:42 UTC (permalink / raw)
To: Yann E. MORIN, linux-kbuild
Cc: linux-kernel, kernel-janitors, trivial, Coccinelle
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
scripts/kconfig/confdata.c | 6 ++----
scripts/kconfig/symbol.c | 3 +--
2 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index f88d90f..3073cb6 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -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;
}
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 7caabdb..3f7797b 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -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)
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [PATCH 1/1] kconfig: Deletion of unnecessary checks before the function call "sym_calc_value"
@ 2014-11-02 19:42 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-02 19:42 UTC (permalink / raw)
To: cocci
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
scripts/kconfig/confdata.c | 6 ++----
scripts/kconfig/symbol.c | 3 +--
2 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index f88d90f..3073cb6 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -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;
}
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 7caabdb..3f7797b 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -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)
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH 1/1] kconfig: Deletion of unnecessary checks before the function call "sym_calc_value"
@ 2014-11-02 19:42 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-02 19:42 UTC (permalink / raw)
To: cocci
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
scripts/kconfig/confdata.c | 6 ++----
scripts/kconfig/symbol.c | 3 +--
2 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index f88d90f..3073cb6 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -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;
}
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 7caabdb..3f7797b 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -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)
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] PCI: EMU10K1: Deletion of unnecessary checks before three function calls
2014-11-02 18:27 ` SF Markus Elfring
(?)
@ 2014-11-03 9:45 ` Takashi Iwai
-1 siblings, 0 replies; 3619+ messages in thread
From: Takashi Iwai @ 2014-11-03 9:45 UTC (permalink / raw)
To: SF Markus Elfring
Cc: Jaroslav Kysela, alsa-devel, linux-kernel, kernel-janitors,
trivial, Coccinelle
At Sun, 02 Nov 2014 19:27:20 +0100,
SF Markus Elfring wrote:
>
> 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.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
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
> ---
> sound/pci/emu10k1/emu10k1_main.c | 9 +++------
> sound/pci/emu10k1/emufx.c | 3 +--
> 2 files changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c
> index 2292697..b4458a6 100644
> --- a/sound/pci/emu10k1/emu10k1_main.c
> +++ b/sound/pci/emu10k1/emu10k1_main.c
> @@ -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)
> diff --git a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c
> index 745f062..eb5c0ab 100644
> --- a/sound/pci/emu10k1/emufx.c
> +++ b/sound/pci/emu10k1/emufx.c
> @@ -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,
> --
> 2.1.3
>
>
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] PCI: EMU10K1: Deletion of unnecessary checks before three function calls
@ 2014-11-03 9:45 ` Takashi Iwai
0 siblings, 0 replies; 3619+ messages in thread
From: Takashi Iwai @ 2014-11-03 9:45 UTC (permalink / raw)
To: SF Markus Elfring
Cc: Jaroslav Kysela, alsa-devel, linux-kernel, kernel-janitors,
trivial, Coccinelle
At Sun, 02 Nov 2014 19:27:20 +0100,
SF Markus Elfring wrote:
>
> 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.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
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
> ---
> sound/pci/emu10k1/emu10k1_main.c | 9 +++------
> sound/pci/emu10k1/emufx.c | 3 +--
> 2 files changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c
> index 2292697..b4458a6 100644
> --- a/sound/pci/emu10k1/emu10k1_main.c
> +++ b/sound/pci/emu10k1/emu10k1_main.c
> @@ -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)
> diff --git a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c
> index 745f062..eb5c0ab 100644
> --- a/sound/pci/emu10k1/emufx.c
> +++ b/sound/pci/emu10k1/emufx.c
> @@ -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,
> --
> 2.1.3
>
>
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH 1/1] PCI: EMU10K1: Deletion of unnecessary checks before three function calls
@ 2014-11-03 9:45 ` Takashi Iwai
0 siblings, 0 replies; 3619+ messages in thread
From: Takashi Iwai @ 2014-11-03 9:45 UTC (permalink / raw)
To: cocci
At Sun, 02 Nov 2014 19:27:20 +0100,
SF Markus Elfring wrote:
>
> 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.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
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
> ---
> sound/pci/emu10k1/emu10k1_main.c | 9 +++------
> sound/pci/emu10k1/emufx.c | 3 +--
> 2 files changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c
> index 2292697..b4458a6 100644
> --- a/sound/pci/emu10k1/emu10k1_main.c
> +++ b/sound/pci/emu10k1/emu10k1_main.c
> @@ -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)
> diff --git a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c
> index 745f062..eb5c0ab 100644
> --- a/sound/pci/emu10k1/emufx.c
> +++ b/sound/pci/emu10k1/emufx.c
> @@ -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,
> --
> 2.1.3
>
>
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] s390/net: Deletion of unnecessary checks before two function calls
2014-10-31 17:40 ` SF Markus Elfring
(?)
@ 2014-11-03 9:50 ` Dan Carpenter
-1 siblings, 0 replies; 3619+ messages in thread
From: Dan Carpenter @ 2014-11-03 9:50 UTC (permalink / raw)
To: SF Markus Elfring
Cc: Ursula Braun, Martin Schwidefsky, Heiko Carstens, Frank Blaschka,
linux390, linux-s390, linux-kernel, kernel-janitors, trivial,
Coccinelle
This 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] s390/net: Deletion of unnecessary checks before two function calls
@ 2014-11-03 9:50 ` Dan Carpenter
0 siblings, 0 replies; 3619+ messages in thread
From: Dan Carpenter @ 2014-11-03 9:50 UTC (permalink / raw)
To: cocci
This 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH 1/1] s390/net: Deletion of unnecessary checks before two function calls
@ 2014-11-03 9:50 ` Dan Carpenter
0 siblings, 0 replies; 3619+ messages in thread
From: Dan Carpenter @ 2014-11-03 9:50 UTC (permalink / raw)
To: cocci
This 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] kconfig: Deletion of unnecessary checks before the function call "sym_calc_value"
2014-11-02 19:42 ` SF Markus Elfring
(?)
@ 2014-11-03 10:35 ` Paul Bolle
-1 siblings, 0 replies; 3619+ messages in thread
From: Paul Bolle @ 2014-11-03 10:35 UTC (permalink / raw)
To: Markus Elfring
Cc: Yann E. MORIN, linux-kbuild, linux-kernel, kernel-janitors,
trivial, Coccinelle
Since you use "SF Markus Elfring", this patch should start with:
From: Markus Elfring <elfring@users.sourceforge.net>
We don't care that you used a sourceforge.net address. Or has SF another
meaning?
On Sun, 2014-11-02 at 20:42 +0100, SF Markus Elfring wrote:
> 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?
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> scripts/kconfig/confdata.c | 6 ++----
> scripts/kconfig/symbol.c | 3 +--
> 2 files changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
> index f88d90f..3073cb6 100644
> --- a/scripts/kconfig/confdata.c
> +++ b/scripts/kconfig/confdata.c
> @@ -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;
> }
>
> diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
> index 7caabdb..3f7797b 100644
> --- a/scripts/kconfig/symbol.c
> +++ b/scripts/kconfig/symbol.c
> @@ -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
Acked-by: Paul Bolle <pebolle@tiscali.nl>
added.
Paul Bolle
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] kconfig: Deletion of unnecessary checks before the function call "sym_calc_value"
@ 2014-11-03 10:35 ` Paul Bolle
0 siblings, 0 replies; 3619+ messages in thread
From: Paul Bolle @ 2014-11-03 10:35 UTC (permalink / raw)
To: cocci
Since you use "SF Markus Elfring", this patch should start with:
From: Markus Elfring <elfring@users.sourceforge.net>
We don't care that you used a sourceforge.net address. Or has SF another
meaning?
On Sun, 2014-11-02 at 20:42 +0100, SF Markus Elfring wrote:
> 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?
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> scripts/kconfig/confdata.c | 6 ++----
> scripts/kconfig/symbol.c | 3 +--
> 2 files changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
> index f88d90f..3073cb6 100644
> --- a/scripts/kconfig/confdata.c
> +++ b/scripts/kconfig/confdata.c
> @@ -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;
> }
>
> diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
> index 7caabdb..3f7797b 100644
> --- a/scripts/kconfig/symbol.c
> +++ b/scripts/kconfig/symbol.c
> @@ -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
Acked-by: Paul Bolle <pebolle@tiscali.nl>
added.
Paul Bolle
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH 1/1] kconfig: Deletion of unnecessary checks before the function call "sym_calc_value"
@ 2014-11-03 10:35 ` Paul Bolle
0 siblings, 0 replies; 3619+ messages in thread
From: Paul Bolle @ 2014-11-03 10:35 UTC (permalink / raw)
To: cocci
Since you use "SF Markus Elfring", this patch should start with:
From: Markus Elfring <elfring@users.sourceforge.net>
We don't care that you used a sourceforge.net address. Or has SF another
meaning?
On Sun, 2014-11-02 at 20:42 +0100, SF Markus Elfring wrote:
> 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?
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> scripts/kconfig/confdata.c | 6 ++----
> scripts/kconfig/symbol.c | 3 +--
> 2 files changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
> index f88d90f..3073cb6 100644
> --- a/scripts/kconfig/confdata.c
> +++ b/scripts/kconfig/confdata.c
> @@ -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;
> }
>
> diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
> index 7caabdb..3f7797b 100644
> --- a/scripts/kconfig/symbol.c
> +++ b/scripts/kconfig/symbol.c
> @@ -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
Acked-by: Paul Bolle <pebolle@tiscali.nl>
added.
Paul Bolle
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] ceph: Deletion of unnecessary checks before two function calls
2014-11-02 14:20 ` SF Markus Elfring
(?)
@ 2014-11-03 10:35 ` Ilya Dryomov
-1 siblings, 0 replies; 3619+ messages in thread
From: Ilya Dryomov @ 2014-11-03 10:35 UTC (permalink / raw)
To: SF Markus Elfring
Cc: Sage Weil, Ceph Development, Linux Kernel Mailing List,
kernel-janitors, trivial, Coccinelle, Yan, Zheng
On Sun, Nov 2, 2014 at 5:20 PM, SF Markus Elfring
<elfring@users.sourceforge.net> wrote:
> The 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.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> 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.
>
> diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
> index 6d1cd45..7d99fc8 100644
> --- a/fs/ceph/caps.c
> +++ b/fs/ceph/caps.c
> @@ -3136,8 +3136,7 @@ flush_cap_releases:
> done:
> mutex_unlock(&session->s_mutex);
> done_unlocked:
> - if (inode)
> - iput(inode);
> + iput(inode);
> return;
>
> bad:
> diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
> index bad07c0..3b0ab05 100644
> --- a/fs/ceph/mds_client.c
> +++ b/fs/ceph/mds_client.c
> @@ -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.
> 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);
>
> diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c
> index f01645a..c1cc993 100644
> --- a/fs/ceph/snap.c
> +++ b/fs/ceph/snap.c
> @@ -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)
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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] ceph: Deletion of unnecessary checks before two function calls
@ 2014-11-03 10:35 ` Ilya Dryomov
0 siblings, 0 replies; 3619+ messages in thread
From: Ilya Dryomov @ 2014-11-03 10:35 UTC (permalink / raw)
To: SF Markus Elfring
Cc: Sage Weil, Ceph Development, Linux Kernel Mailing List,
kernel-janitors, trivial, Coccinelle, Yan, Zheng
On Sun, Nov 2, 2014 at 5:20 PM, SF Markus Elfring
<elfring@users.sourceforge.net> wrote:
> The 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.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> 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.
>
> diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
> index 6d1cd45..7d99fc8 100644
> --- a/fs/ceph/caps.c
> +++ b/fs/ceph/caps.c
> @@ -3136,8 +3136,7 @@ flush_cap_releases:
> done:
> mutex_unlock(&session->s_mutex);
> done_unlocked:
> - if (inode)
> - iput(inode);
> + iput(inode);
> return;
>
> bad:
> diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
> index bad07c0..3b0ab05 100644
> --- a/fs/ceph/mds_client.c
> +++ b/fs/ceph/mds_client.c
> @@ -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.
> 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);
>
> diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c
> index f01645a..c1cc993 100644
> --- a/fs/ceph/snap.c
> +++ b/fs/ceph/snap.c
> @@ -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)
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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH 1/1] ceph: Deletion of unnecessary checks before two function calls
@ 2014-11-03 10:35 ` Ilya Dryomov
0 siblings, 0 replies; 3619+ messages in thread
From: Ilya Dryomov @ 2014-11-03 10:35 UTC (permalink / raw)
To: cocci
On Sun, Nov 2, 2014 at 5:20 PM, SF Markus Elfring
<elfring@users.sourceforge.net> wrote:
> The 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.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> 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.
>
> diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
> index 6d1cd45..7d99fc8 100644
> --- a/fs/ceph/caps.c
> +++ b/fs/ceph/caps.c
> @@ -3136,8 +3136,7 @@ flush_cap_releases:
> done:
> mutex_unlock(&session->s_mutex);
> done_unlocked:
> - if (inode)
> - iput(inode);
> + iput(inode);
> return;
>
> bad:
> diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
> index bad07c0..3b0ab05 100644
> --- a/fs/ceph/mds_client.c
> +++ b/fs/ceph/mds_client.c
> @@ -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.
> 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);
>
> diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c
> index f01645a..c1cc993 100644
> --- a/fs/ceph/snap.c
> +++ b/fs/ceph/snap.c
> @@ -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)
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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] s390/net: Deletion of unnecessary checks before two function calls
2014-10-31 17:40 ` SF Markus Elfring
(?)
@ 2014-11-03 11:04 ` Ursula Braun
-1 siblings, 0 replies; 3619+ messages in thread
From: Ursula Braun @ 2014-11-03 11:04 UTC (permalink / raw)
To: SF Markus Elfring
Cc: Ursula Braun, Martin Schwidefsky, Heiko Carstens, Frank Blaschka,
linux390, linux-s390, linux-kernel, kernel-janitors, trivial,
Coccinelle
I agree with your proposed debug_unregister() changes, but not with your
kfree_fsm() change.
Regards, Ursula Braun
On Fri, 2014-10-31 at 18:40 +0100, SF Markus Elfring wrote:
> The 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.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> 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(-)
>
> diff --git a/drivers/s390/net/claw.c b/drivers/s390/net/claw.c
> index 213e54e..d609ca0 100644
> --- a/drivers/s390/net/claw.c
> +++ b/drivers/s390/net/claw.c
> @@ -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
> diff --git a/drivers/s390/net/ctcm_main.c b/drivers/s390/net/ctcm_main.c
> index e056dd4..34dc0f3 100644
> --- a/drivers/s390/net/ctcm_main.c
> +++ b/drivers/s390/net/ctcm_main.c
> @@ -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]);
> diff --git a/drivers/s390/net/lcs.c b/drivers/s390/net/lcs.c
> index 0a7d87c..5dfa7dd 100644
> --- a/drivers/s390/net/lcs.c
> +++ b/drivers/s390/net/lcs.c
> @@ -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
> diff --git a/drivers/s390/net/netiucv.c b/drivers/s390/net/netiucv.c
> index 0a87809..bdcc3fe 100644
> --- a/drivers/s390/net/netiucv.c
> +++ b/drivers/s390/net/netiucv.c
> @@ -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() */
> }
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] s390/net: Deletion of unnecessary checks before two function calls
@ 2014-11-03 11:04 ` Ursula Braun
0 siblings, 0 replies; 3619+ messages in thread
From: Ursula Braun @ 2014-11-03 11:04 UTC (permalink / raw)
To: cocci
I agree with your proposed debug_unregister() changes, but not with your
kfree_fsm() change.
Regards, Ursula Braun
On Fri, 2014-10-31 at 18:40 +0100, SF Markus Elfring wrote:
> The 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.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> 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(-)
>
> diff --git a/drivers/s390/net/claw.c b/drivers/s390/net/claw.c
> index 213e54e..d609ca0 100644
> --- a/drivers/s390/net/claw.c
> +++ b/drivers/s390/net/claw.c
> @@ -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
> diff --git a/drivers/s390/net/ctcm_main.c b/drivers/s390/net/ctcm_main.c
> index e056dd4..34dc0f3 100644
> --- a/drivers/s390/net/ctcm_main.c
> +++ b/drivers/s390/net/ctcm_main.c
> @@ -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]);
> diff --git a/drivers/s390/net/lcs.c b/drivers/s390/net/lcs.c
> index 0a7d87c..5dfa7dd 100644
> --- a/drivers/s390/net/lcs.c
> +++ b/drivers/s390/net/lcs.c
> @@ -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
> diff --git a/drivers/s390/net/netiucv.c b/drivers/s390/net/netiucv.c
> index 0a87809..bdcc3fe 100644
> --- a/drivers/s390/net/netiucv.c
> +++ b/drivers/s390/net/netiucv.c
> @@ -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() */
> }
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH 1/1] s390/net: Deletion of unnecessary checks before two function calls
@ 2014-11-03 11:04 ` Ursula Braun
0 siblings, 0 replies; 3619+ messages in thread
From: Ursula Braun @ 2014-11-03 11:04 UTC (permalink / raw)
To: cocci
I agree with your proposed debug_unregister() changes, but not with your
kfree_fsm() change.
Regards, Ursula Braun
On Fri, 2014-10-31 at 18:40 +0100, SF Markus Elfring wrote:
> The 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.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> 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(-)
>
> diff --git a/drivers/s390/net/claw.c b/drivers/s390/net/claw.c
> index 213e54e..d609ca0 100644
> --- a/drivers/s390/net/claw.c
> +++ b/drivers/s390/net/claw.c
> @@ -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
> diff --git a/drivers/s390/net/ctcm_main.c b/drivers/s390/net/ctcm_main.c
> index e056dd4..34dc0f3 100644
> --- a/drivers/s390/net/ctcm_main.c
> +++ b/drivers/s390/net/ctcm_main.c
> @@ -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]);
> diff --git a/drivers/s390/net/lcs.c b/drivers/s390/net/lcs.c
> index 0a7d87c..5dfa7dd 100644
> --- a/drivers/s390/net/lcs.c
> +++ b/drivers/s390/net/lcs.c
> @@ -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
> diff --git a/drivers/s390/net/netiucv.c b/drivers/s390/net/netiucv.c
> index 0a87809..bdcc3fe 100644
> --- a/drivers/s390/net/netiucv.c
> +++ b/drivers/s390/net/netiucv.c
> @@ -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() */
> }
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: ceph: Deletion of unnecessary checks before two function calls
2014-11-03 10:35 ` Ilya Dryomov
(?)
(?)
@ 2014-11-03 13:27 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-03 13:27 UTC (permalink / raw)
To: Ilya Dryomov
Cc: Sage Weil, Ceph Development, Linux Kernel Mailing List,
kernel-janitors, trivial, Coccinelle, Yan, Zheng
> 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.
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
>> @@ -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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: ceph: Deletion of unnecessary checks before two function calls
@ 2014-11-03 13:27 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-03 13:27 UTC (permalink / raw)
To: Ilya Dryomov
Cc: Sage Weil, Ceph Development, Linux Kernel Mailing List,
kernel-janitors, trivial, Coccinelle, Yan, Zheng
> 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.
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
>> @@ -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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: ceph: Deletion of unnecessary checks before two function calls
@ 2014-11-03 13:27 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-03 13:27 UTC (permalink / raw)
To: Ilya Dryomov
Cc: Sage Weil, Ceph Development, Linux Kernel Mailing List,
kernel-janitors, trivial, Coccinelle, Yan, Zheng
> 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.
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
>> @@ -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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] ceph: Deletion of unnecessary checks before two function calls
@ 2014-11-03 13:27 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-03 13:27 UTC (permalink / raw)
To: cocci
> 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.
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
>> @@ -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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH resent] ALSA: emu10k1: Deletion of unnecessary checks before three function calls
2014-11-03 9:45 ` Takashi Iwai
(?)
(?)
@ 2014-11-03 14:10 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-03 14:10 UTC (permalink / raw)
To: Takashi Iwai
Cc: Jaroslav Kysela, alsa-devel, linux-kernel, kernel-janitors,
trivial, Coccinelle
[-- Attachment #1: Type: text/plain, Size: 604 bytes --]
> 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?
> 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
[-- Attachment #2: 0001-ALSA-emu10k1-Deletion-of-unnecessary-checks-before-t.patch --]
[-- Type: text/x-patch, Size: 2120 bytes --]
>From 23bb7bd1325b7c9cc81761db3ebf3ea19f85338d Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
sound/pci/emu10k1/emu10k1_main.c | 9 +++------
sound/pci/emu10k1/emufx.c | 3 +--
2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c
index 2292697..b4458a6 100644
--- a/sound/pci/emu10k1/emu10k1_main.c
+++ b/sound/pci/emu10k1/emu10k1_main.c
@@ -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)
diff --git a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c
index 745f062..eb5c0ab 100644
--- a/sound/pci/emu10k1/emufx.c
+++ b/sound/pci/emu10k1/emufx.c
@@ -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,
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [PATCH resent] ALSA: emu10k1: Deletion of unnecessary checks before three function calls
@ 2014-11-03 14:10 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-03 14:10 UTC (permalink / raw)
To: Takashi Iwai
Cc: Jaroslav Kysela, alsa-devel, linux-kernel, kernel-janitors,
trivial, Coccinelle
[-- Attachment #1: Type: text/plain, Size: 604 bytes --]
> 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?
> 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
[-- Attachment #2: 0001-ALSA-emu10k1-Deletion-of-unnecessary-checks-before-t.patch --]
[-- Type: text/x-patch, Size: 2119 bytes --]
From 23bb7bd1325b7c9cc81761db3ebf3ea19f85338d Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
sound/pci/emu10k1/emu10k1_main.c | 9 +++------
sound/pci/emu10k1/emufx.c | 3 +--
2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c
index 2292697..b4458a6 100644
--- a/sound/pci/emu10k1/emu10k1_main.c
+++ b/sound/pci/emu10k1/emu10k1_main.c
@@ -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)
diff --git a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c
index 745f062..eb5c0ab 100644
--- a/sound/pci/emu10k1/emufx.c
+++ b/sound/pci/emu10k1/emufx.c
@@ -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,
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* Re: [PATCH resent] ALSA: emu10k1: Deletion of unnecessary checks before three function calls
@ 2014-11-03 14:10 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-03 14:10 UTC (permalink / raw)
To: Takashi Iwai
Cc: Jaroslav Kysela, alsa-devel, linux-kernel, kernel-janitors,
trivial, Coccinelle
[-- Attachment #1: Type: text/plain, Size: 604 bytes --]
> 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?
> 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
[-- Attachment #2: 0001-ALSA-emu10k1-Deletion-of-unnecessary-checks-before-t.patch --]
[-- Type: text/x-patch, Size: 2120 bytes --]
>From 23bb7bd1325b7c9cc81761db3ebf3ea19f85338d Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
sound/pci/emu10k1/emu10k1_main.c | 9 +++------
sound/pci/emu10k1/emufx.c | 3 +--
2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c
index 2292697..b4458a6 100644
--- a/sound/pci/emu10k1/emu10k1_main.c
+++ b/sound/pci/emu10k1/emu10k1_main.c
@@ -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)
diff --git a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c
index 745f062..eb5c0ab 100644
--- a/sound/pci/emu10k1/emufx.c
+++ b/sound/pci/emu10k1/emufx.c
@@ -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,
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH resent] ALSA: emu10k1: Deletion of unnecessary checks before three function calls
@ 2014-11-03 14:10 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-03 14:10 UTC (permalink / raw)
To: cocci
> 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?
> 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-ALSA-emu10k1-Deletion-of-unnecessary-checks-before-t.patch
Type: text/x-patch
Size: 2120 bytes
Desc: not available
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20141103/7a73952b/attachment.bin>
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH resent] ALSA: emu10k1: Deletion of unnecessary checks before three function calls
2014-11-03 14:10 ` SF Markus Elfring
(?)
@ 2014-11-03 14:17 ` Takashi Iwai
-1 siblings, 0 replies; 3619+ messages in thread
From: Takashi Iwai @ 2014-11-03 14:17 UTC (permalink / raw)
To: SF Markus Elfring
Cc: Jaroslav Kysela, alsa-devel, linux-kernel, kernel-janitors,
trivial, Coccinelle
At Mon, 03 Nov 2014 15:10:40 +0100,
SF Markus Elfring wrote:
>
> > 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.
> > 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH resent] ALSA: emu10k1: Deletion of unnecessary checks before three function calls
@ 2014-11-03 14:17 ` Takashi Iwai
0 siblings, 0 replies; 3619+ messages in thread
From: Takashi Iwai @ 2014-11-03 14:17 UTC (permalink / raw)
To: SF Markus Elfring
Cc: Jaroslav Kysela, alsa-devel, linux-kernel, kernel-janitors,
trivial, Coccinelle
At Mon, 03 Nov 2014 15:10:40 +0100,
SF Markus Elfring wrote:
>
> > 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.
> > 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH resent] ALSA: emu10k1: Deletion of unnecessary checks before three function calls
@ 2014-11-03 14:17 ` Takashi Iwai
0 siblings, 0 replies; 3619+ messages in thread
From: Takashi Iwai @ 2014-11-03 14:17 UTC (permalink / raw)
To: cocci
At Mon, 03 Nov 2014 15:10:40 +0100,
SF Markus Elfring wrote:
>
> > 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.
> > 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: ceph: Deletion of unnecessary checks before two function calls
2014-11-03 13:27 ` SF Markus Elfring
(?)
@ 2014-11-03 14:23 ` Ilya Dryomov
-1 siblings, 0 replies; 3619+ messages in thread
From: Ilya Dryomov @ 2014-11-03 14:23 UTC (permalink / raw)
To: SF Markus Elfring
Cc: Sage Weil, Ceph Development, Linux Kernel Mailing List,
kernel-janitors, trivial, Coccinelle, Yan, Zheng
On Mon, Nov 3, 2014 at 4:27 PM, SF Markus Elfring
<elfring@users.sourceforge.net> wrote:
>> 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.
>
> 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.
>
>
>>> @@ -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?
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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: ceph: Deletion of unnecessary checks before two function calls
@ 2014-11-03 14:23 ` Ilya Dryomov
0 siblings, 0 replies; 3619+ messages in thread
From: Ilya Dryomov @ 2014-11-03 14:23 UTC (permalink / raw)
To: SF Markus Elfring
Cc: Sage Weil, Ceph Development, Linux Kernel Mailing List,
kernel-janitors, trivial, Coccinelle, Yan, Zheng
On Mon, Nov 3, 2014 at 4:27 PM, SF Markus Elfring
<elfring@users.sourceforge.net> wrote:
>> 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.
>
> 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.
>
>
>>> @@ -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?
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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] ceph: Deletion of unnecessary checks before two function calls
@ 2014-11-03 14:23 ` Ilya Dryomov
0 siblings, 0 replies; 3619+ messages in thread
From: Ilya Dryomov @ 2014-11-03 14:23 UTC (permalink / raw)
To: cocci
On Mon, Nov 3, 2014 at 4:27 PM, SF Markus Elfring
<elfring@users.sourceforge.net> wrote:
>> 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.
>
> 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.
>
>
>>> @@ -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?
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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: s390/net: Deletion of unnecessary checks before two function calls
2014-11-03 9:50 ` Dan Carpenter
(?)
@ 2014-11-03 15:55 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-03 15:55 UTC (permalink / raw)
To: Dan Carpenter
Cc: Ursula Braun, Martin Schwidefsky, Heiko Carstens, Frank Blaschka,
linux390, linux-s390, linux-kernel, kernel-janitors, trivial,
Coccinelle
> This one is buggy.
I am still interested to clarify this opinion a bit more.
> I'm sorry, but please stop sending these.
I am going to improve more implementation details in affected source files.
> 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.
> 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?
> 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?
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: s390/net: Deletion of unnecessary checks before two function calls
@ 2014-11-03 15:55 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-03 15:55 UTC (permalink / raw)
To: cocci
> This one is buggy.
I am still interested to clarify this opinion a bit more.
> I'm sorry, but please stop sending these.
I am going to improve more implementation details in affected source files.
> 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.
> 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?
> 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?
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] s390/net: Deletion of unnecessary checks before two function calls
@ 2014-11-03 15:55 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-03 15:55 UTC (permalink / raw)
To: cocci
> This one is buggy.
I am still interested to clarify this opinion a bit more.
> I'm sorry, but please stop sending these.
I am going to improve more implementation details in affected source files.
> 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.
> 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?
> 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?
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: s390/net: Deletion of unnecessary checks before two function calls
2014-11-03 11:04 ` Ursula Braun
(?)
@ 2014-11-03 16:10 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-03 16:10 UTC (permalink / raw)
To: Ursula Braun
Cc: Ursula Braun, Martin Schwidefsky, Heiko Carstens, Frank Blaschka,
linux390, linux-s390, linux-kernel, kernel-janitors, trivial,
Coccinelle
> I agree with your proposed debug_unregister() changes, but not with your
> kfree_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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: s390/net: Deletion of unnecessary checks before two function calls
@ 2014-11-03 16:10 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-03 16:10 UTC (permalink / raw)
To: cocci
> I agree with your proposed debug_unregister() changes, but not with your
> kfree_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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] s390/net: Deletion of unnecessary checks before two function calls
@ 2014-11-03 16:10 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-03 16:10 UTC (permalink / raw)
To: cocci
> I agree with your proposed debug_unregister() changes, but not with your
> kfree_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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: s390/net: Deletion of unnecessary checks before two function calls
2014-11-03 15:55 ` SF Markus Elfring
(?)
@ 2014-11-03 16:25 ` Dan Carpenter
-1 siblings, 0 replies; 3619+ messages in thread
From: Dan Carpenter @ 2014-11-03 16:25 UTC (permalink / raw)
To: SF Markus Elfring
Cc: Ursula Braun, Martin Schwidefsky, Heiko Carstens, Frank Blaschka,
linux390, linux-s390, linux-kernel, kernel-janitors, trivial,
Coccinelle
On Mon, Nov 03, 2014 at 04:55:12PM +0100, SF Markus Elfring wrote:
> > 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: s390/net: Deletion of unnecessary checks before two function calls
@ 2014-11-03 16:25 ` Dan Carpenter
0 siblings, 0 replies; 3619+ messages in thread
From: Dan Carpenter @ 2014-11-03 16:25 UTC (permalink / raw)
To: cocci
On Mon, Nov 03, 2014 at 04:55:12PM +0100, SF Markus Elfring wrote:
> > 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] s390/net: Deletion of unnecessary checks before two function calls
@ 2014-11-03 16:25 ` Dan Carpenter
0 siblings, 0 replies; 3619+ messages in thread
From: Dan Carpenter @ 2014-11-03 16:25 UTC (permalink / raw)
To: cocci
On Mon, Nov 03, 2014 at 04:55:12PM +0100, SF Markus Elfring wrote:
> > 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: s390/net: Deletion of unnecessary checks before two function calls
2014-11-03 16:10 ` SF Markus Elfring
(?)
@ 2014-11-03 16:28 ` Dan Carpenter
-1 siblings, 0 replies; 3619+ messages in thread
From: Dan Carpenter @ 2014-11-03 16:28 UTC (permalink / raw)
To: SF Markus Elfring
Cc: Ursula Braun, Ursula Braun, Martin Schwidefsky, Heiko Carstens,
Frank Blaschka, linux390, linux-s390, linux-kernel,
kernel-janitors, trivial, Coccinelle
On Mon, Nov 03, 2014 at 05:10:35PM +0100, SF Markus Elfring wrote:
> > I agree with your proposed debug_unregister() changes, but not with your
> > kfree_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?
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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: s390/net: Deletion of unnecessary checks before two function calls
@ 2014-11-03 16:28 ` Dan Carpenter
0 siblings, 0 replies; 3619+ messages in thread
From: Dan Carpenter @ 2014-11-03 16:28 UTC (permalink / raw)
To: cocci
On Mon, Nov 03, 2014 at 05:10:35PM +0100, SF Markus Elfring wrote:
> > I agree with your proposed debug_unregister() changes, but not with your
> > kfree_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?
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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] s390/net: Deletion of unnecessary checks before two function calls
@ 2014-11-03 16:28 ` Dan Carpenter
0 siblings, 0 replies; 3619+ messages in thread
From: Dan Carpenter @ 2014-11-03 16:28 UTC (permalink / raw)
To: cocci
On Mon, Nov 03, 2014 at 05:10:35PM +0100, SF Markus Elfring wrote:
> > I agree with your proposed debug_unregister() changes, but not with your
> > kfree_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?
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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: s390/net: Deletion of unnecessary checks before two function calls
2014-11-03 16:25 ` Dan Carpenter
(?)
@ 2014-11-03 16:50 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-03 16:50 UTC (permalink / raw)
To: Dan Carpenter
Cc: Ursula Braun, Martin Schwidefsky, Heiko Carstens, Frank Blaschka,
linux390, linux-s390, linux-kernel, kernel-janitors, trivial,
Coccinelle
> After your patch then it will print warning messages.
To which messages do you refer to?
> 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?
> After: You have to remember that rtw_free_netdev() accepts NULL
> pointers but free_netdev() does not accept NULL pointers.
Are any improvements needed for the corresponding documentation to make it
better accessible besides the source code?
> 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?
> 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
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?
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: s390/net: Deletion of unnecessary checks before two function calls
@ 2014-11-03 16:50 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-03 16:50 UTC (permalink / raw)
To: cocci
> After your patch then it will print warning messages.
To which messages do you refer to?
> 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?
> After: You have to remember that rtw_free_netdev() accepts NULL
> pointers but free_netdev() does not accept NULL pointers.
Are any improvements needed for the corresponding documentation to make it
better accessible besides the source code?
> 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?
> 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
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?
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] s390/net: Deletion of unnecessary checks before two function calls
@ 2014-11-03 16:50 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-03 16:50 UTC (permalink / raw)
To: cocci
> After your patch then it will print warning messages.
To which messages do you refer to?
> 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?
> After: You have to remember that rtw_free_netdev() accepts NULL
> pointers but free_netdev() does not accept NULL pointers.
Are any improvements needed for the corresponding documentation to make it
better accessible besides the source code?
> 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?
> 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
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?
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: s390/net: Deletion of unnecessary checks before two function calls
2014-11-03 16:50 ` SF Markus Elfring
(?)
@ 2014-11-03 17:02 ` Julia Lawall
-1 siblings, 0 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-11-03 17:02 UTC (permalink / raw)
To: SF Markus Elfring
Cc: Dan Carpenter, Ursula Braun, Martin Schwidefsky, Heiko Carstens,
Frank Blaschka, linux390, linux-s390, linux-kernel,
kernel-janitors, trivial, Coccinelle
> > After your patch then it will print warning messages.
> > After: You have to remember that rtw_free_netdev() accepts NULL
> > pointers but free_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.
> > 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: s390/net: Deletion of unnecessary checks before two function calls
@ 2014-11-03 17:02 ` Julia Lawall
0 siblings, 0 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-11-03 17:02 UTC (permalink / raw)
To: cocci
> > After your patch then it will print warning messages.
> > After: You have to remember that rtw_free_netdev() accepts NULL
> > pointers but free_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.
> > 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] s390/net: Deletion of unnecessary checks before two function calls
@ 2014-11-03 17:02 ` Julia Lawall
0 siblings, 0 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-11-03 17:02 UTC (permalink / raw)
To: cocci
> > After your patch then it will print warning messages.
> > After: You have to remember that rtw_free_netdev() accepts NULL
> > pointers but free_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.
> > 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] s390/net: Deletion of unnecessary checks before two function calls
2014-11-03 16:25 ` Dan Carpenter
` (2 preceding siblings ...)
(?)
@ 2014-11-03 17:05 ` Derek M Jones
2014-11-03 17:32 ` Julia Lawall
2014-11-03 21:30 ` [Cocci] Are defensive checks treated differently in specific areas? SF Markus Elfring
-1 siblings, 2 replies; 3619+ messages in thread
From: Derek M Jones @ 2014-11-03 17:05 UTC (permalink / raw)
To: cocci
Dan
> 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.
> 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.
--
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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: s390/net: Deletion of unnecessary checks before two function calls
2014-11-03 16:50 ` SF Markus Elfring
(?)
@ 2014-11-03 17:16 ` Dan Carpenter
-1 siblings, 0 replies; 3619+ messages in thread
From: Dan Carpenter @ 2014-11-03 17:16 UTC (permalink / raw)
To: SF Markus Elfring
Cc: Ursula Braun, Martin Schwidefsky, Heiko Carstens, Frank Blaschka,
linux390, linux-s390, linux-kernel, kernel-janitors, trivial,
Coccinelle
On Mon, Nov 03, 2014 at 05:50:48PM +0100, SF Markus Elfring wrote:
> > After your patch then it will print warning messages.
>
> To which messages do you refer to?
>
Open your eyeballs up and read the code.
>
> > 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.
>
> > After: You have to remember that rtw_free_netdev() accepts NULL
> > pointers but free_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.
>
> > 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.
>
> > 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
>
> 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.
>
>
> > 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: s390/net: Deletion of unnecessary checks before two function calls
@ 2014-11-03 17:16 ` Dan Carpenter
0 siblings, 0 replies; 3619+ messages in thread
From: Dan Carpenter @ 2014-11-03 17:16 UTC (permalink / raw)
To: cocci
On Mon, Nov 03, 2014 at 05:50:48PM +0100, SF Markus Elfring wrote:
> > After your patch then it will print warning messages.
>
> To which messages do you refer to?
>
Open your eyeballs up and read the code.
>
> > 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.
>
> > After: You have to remember that rtw_free_netdev() accepts NULL
> > pointers but free_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.
>
> > 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.
>
> > 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
>
> 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.
>
>
> > 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] s390/net: Deletion of unnecessary checks before two function calls
@ 2014-11-03 17:16 ` Dan Carpenter
0 siblings, 0 replies; 3619+ messages in thread
From: Dan Carpenter @ 2014-11-03 17:16 UTC (permalink / raw)
To: cocci
On Mon, Nov 03, 2014 at 05:50:48PM +0100, SF Markus Elfring wrote:
> > After your patch then it will print warning messages.
>
> To which messages do you refer to?
>
Open your eyeballs up and read the code.
>
> > 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.
>
> > After: You have to remember that rtw_free_netdev() accepts NULL
> > pointers but free_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.
>
> > 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.
>
> > 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
>
> 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.
>
>
> > 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] s390/net: Deletion of unnecessary checks before two function calls
2014-11-03 17:05 ` [Cocci] " Derek M Jones
@ 2014-11-03 17:32 ` Julia Lawall
2014-11-03 21:30 ` [Cocci] Are defensive checks treated differently in specific areas? SF Markus Elfring
1 sibling, 0 replies; 3619+ messages in thread
From: Julia Lawall @ 2014-11-03 17:32 UTC (permalink / raw)
To: cocci
On Mon, 3 Nov 2014, Derek M Jones wrote:
> Dan
>
> > 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.
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.
> > 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: s390/net: Deletion of unnecessary checks before two function calls
2014-11-03 17:16 ` Dan Carpenter
(?)
@ 2014-11-03 17:40 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-03 17:40 UTC (permalink / raw)
To: Dan Carpenter
Cc: Ursula Braun, Martin Schwidefsky, Heiko Carstens, Frank Blaschka,
linux390, linux-s390, linux-kernel, kernel-janitors, trivial,
Coccinelle
> 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.
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: s390/net: Deletion of unnecessary checks before two function calls
@ 2014-11-03 17:40 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-03 17:40 UTC (permalink / raw)
To: cocci
> 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.
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [Cocci] s390/net: Deletion of unnecessary checks before two function calls
@ 2014-11-03 17:40 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-03 17:40 UTC (permalink / raw)
To: cocci
> 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.
> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* [PATCH v2] kconfig: Deletion of unnecessary checks before the function call "sym_calc_value"
2014-11-02 19:42 ` SF Markus Elfring
(?)
@ 2014-11-03 18:40 ` SF Markus Elfring
-1 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-03 18:40 UTC (permalink / raw)
To: Yann E. MORIN, linux-kbuild
Cc: linux-kernel, kernel-janitors, trivial, Coccinelle
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Acked-by: Paul Bolle <pebolle@tiscali.nl>
---
scripts/kconfig/confdata.c | 6 ++----
scripts/kconfig/symbol.c | 3 +--
2 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index f88d90f..3073cb6 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -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;
}
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 7caabdb..3f7797b 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -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)
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [PATCH v2] kconfig: Deletion of unnecessary checks before the function call "sym_calc_value"
@ 2014-11-03 18:40 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-03 18:40 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Acked-by: Paul Bolle <pebolle@tiscali.nl>
---
scripts/kconfig/confdata.c | 6 ++----
scripts/kconfig/symbol.c | 3 +--
2 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index f88d90f..3073cb6 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -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;
}
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 7caabdb..3f7797b 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -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)
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Cocci] [PATCH v2] kconfig: Deletion of unnecessary checks before the function call "sym_calc_value"
@ 2014-11-03 18:40 ` SF Markus Elfring
0 siblings, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-03 18:40 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Acked-by: Paul Bolle <pebolle@tiscali.nl>
---
scripts/kconfig/confdata.c | 6 ++----
scripts/kconfig/symbol.c | 3 +--
2 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index f88d90f..3073cb6 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -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;
}
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 7caabdb..3f7797b 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -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)
--
2.1.3
^ permalink raw reply related [flat|nested] 3619+ messages in thread
* [Cocci] Are defensive checks treated differently in specific areas?
2014-11-03 17:05 ` [Cocci] " Derek M Jones
2014-11-03 17:32 ` Julia Lawall
@ 2014-11-03 21:30 ` SF Markus Elfring
1 sibling, 0 replies; 3619+ messages in thread
From: SF Markus Elfring @ 2014-11-03 21:30 UTC (permalink / raw)
To: cocci
>> 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
^ permalink raw reply [flat|nested] 3619+ messages in thread
* Re: [PATCH 1/1] PCI: Deletion of unnecessary checks before three function calls
2014-11-02 15:12 ` SF Markus Elfring
(?)
@ 2014-11-11 4:07 ` Bjorn Helgaas
-1 siblings, 0 replies; 3619+ messages in thread
From: Bjorn Helgaas @ 2014-11-11 4:07 UTC (permalink / raw)
To: SF Markus Elfring
Cc: Boris Ostrovsky, David Vrabel, Konrad Rzeszutek Wilk, Len Brown,
Rafael J. Wysocki, linux-pci, linux-acpi, linux-kernel,
xen-devel, kernel-janitors, trivial, Coccinelle
On Sun, Nov 02, 2014 at 04:12:30PM +0100, SF Markus Elfring wrote:
> The 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 t