* [Cocci] [coccicheck Linux 3.14-rc5 PATCH 1 of 5] Deletion of unnecessary checks before specific function calls
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
@ 2014-03-05 22:48 ` SF Markus Elfring
2014-03-05 22:50 ` [Cocci] [coccicheck Linux 3.14-rc5 PATCH 2 " SF Markus Elfring
` (52 subsequent siblings)
53 siblings, 0 replies; 268+ 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] 268+ 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:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
2014-03-05 22:48 ` [Cocci] [coccicheck Linux 3.14-rc5 PATCH 1 of 5] " SF Markus Elfring
@ 2014-03-05 22:50 ` SF Markus Elfring
2014-03-05 22:52 ` [Cocci] [coccicheck Linux 3.14-rc5 PATCH 3 " SF Markus Elfring
` (51 subsequent siblings)
53 siblings, 0 replies; 268+ 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] 268+ 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:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
2014-03-05 22:48 ` [Cocci] [coccicheck Linux 3.14-rc5 PATCH 1 of 5] " SF Markus Elfring
2014-03-05 22:50 ` [Cocci] [coccicheck Linux 3.14-rc5 PATCH 2 " SF Markus Elfring
@ 2014-03-05 22:52 ` SF Markus Elfring
2014-03-05 22:55 ` [Cocci] [coccicheck Linux 3.14-rc5 PATCH 4 " SF Markus Elfring
` (50 subsequent siblings)
53 siblings, 0 replies; 268+ 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] 268+ 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:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (2 preceding siblings ...)
2014-03-05 22:52 ` [Cocci] [coccicheck Linux 3.14-rc5 PATCH 3 " SF Markus Elfring
@ 2014-03-05 22:55 ` SF Markus Elfring
2014-03-05 22:58 ` [Cocci] [coccicheck Linux 3.14-rc5 PATCH 5 " SF Markus Elfring
` (49 subsequent siblings)
53 siblings, 0 replies; 268+ 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] 268+ 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:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (3 preceding siblings ...)
2014-03-05 22:55 ` [Cocci] [coccicheck Linux 3.14-rc5 PATCH 4 " SF Markus Elfring
@ 2014-03-05 22:58 ` SF Markus Elfring
2014-10-01 13:01 ` [Cocci] [PATCH with Coccinelle?] " SF Markus Elfring
` (48 subsequent siblings)
53 siblings, 0 replies; 268+ 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] 268+ messages in thread* [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (4 preceding siblings ...)
2014-03-05 22:58 ` [Cocci] [coccicheck Linux 3.14-rc5 PATCH 5 " SF Markus Elfring
@ 2014-10-01 13:01 ` SF Markus Elfring
2014-10-01 14:06 ` [Cocci] [coccicheck PATCH 1/5] " SF Markus Elfring
` (4 more replies)
2014-10-22 14:30 ` [Cocci] [PATCH 1/1] GPU-DRM-nouveau: Deletion of unnecessary checks before two " SF Markus Elfring
` (47 subsequent siblings)
53 siblings, 5 replies; 268+ 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] 268+ messages in thread* [Cocci] [coccicheck PATCH 1/5] Deletion of unnecessary checks before specific function calls
2014-10-01 13:01 ` [Cocci] [PATCH with Coccinelle?] " SF Markus Elfring
@ 2014-10-01 14:06 ` SF Markus Elfring
2014-10-01 14:06 ` [Cocci] [coccicheck PATCH 2/5] " SF Markus Elfring
` (3 subsequent siblings)
4 siblings, 0 replies; 268+ 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] 268+ messages in thread* [Cocci] [coccicheck PATCH 2/5] Deletion of unnecessary checks before specific function calls
2014-10-01 13:01 ` [Cocci] [PATCH with Coccinelle?] " SF Markus Elfring
2014-10-01 14:06 ` [Cocci] [coccicheck PATCH 1/5] " SF Markus Elfring
@ 2014-10-01 14:06 ` SF Markus Elfring
2014-10-01 14:06 ` [Cocci] [coccicheck PATCH 3/5] " SF Markus Elfring
` (2 subsequent siblings)
4 siblings, 0 replies; 268+ 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] 268+ messages in thread* [Cocci] [coccicheck PATCH 3/5] Deletion of unnecessary checks before specific function calls
2014-10-01 13:01 ` [Cocci] [PATCH with Coccinelle?] " SF Markus Elfring
2014-10-01 14:06 ` [Cocci] [coccicheck PATCH 1/5] " SF Markus Elfring
2014-10-01 14:06 ` [Cocci] [coccicheck PATCH 2/5] " SF Markus Elfring
@ 2014-10-01 14:06 ` SF Markus Elfring
2014-10-01 14:07 ` [Cocci] [coccicheck PATCH 4/5] " SF Markus Elfring
2014-10-01 14:07 ` [Cocci] [coccicheck PATCH 5/5] " SF Markus Elfring
4 siblings, 0 replies; 268+ 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] 268+ messages in thread
* [Cocci] [coccicheck PATCH 4/5] Deletion of unnecessary checks before specific function calls
2014-10-01 13:01 ` [Cocci] [PATCH with Coccinelle?] " SF Markus Elfring
` (2 preceding siblings ...)
2014-10-01 14:06 ` [Cocci] [coccicheck PATCH 3/5] " SF Markus Elfring
@ 2014-10-01 14:07 ` SF Markus Elfring
2014-10-01 14:07 ` [Cocci] [coccicheck PATCH 5/5] " SF Markus Elfring
4 siblings, 0 replies; 268+ 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] 268+ messages in thread* [Cocci] [coccicheck PATCH 5/5] Deletion of unnecessary checks before specific function calls
2014-10-01 13:01 ` [Cocci] [PATCH with Coccinelle?] " SF Markus Elfring
` (3 preceding siblings ...)
2014-10-01 14:07 ` [Cocci] [coccicheck PATCH 4/5] " SF Markus Elfring
@ 2014-10-01 14:07 ` SF Markus Elfring
4 siblings, 0 replies; 268+ 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] 268+ messages in thread
* [Cocci] [PATCH 1/1] GPU-DRM-nouveau: Deletion of unnecessary checks before two function calls
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (5 preceding siblings ...)
2014-10-01 13:01 ` [Cocci] [PATCH with Coccinelle?] " SF Markus Elfring
@ 2014-10-22 14:30 ` SF Markus Elfring
2014-10-22 16:48 ` [Cocci] [PATCH 1/1] GPU-DRM-GMA500: " SF Markus Elfring
` (46 subsequent siblings)
53 siblings, 0 replies; 268+ 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] 268+ messages in thread* [Cocci] [PATCH 1/1] GPU-DRM-GMA500: Deletion of unnecessary checks before two function calls
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (6 preceding siblings ...)
2014-10-22 14:30 ` [Cocci] [PATCH 1/1] GPU-DRM-nouveau: Deletion of unnecessary checks before two " SF Markus Elfring
@ 2014-10-22 16:48 ` SF Markus Elfring
2014-10-23 11:26 ` One Thousand Gnomes
2014-10-22 18:00 ` [Cocci] [PATCH 1/1] IOMMU-MSM: Deletion of unnecessary checks before the function call "clk_disable" SF Markus Elfring
` (45 subsequent siblings)
53 siblings, 1 reply; 268+ 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] 268+ messages in thread* [Cocci] [PATCH 1/1] GPU-DRM-GMA500: Deletion of unnecessary checks before two function calls
2014-10-22 16:48 ` [Cocci] [PATCH 1/1] GPU-DRM-GMA500: " SF Markus Elfring
@ 2014-10-23 11:26 ` One Thousand Gnomes
2014-10-26 12:10 ` SF Markus Elfring
0 siblings, 1 reply; 268+ 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] 268+ 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
@ 2014-10-26 12:10 ` SF Markus Elfring
2014-10-26 14:56 ` Arthur Borsboom
0 siblings, 1 reply; 268+ 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] 268+ 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
0 siblings, 0 replies; 268+ 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] 268+ messages in thread
* [Cocci] [PATCH 1/1] IOMMU-MSM: Deletion of unnecessary checks before the function call "clk_disable"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (7 preceding siblings ...)
2014-10-22 16:48 ` [Cocci] [PATCH 1/1] GPU-DRM-GMA500: " SF Markus Elfring
@ 2014-10-22 18:00 ` SF Markus Elfring
2014-10-23 12:51 ` Jörg Rödel
2014-10-22 18:55 ` [Cocci] [PATCH 1/1] SCSI-QLA2XXX: Deletion of unnecessary checks before the function call "vfree" SF Markus Elfring
` (44 subsequent siblings)
53 siblings, 1 reply; 268+ 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] 268+ messages in thread* [Cocci] [PATCH 1/1] SCSI-QLA2XXX: Deletion of unnecessary checks before the function call "vfree"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (8 preceding siblings ...)
2014-10-22 18:00 ` [Cocci] [PATCH 1/1] IOMMU-MSM: Deletion of unnecessary checks before the function call "clk_disable" SF Markus Elfring
@ 2014-10-22 18:55 ` SF Markus Elfring
2014-10-22 19:10 ` [Cocci] [PATCH 1/1] SCSI-QLA2...: " SF Markus Elfring
` (43 subsequent siblings)
53 siblings, 0 replies; 268+ 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] 268+ messages in thread* [Cocci] [PATCH 1/1] SCSI-QLA2...: Deletion of unnecessary checks before the function call "vfree"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (9 preceding siblings ...)
2014-10-22 18:55 ` [Cocci] [PATCH 1/1] SCSI-QLA2XXX: Deletion of unnecessary checks before the function call "vfree" SF Markus Elfring
@ 2014-10-22 19:10 ` SF Markus Elfring
2014-10-23 19:20 ` [Cocci] [PATCH 1/1] staging - rtl8188eu: Deletion of unnecessary checks before three function calls SF Markus Elfring
` (42 subsequent siblings)
53 siblings, 0 replies; 268+ 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] 268+ messages in thread* [Cocci] [PATCH 1/1] staging - rtl8188eu: Deletion of unnecessary checks before three function calls
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (10 preceding siblings ...)
2014-10-22 19:10 ` [Cocci] [PATCH 1/1] SCSI-QLA2...: " SF Markus Elfring
@ 2014-10-23 19:20 ` SF Markus Elfring
2014-10-29 8:47 ` Greg Kroah-Hartman
2014-10-31 17:40 ` [Cocci] [PATCH 1/1] s390/net: Deletion of unnecessary checks before two function calls SF Markus Elfring
` (41 subsequent siblings)
53 siblings, 1 reply; 268+ 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] 268+ messages in thread* [Cocci] [PATCH 1/1] staging - rtl8188eu: Deletion of unnecessary checks before three function calls
2014-10-23 19:20 ` [Cocci] [PATCH 1/1] staging - rtl8188eu: Deletion of unnecessary checks before three function calls SF Markus Elfring
@ 2014-10-29 8:47 ` Greg Kroah-Hartman
2014-10-31 17:55 ` [Cocci] [PATCH resent] staging: " SF Markus Elfring
0 siblings, 1 reply; 268+ 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] 268+ messages in thread
* [Cocci] [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
2014-10-31 18:01 ` Julia Lawall
0 siblings, 1 reply; 268+ 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] 268+ messages in thread* [Cocci] [PATCH resent] staging: rtl8188eu: Deletion of unnecessary checks before three function calls
2014-10-31 17:55 ` [Cocci] [PATCH resent] staging: " SF Markus Elfring
@ 2014-10-31 18:01 ` Julia Lawall
2014-10-31 18:08 ` SF Markus Elfring
2014-11-12 20:20 ` [Cocci] [PATCH v2 0/2] staging: rtl8188eu: Deletion of a few unnecessary checks SF Markus Elfring
0 siblings, 2 replies; 268+ 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] 268+ messages in thread* [Cocci] [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
2014-10-31 18:11 ` Julia Lawall
2014-11-12 20:20 ` [Cocci] [PATCH v2 0/2] staging: rtl8188eu: Deletion of a few unnecessary checks SF Markus Elfring
1 sibling, 1 reply; 268+ 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] 268+ messages in thread
* [Cocci] [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
2014-11-12 10:51 ` [Cocci] [PATCH with SmPL?] staging: rtl8188eu: Adjustments around jump labels SF Markus Elfring
0 siblings, 1 reply; 268+ 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] 268+ messages in thread
* [Cocci] [PATCH with SmPL?] staging: rtl8188eu: Adjustments around jump labels
2014-10-31 18:11 ` Julia Lawall
@ 2014-11-12 10:51 ` SF Markus Elfring
0 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-12 10:51 UTC (permalink / raw)
To: cocci
>>>> @@ -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.
Now I have got a different impression for corresponding improvement possibilities.
elfring at Sonne:~/Projekte/Linux/stable-patched> spatch.opt -debug -sp-file ~/Projekte/Coccinelle/janitor/move_function_call_before_jump_label1.cocci drivers/staging/rtl8188eu/core/rtw_efuse.c
init_defs_builtins: /usr/local/share/coccinelle/standard.h
-----------------------------------------------------------------------
processing semantic patch file: /home/elfring/Projekte/Coccinelle/janitor/move_function_call_before_jump_label1.cocci
with isos from: /usr/local/share/coccinelle/standard.iso
-----------------------------------------------------------------------
@move_function_call_before_jump_label@
expression x;
identifier fu, label;
type t;
@@
t fu(...)
{
... when any
x = kzalloc(...);
if (x == NULL) {
...
goto label;
}
... when any
+ kfree(x);
label:
- kfree(x);
...
}
HANDLING: drivers/staging/rtl8188eu/core/rtw_efuse.c
-----------------------------------------------------------------------
let's go
-----------------------------------------------------------------------
-----------------------------------------------------------------------
-----------------------------------------------------------------------
move_function_call_before_jump_label =
-----------------------------------------------------------------------
dependencies for rule move_function_call_before_jump_label satisfied:
binding in = []
binding relevant in = []
(ONCE) USING optional_storage builtin isomorphism
transformation info returned:
transform state: 5
with rule_elem:
<<< kfree(move_function_call_before_jump_label:x);
move_function_call_before_jump_label:label:
with binding: [move_function_call_before_jump_label.x --> efuseTbl]
transform state: 204
with rule_elem: -kfree-(-move_function_call_before_jump_label:x-)-;
with binding: [move_function_call_before_jump_label.x --> efuseTbl]
binding out = []
transform one node: 204
transform one node: 5
-----------------------------------------------------------------------
Finished
-----------------------------------------------------------------------
diff =
--- drivers/staging/rtl8188eu/core/rtw_efuse.c
+++ /tmp/cocci-output-4498-349827-rtw_efuse.c
@@ -209,8 +209,8 @@ efuse_phymap_to_logical(u8 *phymap, u16
/* 5. Calculate Efuse utilization. */
/* */
+kfree(efuseTbl);
exit:
- kfree(efuseTbl);
kfree(eFuseWord);
}
Check duplication for 1 files
Can my update suggestion be generalised a bit more for the movement of specific jump labels
towards the end of a function implementation like in the use case "efuse_phymap_to_logical()"?
Regards,
Markus
^ permalink raw reply [flat|nested] 268+ messages in thread
* [Cocci] [PATCH v2 0/2] staging: rtl8188eu: Deletion of a few unnecessary checks
2014-10-31 18:01 ` Julia Lawall
2014-10-31 18:08 ` SF Markus Elfring
@ 2014-11-12 20:20 ` SF Markus Elfring
2014-11-12 20:25 ` [Cocci] [PATCH v2 1/2] staging: rtl8188eu: Deletion of unnecessary checks before three function calls SF Markus Elfring
2014-11-12 20:30 ` [Cocci] [PATCH v2 2/2] staging: rtl8188eu: Better memory clean-up in efuse_phymap_to_logical() SF Markus Elfring
1 sibling, 2 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-12 20:20 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 12 Nov 2014 20:42:18 +0100
Another update suggestion was taken into account after patches were applied
from static source code analysis.
Markus Elfring (2):
staging: rtl8188eu: Deletion of unnecessary checks before three
function calls
staging: rtl8188eu: Better memory clean-up in efuse_phymap_to_logical()
drivers/staging/rtl8188eu/core/rtw_efuse.c | 13 ++++++++-----
drivers/staging/rtl8188eu/core/rtw_mlme.c | 3 +--
drivers/staging/rtl8188eu/core/rtw_sta_mgt.c | 3 +--
drivers/staging/rtl8188eu/core/rtw_xmit.c | 6 ++----
drivers/staging/rtl8188eu/os_dep/usb_intf.c | 6 +++---
5 files changed, 15 insertions(+), 16 deletions(-)
--
2.1.3
^ permalink raw reply [flat|nested] 268+ messages in thread* [Cocci] [PATCH v2 1/2] staging: rtl8188eu: Deletion of unnecessary checks before three function calls
2014-11-12 20:20 ` [Cocci] [PATCH v2 0/2] staging: rtl8188eu: Deletion of a few unnecessary checks SF Markus Elfring
@ 2014-11-12 20:25 ` SF Markus Elfring
2014-11-12 21:18 ` Dan Carpenter
2014-11-13 8:47 ` Julia Lawall
2014-11-12 20:30 ` [Cocci] [PATCH v2 2/2] staging: rtl8188eu: Better memory clean-up in efuse_phymap_to_logical() SF Markus Elfring
1 sibling, 2 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-12 20:25 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 12 Nov 2014 20:25:49 +0100
The functions kfree(), rtw_free_netdev() and vfree() test whether their
argument is NULL and then return immediately. Thus the test around the call
is not needed.
This issue was detected by using the Coccinelle software.
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 | 6 +++---
5 files changed, 8 insertions(+), 13 deletions(-)
diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c b/drivers/staging/rtl8188eu/core/rtw_efuse.c
index 5b997b2..697876b 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..4e2c34b 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
@@ -456,8 +456,9 @@ free_adapter:
if (status != _SUCCESS) {
if (pnetdev)
rtw_free_netdev(pnetdev);
- else if (padapter)
+ else
vfree(padapter);
+
padapter = NULL;
}
exit:
@@ -487,8 +488,7 @@ static void rtw_usb_if1_deinit(struct adapter *if1)
DBG_88E("+r871xu_dev_remove, hw_init_completed=%d\n",
if1->hw_init_completed);
rtw_free_drv_sw(if1);
- if (pnetdev)
- rtw_free_netdev(pnetdev);
+ rtw_free_netdev(pnetdev);
}
static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device_id *pdid)
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH v2 1/2] staging: rtl8188eu: Deletion of unnecessary checks before three function calls
2014-11-12 20:25 ` [Cocci] [PATCH v2 1/2] staging: rtl8188eu: Deletion of unnecessary checks before three function calls SF Markus Elfring
@ 2014-11-12 21:18 ` Dan Carpenter
2014-11-12 21:28 ` SF Markus Elfring
2014-11-13 8:47 ` Julia Lawall
1 sibling, 1 reply; 268+ messages in thread
From: Dan Carpenter @ 2014-11-12 21:18 UTC (permalink / raw)
To: cocci
On Wed, Nov 12, 2014 at 09:25:15PM +0100, SF Markus Elfring wrote:
> @@ -487,8 +488,7 @@ static void rtw_usb_if1_deinit(struct adapter *if1)
> DBG_88E("+r871xu_dev_remove, hw_init_completed=%d\n",
> if1->hw_init_completed);
> rtw_free_drv_sw(if1);
> - if (pnetdev)
> - rtw_free_netdev(pnetdev);
> + rtw_free_netdev(pnetdev);
I still feel that hiding the if statement inside the function call makes
the code more subtle and it is a bad harmful thing to do. This is
especially true if you have trained yourself to know that free_netdev()
can't accept NULL pointers.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 268+ messages in thread* [Cocci] [PATCH v2 1/2] staging: rtl8188eu: Deletion of unnecessary checks before three function calls
2014-11-12 21:18 ` Dan Carpenter
@ 2014-11-12 21:28 ` SF Markus Elfring
2014-11-12 21:40 ` Julia Lawall
2014-11-12 22:08 ` Dan Carpenter
0 siblings, 2 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-12 21:28 UTC (permalink / raw)
To: cocci
>> @@ -487,8 +488,7 @@ static void rtw_usb_if1_deinit(struct adapter *if1)
>> DBG_88E("+r871xu_dev_remove, hw_init_completed=%d\n",
>> if1->hw_init_completed);
>> rtw_free_drv_sw(if1);
>> - if (pnetdev)
>> - rtw_free_netdev(pnetdev);
>> + rtw_free_netdev(pnetdev);
>
> I still feel that hiding the if statement inside the function call makes
> the code more subtle and it is a bad harmful thing to do.
I find your feedback interesting.
> This is especially true if you have trained yourself to know that
> free_netdev() can't accept NULL pointers.
Do you need to adjust your concerns a bit over time when function variants
provide a corresponding safety check in their implementations?
Regards,
Markus
^ permalink raw reply [flat|nested] 268+ messages in thread* [Cocci] [PATCH v2 1/2] staging: rtl8188eu: Deletion of unnecessary checks before three function calls
2014-11-12 21:28 ` SF Markus Elfring
@ 2014-11-12 21:40 ` Julia Lawall
2014-11-12 22:08 ` Dan Carpenter
1 sibling, 0 replies; 268+ messages in thread
From: Julia Lawall @ 2014-11-12 21:40 UTC (permalink / raw)
To: cocci
> > This is especially true if you have trained yourself to know that
> > free_netdev() can't accept NULL pointers.
>
> Do you need to adjust your concerns a bit over time when function variants
> provide a corresponding safety check in their implementations?
There would not seem to be any _need_ to do so. An unnecessary null test
is always safe. The only real problem that I can see with an unnecessary
null test in error handling code (intrinsically not critical performance
wise) is if it gives the illusion that a value can be null when it cannot.
julia
^ permalink raw reply [flat|nested] 268+ messages in thread
* [Cocci] [PATCH v2 1/2] staging: rtl8188eu: Deletion of unnecessary checks before three function calls
2014-11-12 21:28 ` SF Markus Elfring
2014-11-12 21:40 ` Julia Lawall
@ 2014-11-12 22:08 ` Dan Carpenter
1 sibling, 0 replies; 268+ messages in thread
From: Dan Carpenter @ 2014-11-12 22:08 UTC (permalink / raw)
To: cocci
On Wed, Nov 12, 2014 at 10:28:41PM +0100, SF Markus Elfring wrote:
> > This is especially true if you have trained yourself to know that
> > free_netdev() can't accept NULL pointers.
>
> Do you need to adjust your concerns a bit over time when function variants
> provide a corresponding safety check in their implementations?
No. Really, free_netdev vs rtw_free_netdev is just an example where it
is really bad, but I feel that all of these patches are misguided and
harmful.
We should have an if statement if the allocation is optional, we should
not have an if statement if the allocation is required.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 268+ messages in thread
* [Cocci] [PATCH v2 1/2] staging: rtl8188eu: Deletion of unnecessary checks before three function calls
2014-11-12 20:25 ` [Cocci] [PATCH v2 1/2] staging: rtl8188eu: Deletion of unnecessary checks before three function calls SF Markus Elfring
2014-11-12 21:18 ` Dan Carpenter
@ 2014-11-13 8:47 ` Julia Lawall
1 sibling, 0 replies; 268+ messages in thread
From: Julia Lawall @ 2014-11-13 8:47 UTC (permalink / raw)
To: cocci
On Wed, 12 Nov 2014, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 12 Nov 2014 20:25:49 +0100
>
> The functions kfree(), rtw_free_netdev() and vfree() test whether their
> argument is NULL and then return immediately. Thus the test around the call
> is not needed.
>
> This issue was detected by using the Coccinelle software.
>
> 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 | 6 +++---
> 5 files changed, 8 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c b/drivers/staging/rtl8188eu/core/rtw_efuse.c
> index 5b997b2..697876b 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);
> }
As far as I can tell, the 2/2 patch in this series proposes a completely
different fix for this code. When you send a series, patch n+1/m is
supposed to apply to the result of patch n/m.
In any case, you can let this one go, because the problem has been fixed
already.
julia
^ permalink raw reply [flat|nested] 268+ messages in thread
* [Cocci] [PATCH v2 2/2] staging: rtl8188eu: Better memory clean-up in efuse_phymap_to_logical()
2014-11-12 20:20 ` [Cocci] [PATCH v2 0/2] staging: rtl8188eu: Deletion of a few unnecessary checks SF Markus Elfring
2014-11-12 20:25 ` [Cocci] [PATCH v2 1/2] staging: rtl8188eu: Deletion of unnecessary checks before three function calls SF Markus Elfring
@ 2014-11-12 20:30 ` SF Markus Elfring
2014-11-12 21:14 ` Dan Carpenter
2014-11-13 8:43 ` Julia Lawall
1 sibling, 2 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-12 20:30 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 12 Nov 2014 20:40:12 +0100
Memory releases were handled in an inefficient way by the implementation of
the efuse_phymap_to_logical() function in case of an allocation failure.
The corresponding clean-up was improved by reordering of kfree() calls
and a few adjustments for jump labels.
Reported-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/staging/rtl8188eu/core/rtw_efuse.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c b/drivers/staging/rtl8188eu/core/rtw_efuse.c
index 697876b..359f169 100644
--- a/drivers/staging/rtl8188eu/core/rtw_efuse.c
+++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c
@@ -112,7 +112,7 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf)
eFuseWord = (u16 **)rtw_malloc2d(EFUSE_MAX_SECTION_88E, EFUSE_MAX_WORD_UNIT, sizeof(u16));
if (eFuseWord == NULL) {
DBG_88E("%s: alloc eFuseWord fail!\n", __func__);
- goto exit;
+ goto cleanup1;
}
/* 0. Refresh efuse init map as all oxFF. */
@@ -130,7 +130,7 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf)
eFuse_Addr++;
} else {
DBG_88E("EFUSE is empty efuse_Addr-%d efuse_data =%x\n", eFuse_Addr, rtemp8);
- goto exit;
+ goto cleanup2;
}
/* */
@@ -209,10 +209,14 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf)
/* 5. Calculate Efuse utilization. */
/* */
-exit:
+cleanup2:
+ kfree(eFuseWord);
+
+cleanup1:
kfree(efuseTbl);
- kfree(eFuseWord);
+exit:
+ ;
}
static void efuse_read_phymap_from_txpktbuf(
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH v2 2/2] staging: rtl8188eu: Better memory clean-up in efuse_phymap_to_logical()
2014-11-12 20:30 ` [Cocci] [PATCH v2 2/2] staging: rtl8188eu: Better memory clean-up in efuse_phymap_to_logical() SF Markus Elfring
@ 2014-11-12 21:14 ` Dan Carpenter
2014-11-12 21:50 ` SF Markus Elfring
2014-11-13 8:43 ` Julia Lawall
1 sibling, 1 reply; 268+ messages in thread
From: Dan Carpenter @ 2014-11-12 21:14 UTC (permalink / raw)
To: cocci
On Wed, Nov 12, 2014 at 09:30:43PM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
Please fix your email client instead.
> + goto cleanup1;
1) Don't use GW-BASIC label names. Label names should reflect what the
label does such as free_fuse_word or free_fuse_tabel.
2) Don't use do-nothing labels. Just return directly.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 268+ messages in thread
* [Cocci] [PATCH v2 2/2] staging: rtl8188eu: Better memory clean-up in efuse_phymap_to_logical()
2014-11-12 21:14 ` Dan Carpenter
@ 2014-11-12 21:50 ` SF Markus Elfring
2014-11-12 22:05 ` Dan Carpenter
0 siblings, 1 reply; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-12 21:50 UTC (permalink / raw)
To: cocci
>> + goto cleanup1;
>
> 1) Don't use GW-BASIC label names. Label names should reflect what the
> label does such as free_fuse_word or free_fuse_tabel.
>
> 2) Don't use do-nothing labels. Just return directly.
Does the document "CodingStyle" need any extensions for special cases?
Are there any update candidates in the chapter "7: Centralized exiting of functions"?
Regards,
Markus
^ permalink raw reply [flat|nested] 268+ messages in thread
* [Cocci] [PATCH v2 2/2] staging: rtl8188eu: Better memory clean-up in efuse_phymap_to_logical()
2014-11-12 21:50 ` SF Markus Elfring
@ 2014-11-12 22:05 ` Dan Carpenter
2014-11-13 8:50 ` SF Markus Elfring
0 siblings, 1 reply; 268+ messages in thread
From: Dan Carpenter @ 2014-11-12 22:05 UTC (permalink / raw)
To: cocci
On Wed, Nov 12, 2014 at 10:50:37PM +0100, SF Markus Elfring wrote:
> >> + goto cleanup1;
> >
> > 1) Don't use GW-BASIC label names. Label names should reflect what the
> > label does such as free_fuse_word or free_fuse_tabel.
> >
> > 2) Don't use do-nothing labels. Just return directly.
>
> Does the document "CodingStyle" need any extensions for special cases?
I don't understand.
> Are there any update candidates in the chapter "7: Centralized exiting of functions"?
CodingStyle says:
"If there is no cleanup needed then just return directly."
What is not clear about that?
regards,
dan carpenter
^ permalink raw reply [flat|nested] 268+ messages in thread
* [Cocci] [PATCH v2 2/2] staging: rtl8188eu: Better memory clean-up in efuse_phymap_to_logical()
2014-11-12 22:05 ` Dan Carpenter
@ 2014-11-13 8:50 ` SF Markus Elfring
0 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-13 8:50 UTC (permalink / raw)
To: cocci
>>>> + goto cleanup1;
>>>
>>> 1) Don't use GW-BASIC label names. Label names should reflect what the
>>> label does such as free_fuse_word or free_fuse_tabel.
>>>
>>> 2) Don't use do-nothing labels. Just return directly.
>>
>> Does the document "CodingStyle" need any extensions for special cases?
>
> I don't understand.
Should the naming convention become more explicit for jump labels?
> CodingStyle says:
>
> "If there is no cleanup needed then just return directly."
Do you want that I send another update suggestion with other corrections
for jump labels in the affected function implementation?
Regards,
Markus
^ permalink raw reply [flat|nested] 268+ messages in thread
* [Cocci] [PATCH v2 2/2] staging: rtl8188eu: Better memory clean-up in efuse_phymap_to_logical()
2014-11-12 20:30 ` [Cocci] [PATCH v2 2/2] staging: rtl8188eu: Better memory clean-up in efuse_phymap_to_logical() SF Markus Elfring
2014-11-12 21:14 ` Dan Carpenter
@ 2014-11-13 8:43 ` Julia Lawall
2014-11-13 9:33 ` SF Markus Elfring
1 sibling, 1 reply; 268+ messages in thread
From: Julia Lawall @ 2014-11-13 8:43 UTC (permalink / raw)
To: cocci
> diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c b/drivers/staging/rtl8188eu/core/rtw_efuse.c
> index 697876b..359f169 100644
> --- a/drivers/staging/rtl8188eu/core/rtw_efuse.c
> +++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c
[...]
> -exit:
> +cleanup2:
> + kfree(eFuseWord);
> +
> +cleanup1:
> kfree(efuseTbl);
>
> - kfree(eFuseWord);
> +exit:
> + ;
> }
You are not using the most recent version of the code. The issue has
already been fixed. Concretely, this part of the function now reads:
exit:
kfree(eFuseWord);
eFuseWord_failed:
kfree(efuseTbl);
julia
^ permalink raw reply [flat|nested] 268+ messages in thread
* [Cocci] [PATCH 1/1] s390/net: Deletion of unnecessary checks before two function calls
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (11 preceding siblings ...)
2014-10-23 19:20 ` [Cocci] [PATCH 1/1] staging - rtl8188eu: Deletion of unnecessary checks before three function calls SF Markus Elfring
@ 2014-10-31 17:40 ` SF Markus Elfring
2014-11-03 9:50 ` Dan Carpenter
2014-11-03 11:04 ` [Cocci] [PATCH 1/1] s390/net: Deletion of unnecessary checks before two function calls Ursula Braun
2014-10-31 21:52 ` [Cocci] [PATCH 1/1] btrfs: Deletion of unnecessary checks before six " SF Markus Elfring
` (40 subsequent siblings)
53 siblings, 2 replies; 268+ 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] 268+ messages in thread* [Cocci] [PATCH 1/1] s390/net: Deletion of unnecessary checks before two function calls
2014-10-31 17:40 ` [Cocci] [PATCH 1/1] s390/net: Deletion of unnecessary checks before two function calls SF Markus Elfring
@ 2014-11-03 9:50 ` Dan Carpenter
2014-11-03 15:55 ` [Cocci] " SF Markus Elfring
2014-11-03 11:04 ` [Cocci] [PATCH 1/1] s390/net: Deletion of unnecessary checks before two function calls Ursula Braun
1 sibling, 1 reply; 268+ 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] 268+ messages in thread
* [Cocci] 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
2014-11-03 16:25 ` Dan Carpenter
0 siblings, 1 reply; 268+ 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] 268+ messages in thread
* [Cocci] s390/net: Deletion of unnecessary checks before two function calls
2014-11-03 15:55 ` [Cocci] " SF Markus Elfring
@ 2014-11-03 16:25 ` Dan Carpenter
2014-11-03 16:50 ` SF Markus Elfring
2014-11-03 17:05 ` Derek M Jones
0 siblings, 2 replies; 268+ 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] 268+ messages in thread
* [Cocci] 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
2014-11-03 17:02 ` Julia Lawall
2014-11-03 17:16 ` Dan Carpenter
2014-11-03 17:05 ` Derek M Jones
1 sibling, 2 replies; 268+ 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] 268+ messages in thread
* [Cocci] 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
2014-11-03 17:16 ` Dan Carpenter
1 sibling, 0 replies; 268+ 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] 268+ messages in thread
* [Cocci] 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
@ 2014-11-03 17:16 ` Dan Carpenter
2014-11-03 17:40 ` SF Markus Elfring
1 sibling, 1 reply; 268+ 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] 268+ messages in thread
* [Cocci] 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
0 siblings, 0 replies; 268+ 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] 268+ messages in thread
* [Cocci] 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
@ 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 sibling, 2 replies; 268+ 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] 268+ messages in thread
* [Cocci] s390/net: Deletion of unnecessary checks before two function calls
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 sibling, 0 replies; 268+ 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] 268+ messages in thread
* [Cocci] Are defensive checks treated differently in specific areas?
2014-11-03 17:05 ` Derek M Jones
2014-11-03 17:32 ` Julia Lawall
@ 2014-11-03 21:30 ` SF Markus Elfring
1 sibling, 0 replies; 268+ 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] 268+ messages in thread
* [Cocci] [PATCH 1/1] s390/net: Deletion of unnecessary checks before two function calls
2014-10-31 17:40 ` [Cocci] [PATCH 1/1] s390/net: Deletion of unnecessary checks before two function calls SF Markus Elfring
2014-11-03 9:50 ` Dan Carpenter
@ 2014-11-03 11:04 ` Ursula Braun
2014-11-03 16:10 ` [Cocci] " SF Markus Elfring
1 sibling, 1 reply; 268+ 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] 268+ messages in thread
* [Cocci] [PATCH 1/1] btrfs: Deletion of unnecessary checks before six function calls
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (12 preceding siblings ...)
2014-10-31 17:40 ` [Cocci] [PATCH 1/1] s390/net: Deletion of unnecessary checks before two function calls SF Markus Elfring
@ 2014-10-31 21:52 ` SF Markus Elfring
2014-10-31 21:59 ` Julia Lawall
2014-11-02 9:40 ` [Cocci] [PATCH 1/1] ocfs2: Deletion of unnecessary checks before two " SF Markus Elfring
` (39 subsequent siblings)
53 siblings, 1 reply; 268+ 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] 268+ messages in thread* [Cocci] [PATCH 1/1] btrfs: Deletion of unnecessary checks before six function calls
2014-10-31 21:52 ` [Cocci] [PATCH 1/1] btrfs: Deletion of unnecessary checks before six " SF Markus Elfring
@ 2014-10-31 21:59 ` Julia Lawall
0 siblings, 0 replies; 268+ 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] 268+ messages in thread
* [Cocci] [PATCH 1/1] ocfs2: Deletion of unnecessary checks before two function calls
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (13 preceding siblings ...)
2014-10-31 21:52 ` [Cocci] [PATCH 1/1] btrfs: Deletion of unnecessary checks before six " SF Markus Elfring
@ 2014-11-02 9:40 ` SF Markus Elfring
2014-11-02 10:51 ` Julia Lawall
2014-11-02 14:20 ` [Cocci] [PATCH 1/1] ceph: " SF Markus Elfring
` (38 subsequent siblings)
53 siblings, 1 reply; 268+ 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] 268+ messages in thread* [Cocci] [PATCH 1/1] ocfs2: Deletion of unnecessary checks before two function calls
2014-11-02 9:40 ` [Cocci] [PATCH 1/1] ocfs2: Deletion of unnecessary checks before two " SF Markus Elfring
@ 2014-11-02 10:51 ` Julia Lawall
0 siblings, 0 replies; 268+ 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] 268+ messages in thread
* [Cocci] [PATCH 1/1] ceph: Deletion of unnecessary checks before two function calls
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (14 preceding siblings ...)
2014-11-02 9:40 ` [Cocci] [PATCH 1/1] ocfs2: Deletion of unnecessary checks before two " SF Markus Elfring
@ 2014-11-02 14:20 ` SF Markus Elfring
2014-11-03 10:35 ` Ilya Dryomov
2014-11-02 15:12 ` [Cocci] [PATCH 1/1] PCI: Deletion of unnecessary checks before three " SF Markus Elfring
` (37 subsequent siblings)
53 siblings, 1 reply; 268+ 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] 268+ messages in thread* [Cocci] [PATCH 1/1] ceph: Deletion of unnecessary checks before two function calls
2014-11-02 14:20 ` [Cocci] [PATCH 1/1] ceph: " SF Markus Elfring
@ 2014-11-03 10:35 ` Ilya Dryomov
2014-11-03 13:27 ` [Cocci] " SF Markus Elfring
0 siblings, 1 reply; 268+ 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] 268+ messages in thread* [Cocci] ceph: Deletion of unnecessary checks before two function calls
2014-11-03 10:35 ` Ilya Dryomov
@ 2014-11-03 13:27 ` SF Markus Elfring
2014-11-03 14:23 ` Ilya Dryomov
0 siblings, 1 reply; 268+ 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] 268+ messages in thread* [Cocci] ceph: Deletion of unnecessary checks before two function calls
2014-11-03 13:27 ` [Cocci] " SF Markus Elfring
@ 2014-11-03 14:23 ` Ilya Dryomov
0 siblings, 0 replies; 268+ 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] 268+ messages in thread
* [Cocci] [PATCH 1/1] PCI: Deletion of unnecessary checks before three function calls
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (15 preceding siblings ...)
2014-11-02 14:20 ` [Cocci] [PATCH 1/1] ceph: " SF Markus Elfring
@ 2014-11-02 15:12 ` SF Markus Elfring
2014-11-11 4:07 ` Bjorn Helgaas
2014-11-02 18:27 ` [Cocci] [PATCH 1/1] PCI: EMU10K1: " SF Markus Elfring
` (36 subsequent siblings)
53 siblings, 1 reply; 268+ 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] 268+ messages in thread* [Cocci] [PATCH 1/1] PCI: Deletion of unnecessary checks before three function calls
2014-11-02 15:12 ` [Cocci] [PATCH 1/1] PCI: Deletion of unnecessary checks before three " SF Markus Elfring
@ 2014-11-11 4:07 ` Bjorn Helgaas
0 siblings, 0 replies; 268+ messages in thread
From: Bjorn Helgaas @ 2014-11-11 4:07 UTC (permalink / raw)
To: cocci
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 the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Applied to pci/misc for v3.19, thanks!
> ---
> 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 [flat|nested] 268+ messages in thread
* [Cocci] [PATCH 1/1] PCI: EMU10K1: Deletion of unnecessary checks before three function calls
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (16 preceding siblings ...)
2014-11-02 15:12 ` [Cocci] [PATCH 1/1] PCI: Deletion of unnecessary checks before three " SF Markus Elfring
@ 2014-11-02 18:27 ` SF Markus Elfring
2014-11-03 9:45 ` Takashi Iwai
2014-11-02 19:42 ` [Cocci] [PATCH 1/1] kconfig: Deletion of unnecessary checks before the function call "sym_calc_value" SF Markus Elfring
` (35 subsequent siblings)
53 siblings, 1 reply; 268+ 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] 268+ messages in thread* [Cocci] [PATCH 1/1] PCI: EMU10K1: Deletion of unnecessary checks before three function calls
2014-11-02 18:27 ` [Cocci] [PATCH 1/1] PCI: EMU10K1: " SF Markus Elfring
@ 2014-11-03 9:45 ` Takashi Iwai
2014-11-03 14:10 ` [Cocci] [PATCH resent] ALSA: emu10k1: " SF Markus Elfring
0 siblings, 1 reply; 268+ 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] 268+ messages in thread
* [Cocci] [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
2014-11-03 14:17 ` Takashi Iwai
0 siblings, 1 reply; 268+ 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] 268+ messages in thread
* [Cocci] [PATCH resent] ALSA: emu10k1: Deletion of unnecessary checks before three function calls
2014-11-03 14:10 ` [Cocci] [PATCH resent] ALSA: emu10k1: " SF Markus Elfring
@ 2014-11-03 14:17 ` Takashi Iwai
0 siblings, 0 replies; 268+ 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] 268+ messages in thread
* [Cocci] [PATCH 1/1] kconfig: Deletion of unnecessary checks before the function call "sym_calc_value"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (17 preceding siblings ...)
2014-11-02 18:27 ` [Cocci] [PATCH 1/1] PCI: EMU10K1: " SF Markus Elfring
@ 2014-11-02 19:42 ` SF Markus Elfring
2014-11-03 10:35 ` Paul Bolle
2014-11-03 18:40 ` [Cocci] [PATCH v2] " SF Markus Elfring
2014-11-15 18:19 ` [Cocci] [PATCH 1/1] fs-ext4: Deletion of an unnecessary check before the function call "iput" SF Markus Elfring
` (34 subsequent siblings)
53 siblings, 2 replies; 268+ 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] 268+ messages in thread* [Cocci] [PATCH 1/1] kconfig: Deletion of unnecessary checks before the function call "sym_calc_value"
2014-11-02 19:42 ` [Cocci] [PATCH 1/1] kconfig: Deletion of unnecessary checks before the function call "sym_calc_value" SF Markus Elfring
@ 2014-11-03 10:35 ` Paul Bolle
2014-11-03 18:40 ` [Cocci] [PATCH v2] " SF Markus Elfring
1 sibling, 0 replies; 268+ 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] 268+ messages in thread* [Cocci] [PATCH v2] kconfig: Deletion of unnecessary checks before the function call "sym_calc_value"
2014-11-02 19:42 ` [Cocci] [PATCH 1/1] kconfig: Deletion of unnecessary checks before the function call "sym_calc_value" SF Markus Elfring
2014-11-03 10:35 ` Paul Bolle
@ 2014-11-03 18:40 ` SF Markus Elfring
1 sibling, 0 replies; 268+ 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] 268+ messages in thread
* [Cocci] [PATCH 1/1] fs-ext4: Deletion of an unnecessary check before the function call "iput"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (18 preceding siblings ...)
2014-11-02 19:42 ` [Cocci] [PATCH 1/1] kconfig: Deletion of unnecessary checks before the function call "sym_calc_value" SF Markus Elfring
@ 2014-11-15 18:19 ` SF Markus Elfring
2014-11-26 1:16 ` [Cocci] [1/1] " Theodore Ts'o
2014-11-15 18:42 ` [Cocci] [PATCH 1/1] ntfs: Deletion of unnecessary checks " SF Markus Elfring
` (33 subsequent siblings)
53 siblings, 1 reply; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-15 18:19 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 15 Nov 2014 19:04:06 +0100
The iput() function tests whether its argument is NULL and then
returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
fs/ext4/mballoc.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 8b0f9ef..e1a2521 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -2712,8 +2712,7 @@ int ext4_mb_release(struct super_block *sb)
}
kfree(sbi->s_mb_offsets);
kfree(sbi->s_mb_maxs);
- if (sbi->s_buddy_cache)
- iput(sbi->s_buddy_cache);
+ iput(sbi->s_buddy_cache);
if (sbi->s_mb_stats) {
ext4_msg(sb, KERN_INFO,
"mballoc: %u blocks %u reqs (%u success)",
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] ntfs: Deletion of unnecessary checks before the function call "iput"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (19 preceding siblings ...)
2014-11-15 18:19 ` [Cocci] [PATCH 1/1] fs-ext4: Deletion of an unnecessary check before the function call "iput" SF Markus Elfring
@ 2014-11-15 18:42 ` SF Markus Elfring
2014-11-15 19:54 ` Julia Lawall
2014-11-15 20:01 ` [Cocci] [PATCH 1/1] fs-fat: Less function calls in fat_fill_super() after error detection SF Markus Elfring
` (32 subsequent siblings)
53 siblings, 1 reply; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-15 18:42 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 15 Nov 2014 19:35:05 +0100
The iput() function tests whether its argument is NULL and then
returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
fs/ntfs/super.c | 21 +++++++--------------
1 file changed, 7 insertions(+), 14 deletions(-)
diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
index 6c3296e..8f22a47 100644
--- a/fs/ntfs/super.c
+++ b/fs/ntfs/super.c
@@ -2204,17 +2204,12 @@ get_ctx_vol_failed:
return true;
#ifdef NTFS_RW
iput_usnjrnl_err_out:
- if (vol->usnjrnl_j_ino)
- iput(vol->usnjrnl_j_ino);
- if (vol->usnjrnl_max_ino)
- iput(vol->usnjrnl_max_ino);
- if (vol->usnjrnl_ino)
- iput(vol->usnjrnl_ino);
+ iput(vol->usnjrnl_j_ino);
+ iput(vol->usnjrnl_max_ino);
+ iput(vol->usnjrnl_ino);
iput_quota_err_out:
- if (vol->quota_q_ino)
- iput(vol->quota_q_ino);
- if (vol->quota_ino)
- iput(vol->quota_ino);
+ iput(vol->quota_q_ino);
+ iput(vol->quota_ino);
iput(vol->extend_ino);
#endif /* NTFS_RW */
iput_sec_err_out:
@@ -2223,8 +2218,7 @@ iput_root_err_out:
iput(vol->root_ino);
iput_logfile_err_out:
#ifdef NTFS_RW
- if (vol->logfile_ino)
- iput(vol->logfile_ino);
+ iput(vol->logfile_ino);
iput_vol_err_out:
#endif /* NTFS_RW */
iput(vol->vol_ino);
@@ -2254,8 +2248,7 @@ iput_mftbmp_err_out:
iput(vol->mftbmp_ino);
iput_mirr_err_out:
#ifdef NTFS_RW
- if (vol->mftmirr_ino)
- iput(vol->mftmirr_ino);
+ iput(vol->mftmirr_ino);
#endif /* NTFS_RW */
return false;
}
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] ntfs: Deletion of unnecessary checks before the function call "iput"
2014-11-15 18:42 ` [Cocci] [PATCH 1/1] ntfs: Deletion of unnecessary checks " SF Markus Elfring
@ 2014-11-15 19:54 ` Julia Lawall
0 siblings, 0 replies; 268+ messages in thread
From: Julia Lawall @ 2014-11-15 19:54 UTC (permalink / raw)
To: cocci
On Sat, 15 Nov 2014, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 15 Nov 2014 19:35:05 +0100
>
> The iput() function tests whether its argument is NULL and then
> returns immediately. Thus the test around the call is not needed.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> fs/ntfs/super.c | 21 +++++++--------------
> 1 file changed, 7 insertions(+), 14 deletions(-)
>
> diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
> index 6c3296e..8f22a47 100644
> --- a/fs/ntfs/super.c
> +++ b/fs/ntfs/super.c
> @@ -2204,17 +2204,12 @@ get_ctx_vol_failed:
> return true;
> #ifdef NTFS_RW
> iput_usnjrnl_err_out:
I don't have time to look at the code now, but since there is an exit
label here, have you checked whether you could improve the gotos in these
cases?
julia
> - if (vol->usnjrnl_j_ino)
> - iput(vol->usnjrnl_j_ino);
> - if (vol->usnjrnl_max_ino)
> - iput(vol->usnjrnl_max_ino);
> - if (vol->usnjrnl_ino)
> - iput(vol->usnjrnl_ino);
> + iput(vol->usnjrnl_j_ino);
> + iput(vol->usnjrnl_max_ino);
> + iput(vol->usnjrnl_ino);
> iput_quota_err_out:
> - if (vol->quota_q_ino)
> - iput(vol->quota_q_ino);
> - if (vol->quota_ino)
> - iput(vol->quota_ino);
> + iput(vol->quota_q_ino);
> + iput(vol->quota_ino);
> iput(vol->extend_ino);
> #endif /* NTFS_RW */
> iput_sec_err_out:
> @@ -2223,8 +2218,7 @@ iput_root_err_out:
> iput(vol->root_ino);
> iput_logfile_err_out:
> #ifdef NTFS_RW
> - if (vol->logfile_ino)
> - iput(vol->logfile_ino);
> + iput(vol->logfile_ino);
> iput_vol_err_out:
> #endif /* NTFS_RW */
> iput(vol->vol_ino);
> @@ -2254,8 +2248,7 @@ iput_mftbmp_err_out:
> iput(vol->mftbmp_ino);
> iput_mirr_err_out:
> #ifdef NTFS_RW
> - if (vol->mftmirr_ino)
> - iput(vol->mftmirr_ino);
> + iput(vol->mftmirr_ino);
> #endif /* NTFS_RW */
> return false;
> }
> --
> 2.1.3
>
>
> _______________________________________________
> Cocci mailing list
> Cocci at systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
^ permalink raw reply [flat|nested] 268+ messages in thread
* [Cocci] [PATCH 1/1] fs-fat: Less function calls in fat_fill_super() after error detection
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (20 preceding siblings ...)
2014-11-15 18:42 ` [Cocci] [PATCH 1/1] ntfs: Deletion of unnecessary checks " SF Markus Elfring
@ 2014-11-15 20:01 ` SF Markus Elfring
2014-11-15 20:18 ` Julia Lawall
2014-11-15 20:44 ` [Cocci] [PATCH 1/1] lib/mpi: Deletion of unnecessary checks before the function call "mpi_free_limb_space" SF Markus Elfring
` (31 subsequent siblings)
53 siblings, 1 reply; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-15 20:01 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 15 Nov 2014 20:55:23 +0100
The iput() function was called in an inefficient way by the implementation
of the fat_fill_super() function in case of an allocation failure.
The corresponding source code was improved by deletion of two unnecessary
null pointer checks and a few adjustments for jump labels.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
fs/fat/inode.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index 756aead..138ab9a 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -1716,20 +1716,20 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat,
fsinfo_inode = new_inode(sb);
if (!fsinfo_inode)
- goto out_fail;
+ goto fsinfo_inode_failure;
fsinfo_inode->i_ino = MSDOS_FSINFO_INO;
sbi->fsinfo_inode = fsinfo_inode;
insert_inode_hash(fsinfo_inode);
root_inode = new_inode(sb);
if (!root_inode)
- goto out_fail;
+ goto other_failure;
root_inode->i_ino = MSDOS_ROOT_INO;
root_inode->i_version = 1;
error = fat_read_root(root_inode);
if (error < 0) {
iput(root_inode);
- goto out_fail;
+ goto other_failure;
}
error = -ENOMEM;
insert_inode_hash(root_inode);
@@ -1737,7 +1737,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat,
sb->s_root = d_make_root(root_inode);
if (!sb->s_root) {
fat_msg(sb, KERN_ERR, "get root inode failed");
- goto out_fail;
+ goto other_failure;
}
if (sbi->options.discard) {
@@ -1756,11 +1756,13 @@ out_invalid:
if (!silent)
fat_msg(sb, KERN_INFO, "Can't find a valid FAT filesystem");
+other_failure:
+ iput(fsinfo_inode);
+
+fsinfo_inode_failure:
+ iput(fat_inode);
+
out_fail:
- if (fsinfo_inode)
- iput(fsinfo_inode);
- if (fat_inode)
- iput(fat_inode);
unload_nls(sbi->nls_io);
unload_nls(sbi->nls_disk);
if (sbi->options.iocharset != fat_default_iocharset)
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] fs-fat: Less function calls in fat_fill_super() after error detection
2014-11-15 20:01 ` [Cocci] [PATCH 1/1] fs-fat: Less function calls in fat_fill_super() after error detection SF Markus Elfring
@ 2014-11-15 20:18 ` Julia Lawall
2014-11-29 6:44 ` [Cocci] [PATCH v2] " SF Markus Elfring
0 siblings, 1 reply; 268+ messages in thread
From: Julia Lawall @ 2014-11-15 20:18 UTC (permalink / raw)
To: cocci
On Sat, 15 Nov 2014, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 15 Nov 2014 20:55:23 +0100
>
> The iput() function was called in an inefficient way by the implementation
> of the fat_fill_super() function in case of an allocation failure.
> The corresponding source code was improved by deletion of two unnecessary
> null pointer checks and a few adjustments for jump labels.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> fs/fat/inode.c | 18 ++++++++++--------
> 1 file changed, 10 insertions(+), 8 deletions(-)
>
> diff --git a/fs/fat/inode.c b/fs/fat/inode.c
> index 756aead..138ab9a 100644
> --- a/fs/fat/inode.c
> +++ b/fs/fat/inode.c
> @@ -1716,20 +1716,20 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat,
>
> fsinfo_inode = new_inode(sb);
> if (!fsinfo_inode)
> - goto out_fail;
> + goto fsinfo_inode_failure;
> fsinfo_inode->i_ino = MSDOS_FSINFO_INO;
> sbi->fsinfo_inode = fsinfo_inode;
> insert_inode_hash(fsinfo_inode);
>
> root_inode = new_inode(sb);
> if (!root_inode)
> - goto out_fail;
> + goto other_failure;
Other_failure is not such a good name. The one above is better.
julia
> root_inode->i_ino = MSDOS_ROOT_INO;
> root_inode->i_version = 1;
> error = fat_read_root(root_inode);
> if (error < 0) {
> iput(root_inode);
> - goto out_fail;
> + goto other_failure;
> }
> error = -ENOMEM;
> insert_inode_hash(root_inode);
> @@ -1737,7 +1737,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat,
> sb->s_root = d_make_root(root_inode);
> if (!sb->s_root) {
> fat_msg(sb, KERN_ERR, "get root inode failed");
> - goto out_fail;
> + goto other_failure;
> }
>
> if (sbi->options.discard) {
> @@ -1756,11 +1756,13 @@ out_invalid:
> if (!silent)
> fat_msg(sb, KERN_INFO, "Can't find a valid FAT filesystem");
>
> +other_failure:
> + iput(fsinfo_inode);
> +
> +fsinfo_inode_failure:
> + iput(fat_inode);
> +
> out_fail:
> - if (fsinfo_inode)
> - iput(fsinfo_inode);
> - if (fat_inode)
> - iput(fat_inode);
> unload_nls(sbi->nls_io);
> unload_nls(sbi->nls_disk);
> if (sbi->options.iocharset != fat_default_iocharset)
> --
> 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] 268+ messages in thread* [Cocci] [PATCH v2] fs-fat: Less function calls in fat_fill_super() after error detection
2014-11-15 20:18 ` Julia Lawall
@ 2014-11-29 6:44 ` SF Markus Elfring
[not found] ` <87sih22sn8.fsf@devron.myhome.or.jp>
0 siblings, 1 reply; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-29 6:44 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 29 Nov 2014 07:37:34 +0100
The iput() function was called in an inefficient way by the implementation
of the fat_fill_super() function in case of an allocation failure.
The corresponding source code was improved by deletion of two unnecessary
null pointer checks and a few adjustments for jump labels.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
fs/fat/inode.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index 756aead..a39afe8 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -1716,20 +1716,20 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat,
fsinfo_inode = new_inode(sb);
if (!fsinfo_inode)
- goto out_fail;
+ goto fsinfo_inode_failure;
fsinfo_inode->i_ino = MSDOS_FSINFO_INO;
sbi->fsinfo_inode = fsinfo_inode;
insert_inode_hash(fsinfo_inode);
root_inode = new_inode(sb);
if (!root_inode)
- goto out_fail;
+ goto failure_exit;
root_inode->i_ino = MSDOS_ROOT_INO;
root_inode->i_version = 1;
error = fat_read_root(root_inode);
if (error < 0) {
iput(root_inode);
- goto out_fail;
+ goto failure_exit;
}
error = -ENOMEM;
insert_inode_hash(root_inode);
@@ -1737,7 +1737,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat,
sb->s_root = d_make_root(root_inode);
if (!sb->s_root) {
fat_msg(sb, KERN_ERR, "get root inode failed");
- goto out_fail;
+ goto failure_exit;
}
if (sbi->options.discard) {
@@ -1756,11 +1756,13 @@ out_invalid:
if (!silent)
fat_msg(sb, KERN_INFO, "Can't find a valid FAT filesystem");
+failure_exit:
+ iput(fsinfo_inode);
+
+fsinfo_inode_failure:
+ iput(fat_inode);
+
out_fail:
- if (fsinfo_inode)
- iput(fsinfo_inode);
- if (fat_inode)
- iput(fat_inode);
unload_nls(sbi->nls_io);
unload_nls(sbi->nls_disk);
if (sbi->options.iocharset != fat_default_iocharset)
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread
* [Cocci] [PATCH 1/1] lib/mpi: Deletion of unnecessary checks before the function call "mpi_free_limb_space"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (21 preceding siblings ...)
2014-11-15 20:01 ` [Cocci] [PATCH 1/1] fs-fat: Less function calls in fat_fill_super() after error detection SF Markus Elfring
@ 2014-11-15 20:44 ` SF Markus Elfring
2014-11-16 10:40 ` [Cocci] [PATCH 1/1] kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end" SF Markus Elfring
` (30 subsequent siblings)
53 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-15 20:44 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 15 Nov 2014 21:33:26 +0100
The mpi_free_limb_space() function tests whether its argument is NULL and
then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
lib/mpi/mpi-pow.c | 15 +++++----------
lib/mpi/mpih-mul.c | 21 +++++++--------------
2 files changed, 12 insertions(+), 24 deletions(-)
diff --git a/lib/mpi/mpi-pow.c b/lib/mpi/mpi-pow.c
index 5464c87..c28882f 100644
--- a/lib/mpi/mpi-pow.c
+++ b/lib/mpi/mpi-pow.c
@@ -308,16 +308,11 @@ leave:
enomem:
if (assign_rp)
mpi_assign_limb_space(res, rp, size);
- if (mp_marker)
- mpi_free_limb_space(mp_marker);
- if (bp_marker)
- mpi_free_limb_space(bp_marker);
- if (ep_marker)
- mpi_free_limb_space(ep_marker);
- if (xp_marker)
- mpi_free_limb_space(xp_marker);
- if (tspace)
- mpi_free_limb_space(tspace);
+ mpi_free_limb_space(mp_marker);
+ mpi_free_limb_space(bp_marker);
+ mpi_free_limb_space(ep_marker);
+ mpi_free_limb_space(xp_marker);
+ mpi_free_limb_space(tspace);
return rc;
}
EXPORT_SYMBOL_GPL(mpi_powm);
diff --git a/lib/mpi/mpih-mul.c b/lib/mpi/mpih-mul.c
index 7c84171..ff021cc 100644
--- a/lib/mpi/mpih-mul.c
+++ b/lib/mpi/mpih-mul.c
@@ -339,8 +339,7 @@ mpihelp_mul_karatsuba_case(mpi_ptr_t prodp,
mpi_limb_t cy;
if (!ctx->tspace || ctx->tspace_size < vsize) {
- if (ctx->tspace)
- mpi_free_limb_space(ctx->tspace);
+ mpi_free_limb_space(ctx->tspace);
ctx->tspace = mpi_alloc_limb_space(2 * vsize);
if (!ctx->tspace)
return -ENOMEM;
@@ -354,12 +353,10 @@ mpihelp_mul_karatsuba_case(mpi_ptr_t prodp,
usize -= vsize;
if (usize >= vsize) {
if (!ctx->tp || ctx->tp_size < vsize) {
- if (ctx->tp)
- mpi_free_limb_space(ctx->tp);
+ mpi_free_limb_space(ctx->tp);
ctx->tp = mpi_alloc_limb_space(2 * vsize);
if (!ctx->tp) {
- if (ctx->tspace)
- mpi_free_limb_space(ctx->tspace);
+ mpi_free_limb_space(ctx->tspace);
ctx->tspace = NULL;
return -ENOMEM;
}
@@ -407,16 +404,12 @@ void mpihelp_release_karatsuba_ctx(struct karatsuba_ctx *ctx)
{
struct karatsuba_ctx *ctx2;
- if (ctx->tp)
- mpi_free_limb_space(ctx->tp);
- if (ctx->tspace)
- mpi_free_limb_space(ctx->tspace);
+ mpi_free_limb_space(ctx->tp);
+ mpi_free_limb_space(ctx->tspace);
for (ctx = ctx->next; ctx; ctx = ctx2) {
ctx2 = ctx->next;
- if (ctx->tp)
- mpi_free_limb_space(ctx->tp);
- if (ctx->tspace)
- mpi_free_limb_space(ctx->tspace);
+ mpi_free_limb_space(ctx->tp);
+ mpi_free_limb_space(ctx->tspace);
kfree(ctx);
}
}
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (22 preceding siblings ...)
2014-11-15 20:44 ` [Cocci] [PATCH 1/1] lib/mpi: Deletion of unnecessary checks before the function call "mpi_free_limb_space" SF Markus Elfring
@ 2014-11-16 10:40 ` SF Markus Elfring
2014-11-16 11:10 ` Dan Carpenter
2014-11-16 11:24 ` [Cocci] [PATCH 1/1] " Dan Carpenter
2014-11-16 12:34 ` [Cocci] [PATCH 1/1] kprobes: Deletion of an unnecessary check before the function call "module_put" SF Markus Elfring
` (29 subsequent siblings)
53 siblings, 2 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-16 10:40 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 16 Nov 2014 11:27:43 +0100
The audit_log_end() function tests whether its argument is NULL and then
returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
kernel/auditsc.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index 21eae3c..1fed61c 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -1470,8 +1470,7 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts
/* Send end of event record to help user space know we are finished */
ab = audit_log_start(context, GFP_KERNEL, AUDIT_EOE);
- if (ab)
- audit_log_end(ab);
+ audit_log_end(ab);
if (call_panic)
audit_panic("error converting sid to string");
}
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end"
2014-11-16 10:40 ` [Cocci] [PATCH 1/1] kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end" SF Markus Elfring
@ 2014-11-16 11:10 ` Dan Carpenter
2014-11-16 11:14 ` Dan Carpenter
2014-11-16 11:24 ` [Cocci] [PATCH 1/1] " Dan Carpenter
1 sibling, 1 reply; 268+ messages in thread
From: Dan Carpenter @ 2014-11-16 11:10 UTC (permalink / raw)
To: cocci
Please don't send these to trivial, because they can introduce bugs.
The make the code less clear and they are a layering violation. If the
other maintainers want to take them that's fine, but don't send it to
trivial.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 268+ messages in thread
* [Cocci] [PATCH 1/1] kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end"
2014-11-16 11:10 ` Dan Carpenter
@ 2014-11-16 11:14 ` Dan Carpenter
2014-11-16 11:48 ` SF Markus Elfring
0 siblings, 1 reply; 268+ messages in thread
From: Dan Carpenter @ 2014-11-16 11:14 UTC (permalink / raw)
To: cocci
On Sun, Nov 16, 2014 at 02:10:23PM +0300, Dan Carpenter wrote:
> Please don't send these to trivial, because they can introduce bugs.
An example of a bug introduced is here:
https://lkml.org/lkml/2014/11/3/505
regards,
dan carpenter
^ permalink raw reply [flat|nested] 268+ messages in thread
* [Cocci] [PATCH 1/1] kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end"
2014-11-16 11:14 ` Dan Carpenter
@ 2014-11-16 11:48 ` SF Markus Elfring
2014-11-17 7:34 ` Dan Carpenter
0 siblings, 1 reply; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-16 11:48 UTC (permalink / raw)
To: cocci
> An example of a bug introduced is here:
>
> https://lkml.org/lkml/2014/11/3/505
It seems that we try to clarify a different interpretation of "bugs", don't we?
It is an usual software development challenge to decide on the best source code places
where to put input parameter validation (and when it can be omitted), isn't it?
Regards,
Markus
^ permalink raw reply [flat|nested] 268+ messages in thread
* [Cocci] [PATCH 1/1] kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end"
2014-11-16 11:48 ` SF Markus Elfring
@ 2014-11-17 7:34 ` Dan Carpenter
2014-11-17 8:56 ` SF Markus Elfring
0 siblings, 1 reply; 268+ messages in thread
From: Dan Carpenter @ 2014-11-17 7:34 UTC (permalink / raw)
To: cocci
On Sun, Nov 16, 2014 at 12:48:37PM +0100, SF Markus Elfring wrote:
> > An example of a bug introduced is here:
> >
> > https://lkml.org/lkml/2014/11/3/505
>
> It seems that we try to clarify a different interpretation of "bugs", don't we?
>
You removed the statement from "if (foo) kfree_fsm(foo);" so now it
prints a warning.
drivers/s390/net/fsm.c
71 void
72 kfree_fsm(fsm_instance *this)
73 {
74 if (this) {
75 if (this->f) {
76 kfree(this->f->jumpmatrix);
77 kfree(this->f);
78 }
79 kfree(this);
80 } else
81 printk(KERN_WARNING
82 "fsm: kfree_fsm called with NULL argument\n");
83 }
> It is an usual software development challenge to decide on the best source code places
> where to put input parameter validation (and when it can be omitted), isn't it?
No, it's not. You should just try to write the most readable software
you can instead of removing if statements because you can.
But that's not my point. My point is that these patches are not always
welcome so we should not merge them through the trivial tree.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end"
2014-11-17 7:34 ` Dan Carpenter
@ 2014-11-17 8:56 ` SF Markus Elfring
2014-11-17 13:45 ` Dan Carpenter
2014-11-23 11:51 ` Julia Lawall
0 siblings, 2 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-17 8:56 UTC (permalink / raw)
To: cocci
> You removed the statement from "if (foo) kfree_fsm(foo);" so now it
> prints a warning.
>
> drivers/s390/net/fsm.c
Would it be better to continue the clarification of affected implementation details
under the discussion topic "s390/net: Deletion of unnecessary checks before two function calls"?
>> It is an usual software development challenge to decide on the best source code places
>> where to put input parameter validation (and when it can be omitted), isn't it?
>
> No, it's not. You should just try to write the most readable software
> you can instead of removing if statements because you can.
Additional safety checks have also got an effect on source code readability, haven't they?
Regards,
Markus
^ permalink raw reply [flat|nested] 268+ messages in thread
* [Cocci] [PATCH 1/1] kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end"
2014-11-17 8:56 ` SF Markus Elfring
@ 2014-11-17 13:45 ` Dan Carpenter
2014-11-23 11:51 ` Julia Lawall
1 sibling, 0 replies; 268+ messages in thread
From: Dan Carpenter @ 2014-11-17 13:45 UTC (permalink / raw)
To: cocci
On Mon, Nov 17, 2014 at 09:56:22AM +0100, SF Markus Elfring wrote:
> > You removed the statement from "if (foo) kfree_fsm(foo);" so now it
> > prints a warning.
> >
> > drivers/s390/net/fsm.c
>
> Would it be better to continue the clarification of affected implementation details
> under the discussion topic "s390/net: Deletion of unnecessary checks before two function calls"?
>
What do you want me to clarify? Do you still not see the bug?
regards,
dan carpenter
^ permalink raw reply [flat|nested] 268+ messages in thread
* [Cocci] [PATCH 1/1] kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end"
2014-11-17 8:56 ` SF Markus Elfring
2014-11-17 13:45 ` Dan Carpenter
@ 2014-11-23 11:51 ` Julia Lawall
2014-11-23 13:24 ` [Cocci] " SF Markus Elfring
1 sibling, 1 reply; 268+ messages in thread
From: Julia Lawall @ 2014-11-23 11:51 UTC (permalink / raw)
To: cocci
> > No, it's not. You should just try to write the most readable software
> > you can instead of removing if statements because you can.
>
> Additional safety checks have also got an effect on source code readability, haven't they?
Normally, tests only hurt readability if they cannot be false or cannot be
true. Making a choice apparent when there really is a choice would seem
to aid understanding. Program analysis tools can also potentially exploit
this information, which you are so systmatically removing.
julia
^ permalink raw reply [flat|nested] 268+ messages in thread
* [Cocci] kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end"
2014-11-23 11:51 ` Julia Lawall
@ 2014-11-23 13:24 ` SF Markus Elfring
2014-11-24 9:03 ` Dan Carpenter
0 siblings, 1 reply; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-23 13:24 UTC (permalink / raw)
To: cocci
> Normally, tests only hurt readability if they cannot be false or cannot be true.
> Making a choice apparent when there really is a choice would seem
> to aid understanding.
I agree also to such facts.
> Program analysis tools can also potentially exploit this information,
The published semantic patch scripts correspond to this desire.
> which you are so systmatically removing.
I try to delete redundant checks in various function implementations as much
as possible.
Regards,
Markus
^ permalink raw reply [flat|nested] 268+ messages in thread
* [Cocci] kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end"
2014-11-23 13:24 ` [Cocci] " SF Markus Elfring
@ 2014-11-24 9:03 ` Dan Carpenter
0 siblings, 0 replies; 268+ messages in thread
From: Dan Carpenter @ 2014-11-24 9:03 UTC (permalink / raw)
To: cocci
On Sun, Nov 23, 2014 at 02:24:32PM +0100, SF Markus Elfring wrote:
> > Program analysis tools can also potentially exploit this information,
>
> The published semantic patch scripts correspond to this desire.
>
Sorry for that.
I have deleted the Smatch check for this so it no longer warns about:
if (foo)
kfree(foo);
regards,
dan carpenter
^ permalink raw reply [flat|nested] 268+ messages in thread
* [Cocci] [PATCH 1/1] kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end"
2014-11-16 10:40 ` [Cocci] [PATCH 1/1] kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end" SF Markus Elfring
2014-11-16 11:10 ` Dan Carpenter
@ 2014-11-16 11:24 ` Dan Carpenter
2014-11-16 12:07 ` [Cocci] [PATCH 1/1] kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end" (or improve error handling?) SF Markus Elfring
1 sibling, 1 reply; 268+ messages in thread
From: Dan Carpenter @ 2014-11-16 11:24 UTC (permalink / raw)
To: cocci
On Sun, Nov 16, 2014 at 11:40:26AM +0100, SF Markus Elfring wrote:
> diff --git a/kernel/auditsc.c b/kernel/auditsc.c
> index 21eae3c..1fed61c 100644
> --- a/kernel/auditsc.c
> +++ b/kernel/auditsc.c
> @@ -1470,8 +1470,7 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts
>
> /* Send end of event record to help user space know we are finished */
> ab = audit_log_start(context, GFP_KERNEL, AUDIT_EOE);
> - if (ab)
> - audit_log_end(ab);
> + audit_log_end(ab);
> if (call_panic)
> audit_panic("error converting sid to string");
> }
I should have tried to explain this in my earlier message...
The original code is very clear, the new code works exactly the same but
it's not clear if the author forgot about handling errors from
audit_log_start(). So now someone will come along later and add:
if (!ab)
return;
We get a lot of mindless "add error handling" patches like that. Even
if no one adds that patch who ever is reading the code will think that
the error handling is missing by mistake and have to read the git log
to determine the original intention.
Instead of hiding the readable code in the git log, let's just leave it
in the source file.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end" (or improve error handling?)
2014-11-16 11:24 ` [Cocci] [PATCH 1/1] " Dan Carpenter
@ 2014-11-16 12:07 ` SF Markus Elfring
0 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-16 12:07 UTC (permalink / raw)
To: cocci
> The original code is very clear, the new code works exactly the same but
> it's not clear if the author forgot about handling errors from
> audit_log_start().
We have got different expectations on source code clarity here.
> So now someone will come along later and add:
> if (!ab)
> return;
>
> We get a lot of mindless "add error handling" patches like that.
This is an interesting background information.
Do you eventually prefer to improve the affected error detection
and corresponding exception handling?
Will a condition check become absolutely necessary there?
Regards,
Markus
^ permalink raw reply [flat|nested] 268+ messages in thread
* [Cocci] [PATCH 1/1] kprobes: Deletion of an unnecessary check before the function call "module_put"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (23 preceding siblings ...)
2014-11-16 10:40 ` [Cocci] [PATCH 1/1] kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end" SF Markus Elfring
@ 2014-11-16 12:34 ` SF Markus Elfring
2014-11-16 13:29 ` Julia Lawall
[not found] ` <5469B08E.90104@hitachi.com>
2014-11-16 13:28 ` [Cocci] [PATCH 1/1] kernel-power: Deletion of an unnecessary check before the function call "vfree" SF Markus Elfring
` (28 subsequent siblings)
53 siblings, 2 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-16 12:34 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 16 Nov 2014 12:20:31 +0100
The module_put() function tests whether its argument is NULL and then
returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
kernel/kprobes.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 3995f54..f1e7d45 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1527,8 +1527,7 @@ int register_kprobe(struct kprobe *p)
out:
mutex_unlock(&kprobe_mutex);
- if (probed_mod)
- module_put(probed_mod);
+ module_put(probed_mod);
return ret;
}
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] kprobes: Deletion of an unnecessary check before the function call "module_put"
2014-11-16 12:34 ` [Cocci] [PATCH 1/1] kprobes: Deletion of an unnecessary check before the function call "module_put" SF Markus Elfring
@ 2014-11-16 13:29 ` Julia Lawall
2014-11-16 14:26 ` SF Markus Elfring
[not found] ` <5469B08E.90104@hitachi.com>
1 sibling, 1 reply; 268+ messages in thread
From: Julia Lawall @ 2014-11-16 13:29 UTC (permalink / raw)
To: cocci
On Sun, 16 Nov 2014, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sun, 16 Nov 2014 12:20:31 +0100
>
> The module_put() function tests whether its argument is NULL and then
> returns immediately. Thus the test around the call is not needed.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> kernel/kprobes.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 3995f54..f1e7d45 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -1527,8 +1527,7 @@ int register_kprobe(struct kprobe *p)
> out:
> mutex_unlock(&kprobe_mutex);
>
> - if (probed_mod)
> - module_put(probed_mod);
> + module_put(probed_mod);
There is an out label, so please check whether the labels could not be
better positioned to avoid calling module_put when it is not needed.
julia
>
> return ret;
> }
> --
> 2.1.3
>
>
> _______________________________________________
> Cocci mailing list
> Cocci at systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
^ permalink raw reply [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] kprobes: Deletion of an unnecessary check before the function call "module_put"
2014-11-16 13:29 ` Julia Lawall
@ 2014-11-16 14:26 ` SF Markus Elfring
2014-11-16 15:43 ` Julia Lawall
0 siblings, 1 reply; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-16 14:26 UTC (permalink / raw)
To: cocci
>> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
>> index 3995f54..f1e7d45 100644
>> --- a/kernel/kprobes.c
>> +++ b/kernel/kprobes.c
>> @@ -1527,8 +1527,7 @@ int register_kprobe(struct kprobe *p)
>> out:
>> mutex_unlock(&kprobe_mutex);
>>
>> - if (probed_mod)
>> - module_put(probed_mod);
>> + module_put(probed_mod);
>
> There is an out label, so please check whether the labels could not be
> better positioned to avoid calling module_put when it is not needed.
I do not see refactoring opportunities around jump labels in this use case
for the implementation of the register_kprobe() function so far because
the mutex_unlock() function must be called.
Would you like to suggest any other source code fine-tuning?
Regards,
Markus
^ permalink raw reply [flat|nested] 268+ messages in thread
* [Cocci] [PATCH 1/1] kprobes: Deletion of an unnecessary check before the function call "module_put"
2014-11-16 14:26 ` SF Markus Elfring
@ 2014-11-16 15:43 ` Julia Lawall
2014-11-16 16:57 ` SF Markus Elfring
0 siblings, 1 reply; 268+ messages in thread
From: Julia Lawall @ 2014-11-16 15:43 UTC (permalink / raw)
To: cocci
On Sun, 16 Nov 2014, SF Markus Elfring wrote:
> >> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> >> index 3995f54..f1e7d45 100644
> >> --- a/kernel/kprobes.c
> >> +++ b/kernel/kprobes.c
> >> @@ -1527,8 +1527,7 @@ int register_kprobe(struct kprobe *p)
> >> out:
> >> mutex_unlock(&kprobe_mutex);
> >>
> >> - if (probed_mod)
> >> - module_put(probed_mod);
> >> + module_put(probed_mod);
> >
> > There is an out label, so please check whether the labels could not be
> > better positioned to avoid calling module_put when it is not needed.
>
> I do not see refactoring opportunities around jump labels in this use case
> for the implementation of the register_kprobe() function so far because
> the mutex_unlock() function must be called.
> Would you like to suggest any other source code fine-tuning?
OK. I don't think that removing the if is a good choice in this case.
The code ret = check_kprobe_address_safe(p, &probed_mod); is unusual, in
that it can fail to do anything in two ways. One is by setting ret, on
detecting an error, and the other is by returning 0 but still putting a
NULL value in probed_mod when there is nothing to do. Thus, in the
successful execution of the rest of the function, a probed module might or
might not exist. The if around the module_put is helpful to the reader to
understand that this possibility exists.
julia
^ permalink raw reply [flat|nested] 268+ messages in thread
[parent not found: <5469B08E.90104@hitachi.com>]
* [Cocci] [PATCH 1/1] kprobes: Deletion of an unnecessary check before the function call "module_put"
[not found] ` <5469B08E.90104@hitachi.com>
@ 2014-11-19 7:08 ` SF Markus Elfring
0 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-19 7:08 UTC (permalink / raw)
To: cocci
>> index 3995f54..f1e7d45 100644
>> --- a/kernel/kprobes.c
>> +++ b/kernel/kprobes.c
>> @@ -1527,8 +1527,7 @@ int register_kprobe(struct kprobe *p)
>> out:
>> mutex_unlock(&kprobe_mutex);
>>
>> - if (probed_mod)
>> - module_put(probed_mod);
>> + module_put(probed_mod);
>
> This is OK, but I you request a comment line over there so that
> code reader can understand it is safe to pass a NULL pointer to
> module_put().
Do you want that I replace the shown null pointer check by a short
comment which repeats an expectation for the affected function call?
Regards,
Markus
^ permalink raw reply [flat|nested] 268+ messages in thread
* [Cocci] [PATCH 1/1] kernel-power: Deletion of an unnecessary check before the function call "vfree"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (24 preceding siblings ...)
2014-11-16 12:34 ` [Cocci] [PATCH 1/1] kprobes: Deletion of an unnecessary check before the function call "module_put" SF Markus Elfring
@ 2014-11-16 13:28 ` SF Markus Elfring
2014-11-16 13:50 ` [Cocci] [PATCH 1/1] kernel-trace: Deletion of an unnecessary check before the function call "iput" SF Markus Elfring
` (27 subsequent siblings)
53 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-16 13:28 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 16 Nov 2014 14:18:28 +0100
The vfree() function performs also input parameter validation. Thus the test
around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
kernel/power/swap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index aaa3261..337c7a9 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -1374,7 +1374,7 @@ out_clean:
kthread_stop(data[thr].thr);
vfree(data);
}
- if (page) vfree(page);
+ vfree(page);
return ret;
}
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] kernel-trace: Deletion of an unnecessary check before the function call "iput"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (25 preceding siblings ...)
2014-11-16 13:28 ` [Cocci] [PATCH 1/1] kernel-power: Deletion of an unnecessary check before the function call "vfree" SF Markus Elfring
@ 2014-11-16 13:50 ` SF Markus Elfring
2014-11-16 15:56 ` Julia Lawall
2014-11-16 22:40 ` [Cocci] [PATCH 1/1] fs-jbd: Deletion of an unnecessary check before the function call "iput" SF Markus Elfring
` (26 subsequent siblings)
53 siblings, 1 reply; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-16 13:50 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 16 Nov 2014 14:46:28 +0100
The iput() function tests whether its argument is NULL and then
returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
kernel/trace/trace_uprobe.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index 33ff6a2..ec002c0 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -552,8 +552,7 @@ error:
return ret;
fail_address_parse:
- if (inode)
- iput(inode);
+ iput(inode);
pr_info("Failed to parse address or file.\n");
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] kernel-trace: Deletion of an unnecessary check before the function call "iput"
2014-11-16 13:50 ` [Cocci] [PATCH 1/1] kernel-trace: Deletion of an unnecessary check before the function call "iput" SF Markus Elfring
@ 2014-11-16 15:56 ` Julia Lawall
2014-11-16 19:13 ` [Cocci] [PATCH v2 0/2] kernel-trace: Fixes around the jump label "fail_address_parse" SF Markus Elfring
0 siblings, 1 reply; 268+ messages in thread
From: Julia Lawall @ 2014-11-16 15:56 UTC (permalink / raw)
To: cocci
On Sun, 16 Nov 2014, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sun, 16 Nov 2014 14:46:28 +0100
>
> The iput() function tests whether its argument is NULL and then
> returns immediately. Thus the test around the call is not needed.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> kernel/trace/trace_uprobe.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
> index 33ff6a2..ec002c0 100644
> --- a/kernel/trace/trace_uprobe.c
> +++ b/kernel/trace/trace_uprobe.c
> @@ -552,8 +552,7 @@ error:
> return ret;
>
> fail_address_parse:
> - if (inode)
> - iput(inode);
> + iput(inode);
There are jumps to fail_address_parse where the value of inode can only be
NULL.
julia
>
> pr_info("Failed to parse address or file.\n");
>
> --
> 2.1.3
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo at vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 268+ messages in thread* [Cocci] [PATCH v2 0/2] kernel-trace: Fixes around the jump label "fail_address_parse"
2014-11-16 15:56 ` Julia Lawall
@ 2014-11-16 19:13 ` SF Markus Elfring
2014-11-16 19:18 ` [Cocci] [PATCH v2 1/2] kernel-trace: Deletion of an unnecessary check before the function call "iput" SF Markus Elfring
2014-11-16 19:22 ` [Cocci] [PATCH v2 2/2] kernel-trace: Less calls for iput() in create_trace_uprobe() after error detection SF Markus Elfring
0 siblings, 2 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-16 19:13 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 16 Nov 2014 19:56:15 +0100
Another update suggestion was taken into account after a patch was applied
from static source code analysis.
Markus Elfring (2):
kernel-trace: Deletion of an unnecessary check before the function
call "iput"
kernel-trace: Less calls for iput() in create_trace_uprobe() after
error detection
kernel/trace/trace_uprobe.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
--
2.1.3
^ permalink raw reply [flat|nested] 268+ messages in thread* [Cocci] [PATCH v2 1/2] kernel-trace: Deletion of an unnecessary check before the function call "iput"
2014-11-16 19:13 ` [Cocci] [PATCH v2 0/2] kernel-trace: Fixes around the jump label "fail_address_parse" SF Markus Elfring
@ 2014-11-16 19:18 ` SF Markus Elfring
2014-11-16 19:22 ` [Cocci] [PATCH v2 2/2] kernel-trace: Less calls for iput() in create_trace_uprobe() after error detection SF Markus Elfring
1 sibling, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-16 19:18 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 16 Nov 2014 14:46:28 +0100
The iput() function tests whether its argument is NULL and then
returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
kernel/trace/trace_uprobe.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index 33ff6a2..ec002c0 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -552,8 +552,7 @@ error:
return ret;
fail_address_parse:
- if (inode)
- iput(inode);
+ iput(inode);
pr_info("Failed to parse address or file.\n");
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH v2 2/2] kernel-trace: Less calls for iput() in create_trace_uprobe() after error detection
2014-11-16 19:13 ` [Cocci] [PATCH v2 0/2] kernel-trace: Fixes around the jump label "fail_address_parse" SF Markus Elfring
2014-11-16 19:18 ` [Cocci] [PATCH v2 1/2] kernel-trace: Deletion of an unnecessary check before the function call "iput" SF Markus Elfring
@ 2014-11-16 19:22 ` SF Markus Elfring
[not found] ` <20141116143120.44421df2@gandalf.local.home>
1 sibling, 1 reply; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-16 19:22 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 16 Nov 2014 19:49:39 +0100
The iput() function was called in three cases by the create_trace_uprobe()
function during error handling even if the passed variable contained still
a null pointer. This implementation detail could be improved by the
introduction of another jump label.
Suggested-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
kernel/trace/trace_uprobe.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index ec002c0..a0288f2 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -434,19 +434,24 @@ static int create_trace_uprobe(int argc, char **argv)
arg = strchr(argv[1], ':');
if (!arg) {
ret = -EINVAL;
- goto fail_address_parse;
+ goto fail_address_parse2;
}
*arg++ = '\0';
filename = argv[1];
ret = kern_path(filename, LOOKUP_FOLLOW, &path);
if (ret)
- goto fail_address_parse;
+ goto fail_address_parse2;
inode = igrab(path.dentry->d_inode);
path_put(&path);
- if (!inode || !S_ISREG(inode->i_mode)) {
+ if (!inode) {
+ ret = -EINVAL;
+ goto fail_address_parse2;
+ }
+
+ if (!S_ISREG(inode->i_mode)) {
ret = -EINVAL;
goto fail_address_parse;
}
@@ -554,6 +559,7 @@ error:
fail_address_parse:
iput(inode);
+fail_address_parse2:
pr_info("Failed to parse address or file.\n");
return ret;
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread
* [Cocci] [PATCH 1/1] fs-jbd: Deletion of an unnecessary check before the function call "iput"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (26 preceding siblings ...)
2014-11-16 13:50 ` [Cocci] [PATCH 1/1] kernel-trace: Deletion of an unnecessary check before the function call "iput" SF Markus Elfring
@ 2014-11-16 22:40 ` SF Markus Elfring
2014-11-17 10:07 ` [Cocci] [PATCH 1/1] ALSA: hda: Deletion of unnecessary checks before two function calls SF Markus Elfring
` (25 subsequent siblings)
53 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-16 22:40 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 16 Nov 2014 23:23:19 +0100
The iput() function tests whether its argument is NULL and then
returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
fs/jbd/journal.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fs/jbd/journal.c b/fs/jbd/journal.c
index 06fe11e..32fe03e 100644
--- a/fs/jbd/journal.c
+++ b/fs/jbd/journal.c
@@ -1373,8 +1373,7 @@ int journal_destroy(journal_t *journal)
}
mutex_unlock(&journal->j_checkpoint_mutex);
- if (journal->j_inode)
- iput(journal->j_inode);
+ iput(journal->j_inode);
if (journal->j_revoke)
journal_destroy_revoke(journal);
kfree(journal->j_wbuf);
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] ALSA: hda: Deletion of unnecessary checks before two function calls
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (27 preceding siblings ...)
2014-11-16 22:40 ` [Cocci] [PATCH 1/1] fs-jbd: Deletion of an unnecessary check before the function call "iput" SF Markus Elfring
@ 2014-11-17 10:07 ` SF Markus Elfring
2014-11-17 10:34 ` [Cocci] [PATCH 1/1] ALSA: ice17xx: Deletion of unnecessary checks before the function call "snd_ac97_resume" SF Markus Elfring
` (24 subsequent siblings)
53 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-17 10:07 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 17 Nov 2014 10:44:33 +0100
The functions kfree() and release_firmware() test whether their argument
is NULL and then return immediately. Thus the test around the call
is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
sound/pci/hda/hda_codec.c | 3 +--
sound/pci/hda/hda_intel.c | 3 +--
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index ec6a7d0..3fe8859 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -827,8 +827,7 @@ static void snd_hda_bus_free(struct hda_bus *bus)
WARN_ON(!list_empty(&bus->codec_list));
if (bus->workq)
flush_workqueue(bus->workq);
- if (bus->unsol)
- kfree(bus->unsol);
+ kfree(bus->unsol);
if (bus->ops.private_free)
bus->ops.private_free(bus);
if (bus->workq)
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 0a7f848..b4ec4e1 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -1129,8 +1129,7 @@ static int azx_free(struct azx *chip)
pci_disable_device(chip->pci);
kfree(chip->azx_dev);
#ifdef CONFIG_SND_HDA_PATCH_LOADER
- if (chip->fw)
- release_firmware(chip->fw);
+ release_firmware(chip->fw);
#endif
if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
hda_display_power(false);
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] ALSA: ice17xx: Deletion of unnecessary checks before the function call "snd_ac97_resume"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (28 preceding siblings ...)
2014-11-17 10:07 ` [Cocci] [PATCH 1/1] ALSA: hda: Deletion of unnecessary checks before two function calls SF Markus Elfring
@ 2014-11-17 10:34 ` SF Markus Elfring
2014-11-17 11:48 ` [Cocci] [PATCH 1/1] ALSA: lola: Deletion of an unnecessary check before the function call "vfree" SF Markus Elfring
` (23 subsequent siblings)
53 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-17 10:34 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 17 Nov 2014 11:28:02 +0100
The snd_ac97_resume() function tests whether its argument is NULL and then
returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
sound/pci/ice1712/ice1712.c | 3 +--
sound/pci/ice1712/ice1724.c | 3 +--
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/sound/pci/ice1712/ice1712.c b/sound/pci/ice1712/ice1712.c
index 87f7fc4..e1e18b5 100644
--- a/sound/pci/ice1712/ice1712.c
+++ b/sound/pci/ice1712/ice1712.c
@@ -2905,8 +2905,7 @@ static int snd_ice1712_resume(struct device *dev)
outw(ice->pm_saved_spdif_ctrl, ICEMT(ice, ROUTE_SPDOUT));
outw(ice->pm_saved_route, ICEMT(ice, ROUTE_PSDOUT03));
- if (ice->ac97)
- snd_ac97_resume(ice->ac97);
+ snd_ac97_resume(ice->ac97);
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0;
diff --git a/sound/pci/ice1712/ice1724.c b/sound/pci/ice1712/ice1724.c
index 08cb08a..0e56835 100644
--- a/sound/pci/ice1712/ice1724.c
+++ b/sound/pci/ice1712/ice1724.c
@@ -2884,8 +2884,7 @@ static int snd_vt1724_resume(struct device *dev)
outb(ice->pm_saved_spdif_cfg, ICEREG1724(ice, SPDIF_CFG));
outl(ice->pm_saved_route, ICEMT1724(ice, ROUTE_PLAYBACK));
- if (ice->ac97)
- snd_ac97_resume(ice->ac97);
+ snd_ac97_resume(ice->ac97);
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0;
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] ALSA: lola: Deletion of an unnecessary check before the function call "vfree"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (29 preceding siblings ...)
2014-11-17 10:34 ` [Cocci] [PATCH 1/1] ALSA: ice17xx: Deletion of unnecessary checks before the function call "snd_ac97_resume" SF Markus Elfring
@ 2014-11-17 11:48 ` SF Markus Elfring
2014-11-17 12:12 ` [Cocci] [PATCH 1/1] ALSA: hdsp: Deletion of an unnecessary check before the function call "release_firmware" SF Markus Elfring
` (22 subsequent siblings)
53 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-17 11:48 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 17 Nov 2014 12:42:16 +0100
The vfree() function performs also input parameter validation. Thus the test
around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
sound/pci/lola/lola_mixer.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/sound/pci/lola/lola_mixer.c b/sound/pci/lola/lola_mixer.c
index 782f4d8..e7fe15d 100644
--- a/sound/pci/lola/lola_mixer.c
+++ b/sound/pci/lola/lola_mixer.c
@@ -108,8 +108,7 @@ int lola_init_pins(struct lola *chip, int dir, int *nidp)
void lola_free_mixer(struct lola *chip)
{
- if (chip->mixer.array_saved)
- vfree(chip->mixer.array_saved);
+ vfree(chip->mixer.array_saved);
}
int lola_init_mixer_widget(struct lola *chip, int nid)
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] ALSA: hdsp: Deletion of an unnecessary check before the function call "release_firmware"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (30 preceding siblings ...)
2014-11-17 11:48 ` [Cocci] [PATCH 1/1] ALSA: lola: Deletion of an unnecessary check before the function call "vfree" SF Markus Elfring
@ 2014-11-17 12:12 ` SF Markus Elfring
2014-11-17 12:41 ` [Cocci] [PATCH 1/1] ALSA: powermac: Deletion of an unnecessary check before the function call "pci_dev_put" SF Markus Elfring
` (21 subsequent siblings)
53 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-17 12:12 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 17 Nov 2014 13:04:14 +0100
The release_firmware() function tests whether its argument is NULL and then
return immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
sound/pci/rme9652/hdsp.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c
index 7646ba1..0ae568d 100644
--- a/sound/pci/rme9652/hdsp.c
+++ b/sound/pci/rme9652/hdsp.c
@@ -5368,8 +5368,7 @@ static int snd_hdsp_free(struct hdsp *hdsp)
snd_hdsp_free_buffers(hdsp);
- if (hdsp->firmware)
- release_firmware(hdsp->firmware);
+ release_firmware(hdsp->firmware);
vfree(hdsp->fw_uploaded);
if (hdsp->iobase)
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] ALSA: powermac: Deletion of an unnecessary check before the function call "pci_dev_put"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (31 preceding siblings ...)
2014-11-17 12:12 ` [Cocci] [PATCH 1/1] ALSA: hdsp: Deletion of an unnecessary check before the function call "release_firmware" SF Markus Elfring
@ 2014-11-17 12:41 ` SF Markus Elfring
2014-11-17 13:42 ` [Cocci] [PATCH 1/1] tools lib traceevent: Deletion of an unnecessary check before the function call "free_arg" SF Markus Elfring
` (20 subsequent siblings)
53 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-17 12:41 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 17 Nov 2014 13:35:54 +0100
The pci_dev_put() function tests whether its argument is NULL and then
returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
sound/ppc/pmac.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/sound/ppc/pmac.c b/sound/ppc/pmac.c
index 8a431bc..5a13b22 100644
--- a/sound/ppc/pmac.c
+++ b/sound/ppc/pmac.c
@@ -887,8 +887,7 @@ static int snd_pmac_free(struct snd_pmac *chip)
}
}
- if (chip->pdev)
- pci_dev_put(chip->pdev);
+ pci_dev_put(chip->pdev);
of_node_put(chip->node);
kfree(chip);
return 0;
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] tools lib traceevent: Deletion of an unnecessary check before the function call "free_arg"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (32 preceding siblings ...)
2014-11-17 12:41 ` [Cocci] [PATCH 1/1] ALSA: powermac: Deletion of an unnecessary check before the function call "pci_dev_put" SF Markus Elfring
@ 2014-11-17 13:42 ` SF Markus Elfring
2014-11-17 17:11 ` [Cocci] [PATCH 1/1] perf tools: Deletion of unnecessary checks before two function calls SF Markus Elfring
` (19 subsequent siblings)
53 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-17 13:42 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 17 Nov 2014 14:38:14 +0100
The free_arg() function tests whether its argument is NULL and then
returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
tools/lib/traceevent/parse-filter.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/tools/lib/traceevent/parse-filter.c b/tools/lib/traceevent/parse-filter.c
index b502344..78debaf 100644
--- a/tools/lib/traceevent/parse-filter.c
+++ b/tools/lib/traceevent/parse-filter.c
@@ -1237,8 +1237,7 @@ filter_event(struct event_filter *filter, struct event_format *event,
if (filter_type == NULL)
return PEVENT_ERRNO__MEM_ALLOC_FAILED;
- if (filter_type->filter)
- free_arg(filter_type->filter);
+ free_arg(filter_type->filter);
filter_type->filter = arg;
return 0;
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] perf tools: Deletion of unnecessary checks before two function calls
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (33 preceding siblings ...)
2014-11-17 13:42 ` [Cocci] [PATCH 1/1] tools lib traceevent: Deletion of an unnecessary check before the function call "free_arg" SF Markus Elfring
@ 2014-11-17 17:11 ` SF Markus Elfring
2014-11-17 17:40 ` [Cocci] [PATCH 1/1] mm/zswap: Deletion of an unnecessary check before the function call "free_percpu" SF Markus Elfring
` (18 subsequent siblings)
53 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-17 17:11 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 17 Nov 2014 18:05:57 +0100
The functions free_event_desc() and strfilter__delete() test whether their
argument is NULL and then return immediately. Thus the test around the call
is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
tools/perf/builtin-probe.c | 6 ++----
| 3 +--
2 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index c63fa29..1b72bf2 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -254,8 +254,7 @@ static int opt_set_filter(const struct option *opt __maybe_unused,
if (str) {
pr_debug2("Set filter: %s\n", str);
- if (params.filter)
- strfilter__delete(params.filter);
+ strfilter__delete(params.filter);
params.filter = strfilter__new(str, &err);
if (!params.filter) {
pr_err("Filter parse error at %td.\n", err - str + 1);
@@ -283,8 +282,7 @@ static void cleanup_params(void)
strlist__delete(params.dellist);
line_range__clear(¶ms.line_range);
free(params.target);
- if (params.filter)
- strfilter__delete(params.filter);
+ strfilter__delete(params.filter);
memset(¶ms, 0, sizeof(params));
}
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 158c787..a62fbc6 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1367,8 +1367,7 @@ out:
free(buf);
return events;
error:
- if (events)
- free_event_desc(events);
+ free_event_desc(events);
events = NULL;
goto out;
}
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] mm/zswap: Deletion of an unnecessary check before the function call "free_percpu"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (34 preceding siblings ...)
2014-11-17 17:11 ` [Cocci] [PATCH 1/1] perf tools: Deletion of unnecessary checks before two function calls SF Markus Elfring
@ 2014-11-17 17:40 ` SF Markus Elfring
2014-11-17 18:19 ` [Cocci] [PATCH 1/1] hfs/hfs+: Deletion of unnecessary checks before the function call "hfs_bnode_put" SF Markus Elfring
` (17 subsequent siblings)
53 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-17 17:40 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 17 Nov 2014 18:33:33 +0100
The free_percpu() function tests whether its argument is NULL and then
returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
mm/zswap.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/mm/zswap.c b/mm/zswap.c
index ea064c1..35629f0 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -152,8 +152,7 @@ static int __init zswap_comp_init(void)
static void zswap_comp_exit(void)
{
/* free percpu transforms */
- if (zswap_comp_pcpu_tfms)
- free_percpu(zswap_comp_pcpu_tfms);
+ free_percpu(zswap_comp_pcpu_tfms);
}
/*********************************
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] hfs/hfs+: Deletion of unnecessary checks before the function call "hfs_bnode_put"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (35 preceding siblings ...)
2014-11-17 17:40 ` [Cocci] [PATCH 1/1] mm/zswap: Deletion of an unnecessary check before the function call "free_percpu" SF Markus Elfring
@ 2014-11-17 18:19 ` SF Markus Elfring
2014-11-17 18:42 ` [Cocci] [PATCH 1/1] configfs: Deletion of unnecessary checks before the function call "config_item_put" SF Markus Elfring
` (16 subsequent siblings)
53 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-17 18:19 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 17 Nov 2014 19:13:56 +0100
The hfs_bnode_put() function tests whether its argument is NULL and then
returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
fs/hfs/bfind.c | 3 +--
fs/hfs/brec.c | 3 +--
fs/hfsplus/bfind.c | 3 +--
fs/hfsplus/brec.c | 3 +--
4 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/fs/hfs/bfind.c b/fs/hfs/bfind.c
index de69d8a..0e26523 100644
--- a/fs/hfs/bfind.c
+++ b/fs/hfs/bfind.c
@@ -100,8 +100,7 @@ int hfs_brec_find(struct hfs_find_data *fd)
int height, res;
tree = fd->tree;
- if (fd->bnode)
- hfs_bnode_put(fd->bnode);
+ hfs_bnode_put(fd->bnode);
fd->bnode = NULL;
nidx = tree->root;
if (!nidx)
diff --git a/fs/hfs/brec.c b/fs/hfs/brec.c
index 9f4ee7f..3a52b2c 100644
--- a/fs/hfs/brec.c
+++ b/fs/hfs/brec.c
@@ -272,8 +272,7 @@ static struct hfs_bnode *hfs_bnode_split(struct hfs_find_data *fd)
/* panic? */
hfs_bnode_put(node);
hfs_bnode_put(new_node);
- if (next_node)
- hfs_bnode_put(next_node);
+ hfs_bnode_put(next_node);
return ERR_PTR(-ENOSPC);
}
diff --git a/fs/hfsplus/bfind.c b/fs/hfsplus/bfind.c
index c1422d9..7be88e3 100644
--- a/fs/hfsplus/bfind.c
+++ b/fs/hfsplus/bfind.c
@@ -171,8 +171,7 @@ int hfs_brec_find(struct hfs_find_data *fd, search_strategy_t do_key_compare)
int height, res;
tree = fd->tree;
- if (fd->bnode)
- hfs_bnode_put(fd->bnode);
+ hfs_bnode_put(fd->bnode);
fd->bnode = NULL;
nidx = tree->root;
if (!nidx)
diff --git a/fs/hfsplus/brec.c b/fs/hfsplus/brec.c
index 6e560d5..59bab47 100644
--- a/fs/hfsplus/brec.c
+++ b/fs/hfsplus/brec.c
@@ -276,8 +276,7 @@ static struct hfs_bnode *hfs_bnode_split(struct hfs_find_data *fd)
/* panic? */
hfs_bnode_put(node);
hfs_bnode_put(new_node);
- if (next_node)
- hfs_bnode_put(next_node);
+ hfs_bnode_put(next_node);
return ERR_PTR(-ENOSPC);
}
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] configfs: Deletion of unnecessary checks before the function call "config_item_put"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (36 preceding siblings ...)
2014-11-17 18:19 ` [Cocci] [PATCH 1/1] hfs/hfs+: Deletion of unnecessary checks before the function call "hfs_bnode_put" SF Markus Elfring
@ 2014-11-17 18:42 ` SF Markus Elfring
2014-11-18 8:35 ` [Cocci] [PATCH 1/1] fs-eventpoll: Deletion of unnecessary checks before the function call "__pm_stay_awake" SF Markus Elfring
` (15 subsequent siblings)
53 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-17 18:42 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 17 Nov 2014 19:37:03 +0100
The config_item_put() function tests whether its argument is NULL and then
returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
fs/configfs/file.c | 3 +--
fs/configfs/item.c | 3 +--
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/fs/configfs/file.c b/fs/configfs/file.c
index 1d1c41f..48f36e7 100644
--- a/fs/configfs/file.c
+++ b/fs/configfs/file.c
@@ -291,8 +291,7 @@ static int configfs_release(struct inode * inode, struct file * filp)
struct module * owner = attr->ca_owner;
struct configfs_buffer * buffer = filp->private_data;
- if (item)
- config_item_put(item);
+ config_item_put(item);
/* After this point, attr should not be accessed. */
module_put(owner);
diff --git a/fs/configfs/item.c b/fs/configfs/item.c
index e65f9ff..891b20e 100644
--- a/fs/configfs/item.c
+++ b/fs/configfs/item.c
@@ -153,8 +153,7 @@ static void config_item_cleanup(struct config_item *item)
t->ct_item_ops->release(item);
if (s)
config_group_put(s);
- if (parent)
- config_item_put(parent);
+ config_item_put(parent);
}
static void config_item_release(struct kref *kref)
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] fs-eventpoll: Deletion of unnecessary checks before the function call "__pm_stay_awake"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (37 preceding siblings ...)
2014-11-17 18:42 ` [Cocci] [PATCH 1/1] configfs: Deletion of unnecessary checks before the function call "config_item_put" SF Markus Elfring
@ 2014-11-18 8:35 ` SF Markus Elfring
2014-11-18 9:10 ` [Cocci] [PATCH 1/1] exofs: Deletion of an unnecessary check before the function call "ore_put_io_state" SF Markus Elfring
` (14 subsequent siblings)
53 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-18 8:35 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 18 Nov 2014 09:27:16 +0100
The __pm_stay_awake() function tests whether its argument is NULL and then
returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
fs/eventpoll.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 7bcfff9..eec2e85 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -555,8 +555,7 @@ static inline void ep_pm_stay_awake(struct epitem *epi)
{
struct wakeup_source *ws = ep_wakeup_source(epi);
- if (ws)
- __pm_stay_awake(ws);
+ __pm_stay_awake(ws);
}
static inline bool ep_has_wakeup_source(struct epitem *epi)
@@ -571,8 +570,7 @@ static inline void ep_pm_stay_awake_rcu(struct epitem *epi)
rcu_read_lock();
ws = rcu_dereference(epi->ws);
- if (ws)
- __pm_stay_awake(ws);
+ __pm_stay_awake(ws);
rcu_read_unlock();
}
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] exofs: Deletion of an unnecessary check before the function call "ore_put_io_state"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (38 preceding siblings ...)
2014-11-18 8:35 ` [Cocci] [PATCH 1/1] fs-eventpoll: Deletion of unnecessary checks before the function call "__pm_stay_awake" SF Markus Elfring
@ 2014-11-18 9:10 ` SF Markus Elfring
2014-11-18 10:35 ` [Cocci] [PATCH 1/1] GFS2: Deletion of unnecessary checks before two function calls SF Markus Elfring
` (13 subsequent siblings)
53 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-18 9:10 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 18 Nov 2014 10:05:19 +0100
The ore_put_io_state() function tests whether its argument is NULL and then
returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
fs/exofs/ore_raid.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fs/exofs/ore_raid.c b/fs/exofs/ore_raid.c
index 84529b8..5dc7c4c 100644
--- a/fs/exofs/ore_raid.c
+++ b/fs/exofs/ore_raid.c
@@ -716,6 +716,5 @@ void _ore_free_raid_stuff(struct ore_io_state *ios)
if (ios->extra_part_alloc)
kfree(ios->per_dev[0].sglist);
}
- if (ios->ios_read_4_write)
- ore_put_io_state(ios->ios_read_4_write);
+ ore_put_io_state(ios->ios_read_4_write);
}
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] GFS2: Deletion of unnecessary checks before two function calls
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (39 preceding siblings ...)
2014-11-18 9:10 ` [Cocci] [PATCH 1/1] exofs: Deletion of an unnecessary check before the function call "ore_put_io_state" SF Markus Elfring
@ 2014-11-18 10:35 ` SF Markus Elfring
2014-11-18 11:20 ` [Cocci] [PATCH 1/1] fs-namespace: Deletion of unnecessary checks before the function call "mntput" SF Markus Elfring
` (12 subsequent siblings)
53 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-18 10:35 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 18 Nov 2014 11:31:23 +0100
The functions iput() and put_pid() test whether their argument is NULL
and then return immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
fs/gfs2/glock.c | 3 +--
fs/gfs2/ops_fstype.c | 3 +--
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index 7f513b1..f4aa085 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -836,8 +836,7 @@ void gfs2_holder_reinit(unsigned int state, unsigned flags, struct gfs2_holder *
gh->gh_flags = flags;
gh->gh_iflags = 0;
gh->gh_ip = (unsigned long)__builtin_return_address(0);
- if (gh->gh_owner_pid)
- put_pid(gh->gh_owner_pid);
+ put_pid(gh->gh_owner_pid);
gh->gh_owner_pid = get_pid(task_pid(current));
}
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index d3eae24..272ff81 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -918,8 +918,7 @@ fail_qc_i:
fail_ut_i:
iput(sdp->sd_sc_inode);
fail:
- if (pn)
- iput(pn);
+ iput(pn);
return error;
}
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] fs-namespace: Deletion of unnecessary checks before the function call "mntput"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (40 preceding siblings ...)
2014-11-18 10:35 ` [Cocci] [PATCH 1/1] GFS2: Deletion of unnecessary checks before two function calls SF Markus Elfring
@ 2014-11-18 11:20 ` SF Markus Elfring
2014-11-18 13:10 ` [Cocci] [PATCH 1/1] NFS: Deletion of unnecessary checks before the function call "nfs_put_client" SF Markus Elfring
` (11 subsequent siblings)
53 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-18 11:20 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 18 Nov 2014 12:10:43 +0100
The mntput() function tests whether its argument is NULL and then
returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
fs/namespace.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/fs/namespace.c b/fs/namespace.c
index 550dbff..3b3710e 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -2615,10 +2615,8 @@ struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
}
namespace_unlock();
- if (rootmnt)
- mntput(rootmnt);
- if (pwdmnt)
- mntput(pwdmnt);
+ mntput(rootmnt);
+ mntput(pwdmnt);
return new_ns;
}
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] NFS: Deletion of unnecessary checks before the function call "nfs_put_client"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (41 preceding siblings ...)
2014-11-18 11:20 ` [Cocci] [PATCH 1/1] fs-namespace: Deletion of unnecessary checks before the function call "mntput" SF Markus Elfring
@ 2014-11-18 13:10 ` SF Markus Elfring
2014-11-18 13:48 ` [Cocci] [PATCH 1/1] nilfs2: Deletion of an unnecessary check before the function call "iput" SF Markus Elfring
` (10 subsequent siblings)
53 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-18 13:10 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 18 Nov 2014 13:23:43 +0100
The nfs_put_client() function tests whether its argument is NULL and then
returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
fs/nfs/filelayout/filelayoutdev.c | 3 +--
fs/nfs/nfs4client.c | 15 +++++----------
2 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/fs/nfs/filelayout/filelayoutdev.c b/fs/nfs/filelayout/filelayoutdev.c
index 8540516..cc5e7d6 100644
--- a/fs/nfs/filelayout/filelayoutdev.c
+++ b/fs/nfs/filelayout/filelayoutdev.c
@@ -204,8 +204,7 @@ destroy_ds(struct nfs4_pnfs_ds *ds)
ifdebug(FACILITY)
print_ds(ds);
- if (ds->ds_clp)
- nfs_put_client(ds->ds_clp);
+ nfs_put_client(ds->ds_clp);
while (!list_empty(&ds->ds_addrs)) {
da = list_first_entry(&ds->ds_addrs,
diff --git a/fs/nfs/nfs4client.c b/fs/nfs/nfs4client.c
index ffdb28d..5f07a0e 100644
--- a/fs/nfs/nfs4client.c
+++ b/fs/nfs/nfs4client.c
@@ -498,8 +498,7 @@ int nfs40_walk_client_list(struct nfs_client *new,
atomic_inc(&pos->cl_count);
spin_unlock(&nn->nfs_client_lock);
- if (prev)
- nfs_put_client(prev);
+ nfs_put_client(prev);
prev = pos;
status = nfs_wait_client_init_complete(pos);
@@ -517,8 +516,7 @@ int nfs40_walk_client_list(struct nfs_client *new,
atomic_inc(&pos->cl_count);
spin_unlock(&nn->nfs_client_lock);
- if (prev)
- nfs_put_client(prev);
+ nfs_put_client(prev);
prev = pos;
status = nfs4_proc_setclientid_confirm(pos, &clid, cred);
@@ -549,8 +547,7 @@ int nfs40_walk_client_list(struct nfs_client *new,
/* No match found. The server lost our clientid */
out:
- if (prev)
- nfs_put_client(prev);
+ nfs_put_client(prev);
dprintk("NFS: <-- %s status = %d\n", __func__, status);
return status;
}
@@ -641,8 +638,7 @@ int nfs41_walk_client_list(struct nfs_client *new,
atomic_inc(&pos->cl_count);
spin_unlock(&nn->nfs_client_lock);
- if (prev)
- nfs_put_client(prev);
+ nfs_put_client(prev);
prev = pos;
status = nfs_wait_client_init_complete(pos);
@@ -675,8 +671,7 @@ int nfs41_walk_client_list(struct nfs_client *new,
/* No matching nfs_client found. */
spin_unlock(&nn->nfs_client_lock);
dprintk("NFS: <-- %s status = %d\n", __func__, status);
- if (prev)
- nfs_put_client(prev);
+ nfs_put_client(prev);
return status;
}
#endif /* CONFIG_NFS_V4_1 */
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] nilfs2: Deletion of an unnecessary check before the function call "iput"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (42 preceding siblings ...)
2014-11-18 13:10 ` [Cocci] [PATCH 1/1] NFS: Deletion of unnecessary checks before the function call "nfs_put_client" SF Markus Elfring
@ 2014-11-18 13:48 ` SF Markus Elfring
2014-11-18 14:51 ` [Cocci] [PATCH 1/1] fs-proc: One function call less in proc_sys_lookup() after error detection SF Markus Elfring
` (9 subsequent siblings)
53 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-18 13:48 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 18 Nov 2014 14:41:27 +0100
The iput() function tests whether its argument is NULL and then
returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
fs/nilfs2/the_nilfs.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fs/nilfs2/the_nilfs.c b/fs/nilfs2/the_nilfs.c
index 9da25fe..69bd801 100644
--- a/fs/nilfs2/the_nilfs.c
+++ b/fs/nilfs2/the_nilfs.c
@@ -808,8 +808,7 @@ void nilfs_put_root(struct nilfs_root *root)
spin_lock(&nilfs->ns_cptree_lock);
rb_erase(&root->rb_node, &nilfs->ns_cptree);
spin_unlock(&nilfs->ns_cptree_lock);
- if (root->ifile)
- iput(root->ifile);
+ iput(root->ifile);
kfree(root);
}
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] fs-proc: One function call less in proc_sys_lookup() after error detection
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (43 preceding siblings ...)
2014-11-18 13:48 ` [Cocci] [PATCH 1/1] nilfs2: Deletion of an unnecessary check before the function call "iput" SF Markus Elfring
@ 2014-11-18 14:51 ` SF Markus Elfring
2014-11-18 17:55 ` [Cocci] [PATCH 0/2] fs-udf: Deletion of two unnecessary checks SF Markus Elfring
` (8 subsequent siblings)
53 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-18 14:51 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 18 Nov 2014 15:42:43 +0100
The sysctl_head_finish() function was called in an inefficient way by the
implementation of the proc_sys_lookup() function in case of a lookup failure.
The corresponding source code was improved by deletion of an unnecessary
null pointer check and a few adjustments for jump labels.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
fs/proc/proc_sysctl.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index f92d5dd..6606aaf 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -457,21 +457,21 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
ret = sysctl_follow_link(&h, &p, current->nsproxy);
err = ERR_PTR(ret);
if (ret)
- goto out;
+ goto inode_failure;
}
err = ERR_PTR(-ENOMEM);
inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
if (!inode)
- goto out;
+ goto inode_failure;
err = NULL;
d_set_d_op(dentry, &proc_sys_dentry_operations);
d_add(dentry, inode);
+inode_failure:
+ sysctl_head_finish(h);
out:
- if (h)
- sysctl_head_finish(h);
sysctl_head_finish(head);
return err;
}
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 0/2] fs-udf: Deletion of two unnecessary checks
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (44 preceding siblings ...)
2014-11-18 14:51 ` [Cocci] [PATCH 1/1] fs-proc: One function call less in proc_sys_lookup() after error detection SF Markus Elfring
@ 2014-11-18 17:55 ` SF Markus Elfring
2014-11-18 18:00 ` [Cocci] [PATCH 1/2] fs-udf: Deletion of unnecessary checks before the function call "iput" SF Markus Elfring
2014-11-18 18:02 ` [Cocci] [PATCH 2/2] fs-udf: One function call less in udf_fill_super() after error detection SF Markus Elfring
2014-11-18 19:16 ` [Cocci] [PATCH 1/1] net: pktgen: Deletion of an unnecessary check before the function call "proc_remove" SF Markus Elfring
` (7 subsequent siblings)
53 siblings, 2 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-18 17:55 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 18 Nov 2014 18:33:08 +0100
Another update suggestion was taken into account after a patch was applied
from static source code analysis.
Markus Elfring (2):
Deletion of unnecessary checks before the function call "iput"
One function call less in udf_fill_super() after error detection
fs/udf/super.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
--
2.1.3
^ permalink raw reply [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/2] fs-udf: Deletion of unnecessary checks before the function call "iput"
2014-11-18 17:55 ` [Cocci] [PATCH 0/2] fs-udf: Deletion of two unnecessary checks SF Markus Elfring
@ 2014-11-18 18:00 ` SF Markus Elfring
2014-11-18 18:02 ` [Cocci] [PATCH 2/2] fs-udf: One function call less in udf_fill_super() after error detection SF Markus Elfring
1 sibling, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-18 18:00 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 18 Nov 2014 17:17:46 +0100
The iput() function tests whether its argument is NULL and then
returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
fs/udf/super.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/fs/udf/super.c b/fs/udf/super.c
index e229315..f93c65d 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -2237,8 +2237,7 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
return 0;
error_out:
- if (sbi->s_vat_inode)
- iput(sbi->s_vat_inode);
+ iput(sbi->s_vat_inode);
#ifdef CONFIG_UDF_NLS
if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
unload_nls(sbi->s_nls_map);
@@ -2291,8 +2290,7 @@ static void udf_put_super(struct super_block *sb)
sbi = UDF_SB(sb);
- if (sbi->s_vat_inode)
- iput(sbi->s_vat_inode);
+ iput(sbi->s_vat_inode);
#ifdef CONFIG_UDF_NLS
if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
unload_nls(sbi->s_nls_map);
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread
* [Cocci] [PATCH 2/2] fs-udf: One function call less in udf_fill_super() after error detection
2014-11-18 17:55 ` [Cocci] [PATCH 0/2] fs-udf: Deletion of two unnecessary checks SF Markus Elfring
2014-11-18 18:00 ` [Cocci] [PATCH 1/2] fs-udf: Deletion of unnecessary checks before the function call "iput" SF Markus Elfring
@ 2014-11-18 18:02 ` SF Markus Elfring
1 sibling, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-18 18:02 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 18 Nov 2014 18:29:10 +0100
The iput() function was called in up to three cases by the udf_fill_super()
function during error handling even if the passed data structure element
contained still a null pointer. This implementation detail could be improved
by the introduction of another jump label.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
fs/udf/super.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/udf/super.c b/fs/udf/super.c
index f93c65d..3ccb2f1 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -2082,12 +2082,12 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
mutex_init(&sbi->s_alloc_mutex);
if (!udf_parse_options((char *)options, &uopt, false))
- goto error_out;
+ goto parse_options_failure;
if (uopt.flags & (1 << UDF_FLAG_UTF8) &&
uopt.flags & (1 << UDF_FLAG_NLS_MAP)) {
udf_err(sb, "utf8 cannot be combined with iocharset\n");
- goto error_out;
+ goto parse_options_failure;
}
#ifdef CONFIG_UDF_NLS
if ((uopt.flags & (1 << UDF_FLAG_NLS_MAP)) && !uopt.nls_map) {
@@ -2238,6 +2238,7 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
error_out:
iput(sbi->s_vat_inode);
+parse_options_failure:
#ifdef CONFIG_UDF_NLS
if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
unload_nls(sbi->s_nls_map);
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread
* [Cocci] [PATCH 1/1] net: pktgen: Deletion of an unnecessary check before the function call "proc_remove"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (45 preceding siblings ...)
2014-11-18 17:55 ` [Cocci] [PATCH 0/2] fs-udf: Deletion of two unnecessary checks SF Markus Elfring
@ 2014-11-18 19:16 ` SF Markus Elfring
2014-11-18 20:08 ` [Cocci] [PATCH 1/1] netlink: Deletion of an unnecessary check before the function call "__module_get" SF Markus Elfring
` (6 subsequent siblings)
53 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-18 19:16 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 18 Nov 2014 20:10:34 +0100
The proc_remove() function tests whether its argument is NULL and then
returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
net/core/pktgen.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 8b849dd..35046a8 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -3698,8 +3698,7 @@ static int pktgen_remove_device(struct pktgen_thread *t,
/* Remove proc before if_list entry, because add_device uses
* list to determine if interface already exist, avoid race
* with proc_create_data() */
- if (pkt_dev->entry)
- proc_remove(pkt_dev->entry);
+ proc_remove(pkt_dev->entry);
/* And update the thread if_list */
_rem_dev_from_if_list(t, pkt_dev);
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] netlink: Deletion of an unnecessary check before the function call "__module_get"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (46 preceding siblings ...)
2014-11-18 19:16 ` [Cocci] [PATCH 1/1] net: pktgen: Deletion of an unnecessary check before the function call "proc_remove" SF Markus Elfring
@ 2014-11-18 20:08 ` SF Markus Elfring
2014-11-18 20:26 ` [Cocci] [PATCH 1/1] net: sched: Deletion of an unnecessary check before the function call "kfree" SF Markus Elfring
` (5 subsequent siblings)
53 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-18 20:08 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 18 Nov 2014 21:03:13 +0100
The __module_get() function tests whether its argument is NULL and then
returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
net/netlink/af_netlink.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index f1de72d..0317b91 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -142,8 +142,7 @@ int netlink_add_tap(struct netlink_tap *nt)
list_add_rcu(&nt->list, &netlink_tap_all);
spin_unlock(&netlink_tap_lock);
- if (nt->module)
- __module_get(nt->module);
+ __module_get(nt->module);
return 0;
}
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] net: sched: Deletion of an unnecessary check before the function call "kfree"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (47 preceding siblings ...)
2014-11-18 20:08 ` [Cocci] [PATCH 1/1] netlink: Deletion of an unnecessary check before the function call "__module_get" SF Markus Elfring
@ 2014-11-18 20:26 ` SF Markus Elfring
2014-11-18 20:45 ` [Cocci] [PATCH 1/1] net: xfrm: Deletion of an unnecessary check before the function call "ipcomp_free_tfms" SF Markus Elfring
` (4 subsequent siblings)
53 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-18 20:26 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 18 Nov 2014 21:21:16 +0100
The kfree() function tests whether its argument is NULL and then
returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
net/sched/cls_bpf.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/net/sched/cls_bpf.c b/net/sched/cls_bpf.c
index 0e30d58..f323944 100644
--- a/net/sched/cls_bpf.c
+++ b/net/sched/cls_bpf.c
@@ -212,8 +212,7 @@ static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,
if (fp_old)
bpf_prog_destroy(fp_old);
- if (bpf_old)
- kfree(bpf_old);
+ kfree(bpf_old);
return 0;
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] net: xfrm: Deletion of an unnecessary check before the function call "ipcomp_free_tfms"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (48 preceding siblings ...)
2014-11-18 20:26 ` [Cocci] [PATCH 1/1] net: sched: Deletion of an unnecessary check before the function call "kfree" SF Markus Elfring
@ 2014-11-18 20:45 ` SF Markus Elfring
2014-11-19 8:45 ` Dan Carpenter
2014-11-18 21:03 ` [Cocci] [PATCH 1/1] keys: Deletion of an unnecessary check before the function call "key_put" SF Markus Elfring
` (3 subsequent siblings)
53 siblings, 1 reply; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-18 20:45 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 18 Nov 2014 21:41:26 +0100
The ipcomp_free_tfms() function tests whether its argument is NULL and then
returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
net/xfrm/xfrm_ipcomp.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/net/xfrm/xfrm_ipcomp.c b/net/xfrm/xfrm_ipcomp.c
index ccfdc71..47863cd 100644
--- a/net/xfrm/xfrm_ipcomp.c
+++ b/net/xfrm/xfrm_ipcomp.c
@@ -320,8 +320,7 @@ error:
static void ipcomp_free_data(struct ipcomp_data *ipcd)
{
- if (ipcd->tfms)
- ipcomp_free_tfms(ipcd->tfms);
+ ipcomp_free_tfms(ipcd->tfms);
ipcomp_free_scratches();
}
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] keys: Deletion of an unnecessary check before the function call "key_put"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (49 preceding siblings ...)
2014-11-18 20:45 ` [Cocci] [PATCH 1/1] net: xfrm: Deletion of an unnecessary check before the function call "ipcomp_free_tfms" SF Markus Elfring
@ 2014-11-18 21:03 ` SF Markus Elfring
2014-11-29 13:42 ` [Cocci] [PATCH 1/1] HID: Wacom: Deletion of an unnecessary check before the function call "vfree" SF Markus Elfring
` (2 subsequent siblings)
53 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-18 21:03 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 18 Nov 2014 21:57:14 +0100
The key_put() function tests whether its argument is NULL and then
returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
security/keys/process_keys.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/security/keys/process_keys.c b/security/keys/process_keys.c
index 0cf8a13..ce00e11 100644
--- a/security/keys/process_keys.c
+++ b/security/keys/process_keys.c
@@ -242,8 +242,7 @@ int install_session_keyring_to_cred(struct cred *cred, struct key *keyring)
old = cred->session_keyring;
rcu_assign_pointer(cred->session_keyring, keyring);
- if (old)
- key_put(old);
+ key_put(old);
return 0;
}
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] HID: Wacom: Deletion of an unnecessary check before the function call "vfree"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (50 preceding siblings ...)
2014-11-18 21:03 ` [Cocci] [PATCH 1/1] keys: Deletion of an unnecessary check before the function call "key_put" SF Markus Elfring
@ 2014-11-29 13:42 ` SF Markus Elfring
2014-11-29 14:05 ` [Cocci] [PATCH 1/1] net: cassini: " SF Markus Elfring
2014-11-29 14:33 ` [Cocci] [PATCH 1/1] HID: Wacom: Deletion of unnecessary checks before the function call "input_free_device" SF Markus Elfring
[not found] ` <66bd684a-98f1-0ec4-aa95-1a966d7c4e90@users.sourceforge.net>
53 siblings, 1 reply; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-29 13:42 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 29 Nov 2014 14:34:59 +0100
The vfree() function performs also input parameter validation.
Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/net/ethernet/sun/cassini.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/sun/cassini.c b/drivers/net/ethernet/sun/cassini.c
index 37f87ff..d745808 100644
--- a/drivers/net/ethernet/sun/cassini.c
+++ b/drivers/net/ethernet/sun/cassini.c
@@ -5179,8 +5179,7 @@ static void cas_remove_one(struct pci_dev *pdev)
cp = netdev_priv(dev);
unregister_netdev(dev);
- if (cp->fw_data)
- vfree(cp->fw_data);
+ vfree(cp->fw_data);
mutex_lock(&cp->pm_mutex);
cancel_work_sync(&cp->reset_task);
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread* [Cocci] [PATCH 1/1] net: cassini: Deletion of an unnecessary check before the function call "vfree"
2014-11-29 13:42 ` [Cocci] [PATCH 1/1] HID: Wacom: Deletion of an unnecessary check before the function call "vfree" SF Markus Elfring
@ 2014-11-29 14:05 ` SF Markus Elfring
0 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-29 14:05 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 29 Nov 2014 14:34:59 +0100
The vfree() function performs also input parameter validation.
Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/net/ethernet/sun/cassini.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/sun/cassini.c b/drivers/net/ethernet/sun/cassini.c
index 37f87ff..d745808 100644
--- a/drivers/net/ethernet/sun/cassini.c
+++ b/drivers/net/ethernet/sun/cassini.c
@@ -5179,8 +5179,7 @@ static void cas_remove_one(struct pci_dev *pdev)
cp = netdev_priv(dev);
unregister_netdev(dev);
- if (cp->fw_data)
- vfree(cp->fw_data);
+ vfree(cp->fw_data);
mutex_lock(&cp->pm_mutex);
cancel_work_sync(&cp->reset_task);
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread
* [Cocci] [PATCH 1/1] HID: Wacom: Deletion of unnecessary checks before the function call "input_free_device"
2014-03-05 22:30 ` [Cocci] [PATCH with Coccinelle?] Deletion of unnecessary checks before specific function calls SF Markus Elfring
` (51 preceding siblings ...)
2014-11-29 13:42 ` [Cocci] [PATCH 1/1] HID: Wacom: Deletion of an unnecessary check before the function call "vfree" SF Markus Elfring
@ 2014-11-29 14:33 ` SF Markus Elfring
[not found] ` <66bd684a-98f1-0ec4-aa95-1a966d7c4e90@users.sourceforge.net>
53 siblings, 0 replies; 268+ messages in thread
From: SF Markus Elfring @ 2014-11-29 14:33 UTC (permalink / raw)
To: cocci
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 29 Nov 2014 15:16:01 +0100
The input_free_device() 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>
---
drivers/hid/wacom_sys.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
index eb55316..21ced00 100644
--- a/drivers/hid/wacom_sys.c
+++ b/drivers/hid/wacom_sys.c
@@ -1099,10 +1099,8 @@ static void wacom_free_inputs(struct wacom *wacom)
{
struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
- if (wacom_wac->input)
- input_free_device(wacom_wac->input);
- if (wacom_wac->pad_input)
- input_free_device(wacom_wac->pad_input);
+ input_free_device(wacom_wac->input);
+ input_free_device(wacom_wac->pad_input);
wacom_wac->input = NULL;
wacom_wac->pad_input = NULL;
}
--
2.1.3
^ permalink raw reply related [flat|nested] 268+ messages in thread[parent not found: <66bd684a-98f1-0ec4-aa95-1a966d7c4e90@users.sourceforge.net>]