> If you are convinced that dropping the null tests is a good idea, then you > can submit the patch that makes the change to the relevant maintainers and > mailing lists. Hello, A couple of functions perform input parameter validation before their implementations will try further actions with side effects. Some calling functions perform similar safety checks. Functions which release a system resource are often documented in the way that they tolerate the passing of a null pointer for example. I do not see a need because of this fact that a function caller repeats a corresponding check. Now I would like to propose such a change again. 1. Extension of the infrastructure for the analysis tool "coccicheck" Semantic patch patterns can help to identify update candidates also in the Linux source file hierarchy. https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/scripts/coccinelle?idyf0345fefaafb7cde301a830471edd21a37989b 2. Clarification for some automated update suggestions My source code search approach found seventy functions at least which might need another review and corresponding corrections for Linux 3.14-rc5. Further software development will point out even more potentially open issues. Regards, Markus
>> If you are convinced that dropping the null tests is a good idea, then you >> can submit the patch that makes the change to the relevant maintainers and >> mailing lists. From 48c9c4f61a7d7ea98538e02631a981a429281005 Mon Sep 17 00:00:00 2001 From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 5 Mar 2014 18:15:34 +0100 Subject: [PATCH 1/5] Addition of a semantic patch file for showing unnecessary checks before a few known functions This semantic patch pattern tries to find source code places where a check is performed for an expression that is passed to a function (like "kfree") which checks this single parameter itself for usability. Redundant value or pointer checks can be avoided here. The pattern contains a special comment in a regular expression for a SmPL constraint which supports extensions. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- .../deletions/delete_unnecessary_checks_template1.cocci | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 scripts/coccinelle/deletions/delete_unnecessary_checks_template1.cocci diff --git a/scripts/coccinelle/deletions/delete_unnecessary_checks_template1.cocci b/scripts/coccinelle/deletions/delete_unnecessary_checks_template1.cocci new file mode 100644 index 0000000..b092051 --- /dev/null +++ b/scripts/coccinelle/deletions/delete_unnecessary_checks_template1.cocci @@ -0,0 +1,13 @@ +@Delete_unnecessary_checks@ +expression x; +identifier release =~ "^(?x) +(?: + (?:kz?|slob_)free +| + (?: +# Alternation placeholder + ) +)$"; +@@ +-if (x) + release(x); -- 1.9.0
>> If you are convinced that dropping the null tests is a good idea, then you >> can submit the patch that makes the change to the relevant maintainers and >> mailing lists. From 1d2de3c3cfa43cc3c78a91200c41cef438b26a8f Mon Sep 17 00:00:00 2001 From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 5 Mar 2014 18:38:43 +0100 Subject: [PATCH 2/5] Addition of a semantic patch file for listing of functions that check their single parameter This semantic patch pattern tries to find functions that check their single parameter for usability. Example: Null pointer checks are often performed as input parameter validation. It uses Python statements to write information about the found source code places in a data format that is a variant of a CSV text file. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- .../list_input_parameter_validation1.cocci | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 scripts/coccinelle/deletions/list_input_parameter_validation1.cocci diff --git a/scripts/coccinelle/deletions/list_input_parameter_validation1.cocci b/scripts/coccinelle/deletions/list_input_parameter_validation1.cocci new file mode 100644 index 0000000..b0a5a52 --- /dev/null +++ b/scripts/coccinelle/deletions/list_input_parameter_validation1.cocci @@ -0,0 +1,55 @@ +@initialize:python@ +@@ +import sys +result = [] +mark = ['"', '', '"'] +delimiter = '|' + +def store_positions(fun, typ, point, places): + """Add source code positions to an internal list.""" + for place in places: + fields = [] + fields.append(fun) + + mark[1] = typ + fields.append(''.join(mark)) + + fields.append(point) + + mark[1] = place.file.replace('"', '""') + fields.append(''.join(mark)) + + fields.append(place.line) + fields.append(str(int(place.column) + 1)) + result.append(delimiter.join(fields)) + +@safety_check@ +identifier work, input; +type data_type; +position pos; +statement is, es; +@@ + void work@pos(data_type input) + { + ... when any +( if (input) is else es +| if (likely(input)) is else es +) + ... when any + } + +@script:python collection depends on safety_check@ +typ << safety_check.data_type; +fun << safety_check.work; +point << safety_check.input; +places << safety_check.pos; +@@ +store_positions(fun, typ, point, places) + +@finalize:python@ +@@ +if result: + result.insert(0, delimiter.join(("function", '"data type"', '"parameter"', '"source file"', "line", "column"))) + print("\r\n".join(result)) +else: + sys.stderr.write("No result for this analysis!\n") -- 1.9.0
>> 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
>> If you are convinced that dropping the null tests is a good idea, then you
>> can submit the patch that makes the change to the relevant maintainers and
>> mailing lists.
From e6a21b920fcca2f6f01c9528909dc036a9b3bc41 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 5 Mar 2014 19:10:32 +0100
Subject: [PATCH 4/5] Addition of a semantic patch file for listing of
unnecessary checks before a few known functions
This semantic patch pattern tries to find source code places where a check
is performed for an expression that is passed to a function (like "kfree")
which checks this single parameter itself for usability.
Redundant value or pointer checks can be avoided here.
The pattern contains a special comment in a regular expression for a SmPL
constraint which supports extensions.
It uses Python statements to write information about the found places in
a data format that is a variant of a CSV text file.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
...nctions_with_unnecessary_checks_template1.cocci | 59 ++++++++++++++++++++++
1 file changed, 59 insertions(+)
create mode 100644
scripts/coccinelle/deletions/list_functions_with_unnecessary_checks_template1.cocci
diff --git
a/scripts/coccinelle/deletions/list_functions_with_unnecessary_checks_template1.cocci
b/scripts/coccinelle/deletions/list_functions_with_unnecessary_checks_template1.cocci
new file mode 100644
index 0000000..d2637e8
--- /dev/null
+++
b/scripts/coccinelle/deletions/list_functions_with_unnecessary_checks_template1.cocci
@@ -0,0 +1,59 @@
+@initialize:python@
+@@
+import sys
+result = []
+mark = ['"', '', '"']
+delimiter = '|'
+
+def store_positions(fun, point, places):
+ """Add source code positions to an internal list."""
+ for place in places:
+ fields = []
+ fields.append(fun)
+
+ fields.append(point)
+
+ mark[1] = place.file.replace('"', '""')
+ fields.append(''.join(mark))
+
+ fields.append(place.line)
+ fields.append(str(int(place.column) + 1))
+ result.append(delimiter.join(fields))
+
+@is_unnecessary_check@
+expression data;
+identifier work;
+identifier release =~ "^(?x)
+(?:
+ (?:kz?|slob_)free
+|
+ (?:
+# Alternation placeholder
+ )
+)$";
+position pos;
+type t;
+@@
+ t work@pos(...)
+ {
+ ... when any
+( if (data) release(data);
+| if (likely(data)) release(data);
+)
+ ... when any
+ }
+
+@script:python collection depends on is_unnecessary_check@
+fun << is_unnecessary_check.work;
+point << is_unnecessary_check.data;
+places << is_unnecessary_check.pos;
+@@
+store_positions(fun, point, places)
+
+@finalize:python@
+@@
+if result:
+ result.insert(0, delimiter.join(("function", '"parameter"', '"source file"',
"line", "column")))
+ print("\r\n".join(result))
+else:
+ sys.stderr.write("No result for this analysis!\n")
--
1.9.0
>> If you are convinced that dropping the null tests is a good idea, then you >> can submit the patch that makes the change to the relevant maintainers and >> mailing lists. From bedf1cb3ddd162ee3b4c31cbb98d97431f70103d Mon Sep 17 00:00:00 2001 From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 5 Mar 2014 19:40:43 +0100 Subject: [PATCH 5/5] Addition of a make file for build automation This script can be used to combine some input files for the desired data output which will eventually show update candidates for further source code review. Some build targets were defined. Values for the used make variables can be adjusted by parameters on the command line as usual. A few implementation details might need more fine-tuning. - Automatic determination of the Linux source directory from a calling make process - Setting of an extra output directory for the generated files Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- scripts/coccinelle/deletions/makefile | 126 ++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 scripts/coccinelle/deletions/makefile diff --git a/scripts/coccinelle/deletions/makefile b/scripts/coccinelle/deletions/makefile new file mode 100644 index 0000000..6464bae --- /dev/null +++ b/scripts/coccinelle/deletions/makefile @@ -0,0 +1,126 @@ +SED=sed +SPATCH=spatch.opt --sp-file +RM=rm -f +LINUX_SOURCE_DIR=/usr/src/linux-stable +EXTRACT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER=list_input_parameter_validation1.cocci +SQLITE=sqlite3 +SQLITE_IMPORT_SCRIPT=handle_function_list.sqlite +SQLITE_IMPORT_SCRIPT_TEMPLATE=handle_function_list_template.sqlite +RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER=list_input_parameter_validation1.txt +RESULT_SQL_DATA_BASE=result.db +RESULT_FUNCTIONS_WITH_PREFIXd_prefix-SQL.txt +RESULT_FUNCTIONS_WITH_UNNECESSARY_CHECKS_AS_LIST=list_functions_with_unnecessary_checks1.txt +RESULT_FUNCTIONS_WITH_UNNECESSARY_CHECKS_AS_PATCH=functions_with_unnecessary_checks1.diff +LOG_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER=list_input_parameter_validation1-errors.txt +LOG_LIST_FUNCTIONS_WITH_UNNECESSARY_CHECKS=list_functions_with_unnecessary_checks1-errors.txt +LOG_PATCH_FUNCTIONS_WITH_UNNECESSARY_CHECKS=functions_with_unnecessary_checks1-errors.txt +LIST_PATTERN_TEMPLATE=list_functions_with_unnecessary_checks_template1.cocci +LIST_PATTERN=list_functions_with_unnecessary_checks1.cocci +PATCH_PATTERN_TEMPLATEÞlete_unnecessary_checks_template1.cocci +PATCH_PATTERNÞlete_unnecessary_checks1.cocci +ESCAPING=XY=$$(< $(RESULT_FUNCTIONS_WITH_PREFIX)) \ + && XY=$${XY/|/ } \ + && XY=$${XY//%/\\%} \ + && $(SED) "s%\# Alternation placeholder%$${XY//$$'\n'/$$'\\\\\n'}%" +TEXT1=A pattern file was built from which a +TEXT2=was generated. Good luck with source code review! + +default: build_update_candidate_list + +$(RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER): \ +$(EXTRACT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) + $(SPATCH) $(EXTRACT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) \ +-dir $(LINUX_SOURCE_DIR) \ +> $@ 2> $(LOG_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) + +# This replacement action is needed for the use case that the corresponding +# variable was overridden. +$(SQLITE_IMPORT_SCRIPT): $(SQLITE_IMPORT_SCRIPT_TEMPLATE) + $(SED) "s%import list_input_pointer_validation1\.txt%import $(subst %,\%,$(RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER))%" \ +$(SQLITE_IMPORT_SCRIPT_TEMPLATE) > $@ + +$(RESULT_SQL_DATA_BASE) $(RESULT_FUNCTIONS_WITH_PREFIX): \ +$(RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) \ +$(SQLITE_IMPORT_SCRIPT) + @$(RM) $(RESULT_SQL_DATA_BASE) + $(SQLITE) -init $(SQLITE_IMPORT_SCRIPT) $(RESULT_SQL_DATA_BASE) \ +'select '\'' | '\'' || function from positions group by function order by function desc;' \ +> $(RESULT_FUNCTIONS_WITH_PREFIX) + +$(LIST_PATTERN): $(RESULT_FUNCTIONS_WITH_PREFIX) + $(ESCAPING) $(LIST_PATTERN_TEMPLATE) > $@ + +$(PATCH_PATTERN): $(RESULT_FUNCTIONS_WITH_PREFIX) + $(ESCAPING) $(PATCH_PATTERN_TEMPLATE) > $@ + +$(RESULT_FUNCTIONS_WITH_UNNECESSARY_CHECKS_AS_LIST): $(LIST_PATTERN) + $(SPATCH) $(LIST_PATTERN) -dir $(LINUX_SOURCE_DIR) \ +> $@ 2> $(LOG_LIST_FUNCTIONS_WITH_UNNECESSARY_CHECKS) + +$(RESULT_FUNCTIONS_WITH_UNNECESSARY_CHECKS_AS_PATCH): $(PATCH_PATTERN) + $(SPATCH) $(PATCH_PATTERN) -dir $(LINUX_SOURCE_DIR) \ +> $@ 2> $(LOG_PATCH_FUNCTIONS_WITH_UNNECESSARY_CHECKS) + +build_check_list generate_list_of_functions_which_check_their_single_parameter: \ +$(RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) + @echo 'The list of functions which check their single parameter was generated.' + +build_import_script: $(SQLITE_IMPORT_SCRIPT) + @echo 'A script was generated which should contain appropriate parameters for a data base.' + +build_data_base: $(RESULT_SQL_DATA_BASE) + @echo 'A SQL data base was built.' + +build_alternation add_prefix_to_functions: build_data_base + @echo 'The function name list was converted to a component for a regular expression.' + +build_list_pattern: $(LIST_PATTERN) + @echo '$(TEXT1) list can be generated.' + +build_patch_pattern: $(PATCH_PATTERN) + @echo '$(TEXT1) patch can be generated.' + +build_update_candidate_list show_list_of_update_candidates: build_list_pattern \ +$(RESULT_FUNCTIONS_WITH_UNNECESSARY_CHECKS_AS_LIST) + @echo 'The list of update candidates $(TEXT2)' + +build_patch show_update_suggestion: build_patch_pattern \ +$(RESULT_FUNCTIONS_WITH_UNNECESSARY_CHECKS_AS_PATCH) + @echo 'A patch file $(TEXT2)' + +all: build_update_candidate_list build_patch + +clean: + $(RM) *-errors.txt \ +$(LIST_PATTERN) \ +$(PATCH_PATTERN) \ +$(RESULT_FUNCTIONS_WITH_PREFIX) \ +$(RESULT_SQL_DATA_BASE) \ +$(RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) \ +$(SQLITE_IMPORT_SCRIPT) + +delete_data_base: + $(RM) $(RESULT_SQL_DATA_BASE) \ +$(RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) + +.PHONY: all \ +build_check_list \ +build_data_base \ +build_import_script \ +build_list_pattern \ +build_patch \ +build_patch_pattern \ +build_update_candidate_list \ +clean \ +default \ +delete_data_base \ +generate_list_of_functions_which_check_their_single_parameter \ +show_list_of_update_candidates \ +show_update_suggestion + + +# The following input files should not need further actions here. +$(EXTRACT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) \ +$(SQLITE_IMPORT_SCRIPT_TEMPLATE) \ +$(LIST_PATTERN_TEMPLATE) \ +$(PATCH_PATTERN_TEMPLATE): ; -- 1.9.0 -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
>> If you are convinced that dropping the null tests is a good idea, then you >> can submit the patch that makes the change to the relevant maintainers and >> mailing lists. Hello, A couple of functions perform input parameter validation before their implementations will try further actions with side effects. Some calling functions perform similar safety checks. Functions which release a system resource are occasionally documented in the way that they tolerate the passing of a null pointer for example. I do not see a need because of this fact that a function caller repeats a corresponding check. Now I would like to propose such a change again. 1. Extension of the infrastructure for the analysis tool "coccicheck" Semantic patch patterns can help to identify update candidates also in the Linux source file hierarchy. https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/scripts/coccinelle?idyf0345fefaafb7cde301a830471edd21a37989b Would you like to reconsider an approach which was discussed with a subject like "scripts/coccinelle/free: Delete NULL test before freeing functions?" a while ago? https://lkml.org/lkml/2014/8/9/36 https://groups.google.com/d/msg/linux.kernel/rIWfYsRRW6I/cTs6y0STf2cJ 2. Clarification for some automated update suggestions My source code search approach found 227 functions with the help of the software "Coccinelle 1.0.0-rc22" at least which might need another review and corresponding corrections for Linux 3.16.3. Further software development will point out even more potentially open issues. Regards, Markus
>>> If you are convinced that dropping the null tests is a good idea, then you >>> can submit the patch that makes the change to the relevant maintainers and >>> mailing lists. From 48c9c4f61a7d7ea98538e02631a981a429281005 Mon Sep 17 00:00:00 2001 From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 5 Mar 2014 18:15:34 +0100 Subject: [PATCH 1/5] Addition of a semantic patch file for showing unnecessary checks before a few known functions This semantic patch pattern tries to find source code places where a check is performed for an expression that is passed to a function (like "kfree") which checks this single parameter itself for usability. Redundant value or pointer checks can be avoided here. The pattern contains a special comment in a regular expression for a SmPL constraint which supports extensions. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- .../deletions/delete_unnecessary_checks_template1.cocci | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 scripts/coccinelle/deletions/delete_unnecessary_checks_template1.cocci diff --git a/scripts/coccinelle/deletions/delete_unnecessary_checks_template1.cocci b/scripts/coccinelle/deletions/delete_unnecessary_checks_template1.cocci new file mode 100644 index 0000000..b092051 --- /dev/null +++ b/scripts/coccinelle/deletions/delete_unnecessary_checks_template1.cocci @@ -0,0 +1,13 @@ +@Delete_unnecessary_checks@ +expression x; +identifier release =~ "^(?x) +(?: + (?:kz?|slob_)free +| + (?: +# Alternation placeholder + ) +)$"; +@@ +-if (x) + release(x); -- 1.9.0
>>> If you are convinced that dropping the null tests is a good idea, then you >>> can submit the patch that makes the change to the relevant maintainers and >>> mailing lists. From 1d2de3c3cfa43cc3c78a91200c41cef438b26a8f Mon Sep 17 00:00:00 2001 From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 5 Mar 2014 18:38:43 +0100 Subject: [PATCH 2/5] Addition of a semantic patch file for listing of functions that check their single parameter This semantic patch pattern tries to find functions that check their single parameter for usability. Example: Null pointer checks are often performed as input parameter validation. It uses Python statements to write information about the found source code places in a data format that is a variant of a CSV text file. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- .../list_input_parameter_validation1.cocci | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 scripts/coccinelle/deletions/list_input_parameter_validation1.cocci diff --git a/scripts/coccinelle/deletions/list_input_parameter_validation1.cocci b/scripts/coccinelle/deletions/list_input_parameter_validation1.cocci new file mode 100644 index 0000000..b0a5a52 --- /dev/null +++ b/scripts/coccinelle/deletions/list_input_parameter_validation1.cocci @@ -0,0 +1,55 @@ +@initialize:python@ +@@ +import sys +result = [] +mark = ['"', '', '"'] +delimiter = '|' + +def store_positions(fun, typ, point, places): + """Add source code positions to an internal list.""" + for place in places: + fields = [] + fields.append(fun) + + mark[1] = typ + fields.append(''.join(mark)) + + fields.append(point) + + mark[1] = place.file.replace('"', '""') + fields.append(''.join(mark)) + + fields.append(place.line) + fields.append(str(int(place.column) + 1)) + result.append(delimiter.join(fields)) + +@safety_check@ +identifier work, input; +type data_type; +position pos; +statement is, es; +@@ + void work@pos(data_type input) + { + ... when any +( if (input) is else es +| if (likely(input)) is else es +) + ... when any + } + +@script:python collection depends on safety_check@ +typ << safety_check.data_type; +fun << safety_check.work; +point << safety_check.input; +places << safety_check.pos; +@@ +store_positions(fun, typ, point, places) + +@finalize:python@ +@@ +if result: + result.insert(0, delimiter.join(("function", '"data type"', '"parameter"', '"source file"', "line", "column"))) + print("\r\n".join(result)) +else: + sys.stderr.write("No result for this analysis!\n") -- 1.9.0
>>> 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
>>> If you are convinced that dropping the null tests is a good idea, then you
>>> can submit the patch that makes the change to the relevant maintainers and
>>> mailing lists.
From e6a21b920fcca2f6f01c9528909dc036a9b3bc41 Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 5 Mar 2014 19:10:32 +0100
Subject: [PATCH 4/5] Addition of a semantic patch file for listing of
unnecessary checks before a few known functions
This semantic patch pattern tries to find source code places where a check
is performed for an expression that is passed to a function (like "kfree")
which checks this single parameter itself for usability.
Redundant value or pointer checks can be avoided here.
The pattern contains a special comment in a regular expression for a SmPL
constraint which supports extensions.
It uses Python statements to write information about the found places in
a data format that is a variant of a CSV text file.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
...nctions_with_unnecessary_checks_template1.cocci | 59 ++++++++++++++++++++++
1 file changed, 59 insertions(+)
create mode 100644
scripts/coccinelle/deletions/list_functions_with_unnecessary_checks_template1.cocci
diff --git
a/scripts/coccinelle/deletions/list_functions_with_unnecessary_checks_template1.cocci
b/scripts/coccinelle/deletions/list_functions_with_unnecessary_checks_template1.cocci
new file mode 100644
index 0000000..d2637e8
--- /dev/null
+++
b/scripts/coccinelle/deletions/list_functions_with_unnecessary_checks_template1.cocci
@@ -0,0 +1,59 @@
+@initialize:python@
+@@
+import sys
+result = []
+mark = ['"', '', '"']
+delimiter = '|'
+
+def store_positions(fun, point, places):
+ """Add source code positions to an internal list."""
+ for place in places:
+ fields = []
+ fields.append(fun)
+
+ fields.append(point)
+
+ mark[1] = place.file.replace('"', '""')
+ fields.append(''.join(mark))
+
+ fields.append(place.line)
+ fields.append(str(int(place.column) + 1))
+ result.append(delimiter.join(fields))
+
+@is_unnecessary_check@
+expression data;
+identifier work;
+identifier release =~ "^(?x)
+(?:
+ (?:kz?|slob_)free
+|
+ (?:
+# Alternation placeholder
+ )
+)$";
+position pos;
+type t;
+@@
+ t work@pos(...)
+ {
+ ... when any
+( if (data) release(data);
+| if (likely(data)) release(data);
+)
+ ... when any
+ }
+
+@script:python collection depends on is_unnecessary_check@
+fun << is_unnecessary_check.work;
+point << is_unnecessary_check.data;
+places << is_unnecessary_check.pos;
+@@
+store_positions(fun, point, places)
+
+@finalize:python@
+@@
+if result:
+ result.insert(0, delimiter.join(("function", '"parameter"', '"source file"',
"line", "column")))
+ print("\r\n".join(result))
+else:
+ sys.stderr.write("No result for this analysis!\n")
--
1.9.0
>>> If you are convinced that dropping the null tests is a good idea, then you >>> can submit the patch that makes the change to the relevant maintainers and >>> mailing lists. From bedf1cb3ddd162ee3b4c31cbb98d97431f70103d Mon Sep 17 00:00:00 2001 From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 5 Mar 2014 19:40:43 +0100 Subject: [PATCH 5/5] Addition of a make file for build automation This script can be used to combine some input files for the desired data output which will eventually show update candidates for further source code review. Some build targets were defined. Values for the used make variables can be adjusted by parameters on the command line as usual. A few implementation details might need more fine-tuning. - Automatic determination of the Linux source directory from a calling make process - Setting of an extra output directory for the generated files Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- scripts/coccinelle/deletions/makefile | 126 ++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 scripts/coccinelle/deletions/makefile diff --git a/scripts/coccinelle/deletions/makefile b/scripts/coccinelle/deletions/makefile new file mode 100644 index 0000000..6464bae --- /dev/null +++ b/scripts/coccinelle/deletions/makefile @@ -0,0 +1,126 @@ +SED=sed +SPATCH=spatch.opt --sp-file +RM=rm -f +LINUX_SOURCE_DIR=/usr/src/linux-stable +EXTRACT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER=list_input_parameter_validation1.cocci +SQLITE=sqlite3 +SQLITE_IMPORT_SCRIPT=handle_function_list.sqlite +SQLITE_IMPORT_SCRIPT_TEMPLATE=handle_function_list_template.sqlite +RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER=list_input_parameter_validation1.txt +RESULT_SQL_DATA_BASE=result.db +RESULT_FUNCTIONS_WITH_PREFIXd_prefix-SQL.txt +RESULT_FUNCTIONS_WITH_UNNECESSARY_CHECKS_AS_LIST=list_functions_with_unnecessary_checks1.txt +RESULT_FUNCTIONS_WITH_UNNECESSARY_CHECKS_AS_PATCH=functions_with_unnecessary_checks1.diff +LOG_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER=list_input_parameter_validation1-errors.txt +LOG_LIST_FUNCTIONS_WITH_UNNECESSARY_CHECKS=list_functions_with_unnecessary_checks1-errors.txt +LOG_PATCH_FUNCTIONS_WITH_UNNECESSARY_CHECKS=functions_with_unnecessary_checks1-errors.txt +LIST_PATTERN_TEMPLATE=list_functions_with_unnecessary_checks_template1.cocci +LIST_PATTERN=list_functions_with_unnecessary_checks1.cocci +PATCH_PATTERN_TEMPLATEÞlete_unnecessary_checks_template1.cocci +PATCH_PATTERNÞlete_unnecessary_checks1.cocci +ESCAPING=XY=$$(< $(RESULT_FUNCTIONS_WITH_PREFIX)) \ + && XY=$${XY/|/ } \ + && XY=$${XY//%/\\%} \ + && $(SED) "s%\# Alternation placeholder%$${XY//$$'\n'/$$'\\\\\n'}%" +TEXT1=A pattern file was built from which a +TEXT2=was generated. Good luck with source code review! + +default: build_update_candidate_list + +$(RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER): \ +$(EXTRACT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) + $(SPATCH) $(EXTRACT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) \ +-dir $(LINUX_SOURCE_DIR) \ +> $@ 2> $(LOG_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) + +# This replacement action is needed for the use case that the corresponding +# variable was overridden. +$(SQLITE_IMPORT_SCRIPT): $(SQLITE_IMPORT_SCRIPT_TEMPLATE) + $(SED) "s%import list_input_pointer_validation1\.txt%import $(subst %,\%,$(RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER))%" \ +$(SQLITE_IMPORT_SCRIPT_TEMPLATE) > $@ + +$(RESULT_SQL_DATA_BASE) $(RESULT_FUNCTIONS_WITH_PREFIX): \ +$(RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) \ +$(SQLITE_IMPORT_SCRIPT) + @$(RM) $(RESULT_SQL_DATA_BASE) + $(SQLITE) -init $(SQLITE_IMPORT_SCRIPT) $(RESULT_SQL_DATA_BASE) \ +'select '\'' | '\'' || function from positions group by function order by function desc;' \ +> $(RESULT_FUNCTIONS_WITH_PREFIX) + +$(LIST_PATTERN): $(RESULT_FUNCTIONS_WITH_PREFIX) + $(ESCAPING) $(LIST_PATTERN_TEMPLATE) > $@ + +$(PATCH_PATTERN): $(RESULT_FUNCTIONS_WITH_PREFIX) + $(ESCAPING) $(PATCH_PATTERN_TEMPLATE) > $@ + +$(RESULT_FUNCTIONS_WITH_UNNECESSARY_CHECKS_AS_LIST): $(LIST_PATTERN) + $(SPATCH) $(LIST_PATTERN) -dir $(LINUX_SOURCE_DIR) \ +> $@ 2> $(LOG_LIST_FUNCTIONS_WITH_UNNECESSARY_CHECKS) + +$(RESULT_FUNCTIONS_WITH_UNNECESSARY_CHECKS_AS_PATCH): $(PATCH_PATTERN) + $(SPATCH) $(PATCH_PATTERN) -dir $(LINUX_SOURCE_DIR) \ +> $@ 2> $(LOG_PATCH_FUNCTIONS_WITH_UNNECESSARY_CHECKS) + +build_check_list generate_list_of_functions_which_check_their_single_parameter: \ +$(RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) + @echo 'The list of functions which check their single parameter was generated.' + +build_import_script: $(SQLITE_IMPORT_SCRIPT) + @echo 'A script was generated which should contain appropriate parameters for a data base.' + +build_data_base: $(RESULT_SQL_DATA_BASE) + @echo 'A SQL data base was built.' + +build_alternation add_prefix_to_functions: build_data_base + @echo 'The function name list was converted to a component for a regular expression.' + +build_list_pattern: $(LIST_PATTERN) + @echo '$(TEXT1) list can be generated.' + +build_patch_pattern: $(PATCH_PATTERN) + @echo '$(TEXT1) patch can be generated.' + +build_update_candidate_list show_list_of_update_candidates: build_list_pattern \ +$(RESULT_FUNCTIONS_WITH_UNNECESSARY_CHECKS_AS_LIST) + @echo 'The list of update candidates $(TEXT2)' + +build_patch show_update_suggestion: build_patch_pattern \ +$(RESULT_FUNCTIONS_WITH_UNNECESSARY_CHECKS_AS_PATCH) + @echo 'A patch file $(TEXT2)' + +all: build_update_candidate_list build_patch + +clean: + $(RM) *-errors.txt \ +$(LIST_PATTERN) \ +$(PATCH_PATTERN) \ +$(RESULT_FUNCTIONS_WITH_PREFIX) \ +$(RESULT_SQL_DATA_BASE) \ +$(RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) \ +$(SQLITE_IMPORT_SCRIPT) + +delete_data_base: + $(RM) $(RESULT_SQL_DATA_BASE) \ +$(RESULT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) + +.PHONY: all \ +build_check_list \ +build_data_base \ +build_import_script \ +build_list_pattern \ +build_patch \ +build_patch_pattern \ +build_update_candidate_list \ +clean \ +default \ +delete_data_base \ +generate_list_of_functions_which_check_their_single_parameter \ +show_list_of_update_candidates \ +show_update_suggestion + + +# The following input files should not need further actions here. +$(EXTRACT_FUNCTIONS_THAT_CHECK_THEIR_SINGLE_PARAMETER) \ +$(SQLITE_IMPORT_SCRIPT_TEMPLATE) \ +$(LIST_PATTERN_TEMPLATE) \ +$(PATCH_PATTERN_TEMPLATE): ; -- 1.9.0 -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
>> 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
>> 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
>> 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
>> 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
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
On Wed, Oct 22, 2014 at 08:00:17PM +0200, SF Markus Elfring wrote:
> drivers/iommu/msm_iommu.c | 3 +--
> drivers/iommu/msm_iommu_dev.c | 6 ++----
> 2 files changed, 3 insertions(+), 6 deletions(-)
Applied to arm/msm, thanks.
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
> 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
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
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
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
On Fri, 31 Oct 2014, SF Markus Elfring wrote: > The functions kfree(), rtw_free_netdev() and vfree() test whether their > argument is NULL and then return immediately. Thus the test around the call > is not needed. > > This issue was detected by using the Coccinelle software. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > drivers/staging/rtl8188eu/core/rtw_efuse.c | 3 +-- > drivers/staging/rtl8188eu/core/rtw_mlme.c | 3 +-- > drivers/staging/rtl8188eu/core/rtw_sta_mgt.c | 3 +-- > drivers/staging/rtl8188eu/core/rtw_xmit.c | 6 ++---- > drivers/staging/rtl8188eu/os_dep/usb_intf.c | 5 ++--- > 5 files changed, 7 insertions(+), 13 deletions(-) > > diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c > b/drivers/staging/rtl8188eu/core/rtw_efuse.c > index 7006088..77f7552 100644 > --- a/drivers/staging/rtl8188eu/core/rtw_efuse.c > +++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c > @@ -212,8 +212,7 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 > _size_byte, u8 *pbuf) > exit: > kfree(efuseTbl); > > - if (eFuseWord) > - kfree(eFuseWord); > + kfree(eFuseWord); I think that this code has been updated already. It would be better to add labels so that kfree is only executed when needed. julia > } > > static void efuse_read_phymap_from_txpktbuf( > diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme.c > b/drivers/staging/rtl8188eu/core/rtw_mlme.c > index 149c271..df54350 100644 > --- a/drivers/staging/rtl8188eu/core/rtw_mlme.c > +++ b/drivers/staging/rtl8188eu/core/rtw_mlme.c > @@ -122,8 +122,7 @@ void rtw_free_mlme_priv(struct mlme_priv *pmlmepriv) > rtw_free_mlme_priv_ie_data(pmlmepriv); > > if (pmlmepriv) { > - if (pmlmepriv->free_bss_buf) > - vfree(pmlmepriv->free_bss_buf); > + vfree(pmlmepriv->free_bss_buf); > } > } > > diff --git a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c > b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c > index e1dc8fa..af1de9c 100644 > --- a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c > +++ b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c > @@ -201,8 +201,7 @@ u32 _rtw_free_sta_priv(struct sta_priv *pstapriv) > > rtw_mfree_sta_priv_lock(pstapriv); > > - if (pstapriv->pallocated_stainfo_buf) > - vfree(pstapriv->pallocated_stainfo_buf); > + vfree(pstapriv->pallocated_stainfo_buf); > } > > return _SUCCESS; > diff --git a/drivers/staging/rtl8188eu/core/rtw_xmit.c > b/drivers/staging/rtl8188eu/core/rtw_xmit.c > index 639ace0..011c9cf 100644 > --- a/drivers/staging/rtl8188eu/core/rtw_xmit.c > +++ b/drivers/staging/rtl8188eu/core/rtw_xmit.c > @@ -246,11 +246,9 @@ void _rtw_free_xmit_priv (struct xmit_priv *pxmitpriv) > pxmitbuf++; > } > > - if (pxmitpriv->pallocated_frame_buf) > - vfree(pxmitpriv->pallocated_frame_buf); > + vfree(pxmitpriv->pallocated_frame_buf); > > - if (pxmitpriv->pallocated_xmitbuf) > - vfree(pxmitpriv->pallocated_xmitbuf); > + vfree(pxmitpriv->pallocated_xmitbuf); > > /* free xmit extension buff */ > pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmit_extbuf; > diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c > b/drivers/staging/rtl8188eu/os_dep/usb_intf.c > index 407a318..cdb70e4 100644 > --- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c > +++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c > @@ -456,7 +456,7 @@ free_adapter: > if (status != _SUCCESS) { > if (pnetdev) > rtw_free_netdev(pnetdev); > - else if (padapter) > + else > vfree(padapter); > padapter = NULL; > } > @@ -487,8 +487,7 @@ static void rtw_usb_if1_deinit(struct adapter *if1) > DBG_88E("+r871xu_dev_remove, hw_init_completed=%d\n", > if1->hw_init_completed); > rtw_free_drv_sw(if1); > - if (pnetdev) > - rtw_free_netdev(pnetdev); > + rtw_free_netdev(pnetdev); > } > > static int rtw_drv_init(struct usb_interface *pusb_intf, const struct > usb_device_id *pdid) > -- > 2.1.2 > > -- > To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >
>> 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
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
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
On Fri, 31 Oct 2014, SF Markus Elfring wrote: > The following functions test whether their argument is NULL and then > return immediately. > * btrfs_free_path() > * free_extent_buffer() > * free_extent_map() > * free_extent_state() > * iput() > * kfree() > > Thus the test around the call is not needed. > > This issue was detected by using the Coccinelle software. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > fs/btrfs/dev-replace.c | 3 +-- > fs/btrfs/extent_io.c | 12 ++++-------- > fs/btrfs/file.c | 6 ++---- > fs/btrfs/free-space-cache.c | 7 +++---- > fs/btrfs/inode.c | 6 ++---- > fs/btrfs/reada.c | 3 +-- > fs/btrfs/relocation.c | 3 +-- > fs/btrfs/tests/btrfs-tests.c | 3 +-- > fs/btrfs/tree-defrag.c | 3 +-- > fs/btrfs/tree-log.c | 6 ++---- > 10 files changed, 18 insertions(+), 34 deletions(-) > > diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c > index 6f662b3..3465029 100644 > --- a/fs/btrfs/dev-replace.c > +++ b/fs/btrfs/dev-replace.c > @@ -183,8 +183,7 @@ no_valid_dev_replace_entry_found: > } > > out: > - if (path) > - btrfs_free_path(path); > + btrfs_free_path(path); It appears to be statically apparent whether btrfs_free_path is needed or not. The code could be changed both not to have the test and not to have the jump and call to btrfs_free_path. This is probably the case for the other occurrences next to labels. julia > return ret; > } > > diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c > index bf3f424..cfbf00a 100644 > --- a/fs/btrfs/extent_io.c > +++ b/fs/btrfs/extent_io.c > @@ -704,8 +704,7 @@ next: > > out: > spin_unlock(&tree->lock); > - if (prealloc) > - free_extent_state(prealloc); > + free_extent_state(prealloc); > > return 0; > > @@ -1006,8 +1005,7 @@ hit_next: > > out: > spin_unlock(&tree->lock); > - if (prealloc) > - free_extent_state(prealloc); > + free_extent_state(prealloc); > > return err; > > @@ -1223,8 +1221,7 @@ hit_next: > > out: > spin_unlock(&tree->lock); > - if (prealloc) > - free_extent_state(prealloc); > + free_extent_state(prealloc); > > return err; > > @@ -4146,8 +4143,7 @@ int extent_readpages(struct extent_io_tree *tree, > __extent_readpages(tree, pagepool, nr, get_extent, &em_cached, > &bio, 0, &bio_flags, READ); > > - if (em_cached) > - free_extent_map(em_cached); > + free_extent_map(em_cached); > > BUG_ON(!list_empty(pages)); > if (bio) > diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c > index a18ceab..add07ce8 100644 > --- a/fs/btrfs/file.c > +++ b/fs/btrfs/file.c > @@ -677,10 +677,8 @@ next: > /* once for the tree*/ > free_extent_map(em); > } > - if (split) > - free_extent_map(split); > - if (split2) > - free_extent_map(split2); > + free_extent_map(split); > + free_extent_map(split2); > } > > /* > diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c > index 3384819..11883e2 100644 > --- a/fs/btrfs/free-space-cache.c > +++ b/fs/btrfs/free-space-cache.c > @@ -1943,8 +1943,7 @@ new_bitmap: > > out: > if (info) { > - if (info->bitmap) > - kfree(info->bitmap); > + kfree(info->bitmap); > kmem_cache_free(btrfs_free_space_cachep, info); > } > > @@ -3322,8 +3321,8 @@ again: > > if (info) > kmem_cache_free(btrfs_free_space_cachep, info); > - if (map) > - kfree(map); > + > + kfree(map); > return 0; > } > > diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c > index d23362f..7301b99 100644 > --- a/fs/btrfs/inode.c > +++ b/fs/btrfs/inode.c > @@ -857,8 +857,7 @@ static u64 get_extent_allocation_hint(struct inode *inode, > u64 start, > em = search_extent_mapping(em_tree, 0, 0); > if (em && em->block_start < EXTENT_MAP_LAST_BYTE) > alloc_hint = em->block_start; > - if (em) > - free_extent_map(em); > + free_extent_map(em); > } else { > alloc_hint = em->block_start; > free_extent_map(em); > @@ -6573,8 +6572,7 @@ out: > > trace_btrfs_get_extent(root, em); > > - if (path) > - btrfs_free_path(path); > + btrfs_free_path(path); > if (trans) { > ret = btrfs_end_transaction(trans, root); > if (!err) > diff --git a/fs/btrfs/reada.c b/fs/btrfs/reada.c > index b63ae20..ec8eb49 100644 > --- a/fs/btrfs/reada.c > +++ b/fs/btrfs/reada.c > @@ -731,8 +731,7 @@ static int reada_start_machine_dev(struct btrfs_fs_info > *fs_info, > else if (eb) > __readahead_hook(fs_info->extent_root, eb, eb->start, ret); > > - if (eb) > - free_extent_buffer(eb); > + free_extent_buffer(eb); > > return 1; > > diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c > index 74257d6..f87a5ee 100644 > --- a/fs/btrfs/relocation.c > +++ b/fs/btrfs/relocation.c > @@ -4158,8 +4158,7 @@ out: > btrfs_end_transaction(trans, root); > btrfs_btree_balance_dirty(root); > if (err) { > - if (inode) > - iput(inode); > + iput(inode); > inode = ERR_PTR(err); > } > return inode; > diff --git a/fs/btrfs/tests/btrfs-tests.c b/fs/btrfs/tests/btrfs-tests.c > index 9626252..7fb123f 100644 > --- a/fs/btrfs/tests/btrfs-tests.c > +++ b/fs/btrfs/tests/btrfs-tests.c > @@ -162,8 +162,7 @@ void btrfs_free_dummy_root(struct btrfs_root *root) > { > if (!root) > return; > - if (root->node) > - free_extent_buffer(root->node); > + free_extent_buffer(root->node); > if (root->fs_info) > btrfs_free_dummy_fs_info(root->fs_info); > kfree(root); > diff --git a/fs/btrfs/tree-defrag.c b/fs/btrfs/tree-defrag.c > index a63719c..c74f106 100644 > --- a/fs/btrfs/tree-defrag.c > +++ b/fs/btrfs/tree-defrag.c > @@ -118,8 +118,7 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, > ret = -EAGAIN; > } > out: > - if (path) > - btrfs_free_path(path); > + btrfs_free_path(path); > if (ret = -EAGAIN) { > if (root->defrag_max.objectid > root->defrag_progress.objectid) > goto done; > diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c > index 1475979..70926a9 100644 > --- a/fs/btrfs/tree-log.c > +++ b/fs/btrfs/tree-log.c > @@ -736,8 +736,7 @@ static noinline int replay_one_extent(struct > btrfs_trans_handle *trans, > inode_add_bytes(inode, nbytes); > ret = btrfs_update_inode(trans, root, inode); > out: > - if (inode) > - iput(inode); > + iput(inode); > return ret; > } > > @@ -2210,8 +2209,7 @@ static noinline int walk_down_log_tree(struct > btrfs_trans_handle *trans, > } > > WARN_ON(*level <= 0); > - if (path->nodes[*level-1]) > - free_extent_buffer(path->nodes[*level-1]); > + free_extent_buffer(path->nodes[*level-1]); > path->nodes[*level-1] = next; > *level = btrfs_header_level(next); > path->slots[*level] = 0; > -- > 2.1.3 > > > _______________________________________________ > Cocci mailing list > Cocci@systeme.lip6.fr > https://systeme.lip6.fr/mailman/listinfo/cocci >
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
On Sun, 2 Nov 2014, SF Markus Elfring wrote: > The functions iput() and ocfs2_free_path() test whether their argument > is NULL and then return immediately. Thus the test around the call > is not needed. Please check whether more labels could be added to avoid executing unnecessary code. julia > This issue was detected by using the Coccinelle software. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > fs/ocfs2/alloc.c | 15 +++++---------- > fs/ocfs2/ioctl.c | 3 +-- > fs/ocfs2/journal.c | 9 +++------ > fs/ocfs2/localalloc.c | 9 +++------ > fs/ocfs2/namei.c | 3 +-- > fs/ocfs2/slot_map.c | 3 +-- > fs/ocfs2/super.c | 3 +-- > 7 files changed, 15 insertions(+), 30 deletions(-) > > diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c > index a93bf98..2e0ab63 100644 > --- a/fs/ocfs2/alloc.c > +++ b/fs/ocfs2/alloc.c > @@ -3453,8 +3453,7 @@ static int ocfs2_merge_rec_right(struct ocfs2_path *left_path, > subtree_index); > } > out: > - if (right_path) > - ocfs2_free_path(right_path); > + ocfs2_free_path(right_path); > return ret; > } > > @@ -3647,8 +3646,7 @@ static int ocfs2_merge_rec_left(struct ocfs2_path *right_path, > right_path, subtree_index); > } > out: > - if (left_path) > - ocfs2_free_path(left_path); > + ocfs2_free_path(left_path); > return ret; > } > > @@ -4431,10 +4429,8 @@ ocfs2_figure_merge_contig_type(struct ocfs2_extent_tree *et, > } > > out: > - if (left_path) > - ocfs2_free_path(left_path); > - if (right_path) > - ocfs2_free_path(right_path); > + ocfs2_free_path(left_path); > + ocfs2_free_path(right_path); > > return ret; > } > @@ -6157,8 +6153,7 @@ int ocfs2_begin_truncate_log_recovery(struct ocfs2_super *osb, > } > > bail: > - if (tl_inode) > - iput(tl_inode); > + iput(tl_inode); > brelse(tl_bh); > > if (status < 0 && (*tl_copy)) { > diff --git a/fs/ocfs2/ioctl.c b/fs/ocfs2/ioctl.c > index 53e6c40..28afb56 100644 > --- a/fs/ocfs2/ioctl.c > +++ b/fs/ocfs2/ioctl.c > @@ -606,8 +606,7 @@ bail: > if (gb_inode) > mutex_unlock(&gb_inode->i_mutex); > > - if (gb_inode) > - iput(gb_inode); > + iput(gb_inode); > > brelse(bh); > > diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c > index 4b0c688..f94be68 100644 > --- a/fs/ocfs2/journal.c > +++ b/fs/ocfs2/journal.c > @@ -1009,8 +1009,7 @@ void ocfs2_journal_shutdown(struct ocfs2_super *osb) > > // up_write(&journal->j_trans_barrier); > done: > - if (inode) > - iput(inode); > + iput(inode); > } > > static void ocfs2_clear_journal_error(struct super_block *sb, > @@ -1646,8 +1645,7 @@ done: > if (got_lock) > ocfs2_inode_unlock(inode, 1); > > - if (inode) > - iput(inode); > + iput(inode); > > brelse(bh); > > @@ -1755,8 +1753,7 @@ static int ocfs2_trylock_journal(struct ocfs2_super *osb, > > ocfs2_inode_unlock(inode, 1); > bail: > - if (inode) > - iput(inode); > + iput(inode); > > return status; > } > diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c > index 0440134..7eca277 100644 > --- a/fs/ocfs2/localalloc.c > +++ b/fs/ocfs2/localalloc.c > @@ -358,8 +358,7 @@ int ocfs2_load_local_alloc(struct ocfs2_super *osb) > bail: > if (status < 0) > brelse(alloc_bh); > - if (inode) > - iput(inode); > + iput(inode); > > trace_ocfs2_load_local_alloc(osb->local_alloc_bits); > > @@ -473,8 +472,7 @@ out_mutex: > iput(main_bm_inode); > > out: > - if (local_alloc_inode) > - iput(local_alloc_inode); > + iput(local_alloc_inode); > > kfree(alloc_copy); > } > @@ -1328,8 +1326,7 @@ bail: > > brelse(main_bm_bh); > > - if (main_bm_inode) > - iput(main_bm_inode); > + iput(main_bm_inode); > > kfree(alloc_copy); > > diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c > index 8add6f1..a02593d 100644 > --- a/fs/ocfs2/namei.c > +++ b/fs/ocfs2/namei.c > @@ -1607,8 +1607,7 @@ bail: > if (new_inode) > sync_mapping_buffers(old_inode->i_mapping); > > - if (new_inode) > - iput(new_inode); > + iput(new_inode); > > ocfs2_free_dir_lookup_result(&target_lookup_res); > ocfs2_free_dir_lookup_result(&old_entry_lookup); > diff --git a/fs/ocfs2/slot_map.c b/fs/ocfs2/slot_map.c > index a88b2a4..c5c6eb0 100644 > --- a/fs/ocfs2/slot_map.c > +++ b/fs/ocfs2/slot_map.c > @@ -322,8 +322,7 @@ static void __ocfs2_free_slot_info(struct ocfs2_slot_info *si) > if (si = NULL) > return; > > - if (si->si_inode) > - iput(si->si_inode); > + iput(si->si_inode); > if (si->si_bh) { > for (i = 0; i < si->si_blocks; i++) { > if (si->si_bh[i]) { > diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c > index 4142546..5860f0f 100644 > --- a/fs/ocfs2/super.c > +++ b/fs/ocfs2/super.c > @@ -1723,8 +1723,7 @@ static int ocfs2_statfs(struct dentry *dentry, struct > kstatfs *buf) > ocfs2_inode_unlock(inode, 0); > status = 0; > bail: > - if (inode) > - iput(inode); > + iput(inode); > > if (status) > mlog_errno(status); > -- > 2.1.3 > > > -- > To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >
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
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
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
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
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 > >
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
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
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
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() */
> }
> 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
[-- Attachment #1: Type: text/plain, Size: 604 bytes --] > Your patch can't be applied cleanly due to your MUA breaking the > lines. Please fix your MUA setup, or use an attachment if it's > impossible, and resend the patch. Thanks for your feedback. Does this example show a conflict between long comments like "snd_emu10k1_ctl_private_free( ... *kctl)" after patch ranges and line length limitation for email eventually? > Also, try to align the subject line with the relevant commits. See > "git log sound/pci/emu10k1" I have attached my update suggestion with a slightly different commit title as before. Is this variant acceptable? Regards, Markus [-- Attachment #2: 0001-ALSA-emu10k1-Deletion-of-unnecessary-checks-before-t.patch --] [-- Type: text/x-patch, Size: 2119 bytes --] From 23bb7bd1325b7c9cc81761db3ebf3ea19f85338d Mon Sep 17 00:00:00 2001 From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 3 Nov 2014 14:54:36 +0100 Subject: [PATCH] ALSA: emu10k1: Deletion of unnecessary checks before three function calls The functions kfree(), release_firmware() and snd_util_memhdr_free() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- sound/pci/emu10k1/emu10k1_main.c | 9 +++------ sound/pci/emu10k1/emufx.c | 3 +-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c index 2292697..b4458a6 100644 --- a/sound/pci/emu10k1/emu10k1_main.c +++ b/sound/pci/emu10k1/emu10k1_main.c @@ -1289,10 +1289,8 @@ static int snd_emu10k1_free(struct snd_emu10k1 *emu) } if (emu->emu1010.firmware_thread) kthread_stop(emu->emu1010.firmware_thread); - if (emu->firmware) - release_firmware(emu->firmware); - if (emu->dock_fw) - release_firmware(emu->dock_fw); + release_firmware(emu->firmware); + release_firmware(emu->dock_fw); if (emu->irq >= 0) free_irq(emu->irq, emu); /* remove reserved page */ @@ -1301,8 +1299,7 @@ static int snd_emu10k1_free(struct snd_emu10k1 *emu) (struct snd_util_memblk *)emu->reserved_page); emu->reserved_page = NULL; } - if (emu->memhdr) - snd_util_memhdr_free(emu->memhdr); + snd_util_memhdr_free(emu->memhdr); if (emu->silent_page.area) snd_dma_free_pages(&emu->silent_page); if (emu->ptb_pages.area) diff --git a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c index 745f062..eb5c0ab 100644 --- a/sound/pci/emu10k1/emufx.c +++ b/sound/pci/emu10k1/emufx.c @@ -777,8 +777,7 @@ static void snd_emu10k1_ctl_private_free(struct snd_kcontrol *kctl) kctl->private_value = 0; list_del(&ctl->list); kfree(ctl); - if (kctl->tlv.p) - kfree(kctl->tlv.p); + kfree(kctl->tlv.p); } static int snd_emu10k1_add_controls(struct snd_emu10k1 *emu, -- 2.1.3
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
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
> 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
> I agree with your proposed debug_unregister() changes, but not with your
> kfree_fsm() change.
Why do you want to keep an additional null pointer check before the call
of the kfree_fsm() function within the implementation of the
netiucv_free_netdevice() function?
Regards,
Markus
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
On Mon, Nov 03, 2014 at 05:10:35PM +0100, SF Markus Elfring wrote:
> > I agree with your proposed debug_unregister() changes, but not with your
> > kfree_fsm() change.
>
> Why do you want to keep an additional null pointer check before the call
> of the kfree_fsm() function within the implementation of the
> netiucv_free_netdevice() function?
Think about how long it takes you to figure this out what the bug is and
then remember that we have to spend that same amount of time multiplied
by the number of patches you have sent.
regards,
dan carpenter
> 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
> > 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
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
> 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
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
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 > >
>>>> @@ -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@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
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
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
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
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
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
>> @@ -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
> > 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
>> + 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
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
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
> 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
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
>>>> + 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
> You are not using the most recent version of the code. The issue has > already been fixed. Thanks for your reminder. https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/drivers/staging/rtl8188eu/core/rtw_efuse.c?id<fab18ce55282a85e2c7e5db15c5daf065efdb4 Regards, Markus
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
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
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@systeme.lip6.fr > https://systeme.lip6.fr/mailman/listinfo/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
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@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >
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
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
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
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
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
> 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
> 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
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
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
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@systeme.lip6.fr > https://systeme.lip6.fr/mailman/listinfo/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
>> 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
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
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@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >
> The if around the module_put is helpful to the reader to understand
> that this possibility exists.
I have got a different opinion. I would still prefer a small code clean-up there.
Regards,
Markus
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
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
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
On Sun, 16 Nov 2014 20:22:22 +0100 SF Markus Elfring <elfring@users.sourceforge.net> wrote: > 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. The first patch is fine, and the only reason is to save the few bytes that the branch check might take. It's in a path that is unlikely to be hit so it is not a performance issue at all. This patch is useless. I rather not apply any patch than to create another jump that skips over the freeing of iput() just because we know inode is null. That's why we had the if (inode) in the first place. So Nack on this patch and I'll contemplate applying the first one. I probably will as it seems rather harmless. Thanks, -- Steve > > 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;
On Sun, 16 Nov 2014, Steven Rostedt wrote:
> On Sun, 16 Nov 2014 20:22:22 +0100
> SF Markus Elfring <elfring@users.sourceforge.net> wrote:
>
> > 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.
>
> The first patch is fine, and the only reason is to save the few bytes
> that the branch check might take. It's in a path that is unlikely to be
> hit so it is not a performance issue at all.
>
> This patch is useless. I rather not apply any patch than to create
> another jump that skips over the freeing of iput() just because we know
> inode is null. That's why we had the if (inode) in the first place.
>
> So Nack on this patch and I'll contemplate applying the first one. I
> probably will as it seems rather harmless.
I wuold have thought that one could have just returned, like in the cases
above... But maybe the printed message is useful.
julia
On Sun, 16 Nov 2014 20:34:59 +0100 (CET)
Julia Lawall <julia.lawall@lip6.fr> wrote:
> I wuold have thought that one could have just returned, like in the cases
> above... But maybe the printed message is useful.
Yes, it lets us know that the format string failed to parse.
-- Steve
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
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
(2014/11/16 21:34), 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); This is OK, but I you request a comment line over there so that code reader can understand it is safe to pass a NULL pointer to module_put(). # and of course don't touch jump label around that :) Thank you, > > return ret; > } > -- Masami HIRAMATSU Software Platform Research Dept. Linux Technology Research Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: masami.hiramatsu.pt@hitachi.com
> 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
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
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
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
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
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
At Mon, 17 Nov 2014 11:07:04 +0100, SF Markus Elfring wrote: > > 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> Applied, thanks. Takashi > --- > 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 > >
At Mon, 17 Nov 2014 11:34:22 +0100, SF Markus Elfring wrote: > > 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> Applied, thanks. Takashi > --- > 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 > >
At Mon, 17 Nov 2014 12:48:44 +0100, SF Markus Elfring wrote: > > 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> Applied, thanks. Takashi > --- > 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 > >
At Mon, 17 Nov 2014 13:12:15 +0100, SF Markus Elfring wrote: > > 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> Applied, thanks. Takashi > --- > 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 > >
At Mon, 17 Nov 2014 13:41:19 +0100, SF Markus Elfring wrote: > > 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> Applied, thanks. Takashi > --- > 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 > >
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 17 Nov 2014 14:05:27 +0100 The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- sound/soc/omap/mcbsp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sound/soc/omap/mcbsp.c b/sound/soc/omap/mcbsp.c index 86c7538..68a1252 100644 --- a/sound/soc/omap/mcbsp.c +++ b/sound/soc/omap/mcbsp.c @@ -621,8 +621,7 @@ void omap_mcbsp_free(struct omap_mcbsp *mcbsp) mcbsp->reg_cache = NULL; spin_unlock(&mcbsp->lock); - if (reg_cache) - kfree(reg_cache); + kfree(reg_cache); } /* -- 2.1.3
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
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
> What do you want me to clarify? Do you still not see the bug?
Would you like to point out that you notice the warning message
"fsm: kfree_fsm called with NULL argument" after my update suggestion?
How do you think about to share a bit more information about the
corresponding function call graph from your test system?
Regards,
Markus
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 ++---- tools/perf/util/header.c | 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)); } diff --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
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
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
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
On 11/17/2014 03:15 PM, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Mon, 17 Nov 2014 14:05:27 +0100
>
> The kfree() function tests whether its argument is NULL and then
> returns immediately. Thus the test around the call is not needed.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> sound/soc/omap/mcbsp.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
Acked-by: Jarkko Nikula <jarkko.nikula@bitmer.com>
On Mon, 2014-11-17 at 19:19 +0100, SF Markus Elfring wrote: > 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. > Thank you. It's the reasonable correction. Looks good for me. Reviewed-by: Vyacheslav Dubeyko <slava@dubeyko.com> Thanks, Vyacheslav Dubeyko. > 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); > } >
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
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
On 11/18/2014 11:10 AM, SF Markus Elfring wrote:
> 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);
> }
>
Thanks will submit for next Kernel
Boaz
On Sun 16-11-14 23:40:18, SF Markus Elfring wrote: > 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(-) Thanks. Merged into my tree. Honza > > 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 > > -- Jan Kara <jack@suse.cz> SUSE Labs, CR
[-- Attachment #1: Type: text/plain, Size: 326 bytes --] On Mon, Nov 17, 2014 at 02:15:01PM +0100, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Mon, 17 Nov 2014 14:05:27 +0100 > > The kfree() function tests whether its argument is NULL and then > returns immediately. Thus the test around the call is not needed. Applied, thanks. [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 473 bytes --]
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
Hi,
Now in the GFS2 -nmw git tree. Thanks,
Steve.
On 18/11/14 10:35, SF Markus Elfring wrote:
> 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;
> }
>
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
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
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
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
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
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
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
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
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 18 Nov 2014 20:37:05 +0100 The functions free_percpu() and module_put() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- net/netfilter/ipvs/ip_vs_ctl.c | 3 +-- net/netfilter/ipvs/ip_vs_pe.c | 3 +-- net/netfilter/ipvs/ip_vs_sched.c | 3 +-- net/netfilter/ipvs/ip_vs_sync.c | 3 +-- net/netfilter/nf_tables_api.c | 3 +-- 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c index fd3f444..7c5e40a 100644 --- a/net/netfilter/ipvs/ip_vs_ctl.c +++ b/net/netfilter/ipvs/ip_vs_ctl.c @@ -465,8 +465,7 @@ __ip_vs_bind_svc(struct ip_vs_dest *dest, struct ip_vs_service *svc) static void ip_vs_service_free(struct ip_vs_service *svc) { - if (svc->stats.cpustats) - free_percpu(svc->stats.cpustats); + free_percpu(svc->stats.cpustats); kfree(svc); } diff --git a/net/netfilter/ipvs/ip_vs_pe.c b/net/netfilter/ipvs/ip_vs_pe.c index 1a82b29..0df17ca 100644 --- a/net/netfilter/ipvs/ip_vs_pe.c +++ b/net/netfilter/ipvs/ip_vs_pe.c @@ -37,8 +37,7 @@ struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name) rcu_read_unlock(); return pe; } - if (pe->module) - module_put(pe->module); + module_put(pe->module); } rcu_read_unlock(); diff --git a/net/netfilter/ipvs/ip_vs_sched.c b/net/netfilter/ipvs/ip_vs_sched.c index 4dbcda6..199760c 100644 --- a/net/netfilter/ipvs/ip_vs_sched.c +++ b/net/netfilter/ipvs/ip_vs_sched.c @@ -104,8 +104,7 @@ static struct ip_vs_scheduler *ip_vs_sched_getbyname(const char *sched_name) mutex_unlock(&ip_vs_sched_mutex); return sched; } - if (sched->module) - module_put(sched->module); + module_put(sched->module); } mutex_unlock(&ip_vs_sched_mutex); diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c index eadffb2..cafe28d 100644 --- a/net/netfilter/ipvs/ip_vs_sync.c +++ b/net/netfilter/ipvs/ip_vs_sync.c @@ -820,8 +820,7 @@ ip_vs_conn_fill_param_sync(struct net *net, int af, union ip_vs_sync_conn *sc, p->pe_data = kmemdup(pe_data, pe_data_len, GFP_ATOMIC); if (!p->pe_data) { - if (p->pe->module) - module_put(p->pe->module); + module_put(p->pe->module); return -ENOMEM; } p->pe_data_len = pe_data_len; diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index deeb95f..b115f54 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -3472,8 +3472,7 @@ static int nf_tables_abort(struct sk_buff *skb) break; case NFT_MSG_NEWCHAIN: if (nft_trans_chain_update(trans)) { - if (nft_trans_chain_stats(trans)) - free_percpu(nft_trans_chain_stats(trans)); + free_percpu(nft_trans_chain_stats(trans)); nft_trans_destroy(trans); } else { -- 2.1.3
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
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
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
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
On Mon, Nov 17, 2014 at 06:40:18PM +0100, SF Markus Elfring wrote: > 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. Thanks for the cleanup! Acked-by: Seth Jennings <sjennings@variantweb.net> > > 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 >
On Sunday, November 16, 2014 02:28:23 PM SF Markus Elfring wrote: > 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> Queued up for 3.19-rc1, thanks! > --- > 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; > } > -- I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
On Tue, 18 Nov 2014 14:48:09 +0100, SF Markus Elfring wrote: > 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> Applied to nilfs2 git tree. Thanks. Ryusuke Konishi > --- > 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 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html
>> 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
On Tue, Nov 18, 2014 at 09:45:41PM +0100, SF Markus Elfring wrote:
> 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.
>
It doesn't though...
regards,
dan carpenter
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 19 Nov 2014 10:11:04 +0100 The kzfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- crypto/drbg.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/crypto/drbg.c b/crypto/drbg.c index a53ee09..b6f22d4 100644 --- a/crypto/drbg.c +++ b/crypto/drbg.c @@ -1151,8 +1151,7 @@ static int drbg_seed(struct drbg_state *drbg, struct drbg_string *pers, drbg->reseed_ctr = 1; out: - if (entropy) - kzfree(entropy); + kzfree(entropy); return ret; } @@ -1161,19 +1160,15 @@ static inline void drbg_dealloc_state(struct drbg_state *drbg) { if (!drbg) return; - if (drbg->V) - kzfree(drbg->V); + kzfree(drbg->V); drbg->V = NULL; - if (drbg->C) - kzfree(drbg->C); + kzfree(drbg->C); drbg->C = NULL; - if (drbg->scratchpad) - kzfree(drbg->scratchpad); + kzfree(drbg->scratchpad); drbg->scratchpad = NULL; drbg->reseed_ctr = 0; #ifdef CONFIG_CRYPTO_FIPS - if (drbg->prev) - kzfree(drbg->prev); + kzfree(drbg->prev); drbg->prev = NULL; drbg->fips_primed = false; #endif @@ -1293,8 +1288,7 @@ static int drbg_make_shadow(struct drbg_state *drbg, struct drbg_state **shadow) return 0; err: - if (tmp) - kzfree(tmp); + kzfree(tmp); return ret; } -- 2.1.3
>> The ipcomp_free_tfms() function tests whether its argument is NULL and then >> returns immediately. Thus the test around the call is not needed. > > It doesn't though... You are right that this function implementation does a bit more before returning because of a detected null pointer. https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/net/xfrm/xfrm_ipcomp.c?id94efd19d5fcae936261bd48e5b33b21897aacf8#n247 Can you agree that input parameter validation is also performed there? Do you want that I resend my patch with a corrected commit message? Regards, Markus
On Wed, 19 Nov 2014, SF Markus Elfring wrote:
> >> The ipcomp_free_tfms() function tests whether its argument is NULL and then
> >> returns immediately. Thus the test around the call is not needed.
> >
> > It doesn't though...
>
> You are right that this function implementation does a bit more before
> returning because of a detected null pointer.
> https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/net/xfrm/xfrm_ipcomp.c?id94efd19d5fcae936261bd48e5b33b21897aacf8#n247
>
> Can you agree that input parameter validation is also performed there?
> Do you want that I resend my patch with a corrected commit message?
This is completely crazy. The function performs a side effect on a data
structure. If the call site doesn't want that done in a certain case,
then it should not be done.
julia
I have come to view you as a very clever troll. You will say infuriating things like "That is an interesting background information but the function implementation update suggestion is correct" and pretend to not see the bug for nine emails. Then you'll say something "Ha ha, I audited all the call trees and it can't actually be NULL so you were getting angry for no reason." Except you'll say it in a more obfuscated way than that. This is what you did last time. regards, dan carpenter
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 19 Nov 2014 11:38:38 +0100 The vunmap() function performes 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/base/firmware_class.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index 3d785eb..532662c 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c @@ -591,8 +591,7 @@ static int fw_map_pages_buf(struct firmware_buf *buf) if (!buf->is_paged_buf) return 0; - if (buf->data) - vunmap(buf->data); + vunmap(buf->data); buf->data = vmap(buf->pages, buf->nr_pages, 0, PAGE_KERNEL_RO); if (!buf->data) return -ENOMEM; -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 19 Nov 2014 12:21:24 +0100 The wakeup_source_unregister() 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/base/power/wakeup.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c index eb1bd2e..87dfc1d 100644 --- a/drivers/base/power/wakeup.c +++ b/drivers/base/power/wakeup.c @@ -267,8 +267,7 @@ int device_wakeup_disable(struct device *dev) return -EINVAL; ws = device_wakeup_detach(dev); - if (ws) - wakeup_source_unregister(ws); + wakeup_source_unregister(ws); return 0; } -- 2.1.3
On Wed, Nov 19, 2014 at 12:26:45PM +0100, SF Markus Elfring wrote:
> --- a/drivers/base/power/wakeup.c
> +++ b/drivers/base/power/wakeup.c
> @@ -267,8 +267,7 @@ int device_wakeup_disable(struct device *dev)
> return -EINVAL;
>
> ws = device_wakeup_detach(dev);
> - if (ws)
> - wakeup_source_unregister(ws);
> + wakeup_source_unregister(ws);
In the original code, it's clear that the programmer thought about what
happens when the device_wakeup_detach() returns NULL but in the new code
that's not clear.
I guess the information is still there in the git archive, but why hide
the good code by covering it with confusing code?
regards,
dan carpenter
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 19 Nov 2014 13:33:32 +0100 The lc_destroy() 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/block/drbd/drbd_nl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c index 1cd47df..0bcb3e0 100644 --- a/drivers/block/drbd/drbd_nl.c +++ b/drivers/block/drbd/drbd_nl.c @@ -1115,8 +1115,7 @@ static int drbd_check_al_size(struct drbd_device *device, struct disk_conf *dc) lc_destroy(n); return -EBUSY; } else { - if (t) - lc_destroy(t); + lc_destroy(t); } drbd_md_mark_dirty(device); /* we changed device->act_log->nr_elemens */ return 0; -- 2.1.3
Am 19.11.2014 13:09, schrieb Dan Carpenter:
> On Wed, Nov 19, 2014 at 12:26:45PM +0100, SF Markus Elfring wrote:
>> --- a/drivers/base/power/wakeup.c
>> +++ b/drivers/base/power/wakeup.c
>> @@ -267,8 +267,7 @@ int device_wakeup_disable(struct device *dev)
>> return -EINVAL;
>>
>> ws = device_wakeup_detach(dev);
>> - if (ws)
>> - wakeup_source_unregister(ws);
>> + wakeup_source_unregister(ws);
>
> In the original code, it's clear that the programmer thought about what
> happens when the device_wakeup_detach() returns NULL but in the new code
> that's not clear.
>
> I guess the information is still there in the git archive, but why hide
> the good code by covering it with confusing code?
>
hi,
just to add an other point of view ...
device_wakeup_detach returns dev->power.wakeup what is never NULL in this case.
(not visible here but a few line before exactly this is checked)
so this code can be compacted to:
wakeup_source_unregister(device_wakeup_detach(dev));
--readability
let the maintainer decide this byte-saving vs readability
re,
wh
On Wed, Nov 19, 2014 at 01:54:49PM +0100, walter harms wrote:
> device_wakeup_detach returns dev->power.wakeup what is never NULL in this case.
> (not visible here but a few line before exactly this is checked)
Huh? I don't see a NULL check.
I think you may be confusing "dev->power.can_wakeup" with
"dev->power.wakeup"?
regards,
dan carpenter
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 19 Nov 2014 14:24:20 +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> --- drivers/char/agp/intel-gtt.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/char/agp/intel-gtt.c b/drivers/char/agp/intel-gtt.c index 9a024f8..db5877e 100644 --- a/drivers/char/agp/intel-gtt.c +++ b/drivers/char/agp/intel-gtt.c @@ -1434,10 +1434,8 @@ void intel_gmch_remove(void) if (--intel_private.refcount) return; - if (intel_private.pcidev) - pci_dev_put(intel_private.pcidev); - if (intel_private.bridge_dev) - pci_dev_put(intel_private.bridge_dev); + pci_dev_put(intel_private.pcidev); + pci_dev_put(intel_private.bridge_dev); intel_private.driver = NULL; } EXPORT_SYMBOL(intel_gmch_remove); -- 2.1.3
Am 19.11.2014 14:05, schrieb Dan Carpenter:
> On Wed, Nov 19, 2014 at 01:54:49PM +0100, walter harms wrote:
>> device_wakeup_detach returns dev->power.wakeup what is never NULL in this case.
>> (not visible here but a few line before exactly this is checked)
>
> Huh? I don't see a NULL check.
>
> I think you may be confusing "dev->power.can_wakeup" with
> "dev->power.wakeup"?
>
>
mea culpa,
you are right dev->power.can_wakeup != dev->power.wakeup
therefore device_wakeup_detach(dev) CAN return NULL
re,
wh
On Tue, Nov 18, 2014 at 08:47:31PM +0100, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Tue, 18 Nov 2014 20:37:05 +0100 > > The functions free_percpu() and module_put() test whether their argument > is NULL and then return immediately. Thus the test around the call is > not needed. @IPVS folks: Since this involves a nf_tables specific chunk, ack your chunks and I'll put this into nf-next to speed up things. Thanks. > This issue was detected by using the Coccinelle software. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > net/netfilter/ipvs/ip_vs_ctl.c | 3 +-- > net/netfilter/ipvs/ip_vs_pe.c | 3 +-- > net/netfilter/ipvs/ip_vs_sched.c | 3 +-- > net/netfilter/ipvs/ip_vs_sync.c | 3 +-- > net/netfilter/nf_tables_api.c | 3 +-- > 5 files changed, 5 insertions(+), 10 deletions(-) > > diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c > index fd3f444..7c5e40a 100644 > --- a/net/netfilter/ipvs/ip_vs_ctl.c > +++ b/net/netfilter/ipvs/ip_vs_ctl.c > @@ -465,8 +465,7 @@ __ip_vs_bind_svc(struct ip_vs_dest *dest, struct ip_vs_service *svc) > > static void ip_vs_service_free(struct ip_vs_service *svc) > { > - if (svc->stats.cpustats) > - free_percpu(svc->stats.cpustats); > + free_percpu(svc->stats.cpustats); > kfree(svc); > } > > diff --git a/net/netfilter/ipvs/ip_vs_pe.c b/net/netfilter/ipvs/ip_vs_pe.c > index 1a82b29..0df17ca 100644 > --- a/net/netfilter/ipvs/ip_vs_pe.c > +++ b/net/netfilter/ipvs/ip_vs_pe.c > @@ -37,8 +37,7 @@ struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name) > rcu_read_unlock(); > return pe; > } > - if (pe->module) > - module_put(pe->module); > + module_put(pe->module); > } > rcu_read_unlock(); > > diff --git a/net/netfilter/ipvs/ip_vs_sched.c b/net/netfilter/ipvs/ip_vs_sched.c > index 4dbcda6..199760c 100644 > --- a/net/netfilter/ipvs/ip_vs_sched.c > +++ b/net/netfilter/ipvs/ip_vs_sched.c > @@ -104,8 +104,7 @@ static struct ip_vs_scheduler *ip_vs_sched_getbyname(const char *sched_name) > mutex_unlock(&ip_vs_sched_mutex); > return sched; > } > - if (sched->module) > - module_put(sched->module); > + module_put(sched->module); > } > > mutex_unlock(&ip_vs_sched_mutex); > diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c > index eadffb2..cafe28d 100644 > --- a/net/netfilter/ipvs/ip_vs_sync.c > +++ b/net/netfilter/ipvs/ip_vs_sync.c > @@ -820,8 +820,7 @@ ip_vs_conn_fill_param_sync(struct net *net, int af, union ip_vs_sync_conn *sc, > > p->pe_data = kmemdup(pe_data, pe_data_len, GFP_ATOMIC); > if (!p->pe_data) { > - if (p->pe->module) > - module_put(p->pe->module); > + module_put(p->pe->module); > return -ENOMEM; > } > p->pe_data_len = pe_data_len; > diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c > index deeb95f..b115f54 100644 > --- a/net/netfilter/nf_tables_api.c > +++ b/net/netfilter/nf_tables_api.c > @@ -3472,8 +3472,7 @@ static int nf_tables_abort(struct sk_buff *skb) > break; > case NFT_MSG_NEWCHAIN: > if (nft_trans_chain_update(trans)) { > - if (nft_trans_chain_stats(trans)) > - free_percpu(nft_trans_chain_stats(trans)); > + free_percpu(nft_trans_chain_stats(trans)); > > nft_trans_destroy(trans); > } else { > -- > 2.1.3 >
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 19 Nov 2014 14:44:15 +0100 The tpm_dev_vendor_release() 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/char/tpm/tpm_i2c_atmel.c | 3 +-- drivers/char/tpm/tpm_i2c_nuvoton.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/char/tpm/tpm_i2c_atmel.c b/drivers/char/tpm/tpm_i2c_atmel.c index 7727292..19c3a7b 100644 --- a/drivers/char/tpm/tpm_i2c_atmel.c +++ b/drivers/char/tpm/tpm_i2c_atmel.c @@ -202,8 +202,7 @@ static int i2c_atmel_remove(struct i2c_client *client) struct device *dev = &(client->dev); struct tpm_chip *chip = dev_get_drvdata(dev); - if (chip) - tpm_dev_vendor_release(chip); + tpm_dev_vendor_release(chip); tpm_remove_hardware(dev); kfree(chip); return 0; diff --git a/drivers/char/tpm/tpm_i2c_nuvoton.c b/drivers/char/tpm/tpm_i2c_nuvoton.c index 7b158ef..8d09628 100644 --- a/drivers/char/tpm/tpm_i2c_nuvoton.c +++ b/drivers/char/tpm/tpm_i2c_nuvoton.c @@ -625,8 +625,7 @@ static int i2c_nuvoton_remove(struct i2c_client *client) struct device *dev = &(client->dev); struct tpm_chip *chip = dev_get_drvdata(dev); - if (chip) - tpm_dev_vendor_release(chip); + tpm_dev_vendor_release(chip); tpm_remove_hardware(dev); kfree(chip); return 0; -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 19 Nov 2014 16:00:13 +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> --- drivers/edac/i3000_edac.c | 3 +-- drivers/edac/i3200_edac.c | 3 +-- drivers/edac/i82443bxgx_edac.c | 3 +-- drivers/edac/x38_edac.c | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c index cd28b96..5cb36a6 100644 --- a/drivers/edac/i3000_edac.c +++ b/drivers/edac/i3000_edac.c @@ -542,8 +542,7 @@ fail1: pci_unregister_driver(&i3000_driver); fail0: - if (mci_pdev) - pci_dev_put(mci_pdev); + pci_dev_put(mci_pdev); return pci_rc; } diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c index aa98b13..4ad062b 100644 --- a/drivers/edac/i3200_edac.c +++ b/drivers/edac/i3200_edac.c @@ -523,8 +523,7 @@ fail1: pci_unregister_driver(&i3200_driver); fail0: - if (mci_pdev) - pci_dev_put(mci_pdev); + pci_dev_put(mci_pdev); return pci_rc; } diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c index d730e276..b4705d9 100644 --- a/drivers/edac/i82443bxgx_edac.c +++ b/drivers/edac/i82443bxgx_edac.c @@ -458,8 +458,7 @@ static void __exit i82443bxgx_edacmc_exit(void) if (!i82443bxgx_registered) i82443bxgx_edacmc_remove_one(mci_pdev); - if (mci_pdev) - pci_dev_put(mci_pdev); + pci_dev_put(mci_pdev); } module_init(i82443bxgx_edacmc_init); diff --git a/drivers/edac/x38_edac.c b/drivers/edac/x38_edac.c index e644b52..7c5cdc6 100644 --- a/drivers/edac/x38_edac.c +++ b/drivers/edac/x38_edac.c @@ -500,8 +500,7 @@ fail1: pci_unregister_driver(&x38_driver); fail0: - if (mci_pdev) - pci_dev_put(mci_pdev); + pci_dev_put(mci_pdev); return pci_rc; } -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 19 Nov 2014 16:33:17 +0100 The release_firmware() 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/gpu/drm/drm_edid_load.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_edid_load.c b/drivers/gpu/drm/drm_edid_load.c index 0a235fe..732cb6f 100644 --- a/drivers/gpu/drm/drm_edid_load.c +++ b/drivers/gpu/drm/drm_edid_load.c @@ -254,8 +254,7 @@ static void *edid_load(struct drm_connector *connector, const char *name, name, connector_name); out: - if (fw) - release_firmware(fw); + release_firmware(fw); return edid; } -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 19 Nov 2014 17:05:20 +0100 The drm_fbdev_cma_hotplug_event() 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/gpu/drm/tilcdc/tilcdc_drv.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.c b/drivers/gpu/drm/tilcdc/tilcdc_drv.c index 000428e..335b1dc 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.c @@ -58,8 +58,7 @@ static struct drm_framebuffer *tilcdc_fb_create(struct drm_device *dev, static void tilcdc_fb_output_poll_changed(struct drm_device *dev) { struct tilcdc_drm_private *priv = dev->dev_private; - if (priv->fbdev) - drm_fbdev_cma_hotplug_event(priv->fbdev); + drm_fbdev_cma_hotplug_event(priv->fbdev); } static const struct drm_mode_config_funcs mode_config_funcs = { -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 19 Nov 2014 17:33:32 +0100 The vunmap() function performes 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/gpu/drm/udl/udl_gem.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/gpu/drm/udl/udl_gem.c b/drivers/gpu/drm/udl/udl_gem.c index 8044f5f..2979625 100644 --- a/drivers/gpu/drm/udl/udl_gem.c +++ b/drivers/gpu/drm/udl/udl_gem.c @@ -164,8 +164,7 @@ void udl_gem_vunmap(struct udl_gem_object *obj) return; } - if (obj->vmapping) - vunmap(obj->vmapping); + vunmap(obj->vmapping); udl_gem_put_pages(obj); } -- 2.1.3
On Wed, Nov 19, 2014 at 04:06:53PM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 19 Nov 2014 16:00:13 +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>
Applied, thanks.
--
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--
On 11/18/2014 12:26 PM, SF Markus Elfring wrote:
> 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;
>
>
Maybe I need some coffee but I can't figure out what this
patch is against...
# grep bpf_old ./net/sched/cls_bpf.c
#
Marcus, what tree are you looking at?
--
John Fastabend Intel Corporation
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 19 Nov 2014 17:50:19 +0100 The vfree() function performes 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/gpu/drm/vmwgfx/vmwgfx_drv.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c index 14b2f50..f9a67b8 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c @@ -889,8 +889,7 @@ static int vmw_driver_unload(struct drm_device *dev) if (dev_priv->ctx.res_ht_initialized) drm_ht_remove(&dev_priv->ctx.res_ht); - if (dev_priv->ctx.cmd_bounce) - vfree(dev_priv->ctx.cmd_bounce); + vfree(dev_priv->ctx.cmd_bounce); if (dev_priv->enable_fb) { vmw_fb_close(dev_priv); vmw_kms_restore_vga(dev_priv); -- 2.1.3
On 11/19/2014 05:47 PM, John Fastabend wrote: > On 11/18/2014 12:26 PM, SF Markus Elfring wrote: >> From: Markus Elfring <elfring@users.sourceforge.net> ... >> if (fp_old) >> bpf_prog_destroy(fp_old); >> - if (bpf_old) >> - kfree(bpf_old); >> + kfree(bpf_old); >> >> return 0; >> > > Maybe I need some coffee but I can't figure out what this > patch is against... > > # grep bpf_old ./net/sched/cls_bpf.c > # Coffee is always good. :) Yeah, you actually removed this in commit 1f947bf151e90ec ("net: sched: rcu'ify cls_bpf"), so looks like Markus's tree is not up to date ...
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 19 Nov 2014 18:30:22 +0100 The functions backlight_device_unregister(), lcd_device_unregister() and rc_unregister_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/hid/hid-picolcd_backlight.c | 3 +-- drivers/hid/hid-picolcd_cir.c | 3 +-- drivers/hid/hid-picolcd_lcd.c | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/hid/hid-picolcd_backlight.c b/drivers/hid/hid-picolcd_backlight.c index a32c5f8..808807a 100644 --- a/drivers/hid/hid-picolcd_backlight.c +++ b/drivers/hid/hid-picolcd_backlight.c @@ -94,8 +94,7 @@ void picolcd_exit_backlight(struct picolcd_data *data) struct backlight_device *bdev = data->backlight; data->backlight = NULL; - if (bdev) - backlight_device_unregister(bdev); + backlight_device_unregister(bdev); } int picolcd_resume_backlight(struct picolcd_data *data) diff --git a/drivers/hid/hid-picolcd_cir.c b/drivers/hid/hid-picolcd_cir.c index 045f8eb..9628651 100644 --- a/drivers/hid/hid-picolcd_cir.c +++ b/drivers/hid/hid-picolcd_cir.c @@ -145,7 +145,6 @@ void picolcd_exit_cir(struct picolcd_data *data) struct rc_dev *rdev = data->rc_dev; data->rc_dev = NULL; - if (rdev) - rc_unregister_device(rdev); + rc_unregister_device(rdev); } diff --git a/drivers/hid/hid-picolcd_lcd.c b/drivers/hid/hid-picolcd_lcd.c index 89821c2..22dcbe1 100644 --- a/drivers/hid/hid-picolcd_lcd.c +++ b/drivers/hid/hid-picolcd_lcd.c @@ -92,8 +92,7 @@ void picolcd_exit_lcd(struct picolcd_data *data) struct lcd_device *ldev = data->lcd; data->lcd = NULL; - if (ldev) - lcd_device_unregister(ldev); + lcd_device_unregister(ldev); } int picolcd_resume_lcd(struct picolcd_data *data) -- 2.1.3
From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Wed, 19 Nov 2014 13:10:03 +0300
> I have come to view you as a very clever troll.
+1
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 19 Nov 2014 19:19:21 +0100 The functions kfree() and pci_dev_put() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/infiniband/hw/mlx4/main.c | 3 +-- drivers/infiniband/hw/mthca/mthca_reset.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c index 8b72cf3..50dee1a 100644 --- a/drivers/infiniband/hw/mlx4/main.c +++ b/drivers/infiniband/hw/mlx4/main.c @@ -2512,8 +2512,7 @@ static void do_slave_init(struct mlx4_ib_dev *ibdev, int slave, int do_init) if (!dm[i]) { pr_err("failed to allocate memory for tunneling qp update work struct\n"); for (i = 0; i < dev->caps.num_ports; i++) { - if (dm[i]) - kfree(dm[i]); + kfree(dm[i]); } goto out; } diff --git a/drivers/infiniband/hw/mthca/mthca_reset.c b/drivers/infiniband/hw/mthca/mthca_reset.c index 74c6a94..c521654 100644 --- a/drivers/infiniband/hw/mthca/mthca_reset.c +++ b/drivers/infiniband/hw/mthca/mthca_reset.c @@ -279,8 +279,7 @@ good: } out: - if (bridge) - pci_dev_put(bridge); + pci_dev_put(bridge); kfree(bridge_header); kfree(hca_header); -- 2.1.3
> Marcus, what tree are you looking at? I dared to base this update suggestion on the source files for Linux 3.17.3. Are newer software developments relevant here? https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/log/net/sched/ Regards, Markus
On 11/19/2014 07:49 PM, SF Markus Elfring wrote:
>> Marcus, what tree are you looking at?
>
> I dared to base this update suggestion on the source files
> for Linux 3.17.3. Are newer software developments relevant here?
>
> https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/log/net/sched/
Pointing to linux-next and saying you based your changes on 3.17.3
is confusing, please look correctly when you provide a link ...
Again, John's commit 1f947bf151e90ec0b removed the relevant part in
cls_bpf_modify_existing() that you're trying to modify:
$ git grep -n bpf_old net/sched/cls_bpf.c
$
Therefore, this patch is not needed.
Thanks !
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 19 Nov 2014 20:48:26 +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/isdn/mISDN/l1oip_codec.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/isdn/mISDN/l1oip_codec.c b/drivers/isdn/mISDN/l1oip_codec.c index a601c84..9b033be 100644 --- a/drivers/isdn/mISDN/l1oip_codec.c +++ b/drivers/isdn/mISDN/l1oip_codec.c @@ -312,10 +312,8 @@ l1oip_ulaw_to_alaw(u8 *data, int len, u8 *result) void l1oip_4bit_free(void) { - if (table_dec) - vfree(table_dec); - if (table_com) - vfree(table_com); + vfree(table_dec); + vfree(table_com); table_com = NULL; table_dec = NULL; } -- 2.1.3
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 18 Nov 2014 20:16:05 +0100
> 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>
Applied, thanks.
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 18 Nov 2014 21:08:39 +0100
> 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>
Applied, thanks.
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 19 Nov 2014 21:25:39 +0100 The kobject_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> --- drivers/md/bcache/super.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index d4713d0..1443c55 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -2076,8 +2076,7 @@ static void bcache_exit(void) { bch_debug_exit(); bch_request_exit(); - if (bcache_kobj) - kobject_put(bcache_kobj); + kobject_put(bcache_kobj); if (bcache_wq) destroy_workqueue(bcache_wq); if (bcache_major) -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 19 Nov 2014 21:48:10 +0100 The functions dm_table_destroy() and vfree() perform 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/md/dm-ioctl.c | 3 +-- drivers/md/dm-snap-persistent.c | 12 ++++-------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c index 5152142..0b925a4 100644 --- a/drivers/md/dm-ioctl.c +++ b/drivers/md/dm-ioctl.c @@ -1050,8 +1050,7 @@ static int do_resume(struct dm_ioctl *param) * Since dm_swap_table synchronizes RCU, nobody should be in * read-side critical section already. */ - if (old_map) - dm_table_destroy(old_map); + dm_table_destroy(old_map); if (!r) __dev_status(md, param); diff --git a/drivers/md/dm-snap-persistent.c b/drivers/md/dm-snap-persistent.c index d6e8817..4b29bac 100644 --- a/drivers/md/dm-snap-persistent.c +++ b/drivers/md/dm-snap-persistent.c @@ -200,16 +200,13 @@ err_area: static void free_area(struct pstore *ps) { - if (ps->area) - vfree(ps->area); + vfree(ps->area); ps->area = NULL; - if (ps->zero_area) - vfree(ps->zero_area); + vfree(ps->zero_area); ps->zero_area = NULL; - if (ps->header_area) - vfree(ps->header_area); + vfree(ps->header_area); ps->header_area = NULL; } @@ -605,8 +602,7 @@ static void persistent_dtr(struct dm_exception_store *store) free_area(ps); /* Allocated in persistent_read_metadata */ - if (ps->callbacks) - vfree(ps->callbacks); + vfree(ps->callbacks); kfree(ps); } -- 2.1.3
On Tue 18-11-14 18:55:32, SF Markus Elfring wrote: > 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. I've merged both patches. Thanks. Honza > > 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 > -- Jan Kara <jack@suse.cz> SUSE Labs, CR
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 19 Nov 2014 20:55:18 +0100
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 19 Nov 2014 20:48:26 +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>
Applied, thanks.
Hello, On Tue, 18 Nov 2014, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Tue, 18 Nov 2014 20:37:05 +0100 > > The functions free_percpu() and module_put() test whether their argument > is NULL and then return immediately. Thus the test around the call is > not needed. > > This issue was detected by using the Coccinelle software. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> Pablo, the IPVS parts look ok to me, Acked-by: Julian Anastasov <ja@ssi.bg> > --- > net/netfilter/ipvs/ip_vs_ctl.c | 3 +-- > net/netfilter/ipvs/ip_vs_pe.c | 3 +-- > net/netfilter/ipvs/ip_vs_sched.c | 3 +-- > net/netfilter/ipvs/ip_vs_sync.c | 3 +-- > net/netfilter/nf_tables_api.c | 3 +-- > 5 files changed, 5 insertions(+), 10 deletions(-) > > diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c > index fd3f444..7c5e40a 100644 > --- a/net/netfilter/ipvs/ip_vs_ctl.c > +++ b/net/netfilter/ipvs/ip_vs_ctl.c > @@ -465,8 +465,7 @@ __ip_vs_bind_svc(struct ip_vs_dest *dest, struct ip_vs_service *svc) > > static void ip_vs_service_free(struct ip_vs_service *svc) > { > - if (svc->stats.cpustats) > - free_percpu(svc->stats.cpustats); > + free_percpu(svc->stats.cpustats); > kfree(svc); > } > > diff --git a/net/netfilter/ipvs/ip_vs_pe.c b/net/netfilter/ipvs/ip_vs_pe.c > index 1a82b29..0df17ca 100644 > --- a/net/netfilter/ipvs/ip_vs_pe.c > +++ b/net/netfilter/ipvs/ip_vs_pe.c > @@ -37,8 +37,7 @@ struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name) > rcu_read_unlock(); > return pe; > } > - if (pe->module) > - module_put(pe->module); > + module_put(pe->module); > } > rcu_read_unlock(); > > diff --git a/net/netfilter/ipvs/ip_vs_sched.c b/net/netfilter/ipvs/ip_vs_sched.c > index 4dbcda6..199760c 100644 > --- a/net/netfilter/ipvs/ip_vs_sched.c > +++ b/net/netfilter/ipvs/ip_vs_sched.c > @@ -104,8 +104,7 @@ static struct ip_vs_scheduler *ip_vs_sched_getbyname(const char *sched_name) > mutex_unlock(&ip_vs_sched_mutex); > return sched; > } > - if (sched->module) > - module_put(sched->module); > + module_put(sched->module); > } > > mutex_unlock(&ip_vs_sched_mutex); > diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c > index eadffb2..cafe28d 100644 > --- a/net/netfilter/ipvs/ip_vs_sync.c > +++ b/net/netfilter/ipvs/ip_vs_sync.c > @@ -820,8 +820,7 @@ ip_vs_conn_fill_param_sync(struct net *net, int af, union ip_vs_sync_conn *sc, > > p->pe_data = kmemdup(pe_data, pe_data_len, GFP_ATOMIC); > if (!p->pe_data) { > - if (p->pe->module) > - module_put(p->pe->module); > + module_put(p->pe->module); > return -ENOMEM; > } > p->pe_data_len = pe_data_len; > diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c > index deeb95f..b115f54 100644 > --- a/net/netfilter/nf_tables_api.c > +++ b/net/netfilter/nf_tables_api.c > @@ -3472,8 +3472,7 @@ static int nf_tables_abort(struct sk_buff *skb) > break; > case NFT_MSG_NEWCHAIN: > if (nft_trans_chain_update(trans)) { > - if (nft_trans_chain_stats(trans)) > - free_percpu(nft_trans_chain_stats(trans)); > + free_percpu(nft_trans_chain_stats(trans)); > > nft_trans_destroy(trans); > } else { > -- > 2.1.3 Regards -- Julian Anastasov <ja@ssi.bg>
On Thu, Nov 20, 2014 at 12:26:56AM +0200, Julian Anastasov wrote: > > Hello, > > On Tue, 18 Nov 2014, SF Markus Elfring wrote: > > > From: Markus Elfring <elfring@users.sourceforge.net> > > Date: Tue, 18 Nov 2014 20:37:05 +0100 > > > > The functions free_percpu() and module_put() test whether their argument > > is NULL and then return immediately. Thus the test around the call is > > not needed. > > > > This issue was detected by using the Coccinelle software. > > > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > > Pablo, the IPVS parts look ok to me, > > Acked-by: Julian Anastasov <ja@ssi.bg> Acked-by: Simon Horman <horms@verge.net.au> > > > --- > > net/netfilter/ipvs/ip_vs_ctl.c | 3 +-- > > net/netfilter/ipvs/ip_vs_pe.c | 3 +-- > > net/netfilter/ipvs/ip_vs_sched.c | 3 +-- > > net/netfilter/ipvs/ip_vs_sync.c | 3 +-- > > net/netfilter/nf_tables_api.c | 3 +-- > > 5 files changed, 5 insertions(+), 10 deletions(-) > > > > diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c > > index fd3f444..7c5e40a 100644 > > --- a/net/netfilter/ipvs/ip_vs_ctl.c > > +++ b/net/netfilter/ipvs/ip_vs_ctl.c > > @@ -465,8 +465,7 @@ __ip_vs_bind_svc(struct ip_vs_dest *dest, struct ip_vs_service *svc) > > > > static void ip_vs_service_free(struct ip_vs_service *svc) > > { > > - if (svc->stats.cpustats) > > - free_percpu(svc->stats.cpustats); > > + free_percpu(svc->stats.cpustats); > > kfree(svc); > > } > > > > diff --git a/net/netfilter/ipvs/ip_vs_pe.c b/net/netfilter/ipvs/ip_vs_pe.c > > index 1a82b29..0df17ca 100644 > > --- a/net/netfilter/ipvs/ip_vs_pe.c > > +++ b/net/netfilter/ipvs/ip_vs_pe.c > > @@ -37,8 +37,7 @@ struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name) > > rcu_read_unlock(); > > return pe; > > } > > - if (pe->module) > > - module_put(pe->module); > > + module_put(pe->module); > > } > > rcu_read_unlock(); > > > > diff --git a/net/netfilter/ipvs/ip_vs_sched.c b/net/netfilter/ipvs/ip_vs_sched.c > > index 4dbcda6..199760c 100644 > > --- a/net/netfilter/ipvs/ip_vs_sched.c > > +++ b/net/netfilter/ipvs/ip_vs_sched.c > > @@ -104,8 +104,7 @@ static struct ip_vs_scheduler *ip_vs_sched_getbyname(const char *sched_name) > > mutex_unlock(&ip_vs_sched_mutex); > > return sched; > > } > > - if (sched->module) > > - module_put(sched->module); > > + module_put(sched->module); > > } > > > > mutex_unlock(&ip_vs_sched_mutex); > > diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c > > index eadffb2..cafe28d 100644 > > --- a/net/netfilter/ipvs/ip_vs_sync.c > > +++ b/net/netfilter/ipvs/ip_vs_sync.c > > @@ -820,8 +820,7 @@ ip_vs_conn_fill_param_sync(struct net *net, int af, union ip_vs_sync_conn *sc, > > > > p->pe_data = kmemdup(pe_data, pe_data_len, GFP_ATOMIC); > > if (!p->pe_data) { > > - if (p->pe->module) > > - module_put(p->pe->module); > > + module_put(p->pe->module); > > return -ENOMEM; > > } > > p->pe_data_len = pe_data_len; > > diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c > > index deeb95f..b115f54 100644 > > --- a/net/netfilter/nf_tables_api.c > > +++ b/net/netfilter/nf_tables_api.c > > @@ -3472,8 +3472,7 @@ static int nf_tables_abort(struct sk_buff *skb) > > break; > > case NFT_MSG_NEWCHAIN: > > if (nft_trans_chain_update(trans)) { > > - if (nft_trans_chain_stats(trans)) > > - free_percpu(nft_trans_chain_stats(trans)); > > + free_percpu(nft_trans_chain_stats(trans)); > > > > nft_trans_destroy(trans); > > } else { > > -- > > 2.1.3 > > Regards > > -- > Julian Anastasov <ja@ssi.bg> >
(2014/11/19 16:08), SF Markus Elfring wrote:
>>> 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?
No, not "want". IMHO, if try_module_get(mod) is done only when mod!=NULL,
we shouldn't call module_put(mod) when mod=NULL (even if it is possible),
because those get/put method must be used as a pair, for the better
understandings.
Thank you,
--
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Research Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@hitachi.com
On November 19, 2014 5:28:59 PM SF Markus Elfring
<elfring@users.sourceforge.net> wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 19 Nov 2014 17:05:20 +0100
>
> The drm_fbdev_cma_hotplug_event() 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/gpu/drm/tilcdc/tilcdc_drv.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.c
> b/drivers/gpu/drm/tilcdc/tilcdc_drv.c
> index 000428e..335b1dc 100644
> --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.c
> +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.c
> @@ -58,8 +58,7 @@ static struct drm_framebuffer *tilcdc_fb_create(struct
> drm_device *dev,
> static void tilcdc_fb_output_poll_changed(struct drm_device *dev)
> {
> struct tilcdc_drm_private *priv = dev->dev_private;
> - if (priv->fbdev)
> - drm_fbdev_cma_hotplug_event(priv->fbdev);
> + drm_fbdev_cma_hotplug_event(priv->fbdev);
> }
>
> static const struct drm_mode_config_funcs mode_config_funcs = {
Reviewed-by: Thierry Reding <thierry.reding@gmail.com>
On November 19, 2014 5:42:26 PM SF Markus Elfring
<elfring@users.sourceforge.net> wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 19 Nov 2014 17:33:32 +0100
>
> The vunmap() function performes 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/gpu/drm/udl/udl_gem.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/udl/udl_gem.c b/drivers/gpu/drm/udl/udl_gem.c
> index 8044f5f..2979625 100644
> --- a/drivers/gpu/drm/udl/udl_gem.c
> +++ b/drivers/gpu/drm/udl/udl_gem.c
> @@ -164,8 +164,7 @@ void udl_gem_vunmap(struct udl_gem_object *obj)
> return;
> }
>
> - if (obj->vmapping)
> - vunmap(obj->vmapping);
> + vunmap(obj->vmapping);
>
> udl_gem_put_pages(obj);
> }
Reviewed-by: Thierry Reding <thierry.reding@gmail.com>
On November 19, 2014 5:57:13 PM SF Markus Elfring
<elfring@users.sourceforge.net> wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 19 Nov 2014 17:50:19 +0100
>
> The vfree() function performes 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/gpu/drm/vmwgfx/vmwgfx_drv.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> index 14b2f50..f9a67b8 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> @@ -889,8 +889,7 @@ static int vmw_driver_unload(struct drm_device *dev)
>
> if (dev_priv->ctx.res_ht_initialized)
> drm_ht_remove(&dev_priv->ctx.res_ht);
> - if (dev_priv->ctx.cmd_bounce)
> - vfree(dev_priv->ctx.cmd_bounce);
> + vfree(dev_priv->ctx.cmd_bounce);
> if (dev_priv->enable_fb) {
> vmw_fb_close(dev_priv);
> vmw_kms_restore_vga(dev_priv);
Reviewed-by: Thierry Reding <thierry.reding@gmail.com>
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 19 Nov 2014 23:30:37 +0100 Another update suggestion was taken into account after a patch was applied from static source code analysis. Markus Elfring (3): DVB-frontends: Deletion of unnecessary checks before the function call "release_firmware" m88ds3103: One function call less in m88ds3103_init() after error detection si2168: One function call less in si2168_init() after error detection drivers/media/dvb-frontends/drx39xyj/drxj.c | 3 +-- drivers/media/dvb-frontends/drxk_hard.c | 3 +-- drivers/media/dvb-frontends/m88ds3103.c | 12 ++++++------ drivers/media/dvb-frontends/si2168.c | 10 +++++----- 4 files changed, 13 insertions(+), 15 deletions(-) -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 19 Nov 2014 23:20:51 +0100 The release_firmware() function was called in some cases by the m88ds3103_init() 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. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/media/dvb-frontends/m88ds3103.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/media/dvb-frontends/m88ds3103.c b/drivers/media/dvb-frontends/m88ds3103.c index e88f0f6..82da715 100644 --- a/drivers/media/dvb-frontends/m88ds3103.c +++ b/drivers/media/dvb-frontends/m88ds3103.c @@ -590,7 +590,7 @@ static int m88ds3103_init(struct dvb_frontend *fe) ret = m88ds3103_wr_reg(priv, 0xb2, 0x01); if (ret) - goto err; + goto error_fw_release; for (remaining = fw->size; remaining > 0; remaining -= (priv->cfg->i2c_wr_max - 1)) { @@ -604,13 +604,13 @@ static int m88ds3103_init(struct dvb_frontend *fe) dev_err(&priv->i2c->dev, "%s: firmware download failed=%d\n", KBUILD_MODNAME, ret); - goto err; + goto error_fw_release; } } ret = m88ds3103_wr_reg(priv, 0xb2, 0x00); if (ret) - goto err; + goto error_fw_release; release_firmware(fw); fw = NULL; @@ -636,9 +636,10 @@ skip_fw_download: priv->warm = true; return 0; -err: - release_firmware(fw); +error_fw_release: + release_firmware(fw); +err: dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); return ret; } -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 19 Nov 2014 22:27:24 +0100 The release_firmware() 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/media/dvb-frontends/drx39xyj/drxj.c | 3 +-- drivers/media/dvb-frontends/drxk_hard.c | 3 +-- drivers/media/dvb-frontends/m88ds3103.c | 3 +-- drivers/media/dvb-frontends/si2168.c | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/media/dvb-frontends/drx39xyj/drxj.c b/drivers/media/dvb-frontends/drx39xyj/drxj.c index 7ca7a21..08e6ca5 100644 --- a/drivers/media/dvb-frontends/drx39xyj/drxj.c +++ b/drivers/media/dvb-frontends/drx39xyj/drxj.c @@ -12255,8 +12255,7 @@ static void drx39xxj_release(struct dvb_frontend *fe) kfree(demod->my_ext_attr); kfree(demod->my_common_attr); kfree(demod->my_i2c_dev_addr); - if (demod->firmware) - release_firmware(demod->firmware); + release_firmware(demod->firmware); kfree(demod); kfree(state); } diff --git a/drivers/media/dvb-frontends/drxk_hard.c b/drivers/media/dvb-frontends/drxk_hard.c index cce94a7..f871478 100644 --- a/drivers/media/dvb-frontends/drxk_hard.c +++ b/drivers/media/dvb-frontends/drxk_hard.c @@ -6309,8 +6309,7 @@ static void drxk_release(struct dvb_frontend *fe) struct drxk_state *state = fe->demodulator_priv; dprintk(1, "\n"); - if (state->fw) - release_firmware(state->fw); + release_firmware(state->fw); kfree(state); } diff --git a/drivers/media/dvb-frontends/m88ds3103.c b/drivers/media/dvb-frontends/m88ds3103.c index dfe0c2f..e88f0f6 100644 --- a/drivers/media/dvb-frontends/m88ds3103.c +++ b/drivers/media/dvb-frontends/m88ds3103.c @@ -637,8 +637,7 @@ skip_fw_download: return 0; err: - if (fw) - release_firmware(fw); + release_firmware(fw); dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); return ret; diff --git a/drivers/media/dvb-frontends/si2168.c b/drivers/media/dvb-frontends/si2168.c index 8f81d97..6a455f9 100644 --- a/drivers/media/dvb-frontends/si2168.c +++ b/drivers/media/dvb-frontends/si2168.c @@ -469,8 +469,7 @@ static int si2168_init(struct dvb_frontend *fe) return 0; err: - if (fw) - release_firmware(fw); + release_firmware(fw); dev_dbg(&s->client->dev, "%s: failed=%d\n", __func__, ret); return ret; -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 19 Nov 2014 23:23:15 +0100 The release_firmware() function was called in some cases by the si2168_init() 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. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/media/dvb-frontends/si2168.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/media/dvb-frontends/si2168.c b/drivers/media/dvb-frontends/si2168.c index 6a455f9..b8c6372 100644 --- a/drivers/media/dvb-frontends/si2168.c +++ b/drivers/media/dvb-frontends/si2168.c @@ -428,7 +428,7 @@ static int si2168_init(struct dvb_frontend *fe) dev_err(&s->client->dev, "%s: firmware file '%s' not found\n", KBUILD_MODNAME, fw_file); - goto err; + goto error_fw_release; } } @@ -448,7 +448,7 @@ static int si2168_init(struct dvb_frontend *fe) dev_err(&s->client->dev, "%s: firmware download failed=%d\n", KBUILD_MODNAME, ret); - goto err; + goto error_fw_release; } } @@ -468,9 +468,10 @@ static int si2168_init(struct dvb_frontend *fe) s->active = true; return 0; -err: - release_firmware(fw); +error_fw_release: + release_firmware(fw); +err: dev_dbg(&s->client->dev, "%s: failed=%d\n", __func__, ret); return ret; } -- 2.1.3
On Wed, 19 Nov 2014, SF Markus Elfring wrote: > > Marcus, what tree are you looking at? > > I dared to base this update suggestion on the source files > for Linux 3.17.3. Are newer software developments relevant here? You should always use linux-next. You should update it every day. julia > https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/log/net/sched/ > > Regards, > Markus > > -- > To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >
On 11/20/2014 09:47 AM, Julia Lawall wrote:
> On Wed, 19 Nov 2014, SF Markus Elfring wrote:
>
>>> Marcus, what tree are you looking at?
>>
>> I dared to base this update suggestion on the source files
>> for Linux 3.17.3. Are newer software developments relevant here?
>
> You should always use linux-next. You should update it every day.
Well, if you send in cleanups to netdev, you should always target
the net-next tree:
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 20 Nov 2014 10:49:07 +0100 The dvb_unregister_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/media/firewire/firedtv-ci.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/media/firewire/firedtv-ci.c b/drivers/media/firewire/firedtv-ci.c index e5ebdbf..e63f582 100644 --- a/drivers/media/firewire/firedtv-ci.c +++ b/drivers/media/firewire/firedtv-ci.c @@ -253,6 +253,5 @@ int fdtv_ca_register(struct firedtv *fdtv) void fdtv_ca_release(struct firedtv *fdtv) { - if (fdtv->cadev) - dvb_unregister_device(fdtv->cadev); + dvb_unregister_device(fdtv->cadev); } -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 20 Nov 2014 11:13:16 +0100 The rc_unregister_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/media/i2c/ir-kbd-i2c.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/media/i2c/ir-kbd-i2c.c b/drivers/media/i2c/ir-kbd-i2c.c index 8311f1a..175a761 100644 --- a/drivers/media/i2c/ir-kbd-i2c.c +++ b/drivers/media/i2c/ir-kbd-i2c.c @@ -464,8 +464,7 @@ static int ir_remove(struct i2c_client *client) cancel_delayed_work_sync(&ir->work); /* unregister device */ - if (ir->rc) - rc_unregister_device(ir->rc); + rc_unregister_device(ir->rc); /* free memory */ return 0; -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 20 Nov 2014 11:44:20 +0100 The functions i2c_put_adapter() 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> --- drivers/media/platform/exynos4-is/fimc-is.c | 6 ++---- drivers/media/platform/s3c-camif/camif-core.c | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/media/platform/exynos4-is/fimc-is.c b/drivers/media/platform/exynos4-is/fimc-is.c index 5476dce..a1db27b 100644 --- a/drivers/media/platform/exynos4-is/fimc-is.c +++ b/drivers/media/platform/exynos4-is/fimc-is.c @@ -428,8 +428,7 @@ static void fimc_is_load_firmware(const struct firmware *fw, void *context) * needed around for copying to the IS working memory every * time before the Cortex-A5 is restarted. */ - if (is->fw.f_w) - release_firmware(is->fw.f_w); + release_firmware(is->fw.f_w); is->fw.f_w = fw; done: mutex_unlock(&is->lock); @@ -937,8 +936,7 @@ static int fimc_is_remove(struct platform_device *pdev) vb2_dma_contig_cleanup_ctx(is->alloc_ctx); fimc_is_put_clocks(is); fimc_is_debugfs_remove(is); - if (is->fw.f_w) - release_firmware(is->fw.f_w); + release_firmware(is->fw.f_w); fimc_is_free_cpu_memory(is); return 0; diff --git a/drivers/media/platform/s3c-camif/camif-core.c b/drivers/media/platform/s3c-camif/camif-core.c index b385747..3b09b5b 100644 --- a/drivers/media/platform/s3c-camif/camif-core.c +++ b/drivers/media/platform/s3c-camif/camif-core.c @@ -256,8 +256,7 @@ static void camif_unregister_sensor(struct camif_dev *camif) v4l2_device_unregister_subdev(sd); camif->sensor.sd = NULL; i2c_unregister_device(client); - if (adapter) - i2c_put_adapter(adapter); + i2c_put_adapter(adapter); } static int camif_create_media_links(struct camif_dev *camif) -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 20 Nov 2014 13:01:32 +0100 The functions input_free_device() and rc_close() 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/media/rc/lirc_dev.c | 3 +-- drivers/media/rc/rc-main.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/media/rc/lirc_dev.c b/drivers/media/rc/lirc_dev.c index dc5cbff..5c232e6 100644 --- a/drivers/media/rc/lirc_dev.c +++ b/drivers/media/rc/lirc_dev.c @@ -518,8 +518,7 @@ int lirc_dev_fop_close(struct inode *inode, struct file *file) WARN_ON(mutex_lock_killable(&lirc_dev_lock)); - if (ir->d.rdev) - rc_close(ir->d.rdev); + rc_close(ir->d.rdev); ir->open--; if (ir->attached) { diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c index 8d3b74c..66df9fb 100644 --- a/drivers/media/rc/rc-main.c +++ b/drivers/media/rc/rc-main.c @@ -1298,8 +1298,7 @@ void rc_free_device(struct rc_dev *dev) if (!dev) return; - if (dev->input_dev) - input_free_device(dev->input_dev); + input_free_device(dev->input_dev); put_device(&dev->dev); -- 2.1.3
On Thu, Nov 20, 2014 at 10:13:59AM +0900, Simon Horman wrote:
> On Thu, Nov 20, 2014 at 12:26:56AM +0200, Julian Anastasov wrote:
> >
> > Hello,
> >
> > On Tue, 18 Nov 2014, SF Markus Elfring wrote:
> >
> > > From: Markus Elfring <elfring@users.sourceforge.net>
> > > Date: Tue, 18 Nov 2014 20:37:05 +0100
> > >
> > > The functions free_percpu() and module_put() test whether their argument
> > > is NULL and then return immediately. Thus the test around the call is
> > > not needed.
> > >
> > > This issue was detected by using the Coccinelle software.
> > >
> > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> >
> > Pablo, the IPVS parts look ok to me,
> >
> > Acked-by: Julian Anastasov <ja@ssi.bg>
>
> Acked-by: Simon Horman <horms@verge.net.au>
Applied, thanks.
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 20 Nov 2014 13:26:36 +0100 The functions pvr2_hdw_destroy(), rc_unregister_device() and vfree() perform 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/media/usb/au0828/au0828-input.c | 3 +-- drivers/media/usb/em28xx/em28xx-input.c | 3 +-- drivers/media/usb/pvrusb2/pvrusb2-context.c | 2 +- drivers/media/usb/s2255/s2255drv.c | 3 +-- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/media/usb/au0828/au0828-input.c b/drivers/media/usb/au0828/au0828-input.c index fd0d3a90..3357141 100644 --- a/drivers/media/usb/au0828/au0828-input.c +++ b/drivers/media/usb/au0828/au0828-input.c @@ -353,8 +353,7 @@ void au0828_rc_unregister(struct au0828_dev *dev) if (!ir) return; - if (ir->rc) - rc_unregister_device(ir->rc); + rc_unregister_device(ir->rc); /* done */ kfree(ir); diff --git a/drivers/media/usb/em28xx/em28xx-input.c b/drivers/media/usb/em28xx/em28xx-input.c index ed843bd..67a22f4 100644 --- a/drivers/media/usb/em28xx/em28xx-input.c +++ b/drivers/media/usb/em28xx/em28xx-input.c @@ -838,8 +838,7 @@ static int em28xx_ir_fini(struct em28xx *dev) if (!ir) goto ref_put; - if (ir->rc) - rc_unregister_device(ir->rc); + rc_unregister_device(ir->rc); /* done */ kfree(ir); diff --git a/drivers/media/usb/pvrusb2/pvrusb2-context.c b/drivers/media/usb/pvrusb2/pvrusb2-context.c index 7c19ff7..c8761c7 100644 --- a/drivers/media/usb/pvrusb2/pvrusb2-context.c +++ b/drivers/media/usb/pvrusb2/pvrusb2-context.c @@ -80,7 +80,7 @@ static void pvr2_context_set_notify(struct pvr2_context *mp, int fl) static void pvr2_context_destroy(struct pvr2_context *mp) { pvr2_trace(PVR2_TRACE_CTXT,"pvr2_context %p (destroy)",mp); - if (mp->hdw) pvr2_hdw_destroy(mp->hdw); + pvr2_hdw_destroy(mp->hdw); pvr2_context_set_notify(mp, 0); mutex_lock(&pvr2_context_mutex); if (mp->exist_next) { diff --git a/drivers/media/usb/s2255/s2255drv.c b/drivers/media/usb/s2255/s2255drv.c index 2c90186..3cab886 100644 --- a/drivers/media/usb/s2255/s2255drv.c +++ b/drivers/media/usb/s2255/s2255drv.c @@ -1976,8 +1976,7 @@ static int s2255_release_sys_buffers(struct s2255_vc *vc) { unsigned long i; for (i = 0; i < SYS_FRAMES; i++) { - if (vc->buffer.frame[i].lpvbits) - vfree(vc->buffer.frame[i].lpvbits); + vfree(vc->buffer.frame[i].lpvbits); vc->buffer.frame[i].lpvbits = NULL; } return 0; -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 20 Nov 2014 13:50:43 +0100 The functions kfree() and pci_dev_put() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/mtd/chips/cfi_cmdset_0001.c | 3 +-- drivers/mtd/devices/pmc551.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c index 3096f3d..286b97a 100644 --- a/drivers/mtd/chips/cfi_cmdset_0001.c +++ b/drivers/mtd/chips/cfi_cmdset_0001.c @@ -2654,8 +2654,7 @@ static void cfi_intelext_destroy(struct mtd_info *mtd) kfree(cfi); for (i = 0; i < mtd->numeraseregions; i++) { region = &mtd->eraseregions[i]; - if (region->lockmap) - kfree(region->lockmap); + kfree(region->lockmap); } kfree(mtd->eraseregions); } diff --git a/drivers/mtd/devices/pmc551.c b/drivers/mtd/devices/pmc551.c index f02603e..708b7e8 100644 --- a/drivers/mtd/devices/pmc551.c +++ b/drivers/mtd/devices/pmc551.c @@ -812,8 +812,7 @@ static int __init init_pmc551(void) } /* Exited early, reference left over */ - if (PCI_Device) - pci_dev_put(PCI_Device); + pci_dev_put(PCI_Device); if (!pmc551list) { printk(KERN_NOTICE "pmc551: not detected\n"); -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 20 Nov 2014 14:22:47 +0100 The of_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> --- drivers/net/ethernet/ibm/emac/core.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c index 87bd953..3f3fba9 100644 --- a/drivers/net/ethernet/ibm/emac/core.c +++ b/drivers/net/ethernet/ibm/emac/core.c @@ -2323,16 +2323,11 @@ static int emac_check_deps(struct emac_instance *dev, static void emac_put_deps(struct emac_instance *dev) { - if (dev->mal_dev) - of_dev_put(dev->mal_dev); - if (dev->zmii_dev) - of_dev_put(dev->zmii_dev); - if (dev->rgmii_dev) - of_dev_put(dev->rgmii_dev); - if (dev->mdio_dev) - of_dev_put(dev->mdio_dev); - if (dev->tah_dev) - of_dev_put(dev->tah_dev); + of_dev_put(dev->mal_dev); + of_dev_put(dev->zmii_dev); + of_dev_put(dev->rgmii_dev); + of_dev_put(dev->mdio_dev); + of_dev_put(dev->tah_dev); } static int emac_of_bus_notify(struct notifier_block *nb, unsigned long action, @@ -2371,8 +2366,7 @@ static int emac_wait_deps(struct emac_instance *dev) bus_unregister_notifier(&platform_bus_type, &emac_of_bus_notifier); err = emac_check_deps(dev, deps) ? 0 : -ENODEV; for (i = 0; i < EMAC_DEP_COUNT; i++) { - if (deps[i].node) - of_node_put(deps[i].node); + of_node_put(deps[i].node); if (err && deps[i].ofdev) of_dev_put(deps[i].ofdev); } @@ -2383,8 +2377,7 @@ static int emac_wait_deps(struct emac_instance *dev) dev->tah_dev = deps[EMAC_DEP_TAH_IDX].ofdev; dev->mdio_dev = deps[EMAC_DEP_MDIO_IDX].ofdev; } - if (deps[EMAC_DEP_PREV_IDX].ofdev) - of_dev_put(deps[EMAC_DEP_PREV_IDX].ofdev); + of_dev_put(deps[EMAC_DEP_PREV_IDX].ofdev); return err; } @@ -3113,8 +3106,7 @@ static void __exit emac_exit(void) /* Destroy EMAC boot list */ for (i = 0; i < EMAC_BOOT_LIST_SIZE; i++) - if (emac_boot_list[i]) - of_node_put(emac_boot_list[i]); + of_node_put(emac_boot_list[i]); } module_init(emac_init); -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 20 Nov 2014 14:47:12 +0100 The functions kfree() and of_node_put() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/net/ethernet/xilinx/ll_temac_main.c | 3 +-- drivers/net/ethernet/xilinx/xilinx_emaclite.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/xilinx/ll_temac_main.c b/drivers/net/ethernet/xilinx/ll_temac_main.c index fda5891..af60867 100644 --- a/drivers/net/ethernet/xilinx/ll_temac_main.c +++ b/drivers/net/ethernet/xilinx/ll_temac_main.c @@ -224,8 +224,7 @@ static void temac_dma_bd_release(struct net_device *ndev) dma_free_coherent(ndev->dev.parent, sizeof(*lp->tx_bd_v) * TX_BD_NUM, lp->tx_bd_v, lp->tx_bd_p); - if (lp->rx_skb) - kfree(lp->rx_skb); + kfree(lp->rx_skb); } /** diff --git a/drivers/net/ethernet/xilinx/xilinx_emaclite.c b/drivers/net/ethernet/xilinx/xilinx_emaclite.c index 28dbbdc..2485879 100644 --- a/drivers/net/ethernet/xilinx/xilinx_emaclite.c +++ b/drivers/net/ethernet/xilinx/xilinx_emaclite.c @@ -1200,8 +1200,7 @@ static int xemaclite_of_remove(struct platform_device *of_dev) unregister_netdev(ndev); - if (lp->phy_node) - of_node_put(lp->phy_node); + of_node_put(lp->phy_node); lp->phy_node = NULL; xemaclite_remove_ndev(ndev); -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 20 Nov 2014 15:15:21 +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/hyperv/netvsc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c index da2d346..ffe7481 100644 --- a/drivers/net/hyperv/netvsc.c +++ b/drivers/net/hyperv/netvsc.c @@ -548,8 +548,7 @@ int netvsc_device_remove(struct hv_device *device) vmbus_close(device->channel); /* Release all resources */ - if (net_device->sub_cb_buf) - vfree(net_device->sub_cb_buf); + vfree(net_device->sub_cb_buf); kfree(net_device); return 0; -- 2.1.3
On Wed, Nov 19, 2014 at 10:20:32AM +0100, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Wed, 19 Nov 2014 10:11:04 +0100 > > The kzfree() function tests whether its argument is NULL and then > returns immediately. Thus the test around the call is not needed. > > This issue was detected by using the Coccinelle software. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> Sorry but you're too late as someone else has already fixed this :) Thanks, -- Email: Herbert Xu <herbert@gondor.apana.org.au> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
On Nov 20 SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Thu, 20 Nov 2014 10:49:07 +0100 > > The dvb_unregister_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> Reviewed-by: Stefan Richter <stefanr@s5r6.in-berlin.de> > --- > drivers/media/firewire/firedtv-ci.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/media/firewire/firedtv-ci.c b/drivers/media/firewire/firedtv-ci.c > index e5ebdbf..e63f582 100644 > --- a/drivers/media/firewire/firedtv-ci.c > +++ b/drivers/media/firewire/firedtv-ci.c > @@ -253,6 +253,5 @@ int fdtv_ca_register(struct firedtv *fdtv) > > void fdtv_ca_release(struct firedtv *fdtv) > { > - if (fdtv->cadev) > - dvb_unregister_device(fdtv->cadev); > + dvb_unregister_device(fdtv->cadev); > } -- Stefan Richter -===-==- =-= =-=-- http://arcgraph.de/sr/
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 20 Nov 2014 16:11:56 +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> --- drivers/net/usb/asix_devices.c | 3 +-- drivers/net/usb/hso.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c index 5d19409..8a7582b 100644 --- a/drivers/net/usb/asix_devices.c +++ b/drivers/net/usb/asix_devices.c @@ -499,8 +499,7 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf) static void ax88772_unbind(struct usbnet *dev, struct usb_interface *intf) { - if (dev->driver_priv) - kfree(dev->driver_priv); + kfree(dev->driver_priv); } static const struct ethtool_ops ax88178_ethtool_ops = { diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c index babda7d..9c5aa92 100644 --- a/drivers/net/usb/hso.c +++ b/drivers/net/usb/hso.c @@ -2746,8 +2746,7 @@ exit: tty_unregister_device(tty_drv, serial->minor); kfree(serial); } - if (hso_dev) - kfree(hso_dev); + kfree(hso_dev); return NULL; } -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 20 Nov 2014 16:42:51 +0100 The functions brcmu_pkt_buf_free_skb() 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> --- drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c | 3 +-- drivers/net/wireless/brcm80211/brcmfmac/firmware.c | 3 +-- drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c | 3 +-- drivers/net/wireless/brcm80211/brcmsmac/main.c | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c b/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c index f55f625..8ff7037 100644 --- a/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c +++ b/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c @@ -2539,8 +2539,7 @@ static void brcmf_sdio_bus_stop(struct device *dev) brcmu_pktq_flush(&bus->txq, true, NULL, NULL); /* Clear any held glomming stuff */ - if (bus->glomd) - brcmu_pkt_buf_free_skb(bus->glomd); + brcmu_pkt_buf_free_skb(bus->glomd); brcmf_sdio_free_glom(bus); /* Clear rx control and wake any waiters */ diff --git a/drivers/net/wireless/brcm80211/brcmfmac/firmware.c b/drivers/net/wireless/brcm80211/brcmfmac/firmware.c index 8ea9f28..3a2d014 100644 --- a/drivers/net/wireless/brcm80211/brcmfmac/firmware.c +++ b/drivers/net/wireless/brcm80211/brcmfmac/firmware.c @@ -262,8 +262,7 @@ static void brcmf_fw_request_nvram_done(const struct firmware *fw, void *ctx) fail: brcmf_dbg(TRACE, "failed: dev=%s\n", dev_name(fwctx->dev)); - if (fwctx->code) - release_firmware(fwctx->code); + release_firmware(fwctx->code); device_release_driver(fwctx->dev); kfree(fwctx); } diff --git a/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c b/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c index 8f8b937..0cb00dc 100644 --- a/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c +++ b/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c @@ -506,8 +506,7 @@ static int brcmf_msgbuf_query_dcmd(struct brcmf_pub *drvr, int ifidx, memcpy(buf, skb->data, (len < msgbuf->ioctl_resp_ret_len) ? len : msgbuf->ioctl_resp_ret_len); } - if (skb) - brcmu_pkt_buf_free_skb(skb); + brcmu_pkt_buf_free_skb(skb); return msgbuf->ioctl_resp_status; } diff --git a/drivers/net/wireless/brcm80211/brcmsmac/main.c b/drivers/net/wireless/brcm80211/brcmsmac/main.c index 1b47482..ce538a1 100644 --- a/drivers/net/wireless/brcm80211/brcmsmac/main.c +++ b/drivers/net/wireless/brcm80211/brcmsmac/main.c @@ -1009,8 +1009,7 @@ brcms_c_dotxstatus(struct brcms_c_info *wlc, struct tx_status *txs) if (txh) trace_brcms_txdesc(&wlc->hw->d11core->dev, txh, sizeof(*txh)); - if (p) - brcmu_pkt_buf_free_skb(p); + brcmu_pkt_buf_free_skb(p); } if (dma && queue < NFIFO) { -- 2.1.3
> Sorry but you're too late as someone else has already fixed this :) Thanks for your feedback. https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/crypto/drbg.c?idFf64f6ef978dc1f36ebaa50ed79c7c8386711ee Regards, Markus
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 20 Nov 2014 17:42:23 +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> --- drivers/pci/hotplug/cpci_hotplug_core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/pci/hotplug/cpci_hotplug_core.c b/drivers/pci/hotplug/cpci_hotplug_core.c index e09cf78..82c969b 100644 --- a/drivers/pci/hotplug/cpci_hotplug_core.c +++ b/drivers/pci/hotplug/cpci_hotplug_core.c @@ -211,8 +211,7 @@ static void release_slot(struct hotplug_slot *hotplug_slot) kfree(slot->hotplug_slot->info); kfree(slot->hotplug_slot); - if (slot->dev) - pci_dev_put(slot->dev); + pci_dev_put(slot->dev); kfree(slot); } -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 20 Nov 2014 18:11:28 +0100 The put_disk() 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/scsi/osd/osd_uld.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/scsi/osd/osd_uld.c b/drivers/scsi/osd/osd_uld.c index e1d9a4c..3d82ee1 100644 --- a/drivers/scsi/osd/osd_uld.c +++ b/drivers/scsi/osd/osd_uld.c @@ -408,8 +408,7 @@ static void __remove(struct device *dev) OSD_INFO("osd_remove %s\n", oud->disk ? oud->disk->disk_name : NULL); - if (oud->disk) - put_disk(oud->disk); + put_disk(oud->disk); ida_remove(&osd_minor_ida, oud->minor); kfree(oud); -- 2.1.3
On Thu, 2014-11-20 at 02:50PM +0100, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Thu, 20 Nov 2014 14:47:12 +0100 > > The functions kfree() and of_node_put() test whether their argument is NULL > and then return immediately. Thus the test around the call is not needed. > > This issue was detected by using the Coccinelle software. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> Reviewed-by: Soren Brinkmann <soren.brinkmann@xilinx.com> Sören -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 20 Nov 2014 18:48:52 +0100 The put_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/scsi/hosts.c | 3 +-- drivers/scsi/scsi_sysfs.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c index 6de80e3..57afb19 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -337,8 +337,7 @@ static void scsi_host_dev_release(struct device *dev) kfree(shost->shost_data); - if (parent) - put_device(parent); + put_device(parent); kfree(shost); } diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index 8b4105a..c977c99 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -426,8 +426,7 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work) kfree(sdev->inquiry); kfree(sdev); - if (parent) - put_device(parent); + put_device(parent); } static void scsi_device_dev_release(struct device *dev) -- 2.1.3
On 11/20/14 16:50, SF Markus Elfring wrote: > From: Markus Elfring<elfring@users.sourceforge.net> > Date: Thu, 20 Nov 2014 16:42:51 +0100 > > The functions brcmu_pkt_buf_free_skb() 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. Goodo for coccinelle and you for running it. Acked-by: Arend van Spriel <arend@broadcom.com> > Signed-off-by: Markus Elfring<elfring@users.sourceforge.net> > --- > drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c | 3 +-- > drivers/net/wireless/brcm80211/brcmfmac/firmware.c | 3 +-- > drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c | 3 +-- > drivers/net/wireless/brcm80211/brcmsmac/main.c | 3 +-- > 4 files changed, 4 insertions(+), 8 deletions(-) > > diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c b/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c > index f55f625..8ff7037 100644 > --- a/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c > +++ b/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c > @@ -2539,8 +2539,7 @@ static void brcmf_sdio_bus_stop(struct device *dev) > brcmu_pktq_flush(&bus->txq, true, NULL, NULL); > > /* Clear any held glomming stuff */ > - if (bus->glomd) > - brcmu_pkt_buf_free_skb(bus->glomd); > + brcmu_pkt_buf_free_skb(bus->glomd); > brcmf_sdio_free_glom(bus); > > /* Clear rx control and wake any waiters */ > diff --git a/drivers/net/wireless/brcm80211/brcmfmac/firmware.c b/drivers/net/wireless/brcm80211/brcmfmac/firmware.c > index 8ea9f28..3a2d014 100644 > --- a/drivers/net/wireless/brcm80211/brcmfmac/firmware.c > +++ b/drivers/net/wireless/brcm80211/brcmfmac/firmware.c > @@ -262,8 +262,7 @@ static void brcmf_fw_request_nvram_done(const struct firmware *fw, void *ctx) > > fail: > brcmf_dbg(TRACE, "failed: dev=%s\n", dev_name(fwctx->dev)); > - if (fwctx->code) > - release_firmware(fwctx->code); > + release_firmware(fwctx->code); > device_release_driver(fwctx->dev); > kfree(fwctx); > } > diff --git a/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c b/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c > index 8f8b937..0cb00dc 100644 > --- a/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c > +++ b/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c > @@ -506,8 +506,7 @@ static int brcmf_msgbuf_query_dcmd(struct brcmf_pub *drvr, int ifidx, > memcpy(buf, skb->data, (len< msgbuf->ioctl_resp_ret_len) ? > len : msgbuf->ioctl_resp_ret_len); > } > - if (skb) > - brcmu_pkt_buf_free_skb(skb); > + brcmu_pkt_buf_free_skb(skb); > > return msgbuf->ioctl_resp_status; > } > diff --git a/drivers/net/wireless/brcm80211/brcmsmac/main.c b/drivers/net/wireless/brcm80211/brcmsmac/main.c > index 1b47482..ce538a1 100644 > --- a/drivers/net/wireless/brcm80211/brcmsmac/main.c > +++ b/drivers/net/wireless/brcm80211/brcmsmac/main.c > @@ -1009,8 +1009,7 @@ brcms_c_dotxstatus(struct brcms_c_info *wlc, struct tx_status *txs) > if (txh) > trace_brcms_txdesc(&wlc->hw->d11core->dev, txh, > sizeof(*txh)); > - if (p) > - brcmu_pkt_buf_free_skb(p); > + brcmu_pkt_buf_free_skb(p); > } > > if (dma&& queue< NFIFO) {
DQoNCj4gLS0tLS1PcmlnaW5hbCBNZXNzYWdlLS0tLS0NCj4gRnJvbTogU0YgTWFya3VzIEVsZnJp bmcgW21haWx0bzplbGZyaW5nQHVzZXJzLnNvdXJjZWZvcmdlLm5ldF0NCj4gU2VudDogVGh1cnNk YXksIE5vdmVtYmVyIDIwLCAyMDE0IDk6MjUgQU0NCj4gVG86IEhhaXlhbmcgWmhhbmc7IEtZIFNy aW5pdmFzYW47IGRldmVsQGxpbnV4ZHJpdmVycHJvamVjdC5vcmc7DQo+IG5ldGRldkB2Z2VyLmtl cm5lbC5vcmcNCj4gQ2M6IExLTUw7IGtlcm5lbC1qYW5pdG9yc0B2Z2VyLmtlcm5lbC5vcmc7IEp1 bGlhIExhd2FsbA0KPiBTdWJqZWN0OiBbUEFUQ0ggMS8xXSBuZXQ6IEh5cGVyLVY6IERlbGV0aW9u IG9mIGFuIHVubmVjZXNzYXJ5IGNoZWNrDQo+IGJlZm9yZSB0aGUgZnVuY3Rpb24gY2FsbCAidmZy ZWUiDQo+IA0KPiBGcm9tOiBNYXJrdXMgRWxmcmluZyA8ZWxmcmluZ0B1c2Vycy5zb3VyY2Vmb3Jn ZS5uZXQ+DQo+IERhdGU6IFRodSwgMjAgTm92IDIwMTQgMTU6MTU6MjEgKzAxMDANCj4gDQo+IFRo ZSB2ZnJlZSgpIGZ1bmN0aW9uIHBlcmZvcm1zIGFsc28gaW5wdXQgcGFyYW1ldGVyIHZhbGlkYXRp b24uIFRodXMgdGhlDQo+IHRlc3QNCj4gYXJvdW5kIHRoZSBjYWxsIGlzIG5vdCBuZWVkZWQuDQo+ IA0KPiBUaGlzIGlzc3VlIHdhcyBkZXRlY3RlZCBieSB1c2luZyB0aGUgQ29jY2luZWxsZSBzb2Z0 d2FyZS4NCj4gDQo+IFNpZ25lZC1vZmYtYnk6IE1hcmt1cyBFbGZyaW5nIDxlbGZyaW5nQHVzZXJz LnNvdXJjZWZvcmdlLm5ldD4NCg0KU2lnbmVkLW9mZi1ieTogSGFpeWFuZyBaaGFuZyA8aGFpeWFu Z3pAbWljcm9zb2Z0LmNvbT4NCg0KVGhhbmtzIQ0KDQo
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 20 Nov 2014 20:10:19 +0100 The fc_fcp_ddp_done() 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/scsi/libfc/fc_exch.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c index 1b3a094..aad6f48 100644 --- a/drivers/scsi/libfc/fc_exch.c +++ b/drivers/scsi/libfc/fc_exch.c @@ -2120,8 +2120,7 @@ static struct fc_seq *fc_exch_seq_send(struct fc_lport *lport, spin_unlock_bh(&ep->ex_lock); return sp; err: - if (fsp) - fc_fcp_ddp_done(fsp); + fc_fcp_ddp_done(fsp); rc = fc_exch_done_locked(ep); spin_unlock_bh(&ep->ex_lock); if (!rc) -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 20 Nov 2014 20:37:30 +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> --- drivers/scsi/eata_pio.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/scsi/eata_pio.c b/drivers/scsi/eata_pio.c index 8319d2b..707f64d 100644 --- a/drivers/scsi/eata_pio.c +++ b/drivers/scsi/eata_pio.c @@ -122,8 +122,7 @@ static int eata_pio_release(struct Scsi_Host *sh) release_region(sh->io_port, sh->n_io_port); } /* At this point the PCI reference can go */ - if (hd->pdev) - pci_dev_put(hd->pdev); + pci_dev_put(hd->pdev); return 1; } -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 20 Nov 2014 23:18:56 +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> --- drivers/scsi/aic94xx/aic94xx_init.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c index c56741f..0bfdcba 100644 --- a/drivers/scsi/aic94xx/aic94xx_init.c +++ b/drivers/scsi/aic94xx/aic94xx_init.c @@ -597,8 +597,7 @@ static void asd_destroy_ha_caches(struct asd_ha_struct *asd_ha) if (asd_ha->hw_prof.scb_ext) asd_free_coherent(asd_ha, asd_ha->hw_prof.scb_ext); - if (asd_ha->hw_prof.ddb_bitmap) - kfree(asd_ha->hw_prof.ddb_bitmap); + kfree(asd_ha->hw_prof.ddb_bitmap); asd_ha->hw_prof.ddb_bitmap = NULL; for (i = 0; i < ASD_MAX_PHYS; i++) { -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 20 Nov 2014 23:43:17 +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/scsi/bfa/bfad_debugfs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/scsi/bfa/bfad_debugfs.c b/drivers/scsi/bfa/bfad_debugfs.c index 8e83d04..a72170f 100644 --- a/drivers/scsi/bfa/bfad_debugfs.c +++ b/drivers/scsi/bfa/bfad_debugfs.c @@ -399,8 +399,7 @@ bfad_debugfs_release_fwtrc(struct inode *inode, struct file *file) if (!fw_debug) return 0; - if (fw_debug->debug_buffer) - vfree(fw_debug->debug_buffer); + vfree(fw_debug->debug_buffer); file->private_data = NULL; kfree(fw_debug); -- 2.1.3
Patch looks good. Thanks! Acked-by: Anil Gurumurthy <anil.gurumurthy@qlogic.com> -----Original Message----- From: SF Markus Elfring [mailto:elfring@users.sourceforge.net] Sent: 21 November 2014 04:17 To: Anil Gurumurthy; James E. J. Bottomley; Sudarsana Kalluru; linux-scsi Cc: linux-kernel; kernel-janitors@vger.kernel.org; Julia Lawall Subject: [PATCH 1/1] SCSI-bfa: Deletion of an unnecessary check before the function call "vfree" From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 20 Nov 2014 23:43:17 +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/scsi/bfa/bfad_debugfs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/scsi/bfa/bfad_debugfs.c b/drivers/scsi/bfa/bfad_debugfs.c index 8e83d04..a72170f 100644 --- a/drivers/scsi/bfa/bfad_debugfs.c +++ b/drivers/scsi/bfa/bfad_debugfs.c @@ -399,8 +399,7 @@ bfad_debugfs_release_fwtrc(struct inode *inode, struct file *file) if (!fw_debug) return 0; - if (fw_debug->debug_buffer) - vfree(fw_debug->debug_buffer); + vfree(fw_debug->debug_buffer); file->private_data = NULL; kfree(fw_debug); -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 21 Nov 2014 09:15:10 +0100 The dst_release() 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/scsi/cxgbi/libcxgbi.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/scsi/cxgbi/libcxgbi.c b/drivers/scsi/cxgbi/libcxgbi.c index addd1dd..95d2654 100644 --- a/drivers/scsi/cxgbi/libcxgbi.c +++ b/drivers/scsi/cxgbi/libcxgbi.c @@ -798,8 +798,7 @@ void cxgbi_sock_closed(struct cxgbi_sock *csk) return; if (csk->saddr.sin_port) sock_put_port(csk); - if (csk->dst) - dst_release(csk->dst); + dst_release(csk->dst); csk->cdev->csk_release_offload_resources(csk); cxgbi_sock_set_state(csk, CTP_CLOSED); cxgbi_inform_iscsi_conn_closing(csk); -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 21 Nov 2014 09:39:43 +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/scsi/fnic/fnic_debugfs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/scsi/fnic/fnic_debugfs.c b/drivers/scsi/fnic/fnic_debugfs.c index 2c613bd..ec70e6d 100644 --- a/drivers/scsi/fnic/fnic_debugfs.c +++ b/drivers/scsi/fnic/fnic_debugfs.c @@ -102,8 +102,7 @@ void fnic_debugfs_terminate(void) debugfs_remove(fnic_trace_debugfs_root); fnic_trace_debugfs_root = NULL; - if (fc_trc_flag) - vfree(fc_trc_flag); + vfree(fc_trc_flag); } /* -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 21 Nov 2014 10:25:45 +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> --- drivers/target/iscsi/iscsi_target_transport.c | 3 +-- drivers/target/target_core_hba.c | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target_transport.c b/drivers/target/iscsi/iscsi_target_transport.c index 882728f..08217d6 100644 --- a/drivers/target/iscsi/iscsi_target_transport.c +++ b/drivers/target/iscsi/iscsi_target_transport.c @@ -26,8 +26,7 @@ struct iscsit_transport *iscsit_get_transport(int type) void iscsit_put_transport(struct iscsit_transport *t) { - if (t->owner) - module_put(t->owner); + module_put(t->owner); } int iscsit_register_transport(struct iscsit_transport *t) diff --git a/drivers/target/target_core_hba.c b/drivers/target/target_core_hba.c index a25051a..e6e496f 100644 --- a/drivers/target/target_core_hba.c +++ b/drivers/target/target_core_hba.c @@ -137,8 +137,7 @@ core_alloc_hba(const char *plugin_name, u32 plugin_dep_id, u32 hba_flags) return hba; out_module_put: - if (hba->transport->owner) - module_put(hba->transport->owner); + module_put(hba->transport->owner); hba->transport = NULL; out_free_hba: kfree(hba); @@ -159,8 +158,7 @@ core_delete_hba(struct se_hba *hba) pr_debug("CORE_HBA[%d] - Detached HBA from Generic Target" " Core\n", hba->hba_id); - if (hba->transport->owner) - module_put(hba->transport->owner); + module_put(hba->transport->owner); hba->transport = NULL; kfree(hba); -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 21 Nov 2014 11:06:33 +0100 The functions cpufreq_cooling_unregister() and thermal_zone_device_unregister() 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/thermal/samsung/exynos_thermal_common.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/thermal/samsung/exynos_thermal_common.c b/drivers/thermal/samsung/exynos_thermal_common.c index 3f5ad25..1cbb9d0 100644 --- a/drivers/thermal/samsung/exynos_thermal_common.c +++ b/drivers/thermal/samsung/exynos_thermal_common.c @@ -417,12 +417,10 @@ void exynos_unregister_thermal(struct thermal_sensor_conf *sensor_conf) th_zone = sensor_conf->pzone_data; - if (th_zone->therm_dev) - thermal_zone_device_unregister(th_zone->therm_dev); + thermal_zone_device_unregister(th_zone->therm_dev); for (i = 0; i < th_zone->cool_dev_size; i++) { - if (th_zone->cool_dev[i]) - cpufreq_cooling_unregister(th_zone->cool_dev[i]); + cpufreq_cooling_unregister(th_zone->cool_dev[i]); } dev_info(sensor_conf->dev, -- 2.1.3
On Fri, 21 Nov 2014, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Fri, 21 Nov 2014 11:06:33 +0100 > > The functions cpufreq_cooling_unregister() and thermal_zone_device_unregister() > 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/thermal/samsung/exynos_thermal_common.c | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/drivers/thermal/samsung/exynos_thermal_common.c b/drivers/thermal/samsung/exynos_thermal_common.c > index 3f5ad25..1cbb9d0 100644 > --- a/drivers/thermal/samsung/exynos_thermal_common.c > +++ b/drivers/thermal/samsung/exynos_thermal_common.c > @@ -417,12 +417,10 @@ void exynos_unregister_thermal(struct thermal_sensor_conf *sensor_conf) > > th_zone = sensor_conf->pzone_data; > > - if (th_zone->therm_dev) > - thermal_zone_device_unregister(th_zone->therm_dev); > + thermal_zone_device_unregister(th_zone->therm_dev); > > for (i = 0; i < th_zone->cool_dev_size; i++) { > - if (th_zone->cool_dev[i]) > - cpufreq_cooling_unregister(th_zone->cool_dev[i]); > + cpufreq_cooling_unregister(th_zone->cool_dev[i]); > } Now you have unnecessary {} julia > > dev_info(sensor_conf->dev, > -- > 2.1.3 > >
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 21 Nov 2014 11:30:18 +0100 The ring_free() 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/thunderbolt/ctl.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/thunderbolt/ctl.c b/drivers/thunderbolt/ctl.c index 799634b..55b9bdf 100644 --- a/drivers/thunderbolt/ctl.c +++ b/drivers/thunderbolt/ctl.c @@ -520,10 +520,8 @@ err: void tb_ctl_free(struct tb_ctl *ctl) { int i; - if (ctl->rx) - ring_free(ctl->rx); - if (ctl->tx) - ring_free(ctl->tx); + ring_free(ctl->rx); + ring_free(ctl->tx); /* free RX packets */ for (i = 0; i < TB_CTL_RX_PKG_COUNT; i++) -- 2.1.3
Hi Markus, ring_free does not check for null: http://lxr.free-electrons.com/source/drivers/thunderbolt/nhi.c#L398 Maybe your software confuses the method with: http://lxr.free-electrons.com/source/drivers/char/tpm/xen-tpmfront.c#L268 Andreas On Fri, Nov 21, 2014 at 11:40 AM, SF Markus Elfring <elfring@users.sourceforge.net> wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Fri, 21 Nov 2014 11:30:18 +0100 > > The ring_free() 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/thunderbolt/ctl.c | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/drivers/thunderbolt/ctl.c b/drivers/thunderbolt/ctl.c > index 799634b..55b9bdf 100644 > --- a/drivers/thunderbolt/ctl.c > +++ b/drivers/thunderbolt/ctl.c > @@ -520,10 +520,8 @@ err: > void tb_ctl_free(struct tb_ctl *ctl) > { > int i; > - if (ctl->rx) > - ring_free(ctl->rx); > - if (ctl->tx) > - ring_free(ctl->tx); > + ring_free(ctl->rx); > + ring_free(ctl->tx); > > /* free RX packets */ > for (i = 0; i < TB_CTL_RX_PKG_COUNT; i++) > -- > 2.1.3 >
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 21 Nov 2014 12:40:32 +0100 The tty_kref_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> --- drivers/tty/hvc/hvsi_lib.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c index 7ae6c29..a270f04 100644 --- a/drivers/tty/hvc/hvsi_lib.c +++ b/drivers/tty/hvc/hvsi_lib.c @@ -405,8 +405,7 @@ void hvsilib_close(struct hvsi_priv *pv, struct hvc_struct *hp) hvsi_send_close(pv); } - if (pv->tty) - tty_kref_put(pv->tty); + tty_kref_put(pv->tty); pv->tty = NULL; } -- 2.1.3
> ring_free does not check for null:
> http://lxr.free-electrons.com/source/drivers/thunderbolt/nhi.c#L398
>
> Maybe your software confuses the method with:
> http://lxr.free-electrons.com/source/drivers/char/tpm/xen-tpmfront.c#L268
Thanks for your feedback.
I am sorry for a bit of confusion here.
1. Would it make sense that a variant for the thunderbolt ring_free()
function will also perform input parameter validation?
2. Are any additional prefixes appropriate so that further name space
conflicts can be better avoided?
Regards,
Markus
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 21 Nov 2014 13:42:29 +0100 The functions put_device() and tty_kref_put() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/tty/tty_io.c | 6 ++---- drivers/tty/tty_port.c | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index 848c17a..3302789 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -169,8 +169,7 @@ void free_tty_struct(struct tty_struct *tty) { if (!tty) return; - if (tty->dev) - put_device(tty->dev); + put_device(tty->dev); kfree(tty->write_buf); tty->magic = 0xDEADDEAD; kfree(tty); @@ -1612,8 +1611,7 @@ static void release_tty(struct tty_struct *tty, int idx) tty->link->port->itty = NULL; cancel_work_sync(&tty->port->buf.work); - if (tty->link) - tty_kref_put(tty->link); + tty_kref_put(tty->link); tty_kref_put(tty); } diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c index 1b93357..856c064 100644 --- a/drivers/tty/tty_port.c +++ b/drivers/tty/tty_port.c @@ -193,8 +193,7 @@ void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty) unsigned long flags; spin_lock_irqsave(&port->lock, flags); - if (port->tty) - tty_kref_put(port->tty); + tty_kref_put(port->tty); port->tty = tty_kref_get(tty); spin_unlock_irqrestore(&port->lock, flags); } -- 2.1.3
>> for (i = 0; i < th_zone->cool_dev_size; i++) {
>> - if (th_zone->cool_dev[i])
>> - cpufreq_cooling_unregister(th_zone->cool_dev[i]);
>> + cpufreq_cooling_unregister(th_zone->cool_dev[i]);
>> }
>
> Now you have unnecessary {}
How are the chances that your source code transformation tool
can also consider the deletion of curly brackets in such an use case?
Can any more pretty-printing rules be integrated from a specific
coding style configuration?
Regards,
Markus
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 21 Nov 2014 14:51:43 +0100 The rndis_add_hdr() 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/usb/gadget/function/f_rndis.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/f_rndis.c b/drivers/usb/gadget/function/f_rndis.c index ddb09dc..da56a5f 100644 --- a/drivers/usb/gadget/function/f_rndis.c +++ b/drivers/usb/gadget/function/f_rndis.c @@ -375,8 +375,7 @@ static struct sk_buff *rndis_add_header(struct gether *port, struct sk_buff *skb2; skb2 = skb_realloc_headroom(skb, sizeof(struct rndis_packet_msg_type)); - if (skb2) - rndis_add_hdr(skb2); + rndis_add_hdr(skb2); dev_kfree_skb(skb); return skb2; -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 21 Nov 2014 15:20:12 +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> --- drivers/usb/host/pci-quirks.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c index 2f3aceb..dd483c1 100644 --- a/drivers/usb/host/pci-quirks.c +++ b/drivers/usb/host/pci-quirks.c @@ -233,10 +233,8 @@ commit: spin_unlock_irqrestore(&amd_lock, flags); - if (info.nb_dev) - pci_dev_put(info.nb_dev); - if (info.smbus_dev) - pci_dev_put(info.smbus_dev); + pci_dev_put(info.nb_dev); + pci_dev_put(info.smbus_dev); } else { /* no race - commit the result */ @@ -447,10 +445,8 @@ void usb_amd_dev_put(void) spin_unlock_irqrestore(&amd_lock, flags); - if (nb) - pci_dev_put(nb); - if (smbus) - pci_dev_put(smbus); + pci_dev_put(nb); + pci_dev_put(smbus); } EXPORT_SYMBOL_GPL(usb_amd_dev_put); -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 21 Nov 2014 15:50:44 +0100 The usb_put_dev() 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/usb/misc/sisusbvga/sisusb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/usb/misc/sisusbvga/sisusb.c b/drivers/usb/misc/sisusbvga/sisusb.c index 633caf6..022dc00 100644 --- a/drivers/usb/misc/sisusbvga/sisusb.c +++ b/drivers/usb/misc/sisusbvga/sisusb.c @@ -2472,8 +2472,7 @@ sisusb_delete(struct kref *kref) if (!sisusb) return; - if (sisusb->sisusb_dev) - usb_put_dev(sisusb->sisusb_dev); + usb_put_dev(sisusb->sisusb_dev); sisusb->sisusb_dev = NULL; sisusb_free_buffers(sisusb); -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 21 Nov 2014 16:15:34 +0100 The release_firmware() 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/usb/serial/mxuport.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/usb/serial/mxuport.c b/drivers/usb/serial/mxuport.c index ab1d690..3653ec1 100644 --- a/drivers/usb/serial/mxuport.c +++ b/drivers/usb/serial/mxuport.c @@ -1101,8 +1101,7 @@ static int mxuport_probe(struct usb_serial *serial, */ usb_set_serial_data(serial, (void *)id->driver_info); out: - if (fw_p) - release_firmware(fw_p); + release_firmware(fw_p); return err; } -- 2.1.3
On Fri, 21 Nov 2014, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Fri, 21 Nov 2014 16:15:34 +0100 > > The release_firmware() 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/usb/serial/mxuport.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/usb/serial/mxuport.c b/drivers/usb/serial/mxuport.c > index ab1d690..3653ec1 100644 > --- a/drivers/usb/serial/mxuport.c > +++ b/drivers/usb/serial/mxuport.c > @@ -1101,8 +1101,7 @@ static int mxuport_probe(struct usb_serial *serial, > */ > usb_set_serial_data(serial, (void *)id->driver_info); > out: > - if (fw_p) > - release_firmware(fw_p); > + release_firmware(fw_p); I think that the if should stay. There were two cases on the allocation, so there should be two cases on the release. julia > return err; > } > > -- > 2.1.3 > > -- > To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 21 Nov 2014 16:33:18 +0100 The usb_put_dev() 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/usb/usbip/vhci_hcd.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c index c02374b..cc1b03e 100644 --- a/drivers/usb/usbip/vhci_hcd.c +++ b/drivers/usb/usbip/vhci_hcd.c @@ -518,8 +518,7 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, dev_info(dev, "SetAddress Request (%d) to port %d\n", ctrlreq->wValue, vdev->rhport); - if (vdev->udev) - usb_put_dev(vdev->udev); + usb_put_dev(vdev->udev); vdev->udev = usb_get_dev(urb->dev); spin_lock(&vdev->ud.lock); @@ -539,8 +538,7 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, usbip_dbg_vhci_hc( "Not yet?:Get_Descriptor to device 0 (get max pipe size)\n"); - if (vdev->udev) - usb_put_dev(vdev->udev); + usb_put_dev(vdev->udev); vdev->udev = usb_get_dev(urb->dev); goto out; @@ -831,8 +829,7 @@ static void vhci_device_reset(struct usbip_device *ud) vdev->speed = 0; vdev->devid = 0; - if (vdev->udev) - usb_put_dev(vdev->udev); + usb_put_dev(vdev->udev); vdev->udev = NULL; if (ud->tcp_socket) { -- 2.1.3
>> diff --git a/drivers/usb/serial/mxuport.c b/drivers/usb/serial/mxuport.c >> index ab1d690..3653ec1 100644 >> --- a/drivers/usb/serial/mxuport.c >> +++ b/drivers/usb/serial/mxuport.c >> @@ -1101,8 +1101,7 @@ static int mxuport_probe(struct usb_serial *serial, >> */ >> usb_set_serial_data(serial, (void *)id->driver_info); >> out: >> - if (fw_p) >> - release_firmware(fw_p); >> + release_firmware(fw_p); > > I think that the if should stay. I have got an other opinion. > There were two cases on the allocation, so there should be two cases > on the release. I find that this implementation detail does not really matter for the necessity of a null pointer check directly before such a function call. Regards, Markus
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 21 Nov 2014 17:11:49 +0100 The functions cpufreq_cooling_unregister() and thermal_zone_device_unregister() 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/thermal/samsung/exynos_thermal_common.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/thermal/samsung/exynos_thermal_common.c b/drivers/thermal/samsung/exynos_thermal_common.c index 3f5ad25..b6be572 100644 --- a/drivers/thermal/samsung/exynos_thermal_common.c +++ b/drivers/thermal/samsung/exynos_thermal_common.c @@ -417,13 +417,10 @@ void exynos_unregister_thermal(struct thermal_sensor_conf *sensor_conf) th_zone = sensor_conf->pzone_data; - if (th_zone->therm_dev) - thermal_zone_device_unregister(th_zone->therm_dev); + thermal_zone_device_unregister(th_zone->therm_dev); - for (i = 0; i < th_zone->cool_dev_size; i++) { - if (th_zone->cool_dev[i]) - cpufreq_cooling_unregister(th_zone->cool_dev[i]); - } + for (i = 0; i < th_zone->cool_dev_size; ++i) + cpufreq_cooling_unregister(th_zone->cool_dev[i]); dev_info(sensor_conf->dev, "Exynos: Kernel Thermal management unregistered\n"); -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 21 Nov 2014 18:34:48 +0100 The functions snd_seq_oss_timer_delete() and vunmap() perform 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/core/seq/oss/seq_oss_init.c | 9 +++------ sound/core/sgbuf.c | 3 +-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/sound/core/seq/oss/seq_oss_init.c b/sound/core/seq/oss/seq_oss_init.c index b9184d2..b0e32e1 100644 --- a/sound/core/seq/oss/seq_oss_init.c +++ b/sound/core/seq/oss/seq_oss_init.c @@ -403,14 +403,11 @@ free_devinfo(void *private) { struct seq_oss_devinfo *dp = (struct seq_oss_devinfo *)private; - if (dp->timer) - snd_seq_oss_timer_delete(dp->timer); + snd_seq_oss_timer_delete(dp->timer); - if (dp->writeq) - snd_seq_oss_writeq_delete(dp->writeq); + snd_seq_oss_writeq_delete(dp->writeq); - if (dp->readq) - snd_seq_oss_readq_delete(dp->readq); + snd_seq_oss_readq_delete(dp->readq); kfree(dp); } diff --git a/sound/core/sgbuf.c b/sound/core/sgbuf.c index 0a41850..84fffab 100644 --- a/sound/core/sgbuf.c +++ b/sound/core/sgbuf.c @@ -39,8 +39,7 @@ int snd_free_sgbuf_pages(struct snd_dma_buffer *dmab) if (! sgbuf) return -EINVAL; - if (dmab->area) - vunmap(dmab->area); + vunmap(dmab->area); dmab->area = NULL; tmpb.dev.type = SNDRV_DMA_TYPE_DEV; -- 2.1.3
On Fri, Nov 21, 2014 at 5:36 PM, SF Markus Elfring
<elfring@users.sourceforge.net> wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 21 Nov 2014 16:33:18 +0100
>
> The usb_put_dev() 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/usb/usbip/vhci_hcd.c | 9 +++------
> 1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
> index c02374b..cc1b03e 100644
> --- a/drivers/usb/usbip/vhci_hcd.c
> +++ b/drivers/usb/usbip/vhci_hcd.c
> @@ -518,8 +518,7 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
> dev_info(dev, "SetAddress Request (%d) to port %d\n",
> ctrlreq->wValue, vdev->rhport);
>
> - if (vdev->udev)
> - usb_put_dev(vdev->udev);
> + usb_put_dev(vdev->udev);
> vdev->udev = usb_get_dev(urb->dev);
>
> spin_lock(&vdev->ud.lock);
> @@ -539,8 +538,7 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
> usbip_dbg_vhci_hc(
> "Not yet?:Get_Descriptor to device 0 (get max pipe size)\n");
>
> - if (vdev->udev)
> - usb_put_dev(vdev->udev);
> + usb_put_dev(vdev->udev);
> vdev->udev = usb_get_dev(urb->dev);
> goto out;
>
> @@ -831,8 +829,7 @@ static void vhci_device_reset(struct usbip_device *ud)
> vdev->speed = 0;
> vdev->devid = 0;
>
> - if (vdev->udev)
> - usb_put_dev(vdev->udev);
> + usb_put_dev(vdev->udev);
> vdev->udev = NULL;
>
> if (ud->tcp_socket) {
> --
> 2.1.3
>
Acked-by: Valentina Manea <valentina.manea.m@gmail.com>
On Fri, 21 Nov 2014, SF Markus Elfring wrote:
> >> diff --git a/drivers/usb/serial/mxuport.c b/drivers/usb/serial/mxuport.c
> >> index ab1d690..3653ec1 100644
> >> --- a/drivers/usb/serial/mxuport.c
> >> +++ b/drivers/usb/serial/mxuport.c
> >> @@ -1101,8 +1101,7 @@ static int mxuport_probe(struct usb_serial *serial,
> >> */
> >> usb_set_serial_data(serial, (void *)id->driver_info);
> >> out:
> >> - if (fw_p)
> >> - release_firmware(fw_p);
> >> + release_firmware(fw_p);
> >
> > I think that the if should stay.
>
> I have got an other opinion.
>
>
> > There were two cases on the allocation, so there should be two cases
> > on the release.
>
> I find that this implementation detail does not really matter for the
> necessity of a null pointer check directly before such a function call.
Conceptually, if it is clear 10 lines above that nothing was allocated,
and there is a fallback to existing data (according to the comment above)
it is strange to be releasing something.
julia
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 21 Nov 2014 19:05:50 +0100 The release_and_free_resource() 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/isa/es1688/es1688_lib.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sound/isa/es1688/es1688_lib.c b/sound/isa/es1688/es1688_lib.c index b3b4f15..fb259491 100644 --- a/sound/isa/es1688/es1688_lib.c +++ b/sound/isa/es1688/es1688_lib.c @@ -614,8 +614,7 @@ static int snd_es1688_free(struct snd_es1688 *chip) { if (chip->hardware != ES1688_HW_UNDEF) snd_es1688_init(chip, 0); - if (chip->res_port) - release_and_free_resource(chip->res_port); + release_and_free_resource(chip->res_port); if (chip->irq >= 0) free_irq(chip->irq, (void *) chip); if (chip->dma8 >= 0) { -- 2.1.3
On Fri, 2014-11-21 at 13:21 +0100, SF Markus Elfring wrote: > 2. Are any additional prefixes appropriate so that further name space > conflicts can be better avoided? To avoid possible external naming conflicts, add tb_ prefix to various ring_<foo> structs and functions. Other miscellanea: o typo/spelling fixes (releated/related, loose/lose) o argument alignment o comment formatting --- Perhaps something like this? unsigned/compiled/untested drivers/thunderbolt/ctl.c | 41 ++++++------- drivers/thunderbolt/nhi.c | 133 +++++++++++++++++++++-------------------- drivers/thunderbolt/nhi.h | 47 ++++++++------- drivers/thunderbolt/nhi_regs.h | 16 ++--- 4 files changed, 121 insertions(+), 116 deletions(-) diff --git a/drivers/thunderbolt/ctl.c b/drivers/thunderbolt/ctl.c index 799634b..52783e0 100644 --- a/drivers/thunderbolt/ctl.c +++ b/drivers/thunderbolt/ctl.c @@ -17,7 +17,7 @@ struct ctl_pkg { struct tb_ctl *ctl; void *buffer; - struct ring_frame frame; + struct tb_ring_frame frame; }; #define TB_CTL_RX_PKG_COUNT 10 @@ -319,8 +319,8 @@ static struct ctl_pkg *tb_ctl_pkg_alloc(struct tb_ctl *ctl) /* RX/TX handling */ -static void tb_ctl_tx_callback(struct tb_ring *ring, struct ring_frame *frame, - bool canceled) +static void tb_ctl_tx_callback(struct tb_ring *ring, + struct tb_ring_frame *frame, bool canceled) { struct ctl_pkg *pkg = container_of(frame, typeof(*pkg), frame); tb_ctl_pkg_free(pkg); @@ -357,7 +357,7 @@ static int tb_ctl_tx(struct tb_ctl *ctl, void *data, size_t len, cpu_to_be32_array(pkg->buffer, data, len / 4); *(__be32 *) (pkg->buffer + len) = tb_crc(pkg->buffer, len); - res = ring_tx(ctl->tx, &pkg->frame); + res = tb_ring_tx(ctl->tx, &pkg->frame); if (res) /* ring is stopped */ tb_ctl_pkg_free(pkg); return res; @@ -386,16 +386,16 @@ static void tb_ctl_handle_plug_event(struct tb_ctl *ctl, static void tb_ctl_rx_submit(struct ctl_pkg *pkg) { - ring_rx(pkg->ctl->rx, &pkg->frame); /* - * We ignore failures during stop. - * All rx packets are referenced - * from ctl->rx_packets, so we do - * not loose them. - */ + tb_ring_rx(pkg->ctl->rx, &pkg->frame); + /* + * We ignore failures during stop. + * All rx packets are referenced from ctl->rx_packets, + * so we do not lose them. + */ } -static void tb_ctl_rx_callback(struct tb_ring *ring, struct ring_frame *frame, - bool canceled) +static void tb_ctl_rx_callback(struct tb_ring *ring, + struct tb_ring_frame *frame, bool canceled) { struct ctl_pkg *pkg = container_of(frame, typeof(*pkg), frame); @@ -488,11 +488,11 @@ struct tb_ctl *tb_ctl_alloc(struct tb_nhi *nhi, hotplug_cb cb, void *cb_data) if (!ctl->frame_pool) goto err; - ctl->tx = ring_alloc_tx(nhi, 0, 10); + ctl->tx = tb_ring_alloc_tx(nhi, 0, 10); if (!ctl->tx) goto err; - ctl->rx = ring_alloc_rx(nhi, 0, 10); + ctl->rx = tb_ring_alloc_rx(nhi, 0, 10); if (!ctl->rx) goto err; @@ -521,9 +521,9 @@ void tb_ctl_free(struct tb_ctl *ctl) { int i; if (ctl->rx) - ring_free(ctl->rx); + tb_ring_free(ctl->rx); if (ctl->tx) - ring_free(ctl->tx); + tb_ring_free(ctl->tx); /* free RX packets */ for (i = 0; i < TB_CTL_RX_PKG_COUNT; i++) @@ -542,8 +542,9 @@ void tb_ctl_start(struct tb_ctl *ctl) { int i; tb_ctl_info(ctl, "control channel starting...\n"); - ring_start(ctl->tx); /* is used to ack hotplug packets, start first */ - ring_start(ctl->rx); + /* is used to ack hotplug packets, start first */ + tb_ring_start(ctl->tx); + tb_ring_start(ctl->rx); for (i = 0; i < TB_CTL_RX_PKG_COUNT; i++) tb_ctl_rx_submit(ctl->rx_packets[i]); } @@ -558,8 +559,8 @@ void tb_ctl_start(struct tb_ctl *ctl) */ void tb_ctl_stop(struct tb_ctl *ctl) { - ring_stop(ctl->rx); - ring_stop(ctl->tx); + tb_ring_stop(ctl->rx); + tb_ring_stop(ctl->tx); if (!kfifo_is_empty(&ctl->response_fifo)) tb_ctl_WARN(ctl, "dangling response in response_fifo\n"); diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c index c68fe12..552683f 100644 --- a/drivers/thunderbolt/nhi.c +++ b/drivers/thunderbolt/nhi.c @@ -22,7 +22,7 @@ #define RING_TYPE(ring) ((ring)->is_tx ? "TX ring" : "RX ring") -static int ring_interrupt_index(struct tb_ring *ring) +static int tb_ring_interrupt_index(struct tb_ring *ring) { int bit = ring->hop; if (!ring->is_tx) @@ -31,14 +31,14 @@ static int ring_interrupt_index(struct tb_ring *ring) } /** - * ring_interrupt_active() - activate/deactivate interrupts for a single ring + * tb_ring_interrupt_active() - activate/deactivate interrupts for a single ring * * ring->nhi->lock must be held. */ -static void ring_interrupt_active(struct tb_ring *ring, bool active) +static void tb_ring_interrupt_active(struct tb_ring *ring, bool active) { - int reg = REG_RING_INTERRUPT_BASE + ring_interrupt_index(ring) / 32; - int bit = ring_interrupt_index(ring) & 31; + int reg = REG_RING_INTERRUPT_BASE + tb_ring_interrupt_index(ring) / 32; + int bit = tb_ring_interrupt_index(ring) & 31; int mask = 1 << bit; u32 old, new; old = ioread32(ring->nhi->iobase + reg); @@ -78,7 +78,7 @@ static void nhi_disable_interrupts(struct tb_nhi *nhi) /* ring helper methods */ -static void __iomem *ring_desc_base(struct tb_ring *ring) +static void __iomem *tb_ring_desc_base(struct tb_ring *ring) { void __iomem *io = ring->nhi->iobase; io += ring->is_tx ? REG_TX_RING_BASE : REG_RX_RING_BASE; @@ -86,7 +86,7 @@ static void __iomem *ring_desc_base(struct tb_ring *ring) return io; } -static void __iomem *ring_options_base(struct tb_ring *ring) +static void __iomem *tb_ring_options_base(struct tb_ring *ring) { void __iomem *io = ring->nhi->iobase; io += ring->is_tx ? REG_TX_OPTIONS_BASE : REG_RX_OPTIONS_BASE; @@ -94,48 +94,49 @@ static void __iomem *ring_options_base(struct tb_ring *ring) return io; } -static void ring_iowrite16desc(struct tb_ring *ring, u32 value, u32 offset) +static void tb_ring_iowrite16desc(struct tb_ring *ring, u32 value, u32 offset) { - iowrite16(value, ring_desc_base(ring) + offset); + iowrite16(value, tb_ring_desc_base(ring) + offset); } -static void ring_iowrite32desc(struct tb_ring *ring, u32 value, u32 offset) +static void tb_ring_iowrite32desc(struct tb_ring *ring, u32 value, u32 offset) { - iowrite32(value, ring_desc_base(ring) + offset); + iowrite32(value, tb_ring_desc_base(ring) + offset); } -static void ring_iowrite64desc(struct tb_ring *ring, u64 value, u32 offset) +static void tb_ring_iowrite64desc(struct tb_ring *ring, u64 value, u32 offset) { - iowrite32(value, ring_desc_base(ring) + offset); - iowrite32(value >> 32, ring_desc_base(ring) + offset + 4); + iowrite32(value, tb_ring_desc_base(ring) + offset); + iowrite32(value >> 32, tb_ring_desc_base(ring) + offset + 4); } -static void ring_iowrite32options(struct tb_ring *ring, u32 value, u32 offset) +static void tb_ring_iowrite32options(struct tb_ring *ring, u32 value, + u32 offset) { - iowrite32(value, ring_options_base(ring) + offset); + iowrite32(value, tb_ring_options_base(ring) + offset); } -static bool ring_full(struct tb_ring *ring) +static bool tb_ring_full(struct tb_ring *ring) { return ((ring->head + 1) % ring->size) = ring->tail; } -static bool ring_empty(struct tb_ring *ring) +static bool tb_ring_empty(struct tb_ring *ring) { return ring->head = ring->tail; } /** - * ring_write_descriptors() - post frames from ring->queue to the controller + * tb_ring_write_descriptors() - post frames from ring->queue to the controller * * ring->lock is held. */ -static void ring_write_descriptors(struct tb_ring *ring) +static void tb_ring_write_descriptors(struct tb_ring *ring) { - struct ring_frame *frame, *n; - struct ring_desc *descriptor; + struct tb_ring_frame *frame, *n; + struct tb_ring_desc *descriptor; list_for_each_entry_safe(frame, n, &ring->queue, list) { - if (ring_full(ring)) + if (tb_ring_full(ring)) break; list_move_tail(&frame->list, &ring->in_flight); descriptor = &ring->descriptors[ring->head]; @@ -148,12 +149,12 @@ static void ring_write_descriptors(struct tb_ring *ring) descriptor->sof = frame->sof; } ring->head = (ring->head + 1) % ring->size; - ring_iowrite16desc(ring, ring->head, ring->is_tx ? 10 : 8); + tb_ring_iowrite16desc(ring, ring->head, ring->is_tx ? 10 : 8); } } /** - * ring_work() - progress completed frames + * tb_ring_work() - progress completed frames * * If the ring is shutting down then all frames are marked as canceled and * their callbacks are invoked. @@ -161,10 +162,10 @@ static void ring_write_descriptors(struct tb_ring *ring) * Otherwise we collect all completed frame from the ring buffer, write new * frame to the ring buffer and invoke the callbacks for the completed frames. */ -static void ring_work(struct work_struct *work) +static void tb_ring_work(struct work_struct *work) { struct tb_ring *ring = container_of(work, typeof(*ring), work); - struct ring_frame *frame; + struct tb_ring_frame *frame; bool canceled = false; LIST_HEAD(done); mutex_lock(&ring->lock); @@ -177,7 +178,7 @@ static void ring_work(struct work_struct *work) goto invoke_callback; } - while (!ring_empty(ring)) { + while (!tb_ring_empty(ring)) { if (!(ring->descriptors[ring->tail].flags & RING_DESC_COMPLETED)) break; @@ -209,7 +210,7 @@ static void ring_work(struct work_struct *work) } ring->tail = (ring->tail + 1) % ring->size; } - ring_write_descriptors(ring); + tb_ring_write_descriptors(ring); invoke_callback: mutex_unlock(&ring->lock); /* allow callbacks to schedule new work */ @@ -224,13 +225,13 @@ invoke_callback: } } -int __ring_enqueue(struct tb_ring *ring, struct ring_frame *frame) +int __tb_ring_enqueue(struct tb_ring *ring, struct tb_ring_frame *frame) { int ret = 0; mutex_lock(&ring->lock); if (ring->running) { list_add_tail(&frame->list, &ring->queue); - ring_write_descriptors(ring); + tb_ring_write_descriptors(ring); } else { ret = -ESHUTDOWN; } @@ -238,8 +239,8 @@ int __ring_enqueue(struct tb_ring *ring, struct ring_frame *frame) return ret; } -static struct tb_ring *ring_alloc(struct tb_nhi *nhi, u32 hop, int size, - bool transmit) +static struct tb_ring *tb_ring_alloc(struct tb_nhi *nhi, u32 hop, int size, + bool transmit) { struct tb_ring *ring = NULL; dev_info(&nhi->pdev->dev, "allocating %s ring %d of size %d\n", @@ -264,7 +265,7 @@ static struct tb_ring *ring_alloc(struct tb_nhi *nhi, u32 hop, int size, mutex_init(&ring->lock); INIT_LIST_HEAD(&ring->queue); INIT_LIST_HEAD(&ring->in_flight); - INIT_WORK(&ring->work, ring_work); + INIT_WORK(&ring->work, tb_ring_work); ring->nhi = nhi; ring->hop = hop; @@ -294,22 +295,22 @@ err: return NULL; } -struct tb_ring *ring_alloc_tx(struct tb_nhi *nhi, int hop, int size) +struct tb_ring *tb_ring_alloc_tx(struct tb_nhi *nhi, int hop, int size) { - return ring_alloc(nhi, hop, size, true); + return tb_ring_alloc(nhi, hop, size, true); } -struct tb_ring *ring_alloc_rx(struct tb_nhi *nhi, int hop, int size) +struct tb_ring *tb_ring_alloc_rx(struct tb_nhi *nhi, int hop, int size) { - return ring_alloc(nhi, hop, size, false); + return tb_ring_alloc(nhi, hop, size, false); } /** - * ring_start() - enable a ring + * tb_ring_start() - enable a ring * - * Must not be invoked in parallel with ring_stop(). + * Must not be invoked in parallel with tb_ring_stop(). */ -void ring_start(struct tb_ring *ring) +void tb_ring_start(struct tb_ring *ring) { mutex_lock(&ring->nhi->lock); mutex_lock(&ring->lock); @@ -320,20 +321,21 @@ void ring_start(struct tb_ring *ring) dev_info(&ring->nhi->pdev->dev, "starting %s %d\n", RING_TYPE(ring), ring->hop); - ring_iowrite64desc(ring, ring->descriptors_dma, 0); + tb_ring_iowrite64desc(ring, ring->descriptors_dma, 0); if (ring->is_tx) { - ring_iowrite32desc(ring, ring->size, 12); - ring_iowrite32options(ring, 0, 4); /* time releated ? */ - ring_iowrite32options(ring, - RING_FLAG_ENABLE | RING_FLAG_RAW, 0); + tb_ring_iowrite32desc(ring, ring->size, 12); + tb_ring_iowrite32options(ring, 0, 4); /* time related ? */ + tb_ring_iowrite32options(ring, + RING_FLAG_ENABLE | RING_FLAG_RAW, 0); } else { - ring_iowrite32desc(ring, - (TB_FRAME_SIZE << 16) | ring->size, 12); - ring_iowrite32options(ring, 0xffffffff, 4); /* SOF EOF mask */ - ring_iowrite32options(ring, - RING_FLAG_ENABLE | RING_FLAG_RAW, 0); + tb_ring_iowrite32desc(ring, + (TB_FRAME_SIZE << 16) | ring->size, 12); + /* SOF EOF mask */ + tb_ring_iowrite32options(ring, 0xffffffff, 4); + tb_ring_iowrite32options(ring, + RING_FLAG_ENABLE | RING_FLAG_RAW, 0); } - ring_interrupt_active(ring, true); + tb_ring_interrupt_active(ring, true); ring->running = true; err: mutex_unlock(&ring->lock); @@ -342,18 +344,19 @@ err: /** - * ring_stop() - shutdown a ring + * tb_ring_stop() - shutdown a ring * * Must not be invoked from a callback. * - * This method will disable the ring. Further calls to ring_tx/ring_rx will - * return -ESHUTDOWN until ring_stop has been called. + * This method will disable the ring. + * Further calls to tb_ring_tx/tb_ring_rx will return -ESHUTDOWN + * until tb_ring_stop has been called. * * All enqueued frames will be canceled and their callbacks will be executed * with frame->canceled set to true (on the callback thread). This method * returns only after all callback invocations have finished. */ -void ring_stop(struct tb_ring *ring) +void tb_ring_stop(struct tb_ring *ring) { mutex_lock(&ring->nhi->lock); mutex_lock(&ring->lock); @@ -364,12 +367,12 @@ void ring_stop(struct tb_ring *ring) RING_TYPE(ring), ring->hop); goto err; } - ring_interrupt_active(ring, false); + tb_ring_interrupt_active(ring, false); - ring_iowrite32options(ring, 0, 0); - ring_iowrite64desc(ring, 0, 0); - ring_iowrite16desc(ring, 0, ring->is_tx ? 10 : 8); - ring_iowrite32desc(ring, 0, 12); + tb_ring_iowrite32options(ring, 0, 0); + tb_ring_iowrite64desc(ring, 0, 0); + tb_ring_iowrite16desc(ring, 0, ring->is_tx ? 10 : 8); + tb_ring_iowrite32desc(ring, 0, 12); ring->head = 0; ring->tail = 0; ring->running = false; @@ -386,16 +389,16 @@ err: } /* - * ring_free() - free ring + * tb_ring_free() - free ring * * When this method returns all invocations of ring->callback will have * finished. * * Ring must be stopped. * - * Must NOT be called from ring_frame->callback! + * Must NOT be called from tb_ring_frame->callback! */ -void ring_free(struct tb_ring *ring) +void tb_ring_free(struct tb_ring *ring) { mutex_lock(&ring->nhi->lock); /* @@ -428,7 +431,7 @@ void ring_free(struct tb_ring *ring) mutex_unlock(&ring->nhi->lock); /** * ring->work can no longer be scheduled (it is scheduled only by - * nhi_interrupt_work and ring_stop). Wait for it to finish before + * nhi_interrupt_work and tb_ring_stop). Wait for it to finish before * freeing the ring. */ flush_work(&ring->work); diff --git a/drivers/thunderbolt/nhi.h b/drivers/thunderbolt/nhi.h index 3172429..98f57d5 100644 --- a/drivers/thunderbolt/nhi.h +++ b/drivers/thunderbolt/nhi.h @@ -37,7 +37,7 @@ struct tb_ring { int hop; int head; /* write next descriptor here */ int tail; /* complete next descriptor here */ - struct ring_desc *descriptors; + struct tb_ring_desc *descriptors; dma_addr_t descriptors_dma; struct list_head queue; struct list_head in_flight; @@ -46,15 +46,16 @@ struct tb_ring { bool running:1; }; -struct ring_frame; -typedef void (*ring_cb)(struct tb_ring*, struct ring_frame*, bool canceled); +struct tb_ring_frame; +typedef void (*tb_ring_cb)(struct tb_ring *ring, struct tb_ring_frame *frame, + bool canceled); /** - * struct ring_frame - for use with ring_rx/ring_tx + * struct tb_ring_frame - for use with tb_ring_rx/tb_ring_tx */ -struct ring_frame { +struct tb_ring_frame { dma_addr_t buffer_phy; - ring_cb callback; + tb_ring_cb callback; struct list_head list; u32 size:12; /* TX: in, RX: out*/ u32 flags:12; /* RX: out */ @@ -62,18 +63,18 @@ struct ring_frame { u32 sof:4; /* TX:in, RX: out */ }; -#define TB_FRAME_SIZE 0x100 /* minimum size for ring_rx */ +#define TB_FRAME_SIZE 0x100 /* minimum size for tb_ring_rx */ -struct tb_ring *ring_alloc_tx(struct tb_nhi *nhi, int hop, int size); -struct tb_ring *ring_alloc_rx(struct tb_nhi *nhi, int hop, int size); -void ring_start(struct tb_ring *ring); -void ring_stop(struct tb_ring *ring); -void ring_free(struct tb_ring *ring); +struct tb_ring *tb_ring_alloc_tx(struct tb_nhi *nhi, int hop, int size); +struct tb_ring *tb_ring_alloc_rx(struct tb_nhi *nhi, int hop, int size); +void tb_ring_start(struct tb_ring *ring); +void tb_ring_stop(struct tb_ring *ring); +void tb_ring_free(struct tb_ring *ring); -int __ring_enqueue(struct tb_ring *ring, struct ring_frame *frame); +int __tb_ring_enqueue(struct tb_ring *ring, struct tb_ring_frame *frame); /** - * ring_rx() - enqueue a frame on an RX ring + * tb_ring_rx() - enqueue a frame on an RX ring * * frame->buffer, frame->buffer_phy and frame->callback have to be set. The * buffer must contain at least TB_FRAME_SIZE bytes. @@ -81,34 +82,34 @@ int __ring_enqueue(struct tb_ring *ring, struct ring_frame *frame); * frame->callback will be invoked with frame->size, frame->flags, frame->eof, * frame->sof set once the frame has been received. * - * If ring_stop is called after the packet has been enqueued frame->callback + * If tb_ring_stop is called after the packet has been enqueued frame->callback * will be called with canceled set to true. * - * Return: Returns ESHUTDOWN if ring_stop has been called. Zero otherwise. + * Return: Returns ESHUTDOWN if tb_ring_stop has been called. Zero otherwise. */ -static inline int ring_rx(struct tb_ring *ring, struct ring_frame *frame) +static inline int tb_ring_rx(struct tb_ring *ring, struct tb_ring_frame *frame) { WARN_ON(ring->is_tx); - return __ring_enqueue(ring, frame); + return __tb_ring_enqueue(ring, frame); } /** - * ring_tx() - enqueue a frame on an TX ring + * tb_ring_tx() - enqueue a frame on an TX ring * * frame->buffer, frame->buffer_phy, frame->callback, frame->size, frame->eof * and frame->sof have to be set. * * frame->callback will be invoked with once the frame has been transmitted. * - * If ring_stop is called after the packet has been enqueued frame->callback + * If tb_ring_stop is called after the packet has been enqueued frame->callback * will be called with canceled set to true. * - * Return: Returns ESHUTDOWN if ring_stop has been called. Zero otherwise. + * Return: Returns ESHUTDOWN if tb_ring_stop has been called. Zero otherwise. */ -static inline int ring_tx(struct tb_ring *ring, struct ring_frame *frame) +static inline int tb_ring_tx(struct tb_ring *ring, struct tb_ring_frame *frame) { WARN_ON(!ring->is_tx); - return __ring_enqueue(ring, frame); + return __tb_ring_enqueue(ring, frame); } #endif diff --git a/drivers/thunderbolt/nhi_regs.h b/drivers/thunderbolt/nhi_regs.h index 86b996c..23b7059 100644 --- a/drivers/thunderbolt/nhi_regs.h +++ b/drivers/thunderbolt/nhi_regs.h @@ -9,7 +9,7 @@ #include <linux/types.h> -enum ring_flags { +enum tb_ring_flags { RING_FLAG_ISOCH_ENABLE = 1 << 27, /* TX only? */ RING_FLAG_E2E_FLOW_CONTROL = 1 << 28, RING_FLAG_PCI_NO_SNOOP = 1 << 29, @@ -17,7 +17,7 @@ enum ring_flags { RING_FLAG_ENABLE = 1 << 31, }; -enum ring_desc_flags { +enum tb_ring_desc_flags { RING_DESC_ISOCH = 0x1, /* TX only? */ RING_DESC_COMPLETED = 0x2, /* set by NHI */ RING_DESC_POSTED = 0x4, /* always set this */ @@ -25,17 +25,17 @@ enum ring_desc_flags { }; /** - * struct ring_desc - TX/RX ring entry + * struct tb_ring_desc - TX/RX ring entry * * For TX set length/eof/sof. * For RX length/eof/sof are set by the NHI. */ -struct ring_desc { +struct tb_ring_desc { u64 phys; u32 length:12; u32 eof:4; u32 sof:4; - enum ring_desc_flags flags:12; + enum tb_ring_desc_flags flags:12; u32 time; /* write zero */ } __packed; @@ -43,7 +43,7 @@ struct ring_desc { /* * 16 bytes per entry, one entry for every hop (REG_HOP_COUNT) - * 00: physical pointer to an array of struct ring_desc + * 00: physical pointer to an array of struct tb_ring_desc * 08: ring tail (set by NHI) * 10: ring head (index of first non posted descriptor) * 12: descriptor count @@ -52,7 +52,7 @@ struct ring_desc { /* * 16 bytes per entry, one entry for every hop (REG_HOP_COUNT) - * 00: physical pointer to an array of struct ring_desc + * 00: physical pointer to an array of struct tb_ring_desc * 08: ring head (index of first not posted descriptor) * 10: ring tail (set by NHI) * 12: descriptor count @@ -70,7 +70,7 @@ struct ring_desc { /* * 32 bytes per entry, one entry for every hop (REG_HOP_COUNT) - * 00: enum ring_flags + * 00: enum tb_ring_flags * If RING_FLAG_E2E_FLOW_CONTROL is set then bits 13-23 must be set to * the corresponding TX hop id. * 04: EOF/SOF mask (ignored for RING_FLAG_RAW rings)
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 21 Nov 2014 19:32:02 +0100 The functions release_and_free_resource() 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/isa/sb/emu8000_synth.c | 3 +-- sound/isa/sb/sb_common.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c index 4e3fcfb..95b39be 100644 --- a/sound/isa/sb/emu8000_synth.c +++ b/sound/isa/sb/emu8000_synth.c @@ -105,8 +105,7 @@ static int snd_emu8000_delete_device(struct snd_seq_device *dev) snd_device_free(dev->card, hw->pcm); if (hw->emu) snd_emux_free(hw->emu); - if (hw->memhdr) - snd_util_memhdr_free(hw->memhdr); + snd_util_memhdr_free(hw->memhdr); hw->emu = NULL; hw->memhdr = NULL; return 0; diff --git a/sound/isa/sb/sb_common.c b/sound/isa/sb/sb_common.c index 3ef9906..f22b448 100644 --- a/sound/isa/sb/sb_common.c +++ b/sound/isa/sb/sb_common.c @@ -184,8 +184,7 @@ static int snd_sbdsp_probe(struct snd_sb * chip) static int snd_sbdsp_free(struct snd_sb *chip) { - if (chip->res_port) - release_and_free_resource(chip->res_port); + release_and_free_resource(chip->res_port); if (chip->irq >= 0) free_irq(chip->irq, (void *) chip); #ifdef CONFIG_ISA -- 2.1.3
At Fri, 21 Nov 2014 18:40:49 +0100, SF Markus Elfring wrote: > > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Fri, 21 Nov 2014 18:34:48 +0100 > > The functions snd_seq_oss_timer_delete() and vunmap() perform 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> Applied, thanks. Takashi > --- > sound/core/seq/oss/seq_oss_init.c | 9 +++------ > sound/core/sgbuf.c | 3 +-- > 2 files changed, 4 insertions(+), 8 deletions(-) > > diff --git a/sound/core/seq/oss/seq_oss_init.c b/sound/core/seq/oss/seq_oss_init.c > index b9184d2..b0e32e1 100644 > --- a/sound/core/seq/oss/seq_oss_init.c > +++ b/sound/core/seq/oss/seq_oss_init.c > @@ -403,14 +403,11 @@ free_devinfo(void *private) > { > struct seq_oss_devinfo *dp = (struct seq_oss_devinfo *)private; > > - if (dp->timer) > - snd_seq_oss_timer_delete(dp->timer); > + snd_seq_oss_timer_delete(dp->timer); > > - if (dp->writeq) > - snd_seq_oss_writeq_delete(dp->writeq); > + snd_seq_oss_writeq_delete(dp->writeq); > > - if (dp->readq) > - snd_seq_oss_readq_delete(dp->readq); > + snd_seq_oss_readq_delete(dp->readq); > > kfree(dp); > } > diff --git a/sound/core/sgbuf.c b/sound/core/sgbuf.c > index 0a41850..84fffab 100644 > --- a/sound/core/sgbuf.c > +++ b/sound/core/sgbuf.c > @@ -39,8 +39,7 @@ int snd_free_sgbuf_pages(struct snd_dma_buffer *dmab) > if (! sgbuf) > return -EINVAL; > > - if (dmab->area) > - vunmap(dmab->area); > + vunmap(dmab->area); > dmab->area = NULL; > > tmpb.dev.type = SNDRV_DMA_TYPE_DEV; > -- > 2.1.3 >
At Fri, 21 Nov 2014 19:11:47 +0100, SF Markus Elfring wrote: > > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Fri, 21 Nov 2014 19:05:50 +0100 > > The release_and_free_resource() 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> Applied, thanks. Takashi > --- > sound/isa/es1688/es1688_lib.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/sound/isa/es1688/es1688_lib.c b/sound/isa/es1688/es1688_lib.c > index b3b4f15..fb259491 100644 > --- a/sound/isa/es1688/es1688_lib.c > +++ b/sound/isa/es1688/es1688_lib.c > @@ -614,8 +614,7 @@ static int snd_es1688_free(struct snd_es1688 *chip) > { > if (chip->hardware != ES1688_HW_UNDEF) > snd_es1688_init(chip, 0); > - if (chip->res_port) > - release_and_free_resource(chip->res_port); > + release_and_free_resource(chip->res_port); > if (chip->irq >= 0) > free_irq(chip->irq, (void *) chip); > if (chip->dma8 >= 0) { > -- > 2.1.3 >
At Fri, 21 Nov 2014 19:35:18 +0100, SF Markus Elfring wrote: > > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Fri, 21 Nov 2014 19:32:02 +0100 > > The functions release_and_free_resource() 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> Applied, thanks. Takashi > --- > sound/isa/sb/emu8000_synth.c | 3 +-- > sound/isa/sb/sb_common.c | 3 +-- > 2 files changed, 2 insertions(+), 4 deletions(-) > > diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c > index 4e3fcfb..95b39be 100644 > --- a/sound/isa/sb/emu8000_synth.c > +++ b/sound/isa/sb/emu8000_synth.c > @@ -105,8 +105,7 @@ static int snd_emu8000_delete_device(struct snd_seq_device *dev) > snd_device_free(dev->card, hw->pcm); > if (hw->emu) > snd_emux_free(hw->emu); > - if (hw->memhdr) > - snd_util_memhdr_free(hw->memhdr); > + snd_util_memhdr_free(hw->memhdr); > hw->emu = NULL; > hw->memhdr = NULL; > return 0; > diff --git a/sound/isa/sb/sb_common.c b/sound/isa/sb/sb_common.c > index 3ef9906..f22b448 100644 > --- a/sound/isa/sb/sb_common.c > +++ b/sound/isa/sb/sb_common.c > @@ -184,8 +184,7 @@ static int snd_sbdsp_probe(struct snd_sb * chip) > > static int snd_sbdsp_free(struct snd_sb *chip) > { > - if (chip->res_port) > - release_and_free_resource(chip->res_port); > + release_and_free_resource(chip->res_port); > if (chip->irq >= 0) > free_irq(chip->irq, (void *) chip); > #ifdef CONFIG_ISA > -- > 2.1.3 >
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 21 Nov 2014 20:22:32 +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> --- drivers/ide/ide.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c index 2ce6268..e29b02c 100644 --- a/drivers/ide/ide.c +++ b/drivers/ide/ide.c @@ -101,8 +101,7 @@ void ide_device_put(ide_drive_t *drive) struct device *host_dev = drive->hwif->host->dev[0]; struct module *module = host_dev ? host_dev->driver->owner : NULL; - if (module) - module_put(module); + module_put(module); #endif put_device(&drive->gendev); } -- 2.1.3
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 20 Nov 2014 14:28:25 +0100
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 20 Nov 2014 14:22:47 +0100
>
> The of_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>
Applied.
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 20 Nov 2014 14:50:26 +0100
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 20 Nov 2014 14:47:12 +0100
>
> The functions kfree() and of_node_put() test whether their argument is NULL
> and then return immediately. Thus the test around the call is not needed.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Applied.
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 20 Nov 2014 15:25:27 +0100
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 20 Nov 2014 15:15:21 +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>
This does not apply to the net-next tree, please respin.
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 20 Nov 2014 16:16:16 +0100
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 20 Nov 2014 16:11:56 +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>
Applied.
On Fri, 2014-11-21 at 10:30 +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 21 Nov 2014 10:25:45 +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>
> ---
> drivers/target/iscsi/iscsi_target_transport.c | 3 +--
> drivers/target/target_core_hba.c | 6 ++----
> 2 files changed, 3 insertions(+), 6 deletions(-)
>
Applied to target-pending/for-next.
Thanks Markus!
--nab
> This does not apply to the net-next tree, please respin.
Thanks for your reply.
How do you think about to try out the scripts which I published
in March to get more constructive feedback?
Will they run faster for another analysis on current
Linux source files with your test systems (than my computer)?
Regards,
Markus
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 21 Nov 2014 23:15:42 +0100
>> This does not apply to the net-next tree, please respin.
>
> Thanks for your reply.
>
> How do you think about to try out the scripts which I published
> in March to get more constructive feedback?
This has nothing to do with me asking you to frame your patches
against the correct tree.
If I had time to investigate automation of changes using such
tools, I would participate in such discussions, but I don't.
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 21 Nov 2014 23:57:28 +0100 The unw_remove_unwind_table() 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> --- arch/ia64/kernel/module.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c index 24603be..30ff27d 100644 --- a/arch/ia64/kernel/module.c +++ b/arch/ia64/kernel/module.c @@ -946,8 +946,6 @@ module_finalize (const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs, struct module *mo void module_arch_cleanup (struct module *mod) { - if (mod->arch.init_unw_table) - unw_remove_unwind_table(mod->arch.init_unw_table); - if (mod->arch.core_unw_table) - unw_remove_unwind_table(mod->arch.core_unw_table); + unw_remove_unwind_table(mod->arch.init_unw_table); + unw_remove_unwind_table(mod->arch.core_unw_table); } -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 22 Nov 2014 10:50:33 +0100 The functions clk_disable(), of_node_put() and omap_device_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> --- arch/arm/mach-omap2/omap_device.c | 3 +-- arch/arm/mach-omap2/omap_hwmod.c | 3 +-- arch/arm/mach-omap2/timer.c | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c index d22c30d..5108859 100644 --- a/arch/arm/mach-omap2/omap_device.c +++ b/arch/arm/mach-omap2/omap_device.c @@ -199,8 +199,7 @@ static int _omap_device_notifier_call(struct notifier_block *nb, switch (event) { case BUS_NOTIFY_DEL_DEVICE: - if (pdev->archdata.od) - omap_device_delete(pdev->archdata.od); + omap_device_delete(pdev->archdata.od); break; case BUS_NOTIFY_ADD_DEVICE: if (pdev->dev.of_node) diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c index 9e91a4e..e2406c4 100644 --- a/arch/arm/mach-omap2/omap_hwmod.c +++ b/arch/arm/mach-omap2/omap_hwmod.c @@ -917,8 +917,7 @@ static int _disable_clocks(struct omap_hwmod *oh) pr_debug("omap_hwmod: %s: disabling clocks\n", oh->name); - if (oh->_clk) - clk_disable(oh->_clk); + clk_disable(oh->_clk); p = oh->slave_ports.next; diff --git a/arch/arm/mach-omap2/timer.c b/arch/arm/mach-omap2/timer.c index 43d03fb..5b428a0 100644 --- a/arch/arm/mach-omap2/timer.c +++ b/arch/arm/mach-omap2/timer.c @@ -205,8 +205,7 @@ static void __init omap_dmtimer_init(void) /* If we are a secure device, remove any secure timer nodes */ if ((omap_type() != OMAP2_DEVICE_TYPE_GP)) { np = omap_get_timer_dt(omap_timer_match, "ti,timer-secure"); - if (np) - of_node_put(np); + of_node_put(np); } } -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 22 Nov 2014 11:33:16 +0100 The functions smp_set_ops() and unwind_table_del() 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> --- arch/arm/kernel/module.c | 3 +-- arch/arm/kernel/setup.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c index 6a4dffe..3dffad1 100644 --- a/arch/arm/kernel/module.c +++ b/arch/arm/kernel/module.c @@ -350,7 +350,6 @@ module_arch_cleanup(struct module *mod) int i; for (i = 0; i < ARM_SEC_MAX; i++) - if (mod->arch.unwind[i]) - unwind_table_del(mod->arch.unwind[i]); + unwind_table_del(mod->arch.unwind[i]); #endif } diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index 84db893d..a7018a2 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -929,7 +929,7 @@ void __init setup_arch(char **cmdline_p) if (!mdesc->smp_init || !mdesc->smp_init()) { if (psci_smp_available()) smp_set_ops(&psci_smp_ops); - else if (mdesc->smp) + else smp_set_ops(mdesc->smp); } smp_init_cpus(); -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 22 Nov 2014 12:55:28 +0100 The free_tce_table() 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> --- arch/x86/kernel/pci-calgary_64.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c index 0497f71..d22a386 100644 --- a/arch/x86/kernel/pci-calgary_64.c +++ b/arch/x86/kernel/pci-calgary_64.c @@ -1476,8 +1476,7 @@ cleanup: for (--bus; bus >= 0; --bus) { struct calgary_bus_info *info = &bus_info[bus]; - if (info->tce_space) - free_tce_table(info->tce_space); + free_tce_table(info->tce_space); } return -ENOMEM; } -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 22 Nov 2014 14:01:27 +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> --- arch/x86/kernel/cpu/perf_event_amd_uncore.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/cpu/perf_event_amd_uncore.c b/arch/x86/kernel/cpu/perf_event_amd_uncore.c index 30790d7..4856232 100644 --- a/arch/x86/kernel/cpu/perf_event_amd_uncore.c +++ b/arch/x86/kernel/cpu/perf_event_amd_uncore.c @@ -592,11 +592,9 @@ fail_online: fail_l2: if (cpu_has_perfctr_nb) perf_pmu_unregister(&amd_nb_pmu); - if (amd_uncore_l2) - free_percpu(amd_uncore_l2); + free_percpu(amd_uncore_l2); fail_nb: - if (amd_uncore_nb) - free_percpu(amd_uncore_nb); + free_percpu(amd_uncore_nb); fail_nodev: return ret; -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 22 Nov 2014 15:00:55 +0100 The debug_unregister() 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> --- arch/s390/pci/pci_debug.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/arch/s390/pci/pci_debug.c b/arch/s390/pci/pci_debug.c index eec598c..18403a7 100644 --- a/arch/s390/pci/pci_debug.c +++ b/arch/s390/pci/pci_debug.c @@ -158,10 +158,8 @@ int __init zpci_debug_init(void) void zpci_debug_exit(void) { - if (pci_debug_msg_id) - debug_unregister(pci_debug_msg_id); - if (pci_debug_err_id) - debug_unregister(pci_debug_err_id); + debug_unregister(pci_debug_msg_id); + debug_unregister(pci_debug_err_id); debugfs_remove(debugfs_root); } -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 22 Nov 2014 16:18:20 +0100 The of_node_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> --- arch/powerpc/platforms/83xx/usb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/powerpc/platforms/83xx/usb.c b/arch/powerpc/platforms/83xx/usb.c index 1ad748b..5c31d82 100644 --- a/arch/powerpc/platforms/83xx/usb.c +++ b/arch/powerpc/platforms/83xx/usb.c @@ -162,8 +162,7 @@ int mpc831x_usb_cfg(void) iounmap(immap); - if (immr_node) - of_node_put(immr_node); + of_node_put(immr_node); /* Map USB SOC space */ ret = of_address_to_resource(np, 0, &res); -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 22 Nov 2014 16:51:31 +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/video/fbdev/sh_mobile_lcdcfb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c index 2bcc84a..cfde21d 100644 --- a/drivers/video/fbdev/sh_mobile_lcdcfb.c +++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c @@ -2181,8 +2181,7 @@ sh_mobile_lcdc_channel_fb_cleanup(struct sh_mobile_lcdc_chan *ch) if (!info || !info->device) return; - if (ch->sglist) - vfree(ch->sglist); + vfree(ch->sglist); fb_dealloc_cmap(&info->cmap); framebuffer_release(info); -- 2.1.3
This one is buggy. regards, dan carpenter
> This has nothing to do with me asking you to frame your patches
> against the correct tree.
I imagine than someone other can also pick up this update suggestion
(a simple change of two lines) quicker before I might try another
software build again from a different commit as a base.
Regards,
Markus
On Sun, 2014-11-23 at 01:51 +0100, SF Markus Elfring wrote:
> > This has nothing to do with me asking you to frame your patches
> > against the correct tree.
>
> I imagine than someone other can also pick up this update suggestion
> (a simple change of two lines) quicker before I might try another
> software build again from a different commit as a base.
I have no idea why someone would do that.
If you don't bother resubmit, nobody will.
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 23 Nov 2014 01:51:24 +0100
>> This has nothing to do with me asking you to frame your patches
>> against the correct tree.
>
> I imagine than someone other can also pick up this update suggestion
> (a simple change of two lines) quicker before I might try another
> software build again from a different commit as a base.
Whereas if you learn how to base your changes cleanly on the correct
base now, all of your future submissions will go quickly and smoothly
into my tree.
>> I imagine than someone other can also pick up this update suggestion >> (a simple change of two lines) quicker before I might try another >> software build again from a different commit as a base. > > I have no idea why someone would do that. I imagine that other software users (besides me) like developers and testers might also become curious to try the proposed changes out. How much will they eventually help to run Linux components a bit faster? > If you don't bother resubmit, nobody will. I hope that there are more possibilities for anticipation and acceptance of source code improvement potentials. Would you also like to contribute a bit more fine-tuning for the affected software versions? Regards, Markus
> Whereas if you learn how to base your changes cleanly on the correct
> base now, all of your future submissions will go quickly and smoothly
> into my tree.
My reluctance to work with more Linux repositories will evolve
over time. The faster affected software versions can be rebuilt
the more it will become interesting to try even more source
code improvements out, won't it?
I find it nice that you could accept update suggestions for
a few other Linux components already.
Regards,
Markus
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 23 Nov 2014 11:00:26 +0100 The uvesafb_free() 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/video/fbdev/uvesafb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c index 509d452..f718627 100644 --- a/drivers/video/fbdev/uvesafb.c +++ b/drivers/video/fbdev/uvesafb.c @@ -1219,8 +1219,7 @@ static int uvesafb_release(struct fb_info *info, int user) uvesafb_vbe_state_restore(par, par->vbe_state_orig); out: atomic_dec(&par->ref_count); - if (task) - uvesafb_free(task); + uvesafb_free(task); return 0; } -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 23 Nov 2014 11:40:47 +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/video/fbdev/udlfb.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c index 77b890e..01fff0c 100644 --- a/drivers/video/fbdev/udlfb.c +++ b/drivers/video/fbdev/udlfb.c @@ -922,8 +922,7 @@ static void dlfb_free(struct kref *kref) { struct dlfb_data *dev = container_of(kref, struct dlfb_data, kref); - if (dev->backing_buffer) - vfree(dev->backing_buffer); + vfree(dev->backing_buffer); kfree(dev->edid); @@ -953,8 +952,7 @@ static void dlfb_free_framebuffer(struct dlfb_data *dev) fb_dealloc_cmap(&info->cmap); if (info->monspecs.modedb) fb_destroy_modedb(info->monspecs.modedb); - if (info->screen_base) - vfree(info->screen_base); + vfree(info->screen_base); fb_destroy_modelist(&info->modelist); @@ -1203,8 +1201,7 @@ static int dlfb_realloc_framebuffer(struct dlfb_data *dev, struct fb_info *info) if (!new_back) pr_info("No shadow/backing buffer allocated\n"); else { - if (dev->backing_buffer) - vfree(dev->backing_buffer); + vfree(dev->backing_buffer); dev->backing_buffer = new_back; } } -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 23 Nov 2014 12:30:33 +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/video/fbdev/smscufx.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c index d513ed6..9279e5f 100644 --- a/drivers/video/fbdev/smscufx.c +++ b/drivers/video/fbdev/smscufx.c @@ -1142,8 +1142,7 @@ static void ufx_free_framebuffer_work(struct work_struct *work) fb_dealloc_cmap(&info->cmap); if (info->monspecs.modedb) fb_destroy_modedb(info->monspecs.modedb); - if (info->screen_base) - vfree(info->screen_base); + vfree(info->screen_base); fb_destroy_modelist(&info->modelist); @@ -1743,8 +1742,7 @@ error: fb_dealloc_cmap(&info->cmap); if (info->monspecs.modedb) fb_destroy_modedb(info->monspecs.modedb); - if (info->screen_base) - vfree(info->screen_base); + vfree(info->screen_base); fb_destroy_modelist(&info->modelist); -- 2.1.3
> > 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
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 23 Nov 2014 12:55:25 +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> --- drivers/video/fbdev/sis/sis_main.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/drivers/video/fbdev/sis/sis_main.c b/drivers/video/fbdev/sis/sis_main.c index 3f12a2d..6548a3e 100644 --- a/drivers/video/fbdev/sis/sis_main.c +++ b/drivers/video/fbdev/sis/sis_main.c @@ -5989,7 +5989,7 @@ static int sisfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if(!ivideo->sisvga_enabled) { if(pci_enable_device(pdev)) { - if(ivideo->nbridge) pci_dev_put(ivideo->nbridge); + pci_dev_put(ivideo->nbridge); framebuffer_release(sis_fb_info); return -EIO; } @@ -6202,10 +6202,8 @@ error_0: iounmap(ivideo->video_vbase); error_1: release_mem_region(ivideo->video_base, ivideo->video_size); error_2: release_mem_region(ivideo->mmio_base, ivideo->mmio_size); error_3: vfree(ivideo->bios_abase); - if(ivideo->lpcdev) - pci_dev_put(ivideo->lpcdev); - if(ivideo->nbridge) - pci_dev_put(ivideo->nbridge); + pci_dev_put(ivideo->lpcdev); + pci_dev_put(ivideo->nbridge); if(!ivideo->sisvga_enabled) pci_disable_device(pdev); framebuffer_release(sis_fb_info); @@ -6505,11 +6503,9 @@ static void sisfb_remove(struct pci_dev *pdev) vfree(ivideo->bios_abase); - if(ivideo->lpcdev) - pci_dev_put(ivideo->lpcdev); + pci_dev_put(ivideo->lpcdev); - if(ivideo->nbridge) - pci_dev_put(ivideo->nbridge); + pci_dev_put(ivideo->nbridge); #ifdef CONFIG_MTRR /* Release MTRR region */ -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 23 Nov 2014 14:07:22 +0100 The i2c_put_adapter() 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/video/fbdev/omap2/displays-new/connector-dvi.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/video/fbdev/omap2/displays-new/connector-dvi.c b/drivers/video/fbdev/omap2/displays-new/connector-dvi.c index 74de2bc..196c61a 100644 --- a/drivers/video/fbdev/omap2/displays-new/connector-dvi.c +++ b/drivers/video/fbdev/omap2/displays-new/connector-dvi.c @@ -262,8 +262,7 @@ static int dvic_probe_pdata(struct platform_device *pdev) in = omap_dss_find_output(pdata->source); if (in = NULL) { - if (ddata->i2c_adapter) - i2c_put_adapter(ddata->i2c_adapter); + i2c_put_adapter(ddata->i2c_adapter); dev_err(&pdev->dev, "Failed to find video source\n"); return -EPROBE_DEFER; @@ -352,8 +351,7 @@ static int dvic_probe(struct platform_device *pdev) err_reg: omap_dss_put_device(ddata->in); - if (ddata->i2c_adapter) - i2c_put_adapter(ddata->i2c_adapter); + i2c_put_adapter(ddata->i2c_adapter); return r; } @@ -371,8 +369,7 @@ static int __exit dvic_remove(struct platform_device *pdev) omap_dss_put_device(in); - if (ddata->i2c_adapter) - i2c_put_adapter(ddata->i2c_adapter); + i2c_put_adapter(ddata->i2c_adapter); return 0; } -- 2.1.3
> 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
>> 2. Are any additional prefixes appropriate so that further name space >> conflicts can be better avoided? > > To avoid possible external naming conflicts, add tb_ prefix to > various ring_<foo> structs and functions. Do you imagine that any XEN software developers need also to reconsider this implementation detail? https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/drivers/char/tpm/xen-tpmfront.c?idü14f9c1272f62c3e8d01300f52467c0d9af50f9#n268 Regards, Markus -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 23 Nov 2014 15:15:29 +0100 The backlight_device_unregister() 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/video/fbdev/mx3fb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/video/fbdev/mx3fb.c b/drivers/video/fbdev/mx3fb.c index c645a0a..b2d2151 100644 --- a/drivers/video/fbdev/mx3fb.c +++ b/drivers/video/fbdev/mx3fb.c @@ -334,8 +334,7 @@ static void mx3fb_init_backlight(struct mx3fb_data *fbd) static void mx3fb_exit_backlight(struct mx3fb_data *fbd) { - if (fbd->bl) - backlight_device_unregister(fbd->bl); + backlight_device_unregister(fbd->bl); } static void mx3fb_dma_done(void *); -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 23 Nov 2014 15:45:03 +0100 The mmp_unregister_path() 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/video/fbdev/mmp/hw/mmp_ctrl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/video/fbdev/mmp/hw/mmp_ctrl.c b/drivers/video/fbdev/mmp/hw/mmp_ctrl.c index 8621a9f..3c12bd8 100644 --- a/drivers/video/fbdev/mmp/hw/mmp_ctrl.c +++ b/drivers/video/fbdev/mmp/hw/mmp_ctrl.c @@ -441,8 +441,7 @@ static void path_deinit(struct mmphw_path_plat *path_plat) if (!path_plat) return; - if (path_plat->path) - mmp_unregister_path(path_plat->path); + mmp_unregister_path(path_plat->path); } static int mmphw_probe(struct platform_device *pdev) -- 2.1.3
On Sun, 2014-11-23 at 15:14 +0100, SF Markus Elfring wrote: > >> 2. Are any additional prefixes appropriate so that further name space > >> conflicts can be better avoided? > > > > To avoid possible external naming conflicts, add tb_ prefix to > > various ring_<foo> structs and functions. > > Do you imagine that any XEN software developers need also to reconsider > this implementation detail? > https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/drivers/char/tpm/xen-tpmfront.c?idü14f9c1272f62c3e8d01300f52467c0d9af50f9#n268 I think static functions can be named whatever the developer chooses. -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 23 Nov 2014 16:30:05 +0100 The framebuffer_release() 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/video/fbdev/via/viafbdev.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/video/fbdev/via/viafbdev.c b/drivers/video/fbdev/via/viafbdev.c index 325c43c..f9718f0 100644 --- a/drivers/video/fbdev/via/viafbdev.c +++ b/drivers/video/fbdev/via/viafbdev.c @@ -1937,8 +1937,7 @@ out_fb1_unreg_lcd_cle266: out_dealloc_cmap: fb_dealloc_cmap(&viafbinfo->cmap); out_fb1_release: - if (viafbinfo1) - framebuffer_release(viafbinfo1); + framebuffer_release(viafbinfo1); out_fb_release: i2c_bus_free(viaparinfo->shared); framebuffer_release(viafbinfo); -- 2.1.3
>> https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/drivers/char/tpm/xen-tpmfront.c?idü14f9c1272f62c3e8d01300f52467c0d9af50f9#n268 > > I think static functions can be named whatever > the developer chooses. I agree also that this implementation detail is correct in principle. Is a renaming of such identifiers feasible so that the probability of other name clashes can be reduced and corresponding static source code analysis might become a bit easier? How do you prefer to handle name space issues? Regards, Markus -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Sun, Nov 23, 2014 at 4:20 PM, Joe Perches <joe@perches.com> wrote: > On Sun, 2014-11-23 at 15:14 +0100, SF Markus Elfring wrote: >> >> 2. Are any additional prefixes appropriate so that further name space >> >> conflicts can be better avoided? >> > >> > To avoid possible external naming conflicts, add tb_ prefix to >> > various ring_<foo> structs and functions. >> >> Do you imagine that any XEN software developers need also to reconsider >> this implementation detail? >> https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/drivers/char/tpm/xen-tpmfront.c?idü14f9c1272f62c3e8d01300f52467c0d9af50f9#n268 > > I think static functions can be named whatever > the developer chooses. Do symbols which are not exported (no EXPORT_SYMBOL_(GPL)) cause conflicts? I was under the impression that those are module private. If they are indeed private then I would prefer to not rename them. -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Sun, 23 Nov 2014, SF Markus Elfring wrote: > >> https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/drivers/char/tpm/xen-tpmfront.c?idü14f9c1272f62c3e8d01300f52467c0d9af50f9#n268 > > > > I think static functions can be named whatever > > the developer chooses. > > I agree also that this implementation detail is correct in principle. > > Is a renaming of such identifiers feasible so that the probability of > other name clashes can be reduced and corresponding static source > code analysis might become a bit easier? Why not just make the static source code analysis aware of the problem? You can treat static functions differently that non-static ones. There is no need to change the code. julia -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Sun, 2014-11-23 at 16:45 +0100, Andreas Noever wrote: > On Sun, Nov 23, 2014 at 4:20 PM, Joe Perches <joe@perches.com> wrote: > > On Sun, 2014-11-23 at 15:14 +0100, SF Markus Elfring wrote: > >> >> 2. Are any additional prefixes appropriate so that further name space > >> >> conflicts can be better avoided? > >> > > >> > To avoid possible external naming conflicts, add tb_ prefix to > >> > various ring_<foo> structs and functions. > >> > >> Do you imagine that any XEN software developers need also to reconsider > >> this implementation detail? > >> https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/drivers/char/tpm/xen-tpmfront.c?idü14f9c1272f62c3e8d01300f52467c0d9af50f9#n268 > > > > I think static functions can be named whatever > > the developer chooses. > Do symbols which are not exported (no EXPORT_SYMBOL_(GPL)) cause > conflicts? If the symbol is not static, yes. eg: the static uses of "debug" as a control variable vs the non-static uses of <prefix>debug when shared among multiple objects in a single driver. -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 23 Nov 2014 17:05:18 +0100 The platform_device_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> --- drivers/video/fbdev/uvesafb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c index 509d452..17b2e8c 100644 --- a/drivers/video/fbdev/uvesafb.c +++ b/drivers/video/fbdev/uvesafb.c @@ -1923,8 +1923,7 @@ static int uvesafb_init(void) err = -ENOMEM; if (err) { - if (uvesafb_device) - platform_device_put(uvesafb_device); + platform_device_put(uvesafb_device); platform_driver_unregister(&uvesafb_driver); cn_del_callback(&uvesafb_cn_id); return err; -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 23 Nov 2014 17:33:08 +0100 The backlight_device_unregister() 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/video/backlight/lp8788_bl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/video/backlight/lp8788_bl.c b/drivers/video/backlight/lp8788_bl.c index d6c4f6a..24a055c 100644 --- a/drivers/video/backlight/lp8788_bl.c +++ b/drivers/video/backlight/lp8788_bl.c @@ -221,8 +221,7 @@ static void lp8788_backlight_unregister(struct lp8788_bl *bl) { struct backlight_device *bl_dev = bl->bl_dev; - if (bl_dev) - backlight_device_unregister(bl_dev); + backlight_device_unregister(bl_dev); } static ssize_t lp8788_get_bl_ctl_mode(struct device *dev, -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 23 Nov 2014 19:13:56 +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 two function calls One function call less in ion_buffer_create() after error detection drivers/staging/android/ion/ion.c | 9 +++------ drivers/staging/android/ion/ion_dummy_driver.c | 6 ++---- drivers/staging/android/ion/tegra/tegra_ion.c | 6 ++---- 3 files changed, 7 insertions(+), 14 deletions(-) -- 2.1.3
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 23 Nov 2014 08:18:31 +0100
>> Whereas if you learn how to base your changes cleanly on the correct
>> base now, all of your future submissions will go quickly and smoothly
>> into my tree.
>
> My reluctance to work with more Linux repositories will evolve
> over time. The faster affected software versions can be rebuilt
> the more it will become interesting to try even more source
> code improvements out, won't it?
>
> I find it nice that you could accept update suggestions for
> a few other Linux components already.
You are seriously starting to waste our time.
Either resubmit your changes against a clean base, or more on.
Seriously, all I am purely interested in is seeing properly submitted
patches, reviewing them, and then integrating them. Anything else is
pure noise to me.
Thanks.
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 23 Nov 2014 18:48:15 +0100 The functions ion_heap_destroy() and vfree() perform 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/staging/android/ion/ion.c | 6 ++---- drivers/staging/android/ion/ion_dummy_driver.c | 6 ++---- drivers/staging/android/ion/tegra/tegra_ion.c | 6 ++---- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 2703609..df12cc3 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -263,8 +263,7 @@ err: heap->ops->unmap_dma(heap, buffer); heap->ops->free(buffer); err1: - if (buffer->pages) - vfree(buffer->pages); + vfree(buffer->pages); err2: kfree(buffer); return ERR_PTR(ret); @@ -276,8 +275,7 @@ void ion_buffer_destroy(struct ion_buffer *buffer) buffer->heap->ops->unmap_kernel(buffer->heap, buffer); buffer->heap->ops->unmap_dma(buffer->heap, buffer); buffer->heap->ops->free(buffer); - if (buffer->pages) - vfree(buffer->pages); + vfree(buffer->pages); kfree(buffer); } diff --git a/drivers/staging/android/ion/ion_dummy_driver.c b/drivers/staging/android/ion/ion_dummy_driver.c index 3a45e79..d06bf52 100644 --- a/drivers/staging/android/ion/ion_dummy_driver.c +++ b/drivers/staging/android/ion/ion_dummy_driver.c @@ -112,10 +112,8 @@ static int __init ion_dummy_init(void) } return 0; err: - for (i = 0; i < dummy_ion_pdata.nr; i++) { - if (heaps[i]) - ion_heap_destroy(heaps[i]); - } + for (i = 0; i < dummy_ion_pdata.nr; ++i) + ion_heap_destroy(heaps[i]); kfree(heaps); if (carveout_ptr) { diff --git a/drivers/staging/android/ion/tegra/tegra_ion.c b/drivers/staging/android/ion/tegra/tegra_ion.c index 11c7cce..5b8ef0e 100644 --- a/drivers/staging/android/ion/tegra/tegra_ion.c +++ b/drivers/staging/android/ion/tegra/tegra_ion.c @@ -54,10 +54,8 @@ static int tegra_ion_probe(struct platform_device *pdev) platform_set_drvdata(pdev, idev); return 0; err: - for (i = 0; i < num_heaps; i++) { - if (heaps[i]) - ion_heap_destroy(heaps[i]); - } + for (i = 0; i < num_heaps; ++i) + ion_heap_destroy(heaps[i]); return err; } -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 23 Nov 2014 19:12:29 +0100 The jump label "err1" was used by the ion_buffer_create() function in case of a memory allocation failure just to pass a null pointer to a vfree() function call by a data structure element. This implementation detail could be improved by the deletion of this inappropriate jump label. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/staging/android/ion/ion.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index df12cc3..7a26b85 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -226,7 +226,7 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap, buffer->pages = vmalloc(sizeof(struct page *) * num_pages); if (!buffer->pages) { ret = -ENOMEM; - goto err1; + goto err2; } for_each_sg(table->sgl, sg, table->nents, i) { @@ -262,7 +262,6 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap, err: heap->ops->unmap_dma(heap, buffer); heap->ops->free(buffer); -err1: vfree(buffer->pages); err2: kfree(buffer); -- 2.1.3
> Why not just make the static source code analysis aware of the problem? This is also possible, of course. > You can treat static functions differently that non-static ones. I have added this detail to my ideas around the next fine-tuning for the published semantic patch approach. > There is no need to change the code. Can name space prefixes help to make source code a bit safer eventually? Regards, Markus
On Sun, 2014-11-23 at 20:03 +0100, SF Markus Elfring wrote:
> > Why not just make the static source code analysis aware of the problem?
>
> This is also possible, of course.
>
>
> > You can treat static functions differently that non-static ones.
>
> I have added this detail to my ideas around the next fine-tuning
> for the published semantic patch approach.
>
>
> > There is no need to change the code.
>
> Can name space prefixes help to make source code a bit safer eventually?
Not really.
Adding prefixes can make code unnecessarily more verbose though.
On Mon, Nov 24, 2014 at 10:04:16PM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Mon, 24 Nov 2014 22:00:21 +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>
Thanks Markus, queued.
--
Darren Hart
Intel Open Source Technology Center
On Mon, Nov 24, 2014 at 08:40:22PM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Mon, 24 Nov 2014 20:30:29 +0100
>
> The backlight_device_unregister() 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>
Thanks Markus, queued.
--
Darren Hart
Intel Open Source Technology Center
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
On Fri, Nov 21, 2014 at 06:59:00PM +0100, Julia Lawall wrote:
> On Fri, 21 Nov 2014, SF Markus Elfring wrote:
>
> > >> diff --git a/drivers/usb/serial/mxuport.c b/drivers/usb/serial/mxuport.c
> > >> index ab1d690..3653ec1 100644
> > >> --- a/drivers/usb/serial/mxuport.c
> > >> +++ b/drivers/usb/serial/mxuport.c
> > >> @@ -1101,8 +1101,7 @@ static int mxuport_probe(struct usb_serial *serial,
> > >> */
> > >> usb_set_serial_data(serial, (void *)id->driver_info);
> > >> out:
> > >> - if (fw_p)
> > >> - release_firmware(fw_p);
> > >> + release_firmware(fw_p);
> > >
> > > I think that the if should stay.
> >
> > I have got an other opinion.
> >
> >
> > > There were two cases on the allocation, so there should be two cases
> > > on the release.
> >
> > I find that this implementation detail does not really matter for the
> > necessity of a null pointer check directly before such a function call.
>
> Conceptually, if it is clear 10 lines above that nothing was allocated,
> and there is a fallback to existing data (according to the comment above)
> it is strange to be releasing something.
I agree with Julia here and will not apply this one.
Thanks,
Johan
On Sun, 23 Nov 2014, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sun, 23 Nov 2014 17:33:08 +0100 What format is this? Can you use `git format-patch` and `git send-email` instead please? > The backlight_device_unregister() 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/video/backlight/lp8788_bl.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/video/backlight/lp8788_bl.c b/drivers/video/backlight/lp8788_bl.c > index d6c4f6a..24a055c 100644 > --- a/drivers/video/backlight/lp8788_bl.c > +++ b/drivers/video/backlight/lp8788_bl.c > @@ -221,8 +221,7 @@ static void lp8788_backlight_unregister(struct lp8788_bl *bl) > { > struct backlight_device *bl_dev = bl->bl_dev; > > - if (bl_dev) > - backlight_device_unregister(bl_dev); > + backlight_device_unregister(bl_dev); > } > > static ssize_t lp8788_get_bl_ctl_mode(struct device *dev, -- Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Sun, 23 Nov 2014, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sun, 23 Nov 2014 17:33:08 +0100 > > The backlight_device_unregister() function tests whether its argument is NULL > and then returns immediately. Thus the test around the call is not needed. Also the $SUBJECT should be less than 75 chars. > This issue was detected by using the Coccinelle software. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > drivers/video/backlight/lp8788_bl.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/video/backlight/lp8788_bl.c b/drivers/video/backlight/lp8788_bl.c > index d6c4f6a..24a055c 100644 > --- a/drivers/video/backlight/lp8788_bl.c > +++ b/drivers/video/backlight/lp8788_bl.c > @@ -221,8 +221,7 @@ static void lp8788_backlight_unregister(struct lp8788_bl *bl) > { > struct backlight_device *bl_dev = bl->bl_dev; > > - if (bl_dev) > - backlight_device_unregister(bl_dev); > + backlight_device_unregister(bl_dev); > } > > static ssize_t lp8788_get_bl_ctl_mode(struct device *dev, -- Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Markus Elfring <elfring@users.sourceforge.net> The backlight_device_unregister() 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/video/backlight/lp8788_bl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/video/backlight/lp8788_bl.c b/drivers/video/backlight/lp8788_bl.c index d6c4f6a..24a055c 100644 --- a/drivers/video/backlight/lp8788_bl.c +++ b/drivers/video/backlight/lp8788_bl.c @@ -221,8 +221,7 @@ static void lp8788_backlight_unregister(struct lp8788_bl *bl) { struct backlight_device *bl_dev = bl->bl_dev; - if (bl_dev) - backlight_device_unregister(bl_dev); + backlight_device_unregister(bl_dev); } static ssize_t lp8788_get_bl_ctl_mode(struct device *dev, -- 2.1.3
On Sat, 22 Nov 2014, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 22 Nov 2014 15:00:55 +0100
>
> The debug_unregister() 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>
> ---
> arch/s390/pci/pci_debug.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/arch/s390/pci/pci_debug.c b/arch/s390/pci/pci_debug.c
> index eec598c..18403a7 100644
> --- a/arch/s390/pci/pci_debug.c
> +++ b/arch/s390/pci/pci_debug.c
> @@ -158,10 +158,8 @@ int __init zpci_debug_init(void)
>
> void zpci_debug_exit(void)
> {
> - if (pci_debug_msg_id)
> - debug_unregister(pci_debug_msg_id);
> - if (pci_debug_err_id)
> - debug_unregister(pci_debug_err_id);
> + debug_unregister(pci_debug_msg_id);
> + debug_unregister(pci_debug_err_id);
>
> debugfs_remove(debugfs_root);
> }
Applied.
Thanks,
Sebastian
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 24 Nov 2014 20:30:29 +0100 The backlight_device_unregister() 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/platform/x86/asus-laptop.c | 3 +-- drivers/platform/x86/asus-wmi.c | 3 +-- drivers/platform/x86/eeepc-laptop.c | 3 +-- drivers/platform/x86/fujitsu-laptop.c | 6 ++---- drivers/platform/x86/ideapad-laptop.c | 3 +-- drivers/platform/x86/intel_oaktrail.c | 3 +-- drivers/platform/x86/msi-wmi.c | 3 +-- drivers/platform/x86/sony-laptop.c | 3 +-- drivers/platform/x86/toshiba_acpi.c | 3 +-- 9 files changed, 10 insertions(+), 20 deletions(-) diff --git a/drivers/platform/x86/asus-laptop.c b/drivers/platform/x86/asus-laptop.c index 7f4dc6f..11fac1a 100644 --- a/drivers/platform/x86/asus-laptop.c +++ b/drivers/platform/x86/asus-laptop.c @@ -843,8 +843,7 @@ static int asus_backlight_init(struct asus_laptop *asus) static void asus_backlight_exit(struct asus_laptop *asus) { - if (asus->backlight_device) - backlight_device_unregister(asus->backlight_device); + backlight_device_unregister(asus->backlight_device); asus->backlight_device = NULL; } diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 21fc932..7543a56 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -1308,8 +1308,7 @@ static int asus_wmi_backlight_init(struct asus_wmi *asus) static void asus_wmi_backlight_exit(struct asus_wmi *asus) { - if (asus->backlight_device) - backlight_device_unregister(asus->backlight_device); + backlight_device_unregister(asus->backlight_device); asus->backlight_device = NULL; } diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c index bd533c2..9bc7eb7 100644 --- a/drivers/platform/x86/eeepc-laptop.c +++ b/drivers/platform/x86/eeepc-laptop.c @@ -1158,8 +1158,7 @@ static int eeepc_backlight_init(struct eeepc_laptop *eeepc) static void eeepc_backlight_exit(struct eeepc_laptop *eeepc) { - if (eeepc->backlight_device) - backlight_device_unregister(eeepc->backlight_device); + backlight_device_unregister(eeepc->backlight_device); eeepc->backlight_device = NULL; } diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c index 87aa28c..f1a670b 100644 --- a/drivers/platform/x86/fujitsu-laptop.c +++ b/drivers/platform/x86/fujitsu-laptop.c @@ -1147,8 +1147,7 @@ fail_hotkey1: fail_hotkey: platform_driver_unregister(&fujitsupf_driver); fail_backlight: - if (fujitsu->bl_device) - backlight_device_unregister(fujitsu->bl_device); + backlight_device_unregister(fujitsu->bl_device); fail_sysfs_group: sysfs_remove_group(&fujitsu->pf_device->dev.kobj, &fujitsupf_attribute_group); @@ -1172,8 +1171,7 @@ static void __exit fujitsu_cleanup(void) platform_driver_unregister(&fujitsupf_driver); - if (fujitsu->bl_device) - backlight_device_unregister(fujitsu->bl_device); + backlight_device_unregister(fujitsu->bl_device); sysfs_remove_group(&fujitsu->pf_device->dev.kobj, &fujitsupf_attribute_group); diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index ed494f3..3163061 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -729,8 +729,7 @@ static int ideapad_backlight_init(struct ideapad_private *priv) static void ideapad_backlight_exit(struct ideapad_private *priv) { - if (priv->blightdev) - backlight_device_unregister(priv->blightdev); + backlight_device_unregister(priv->blightdev); priv->blightdev = NULL; } diff --git a/drivers/platform/x86/intel_oaktrail.c b/drivers/platform/x86/intel_oaktrail.c index 4bc9604..0dd72cf 100644 --- a/drivers/platform/x86/intel_oaktrail.c +++ b/drivers/platform/x86/intel_oaktrail.c @@ -271,8 +271,7 @@ static int oaktrail_backlight_init(void) static void oaktrail_backlight_exit(void) { - if (oaktrail_bl_device) - backlight_device_unregister(oaktrail_bl_device); + backlight_device_unregister(oaktrail_bl_device); } static int oaktrail_probe(struct platform_device *pdev) diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c index 70222f2..6d2bac0 100644 --- a/drivers/platform/x86/msi-wmi.c +++ b/drivers/platform/x86/msi-wmi.c @@ -354,8 +354,7 @@ static void __exit msi_wmi_exit(void) sparse_keymap_free(msi_wmi_input_dev); input_unregister_device(msi_wmi_input_dev); } - if (backlight) - backlight_device_unregister(backlight); + backlight_device_unregister(backlight); } module_init(msi_wmi_init); diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c index 26ad9ff..a48cdc7 100644 --- a/drivers/platform/x86/sony-laptop.c +++ b/drivers/platform/x86/sony-laptop.c @@ -3141,8 +3141,7 @@ static void sony_nc_backlight_setup(void) static void sony_nc_backlight_cleanup(void) { - if (sony_bl_props.dev) - backlight_device_unregister(sony_bl_props.dev); + backlight_device_unregister(sony_bl_props.dev); } static int sony_nc_add(struct acpi_device *device) diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index d0dce73..703a68a 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -1647,8 +1647,7 @@ static int toshiba_acpi_remove(struct acpi_device *acpi_dev) rfkill_destroy(dev->bt_rfk); } - if (dev->backlight_dev) - backlight_device_unregister(dev->backlight_dev); + backlight_device_unregister(dev->backlight_dev); if (dev->illumination_supported) led_classdev_unregister(&dev->led_dev); -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 24 Nov 2014 22:00:21 +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> --- drivers/platform/x86/sony-laptop.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c index 26ad9ff..22b173d 100644 --- a/drivers/platform/x86/sony-laptop.c +++ b/drivers/platform/x86/sony-laptop.c @@ -3717,8 +3717,7 @@ static void sony_pic_detect_device_type(struct sony_pic_dev *dev) dev->event_types = type2_events; out: - if (pcidev) - pci_dev_put(pcidev); + pci_dev_put(pcidev); pr_info("detected Type%d model\n", dev->model = SONYPI_DEVICE_TYPE1 ? 1 : -- 2.1.3
Hi Markus, Le lundi 24 novembre 2014, 20:40:22 SF Markus Elfring a écrit : > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Mon, 24 Nov 2014 20:30:29 +0100 > > The backlight_device_unregister() 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. What script was used ? Is it in scripts/coccinelle ? > diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c > index 70222f2..6d2bac0 100644 > --- a/drivers/platform/x86/msi-wmi.c > +++ b/drivers/platform/x86/msi-wmi.c > @@ -354,8 +354,7 @@ static void __exit msi_wmi_exit(void) > sparse_keymap_free(msi_wmi_input_dev); > input_unregister_device(msi_wmi_input_dev); > } > - if (backlight) > - backlight_device_unregister(backlight); > + backlight_device_unregister(backlight); > } > > module_init(msi_wmi_init); For this part: Acked-by: Anisse Astier <anisse@astier.eu> Regards, Anisse -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 24 Nov 2014 22:32:30 +0100 The rc_unregister_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/media/common/siano/smsir.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/media/common/siano/smsir.c b/drivers/media/common/siano/smsir.c index 273043e..35d0e88 100644 --- a/drivers/media/common/siano/smsir.c +++ b/drivers/media/common/siano/smsir.c @@ -107,8 +107,7 @@ int sms_ir_init(struct smscore_device_t *coredev) void sms_ir_exit(struct smscore_device_t *coredev) { - if (coredev->ir.dev) - rc_unregister_device(coredev->ir.dev); + rc_unregister_device(coredev->ir.dev); sms_log(""); } -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 24 Nov 2014 22:58:48 +0100 The backlight_device_unregister() 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/staging/olpc_dcon/olpc_dcon.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/staging/olpc_dcon/olpc_dcon.c b/drivers/staging/olpc_dcon/olpc_dcon.c index eb83b28..6a9a881 100644 --- a/drivers/staging/olpc_dcon/olpc_dcon.c +++ b/drivers/staging/olpc_dcon/olpc_dcon.c @@ -682,8 +682,7 @@ static int dcon_remove(struct i2c_client *client) free_irq(DCON_IRQ, dcon); - if (dcon->bl_dev) - backlight_device_unregister(dcon->bl_dev); + backlight_device_unregister(dcon->bl_dev); if (dcon_device != NULL) platform_device_unregister(dcon_device); -- 2.1.3
>> This issue was detected by using the Coccinelle software. > > What script was used ? A semantic patch approach which I published on the mailing lists in March is in action on my software development system for a while. > Is it in scripts/coccinelle ? Not yet. I hope that the involved update suggestions got sufficient positive feedback to integrate five scripts there. Regards, Markus
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 25 Nov 2014 13:44:20 +0100 The release_firmware() 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/gpu/drm/msm/adreno/adreno_gpu.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/msm/adreno/adreno_gpu.c b/drivers/gpu/drm/msm/adreno/adreno_gpu.c index 655ce5b..757052c 100644 --- a/drivers/gpu/drm/msm/adreno/adreno_gpu.c +++ b/drivers/gpu/drm/msm/adreno/adreno_gpu.c @@ -404,9 +404,7 @@ void adreno_gpu_cleanup(struct adreno_gpu *gpu) msm_gem_put_iova(gpu->memptrs_bo, gpu->base.id); drm_gem_object_unreference(gpu->memptrs_bo); } - if (gpu->pm4) - release_firmware(gpu->pm4); - if (gpu->pfp) - release_firmware(gpu->pfp); + release_firmware(gpu->pm4); + release_firmware(gpu->pfp); msm_gpu_cleanup(&gpu->base); } -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 25 Nov 2014 14:30:28 +0100 The functions framebuffer_release() and vunmap() perform 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/gpu/drm/msm/msm_fbdev.c | 3 +-- drivers/gpu/drm/msm/msm_gem.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_fbdev.c b/drivers/gpu/drm/msm/msm_fbdev.c index ab5bfd2..fd5a6f3 100644 --- a/drivers/gpu/drm/msm/msm_fbdev.c +++ b/drivers/gpu/drm/msm/msm_fbdev.c @@ -193,8 +193,7 @@ fail_unlock: fail: if (ret) { - if (fbi) - framebuffer_release(fbi); + framebuffer_release(fbi); if (fb) { drm_framebuffer_unregister_private(fb); drm_framebuffer_remove(fb); diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c index 4b1b82a..157cf21 100644 --- a/drivers/gpu/drm/msm/msm_gem.c +++ b/drivers/gpu/drm/msm/msm_gem.c @@ -543,8 +543,7 @@ void msm_gem_free_object(struct drm_gem_object *obj) drm_free_large(msm_obj->pages); } else { - if (msm_obj->vaddr) - vunmap(msm_obj->vaddr); + vunmap(msm_obj->vaddr); put_pages(obj); } -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 25 Nov 2014 16:06:19 +0100 The drm_fbdev_cma_restore_mode() 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/staging/imx-drm/imx-drm-core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c index 6b22106..0a1ecef 100644 --- a/drivers/staging/imx-drm/imx-drm-core.c +++ b/drivers/staging/imx-drm/imx-drm-core.c @@ -64,8 +64,7 @@ static void imx_drm_driver_lastclose(struct drm_device *drm) #if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER) struct imx_drm_device *imxdrm = drm->dev_private; - if (imxdrm->fbhelper) - drm_fbdev_cma_restore_mode(imxdrm->fbhelper); + drm_fbdev_cma_restore_mode(imxdrm->fbhelper); #endif } -- 2.1.3
On Sat, Nov 22, 2014 at 7:00 AM, SF Markus Elfring <elfring@users.sourceforge.net> wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sat, 22 Nov 2014 12:55:28 +0100 > > The free_tce_table() 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> Looks good to me Acked-by: Jon Mason <jdmason@kudzu.us> > --- > arch/x86/kernel/pci-calgary_64.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c > index 0497f71..d22a386 100644 > --- a/arch/x86/kernel/pci-calgary_64.c > +++ b/arch/x86/kernel/pci-calgary_64.c > @@ -1476,8 +1476,7 @@ cleanup: > for (--bus; bus >= 0; --bus) { > struct calgary_bus_info *info = &bus_info[bus]; > > - if (info->tce_space) > - free_tce_table(info->tce_space); > + free_tce_table(info->tce_space); > } > return -ENOMEM; > } > -- > 2.1.3 >
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 25 Nov 2014 16:51:08 +0100 The oz_free_urb_link() 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/staging/ozwpan/ozhcd.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/staging/ozwpan/ozhcd.c b/drivers/staging/ozwpan/ozhcd.c index 30bd928..c9b6d98 100644 --- a/drivers/staging/ozwpan/ozhcd.c +++ b/drivers/staging/ozwpan/ozhcd.c @@ -411,8 +411,7 @@ static void oz_complete_urb(struct usb_hcd *hcd, struct urb *urb, } spin_lock(&g_tasklet_lock); spin_unlock_irqrestore(&g_tasklet_lock, irq_state); - if (cancel_urbl) - oz_free_urb_link(cancel_urbl); + oz_free_urb_link(cancel_urbl); } /* @@ -581,8 +580,7 @@ static int oz_dequeue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir, } } spin_unlock_bh(&port->ozhcd->hcd_lock); - if (urbl) - oz_free_urb_link(urbl); + oz_free_urb_link(urbl); return urbl ? 0 : -EIDRM; } -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 25 Nov 2014 22:33:45 +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> Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com> --- drivers/net/hyperv/netvsc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c index 6b46311..6fc834e 100644 --- a/drivers/net/hyperv/netvsc.c +++ b/drivers/net/hyperv/netvsc.c @@ -561,9 +561,7 @@ int netvsc_device_remove(struct hv_device *device) vmbus_close(device->channel); /* Release all resources */ - if (net_device->sub_cb_buf) - vfree(net_device->sub_cb_buf); - + vfree(net_device->sub_cb_buf); free_netvsc_device(net_device); return 0; } -- 2.1.3
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 25 Nov 2014 22:55:34 +0100
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Tue, 25 Nov 2014 22:33:45 +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>
> Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Applied, thanks.
On Sat, Nov 15, 2014 at 07:19:36PM +0100, SF Markus Elfring wrote:
> 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>
Thanks, applied.
- Ted
On Thu, Nov 20, 2014 at 01:55:23PM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 20 Nov 2014 13:50:43 +0100
>
> The functions kfree() and pci_dev_put() test whether their argument is NULL
> and then return immediately. Thus the test around the call is not needed.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Applied to l2-mtd.git.
Brian
On Sun, Nov 23, 2014 at 07:44:08PM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sun, 23 Nov 2014 19:12:29 +0100
>
> The jump label "err1" was used by the ion_buffer_create() function in case of
> a memory allocation failure just to pass a null pointer to a vfree() function
> call by a data structure element.
> This implementation detail could be improved by the deletion of this
> inappropriate jump label.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> drivers/staging/android/ion/ion.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c
> index df12cc3..7a26b85 100644
> --- a/drivers/staging/android/ion/ion.c
> +++ b/drivers/staging/android/ion/ion.c
> @@ -226,7 +226,7 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
> buffer->pages = vmalloc(sizeof(struct page *) * num_pages);
> if (!buffer->pages) {
> ret = -ENOMEM;
> - goto err1;
> + goto err2;
> }
>
> for_each_sg(table->sgl, sg, table->nents, i) {
> @@ -262,7 +262,6 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
> err:
> heap->ops->unmap_dma(heap, buffer);
> heap->ops->free(buffer);
> -err1:
> vfree(buffer->pages);
> err2:
Now we have "err" and "err2", which doesn't make much sense, please fix
up.
>> diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c
>> index df12cc3..7a26b85 100644
>> --- a/drivers/staging/android/ion/ion.c
>> +++ b/drivers/staging/android/ion/ion.c
>> @@ -226,7 +226,7 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
>> buffer->pages = vmalloc(sizeof(struct page *) * num_pages);
>> if (!buffer->pages) {
>> ret = -ENOMEM;
>> - goto err1;
>> + goto err2;
>> }
>>
>> for_each_sg(table->sgl, sg, table->nents, i) {
>> @@ -262,7 +262,6 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
>> err:
>> heap->ops->unmap_dma(heap, buffer);
>> heap->ops->free(buffer);
>> -err1:
>> vfree(buffer->pages);
>> err2:
>
> Now we have "err" and "err2", which doesn't make much sense,
> please fix up.
How do you want this source code to be improved?
Should I introduce longer names for the affected jump labels?
Regards,
Markus
Am 27.11.2014 15:25, schrieb SF Markus Elfring:
>>> diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c
>>> index df12cc3..7a26b85 100644
>>> --- a/drivers/staging/android/ion/ion.c
>>> +++ b/drivers/staging/android/ion/ion.c
>>> @@ -226,7 +226,7 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
>>> buffer->pages = vmalloc(sizeof(struct page *) * num_pages);
>>> if (!buffer->pages) {
>>> ret = -ENOMEM;
>>> - goto err1;
>>> + goto err2;
>>> }
>>>
>>> for_each_sg(table->sgl, sg, table->nents, i) {
>>> @@ -262,7 +262,6 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
>>> err:
>>> heap->ops->unmap_dma(heap, buffer);
>>> heap->ops->free(buffer);
>>> -err1:
>>> vfree(buffer->pages);
>>> err2:
>>
>> Now we have "err" and "err2", which doesn't make much sense,
>> please fix up.
>
> How do you want this source code to be improved?
> Should I introduce longer names for the affected jump labels?
>
hi markus,
the confusion arises because the errX are numbered and now on in the sequence is missing.
So far i see you can renumber them or give more descriptiv names.
hope that helps,
re,
wh
On Mon, 24 Nov 2014, SF Markus Elfring wrote:
> >> This issue was detected by using the Coccinelle software.
> >
> > What script was used ?
>
> A semantic patch approach which I published on the mailing lists in March
> is in action on my software development system for a while.
>
>
> > Is it in scripts/coccinelle ?
>
> Not yet.
>
> I hope that the involved update suggestions got sufficient positive feedback
> to integrate five scripts there.
The current scripts are very complicated, involving the interaction
between multiple scripts and a database, and I think they are not very
suitable for make coccicheck. Also, the idea of removing the null checks
is not appropriate in all contexts. Perhaps it could be possible to add
a script to the Linux kernel that handles a number of common cases for
which removing the null test is widely considered to be desirable.
julia
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
SF Markus Elfring <elfring@users.sourceforge.net> writes:
> 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.
iput() checks NULL of inode. What is wrong just remove NULL check,
instead of adding new jump labels?
Thanks.
--
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
On Sat, 29 Nov 2014, OGAWA Hirofumi wrote:
> SF Markus Elfring <elfring@users.sourceforge.net> writes:
>
> > 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.
>
> iput() checks NULL of inode. What is wrong just remove NULL check,
> instead of adding new jump labels?
Personally, I prefer that code that can be statically determined not to
need to be executed not to be executed. It can make the code easier to
understand, because each function is only called when doing so is useful,
and it can be helpful to static analysis.
julia
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
Julia Lawall <julia.lawall@lip6.fr> writes:
>> iput() checks NULL of inode. What is wrong just remove NULL check,
>> instead of adding new jump labels?
>
> Personally, I prefer that code that can be statically determined not to
> need to be executed not to be executed. It can make the code easier to
> understand, because each function is only called when doing so is useful,
> and it can be helpful to static analysis.
Hm, first of all, we want to prevent the bugs. More labels are more
chances of bug (and we don't care micro optimize on this error path),
isn't it? Increasing the chance of bugs and bothers developers for
analyzer sounds like strange.
(And we are initializing those for avoiding to be bothered by choosing
correct label. If we really care micro optimize, initialization of those
should not be required and should not be touched on other paths, and gcc
can warn its usage.)
Thanks.
--
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
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
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
> More labels are more chances of bug (and we don't care micro optimize > on this error path), isn't it? I would prefer that a few jump targets can be redirected so that unnecessary function calls (and corresponding checks) can be avoided. > Increasing the chance of bugs and bothers developers for analyzer sounds > like strange. There are different opinions around source code clarity. > (And we are initializing those for avoiding to be bothered by choosing > correct label. Pointer initialisation is convenient and safe in some use cases, isn't it? > If we really care micro optimize, initialization of those should not > be required and should not be touched on other paths, and gcc can warn > its usage.) I imagine that a software optimiser can eventually perform better job if unneeded statements could be omitted, couldn't it? Regards, Markus
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 29 Nov 2014 16:23:20 +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> --- drivers/net/ipvlan/ipvlan_main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/ipvlan/ipvlan_main.c b/drivers/net/ipvlan/ipvlan_main.c index 96b71b0..feb1853 100644 --- a/drivers/net/ipvlan/ipvlan_main.c +++ b/drivers/net/ipvlan/ipvlan_main.c @@ -125,8 +125,7 @@ static void ipvlan_uninit(struct net_device *dev) struct ipvl_dev *ipvlan = netdev_priv(dev); struct ipvl_port *port = ipvlan->port; - if (ipvlan->pcpu_stats) - free_percpu(ipvlan->pcpu_stats); + free_percpu(ipvlan->pcpu_stats); port->count -= 1; if (!port->count) -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 29 Nov 2014 16:42:50 +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/notify/inode_mark.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/notify/inode_mark.c b/fs/notify/inode_mark.c index 3daf513..d8157a6 100644 --- a/fs/notify/inode_mark.c +++ b/fs/notify/inode_mark.c @@ -231,8 +231,7 @@ void fsnotify_unmount_inodes(struct list_head *list) */ spin_unlock(&inode_sb_list_lock); - if (need_iput_tmp) - iput(need_iput_tmp); + iput(need_iput_tmp); /* for each watch, send FS_UNMOUNT and then remove it */ fsnotify(inode, FS_UNMOUNT, inode, FSNOTIFY_EVENT_INODE, NULL, 0); -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 29 Nov 2014 17:00:21 +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/namei.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index ca81416..ce69074 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3759,8 +3759,7 @@ exit2: dput(dentry); } mutex_unlock(&nd.path.dentry->d_inode->i_mutex); - if (inode) - iput(inode); /* truncate the inode here */ + iput(inode); /* truncate the inode here */ inode = NULL; if (delegated_inode) { error = break_deleg_wait(&delegated_inode); -- 2.1.3
SF Markus Elfring <elfring@users.sourceforge.net> writes:
>> More labels are more chances of bug (and we don't care micro optimize
>> on this error path), isn't it?
>
> I would prefer that a few jump targets can be redirected so that unnecessary
> function calls (and corresponding checks) can be avoided.
It is from real bugs in my experience, it saw several times those (mine
and other guys, in linux and others). And I think it doesn't have value
to maintain labels for micro optimization in *this error path* though.
So, if you or analyzer can check bugs by the patches affect to those
label usage in future,
Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
--
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 29 Nov 2014 17:40:22 +0100 The functions xfs_blkdev_put() and xfs_qm_dqrele() 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/xfs/xfs_qm.c | 12 +++++------- fs/xfs/xfs_super.c | 3 +-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/fs/xfs/xfs_qm.c b/fs/xfs/xfs_qm.c index d68f230..9a4b50a 100644 --- a/fs/xfs/xfs_qm.c +++ b/fs/xfs/xfs_qm.c @@ -1749,23 +1749,21 @@ xfs_qm_vop_dqalloc( xfs_iunlock(ip, lockflags); if (O_udqpp) *O_udqpp = uq; - else if (uq) + else xfs_qm_dqrele(uq); if (O_gdqpp) *O_gdqpp = gq; - else if (gq) + else xfs_qm_dqrele(gq); if (O_pdqpp) *O_pdqpp = pq; - else if (pq) + else xfs_qm_dqrele(pq); return 0; error_rele: - if (gq) - xfs_qm_dqrele(gq); - if (uq) - xfs_qm_dqrele(uq); + xfs_qm_dqrele(gq); + xfs_qm_dqrele(uq); return error; } diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index 206b97f..97eaa25 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -796,8 +796,7 @@ xfs_open_devices( out_free_ddev_targ: xfs_free_buftarg(mp, mp->m_ddev_targp); out_close_rtdev: - if (rtdev) - xfs_blkdev_put(rtdev); + xfs_blkdev_put(rtdev); out_close_logdev: if (logdev && logdev != ddev) xfs_blkdev_put(logdev); -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 29 Nov 2014 17:55:39 +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> --- fs/dlm/lockspace.c | 3 +-- fs/dlm/memory.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c index f3e7278..b660b93 100644 --- a/fs/dlm/lockspace.c +++ b/fs/dlm/lockspace.c @@ -674,8 +674,7 @@ static int new_lockspace(const char *name, const char *cluster, out_lkbidr: idr_destroy(&ls->ls_lkbidr); for (i = 0; i < DLM_REMOVE_NAMES_MAX; i++) { - if (ls->ls_remove_names[i]) - kfree(ls->ls_remove_names[i]); + kfree(ls->ls_remove_names[i]); } out_rsbtbl: vfree(ls->ls_rsbtbl); diff --git a/fs/dlm/memory.c b/fs/dlm/memory.c index 7cd24bc..2d2eaa0 100644 --- a/fs/dlm/memory.c +++ b/fs/dlm/memory.c @@ -86,8 +86,7 @@ void dlm_free_lkb(struct dlm_lkb *lkb) struct dlm_user_args *ua; ua = lkb->lkb_ua; if (ua) { - if (ua->lksb.sb_lvbptr) - kfree(ua->lksb.sb_lvbptr); + kfree(ua->lksb.sb_lvbptr); kfree(ua); } } -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 29 Nov 2014 18:34:20 +0100 The clk_disable() 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/spi/spi-txx9.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/spi/spi-txx9.c b/drivers/spi/spi-txx9.c index 0da7c67..9190124 100644 --- a/drivers/spi/spi-txx9.c +++ b/drivers/spi/spi-txx9.c @@ -402,8 +402,7 @@ exit_busy: exit: if (c->workqueue) destroy_workqueue(c->workqueue); - if (c->clk) - clk_disable(c->clk); + clk_disable(c->clk); spi_master_put(master); return ret; } -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 29 Nov 2014 18:55:40 +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> --- drivers/net/ethernet/pasemi/pasemi_mac.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/pasemi/pasemi_mac.c b/drivers/net/ethernet/pasemi/pasemi_mac.c index 30d934d..44e8d7d 100644 --- a/drivers/net/ethernet/pasemi/pasemi_mac.c +++ b/drivers/net/ethernet/pasemi/pasemi_mac.c @@ -1837,10 +1837,8 @@ pasemi_mac_probe(struct pci_dev *pdev, const struct pci_device_id *ent) return err; out: - if (mac->iob_pdev) - pci_dev_put(mac->iob_pdev); - if (mac->dma_pdev) - pci_dev_put(mac->dma_pdev); + pci_dev_put(mac->iob_pdev); + pci_dev_put(mac->dma_pdev); free_netdev(dev); out_disable_device: -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 30 Nov 2014 10:59:10 +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> --- drivers/acpi/ioapic.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/acpi/ioapic.c b/drivers/acpi/ioapic.c index 9a631a6..35963d3 100644 --- a/drivers/acpi/ioapic.c +++ b/drivers/acpi/ioapic.c @@ -185,8 +185,7 @@ exit_disable: if (dev) pci_disable_device(dev); exit_put: - if (dev) - pci_dev_put(dev); + pci_dev_put(dev); exit_free: kfree(ioapic); exit: -- 2.1.3
Applied to my tree: https://github.com/PeterHuewe/linux-tpmdd for-james Will be included in the next pull-request. Thanks, Peter
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 30 Nov 2014 17:25:40 +0100 Further update suggestions were taken into account after a patch was applied from static source code analysis. Markus Elfring (3): Deletion of unnecessary checks before the function call "kfree" Less function calls in mppe_alloc() after error detection Delete an unnecessary assignment drivers/net/ppp/ppp_mppe.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 30 Nov 2014 17:02:07 +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> --- drivers/net/ppp/ppp_mppe.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/net/ppp/ppp_mppe.c b/drivers/net/ppp/ppp_mppe.c index 911b216..7e44212 100644 --- a/drivers/net/ppp/ppp_mppe.c +++ b/drivers/net/ppp/ppp_mppe.c @@ -238,8 +238,7 @@ static void *mppe_alloc(unsigned char *options, int optlen) return (void *)state; out_free: - if (state->sha1_digest) - kfree(state->sha1_digest); + kfree(state->sha1_digest); if (state->sha1) crypto_free_hash(state->sha1); if (state->arc4) @@ -256,13 +255,12 @@ static void mppe_free(void *arg) { struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg; if (state) { - if (state->sha1_digest) kfree(state->sha1_digest); - if (state->sha1) - crypto_free_hash(state->sha1); - if (state->arc4) - crypto_free_blkcipher(state->arc4); - kfree(state); + if (state->sha1) + crypto_free_hash(state->sha1); + if (state->arc4) + crypto_free_blkcipher(state->arc4); + kfree(state); } } -- 2.1.3
From 06c1a0fff81142dfa6d933479e17bb1b45ab9dc7 Mon Sep 17 00:00:00 2001 From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 30 Nov 2014 17:07:34 +0100 The functions crypto_free_blkcipher((), crypto_free_hash() and kfree() could be called in some cases by the mppe_alloc() function during error handling even if the passed data structure element contained still a null pointer. This implementation detail could be improved by adjustments for jump labels. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/net/ppp/ppp_mppe.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/drivers/net/ppp/ppp_mppe.c b/drivers/net/ppp/ppp_mppe.c index 7e44212..962c1a0 100644 --- a/drivers/net/ppp/ppp_mppe.c +++ b/drivers/net/ppp/ppp_mppe.c @@ -197,11 +197,11 @@ static void *mppe_alloc(unsigned char *options, int optlen) if (optlen != CILEN_MPPE + sizeof(state->master_key) || options[0] != CI_MPPE || options[1] != CILEN_MPPE) - goto out; + return NULL; state = kzalloc(sizeof(*state), GFP_KERNEL); if (state = NULL) - goto out; + return NULL; state->arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC); @@ -213,16 +213,16 @@ static void *mppe_alloc(unsigned char *options, int optlen) state->sha1 = crypto_alloc_hash("sha1", 0, CRYPTO_ALG_ASYNC); if (IS_ERR(state->sha1)) { state->sha1 = NULL; - goto out_free; + goto out_free_blkcipher; } digestsize = crypto_hash_digestsize(state->sha1); if (digestsize < MPPE_MAX_KEY_LEN) - goto out_free; + goto out_free_hash; state->sha1_digest = kmalloc(digestsize, GFP_KERNEL); if (!state->sha1_digest) - goto out_free; + goto out_free_hash; /* Save keys. */ memcpy(state->master_key, &options[CILEN_MPPE], @@ -237,14 +237,12 @@ static void *mppe_alloc(unsigned char *options, int optlen) return (void *)state; - out_free: - kfree(state->sha1_digest); - if (state->sha1) - crypto_free_hash(state->sha1); - if (state->arc4) - crypto_free_blkcipher(state->arc4); - kfree(state); - out: +out_free_hash: + crypto_free_hash(state->sha1); +out_free_blkcipher: + crypto_free_blkcipher(state->arc4); +out_free: + kfree(state); return NULL; } -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 30 Nov 2014 17:17:36 +0100 The data structure element "arc4" was assigned a null pointer by the mppe_alloc() function if a previous function call "crypto_alloc_blkcipher" failed. This assignment became unnecessary with previous source code adjustments. Let us delete it from the affected implementation because the element "arc4" will not be accessible outside the function after the detected allocation failure. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/net/ppp/ppp_mppe.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/net/ppp/ppp_mppe.c b/drivers/net/ppp/ppp_mppe.c index 962c1a0..d913bc9 100644 --- a/drivers/net/ppp/ppp_mppe.c +++ b/drivers/net/ppp/ppp_mppe.c @@ -205,10 +205,8 @@ static void *mppe_alloc(unsigned char *options, int optlen) state->arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC); - if (IS_ERR(state->arc4)) { - state->arc4 = NULL; + if (IS_ERR(state->arc4)) goto out_free; - } state->sha1 = crypto_alloc_hash("sha1", 0, CRYPTO_ALG_ASYNC); if (IS_ERR(state->sha1)) { -- 2.1.3
On 29.11.2014 19:00, SF Markus Elfring wrote:
> out:
> - if (mac->iob_pdev)
> - pci_dev_put(mac->iob_pdev);
> - if (mac->dma_pdev)
> - pci_dev_put(mac->dma_pdev);
> + pci_dev_put(mac->iob_pdev);
> + pci_dev_put(mac->dma_pdev);
>
> free_netdev(dev);
> out_disable_device:
>
Hi,
I know there has been some criticism about those kind of "code
improvements" already but i would like to point out just one more thing:
Some of those NULL pointer checks on input parameters may have been
added subsequently to functions. So there may be older kernel versions
out there in which those checks dont exists in some cases. If some of
the now "cleaned up" code is backported to such a kernel chances are
good that those missing checks are overseen. And then neither caller nor
callee is doing the NULL pointer check.
Quite frankly i would vote for the opposite approach: Never rely on the
callee do to checks for NULL and do it always in the caller. An
exception could be for calls on a fast path. But most of those checks
are done on error paths anyway.
Just my 2 cents.
Regards,
Lino
On Sun, 30 Nov 2014, Lino Sanfilippo wrote:
> On 29.11.2014 19:00, SF Markus Elfring wrote:
>
> > out:
> > - if (mac->iob_pdev)
> > - pci_dev_put(mac->iob_pdev);
> > - if (mac->dma_pdev)
> > - pci_dev_put(mac->dma_pdev);
> > + pci_dev_put(mac->iob_pdev);
> > + pci_dev_put(mac->dma_pdev);
> >
> > free_netdev(dev);
> > out_disable_device:
> >
>
> Hi,
>
> I know there has been some criticism about those kind of "code
> improvements" already but i would like to point out just one more thing:
>
> Some of those NULL pointer checks on input parameters may have been
> added subsequently to functions. So there may be older kernel versions
> out there in which those checks dont exists in some cases. If some of
> the now "cleaned up" code is backported to such a kernel chances are
> good that those missing checks are overseen. And then neither caller nor
> callee is doing the NULL pointer check.
>
> Quite frankly i would vote for the opposite approach: Never rely on the
> callee do to checks for NULL and do it always in the caller. An
> exception could be for calls on a fast path. But most of those checks
> are done on error paths anyway.
I have heard of at least one case where the problem you are raising
happened in practice...
julia
On 30.11.2014 18:47, Julia Lawall wrote:
>
> I have heard of at least one case where the problem you are raising
> happened in practice...
>
> julia
If one case is known then there are probably a lot more that have not
been discovered yet.
Maybe this topic should be clarified somewhere (e.g. in "CodingStyle")?
On the other hand i always found it obvious that its the callers
responsibility to only pass sane parameters to the called functions...
Regards,
Lino
On Sun, 2014-11-30 at 17:47 +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sun, 30 Nov 2014 17:17:36 +0100
>
> The data structure element "arc4" was assigned a null pointer by the
> mppe_alloc() function if a previous function call "crypto_alloc_blkcipher"
> failed. This assignment became unnecessary with previous source
> code adjustments.
> Let us delete it from the affected implementation because the element "arc4"
> will not be accessible outside the function after the detected
> allocation failure.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> drivers/net/ppp/ppp_mppe.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/net/ppp/ppp_mppe.c b/drivers/net/ppp/ppp_mppe.c
> index 962c1a0..d913bc9 100644
> --- a/drivers/net/ppp/ppp_mppe.c
> +++ b/drivers/net/ppp/ppp_mppe.c
> @@ -205,10 +205,8 @@ static void *mppe_alloc(unsigned char *options, int optlen)
>
>
> state->arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
> - if (IS_ERR(state->arc4)) {
> - state->arc4 = NULL;
> + if (IS_ERR(state->arc4))
> goto out_free;
> - }
>
> state->sha1 = crypto_alloc_hash("sha1", 0, CRYPTO_ALG_ASYNC);
> if (IS_ERR(state->sha1)) {
I have no idea why its a patch on its own, and why state->arc4 gets
special treatment while state->sha1 does not.
This definitely belongs to the previous patch, refactoring error
handling in mppe_alloc()
Also, it seems your patches do not fix bugs, so so you need to target
net-next tree, as explained in Documentation/networking/netdev-FAQ.txt
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 30 Nov 2014 20:50:15 +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 "release_firmware" One function call less in si2157_init() after error detection drivers/media/tuners/si2157.c | 9 ++++----- drivers/media/tuners/xc5000.c | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-) -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 30 Nov 2014 19:05:48 +0100 The release_firmware() 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/media/tuners/si2157.c | 3 +-- drivers/media/tuners/xc5000.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/media/tuners/si2157.c b/drivers/media/tuners/si2157.c index 8e57696..e17ab1f 100644 --- a/drivers/media/tuners/si2157.c +++ b/drivers/media/tuners/si2157.c @@ -196,8 +196,7 @@ warm: return 0; err: - if (fw) - release_firmware(fw); + release_firmware(fw); dev_dbg(&s->client->dev, "failed=%d\n", ret); return ret; diff --git a/drivers/media/tuners/xc5000.c b/drivers/media/tuners/xc5000.c index 705c258..2a039de 100644 --- a/drivers/media/tuners/xc5000.c +++ b/drivers/media/tuners/xc5000.c @@ -1336,8 +1336,7 @@ static int xc5000_release(struct dvb_frontend *fe) if (priv) { cancel_delayed_work(&priv->timer_sleep); - if (priv->firmware) - release_firmware(priv->firmware); + release_firmware(priv->firmware); hybrid_tuner_release_state(priv); } -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 30 Nov 2014 20:48:24 +0100 The release_firmware() function was called in some cases by the si2157_init() 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. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/media/tuners/si2157.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/media/tuners/si2157.c b/drivers/media/tuners/si2157.c index e17ab1f..2180de9 100644 --- a/drivers/media/tuners/si2157.c +++ b/drivers/media/tuners/si2157.c @@ -157,7 +157,7 @@ static int si2157_init(struct dvb_frontend *fe) dev_err(&s->client->dev, "firmware file '%s' is invalid\n", fw_file); ret = -EINVAL; - goto err; + goto fw_release_exit; } dev_info(&s->client->dev, "downloading firmware from file '%s'\n", @@ -173,7 +173,7 @@ static int si2157_init(struct dvb_frontend *fe) dev_err(&s->client->dev, "firmware download failed=%d\n", ret); - goto err; + goto fw_release_exit; } } @@ -195,9 +195,9 @@ warm: s->active = true; return 0; -err: +fw_release_exit: release_firmware(fw); - +err: dev_dbg(&s->client->dev, "failed=%d\n", ret); return ret; } -- 2.1.3
> Maybe this topic should be clarified somewhere (e.g. in "CodingStyle")?
> On the other hand i always found it obvious that its the callers
> responsibility to only pass sane parameters to the called functions...
Can you imagine that any more source code places which would benefit from
check adjustments because of defensive programming?
Regards,
Markus
> I have no idea why its a patch on its own, and why state->arc4 gets > special treatment while state->sha1 does not. I did not fiddle with the data structure element "sha1" because I assumed that it might be still relevant for the call of a function like crypto_free_blkcipher(). > This definitely belongs to the previous patch, refactoring error > handling in mppe_alloc() I have got different preferences for change distribution over several patches here. I find it safer to tackle an assignment clean-up after adjustments for jump labels. > Also, it seems your patches do not fix bugs, so so you need to target > net-next tree, as explained in Documentation/networking/netdev-FAQ.txt Do you want that I resend my update suggestion? Regards, Markus
On 30.11.2014 21:40, SF Markus Elfring wrote:
>> Maybe this topic should be clarified somewhere (e.g. in "CodingStyle")?
>> On the other hand i always found it obvious that its the callers
>> responsibility to only pass sane parameters to the called functions...
>
> Can you imagine that any more source code places which would benefit from
> check adjustments because of defensive programming?
>
I am not sure if i understand your question correctly. But i would not
call sanity checks for function parameters "defensive programming". I
would rather call it not being totally careless. So to me the question
if those checks should be done or not is different from the question
whether there are code parts that would benefit from an adjustment to
defensive programming.
Regards,
Lino
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 30 Nov 2014 22:50:20 +0100 The dvb_unregister_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/media/pci/ddbridge/ddbridge-core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c index c82e855..9e3492e 100644 --- a/drivers/media/pci/ddbridge/ddbridge-core.c +++ b/drivers/media/pci/ddbridge/ddbridge-core.c @@ -1118,8 +1118,7 @@ static void ddb_ports_detach(struct ddb *dev) dvb_input_detach(port->input[1]); break; case DDB_PORT_CI: - if (port->output->dev) - dvb_unregister_device(port->output->dev); + dvb_unregister_device(port->output->dev); if (port->en) { ddb_input_stop(port->input[0]); ddb_output_stop(port->output); -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 30 Nov 2014 23:10:51 +0100 The vb2_put_vma() 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/media/v4l2-core/videobuf2-vmalloc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/media/v4l2-core/videobuf2-vmalloc.c b/drivers/media/v4l2-core/videobuf2-vmalloc.c index 3966b12..fba944e 100644 --- a/drivers/media/v4l2-core/videobuf2-vmalloc.c +++ b/drivers/media/v4l2-core/videobuf2-vmalloc.c @@ -154,8 +154,7 @@ static void vb2_vmalloc_put_userptr(void *buf_priv) } kfree(buf->pages); } else { - if (buf->vma) - vb2_put_vma(buf->vma); + vb2_put_vma(buf->vma); iounmap(buf->vaddr); } kfree(buf); -- 2.1.3
On Sat, Nov 29, 2014 at 05:45:23PM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 29 Nov 2014 17:40:22 +0100
>
> The functions xfs_blkdev_put() and xfs_qm_dqrele() 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>
Looks fine.
Reviewed-by: Dave Chinner <dchinner@redhat.com>
--
Dave Chinner
david@fromorbit.com
> I know there has been some criticism about those kind of "code > improvements" already but i would like to point out just one more thing: > > Some of those NULL pointer checks on input parameters may have been > added subsequently to functions. So there may be older kernel versions > out there in which those checks dont exists in some cases. If some of > the now "cleaned up" code is backported to such a kernel chances are > good that those missing checks are overseen. And then neither caller nor > callee is doing the NULL pointer check. I guess that the Coccinelle software can also help you in this use case. How do you think about to shield against "unwanted" or unexpected collateral evolutions with additional inline functions? I assume that a few backporters can tell you more about their corresponding software development experiences. http://www.do-not-panic.com/2014/04/automatic-linux-kernel-backporting-with-coccinelle.html Regards, Markus
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 1 Dec 2014 05:45:42 +0100 The thermal_zone_device_unregister() 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/thermal/int340x_thermal/int3403_thermal.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/thermal/int340x_thermal/int3403_thermal.c b/drivers/thermal/int340x_thermal/int3403_thermal.c index 6e9fb62..790b8f6 100644 --- a/drivers/thermal/int340x_thermal/int3403_thermal.c +++ b/drivers/thermal/int340x_thermal/int3403_thermal.c @@ -293,8 +293,7 @@ static int int3403_sensor_add(struct int3403_priv *priv) return 0; err_free_obj: - if (obj->tzone) - thermal_zone_device_unregister(obj->tzone); + thermal_zone_device_unregister(obj->tzone); return result; } -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 1 Dec 2014 06:06:57 +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> --- drivers/dma/dmaengine.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c index 24bfaf0..e057935 100644 --- a/drivers/dma/dmaengine.c +++ b/drivers/dma/dmaengine.c @@ -330,8 +330,7 @@ static int __init dma_channel_table_init(void) if (err) { pr_err("initialization failure\n"); for_each_dma_cap_mask(cap, dma_cap_mask_all) - if (channel_table[cap]) - free_percpu(channel_table[cap]); + free_percpu(channel_table[cap]); } return err; -- 2.1.3
On Sat, Nov 29, 2014 at 10:59:47PM +0900, OGAWA Hirofumi wrote:
> Julia Lawall <julia.lawall@lip6.fr> writes:
>
> >> iput() checks NULL of inode. What is wrong just remove NULL check,
> >> instead of adding new jump labels?
> >
> > Personally, I prefer that code that can be statically determined not to
> > need to be executed not to be executed. It can make the code easier to
> > understand, because each function is only called when doing so is useful,
> > and it can be helpful to static analysis.
>
> Hm, first of all, we want to prevent the bugs. More labels are more
> chances of bug (and we don't care micro optimize on this error path),
> isn't it? Increasing the chance of bugs and bothers developers for
> analyzer sounds like strange.
Oh wow! Absolutely not. "One Err Bugs" are one of the most common
kinds of bugs we have in the kernel. This is where you have just one
error label and the bugs look like this:
err:
kfree(foo->bar);
kfree(foo);
but foo is NULL. Mixing the error paths together it always creates
confusion. I fix so many of these bugs... We get a few new ones every
week.
Meanwhile Markus's error labels are absolutely useless. They give no
indication of what going to the label does.
regards,
dan carpenter
On Mon, 1 Dec 2014, Dan Carpenter wrote:
> On Sat, Nov 29, 2014 at 10:59:47PM +0900, OGAWA Hirofumi wrote:
> > Julia Lawall <julia.lawall@lip6.fr> writes:
> >
> > >> iput() checks NULL of inode. What is wrong just remove NULL check,
> > >> instead of adding new jump labels?
> > >
> > > Personally, I prefer that code that can be statically determined not to
> > > need to be executed not to be executed. It can make the code easier to
> > > understand, because each function is only called when doing so is useful,
> > > and it can be helpful to static analysis.
> >
> > Hm, first of all, we want to prevent the bugs. More labels are more
> > chances of bug (and we don't care micro optimize on this error path),
> > isn't it? Increasing the chance of bugs and bothers developers for
> > analyzer sounds like strange.
>
> Oh wow! Absolutely not. "One Err Bugs" are one of the most common
> kinds of bugs we have in the kernel. This is where you have just one
> error label and the bugs look like this:
>
> err:
> kfree(foo->bar);
> kfree(foo);
>
> but foo is NULL. Mixing the error paths together it always creates
> confusion. I fix so many of these bugs... We get a few new ones every
> week.
Just for concreteness, from drivers/clk/st/clkgen-mux.c (- indicates
lines of interest, not lines to remove):
@@ -722,7 +722,6 @@ void __init st_of_clkgen_vcc_setup(struc
return;
clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL);
- if (!clk_data)
goto err;
clk_data->clk_num = VCC_MAX_CHANNELS;
@@ -808,7 +807,6 @@ void __init st_of_clkgen_vcc_setup(struc
return;
err:
- for (i = 0; i < clk_data->clk_num; i++) {
struct clk_composite *composite;
if (!clk_data->clks[i])
julia
Hello, On 2014-11-30 23:23, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sun, 30 Nov 2014 23:10:51 +0100 > > The vb2_put_vma() 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: Marek Szyprowski <m.szyprowski@samsung.com> > --- > drivers/media/v4l2-core/videobuf2-vmalloc.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/media/v4l2-core/videobuf2-vmalloc.c b/drivers/media/v4l2-core/videobuf2-vmalloc.c > index 3966b12..fba944e 100644 > --- a/drivers/media/v4l2-core/videobuf2-vmalloc.c > +++ b/drivers/media/v4l2-core/videobuf2-vmalloc.c > @@ -154,8 +154,7 @@ static void vb2_vmalloc_put_userptr(void *buf_priv) > } > kfree(buf->pages); > } else { > - if (buf->vma) > - vb2_put_vma(buf->vma); > + vb2_put_vma(buf->vma); > iounmap(buf->vaddr); > } > kfree(buf); Best regards -- Marek Szyprowski, PhD Samsung R&D Institute Poland
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 1 Dec 2014 11:18:21 +0100 The ceph_put_snap_context() 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/block/rbd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 27b71a0..3c34ab5 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -3405,8 +3405,7 @@ err_rq: if (result) rbd_warn(rbd_dev, "%s %llx at %llx result %d", obj_op_name(op_type), length, offset, result); - if (snapc) - ceph_put_snap_context(snapc); + ceph_put_snap_context(snapc); blk_end_request_all(rq, result); } -- 2.1.3
On Mon, Dec 1, 2014 at 1:23 PM, SF Markus Elfring
<elfring@users.sourceforge.net> wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Mon, 1 Dec 2014 11:18:21 +0100
>
> The ceph_put_snap_context() 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/block/rbd.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
> index 27b71a0..3c34ab5 100644
> --- a/drivers/block/rbd.c
> +++ b/drivers/block/rbd.c
> @@ -3405,8 +3405,7 @@ err_rq:
> if (result)
> rbd_warn(rbd_dev, "%s %llx at %llx result %d",
> obj_op_name(op_type), length, offset, result);
> - if (snapc)
> - ceph_put_snap_context(snapc);
> + ceph_put_snap_context(snapc);
> blk_end_request_all(rq, result);
> }
>
I squashed it into your "ceph: Deletion of unnecessary checks before two
function calls", which deals with ceph_put_snap_context() in fs/ceph.
Thanks,
Ilya
Hello. On 11/30/2014 7:44 PM, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sun, 30 Nov 2014 17:02:07 +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> > --- > drivers/net/ppp/ppp_mppe.c | 14 ++++++-------- > 1 file changed, 6 insertions(+), 8 deletions(-) > diff --git a/drivers/net/ppp/ppp_mppe.c b/drivers/net/ppp/ppp_mppe.c > index 911b216..7e44212 100644 > --- a/drivers/net/ppp/ppp_mppe.c > +++ b/drivers/net/ppp/ppp_mppe.c > @@ -238,8 +238,7 @@ static void *mppe_alloc(unsigned char *options, int optlen) > return (void *)state; > > out_free: > - if (state->sha1_digest) > - kfree(state->sha1_digest); > + kfree(state->sha1_digest); Please keep this line aligned to the others. > if (state->sha1) > crypto_free_hash(state->sha1); > if (state->arc4) [...] WBR, Sergei
>> diff --git a/drivers/net/ppp/ppp_mppe.c b/drivers/net/ppp/ppp_mppe.c
>> index 911b216..7e44212 100644
>> --- a/drivers/net/ppp/ppp_mppe.c
>> +++ b/drivers/net/ppp/ppp_mppe.c
>> @@ -238,8 +238,7 @@ static void *mppe_alloc(unsigned char *options, int optlen)
>> return (void *)state;
>>
>> out_free:
>> - if (state->sha1_digest)
>> - kfree(state->sha1_digest);
>> + kfree(state->sha1_digest);
>
> Please keep this line aligned to the others.
Can it be that the previous source code contained unwanted space
characters at this place?
Do you want indentation fixes as a separate update step?
Regards,
Markus
> Mixing the error paths together it always creates confusion. > I fix so many of these bugs... We get a few new ones every week. Would you like to get help here from any other automatic semantic patch approaches? > Meanwhile Markus's error labels are absolutely useless. They give no > indication of what going to the label does. Which names would be better acceptable for you? Regards, Markus
[-- Attachment #1: Type: text/plain, Size: 1612 bytes --] On Tue, Nov 25, 2014 at 01:50:25PM +0100, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> You can probably get rid of this if you configure your emailer properly. > Date: Tue, 25 Nov 2014 13:44:20 +0100 This is odd. I've never seen git send-email generate these. I didn't notice with your earlier patches, but the subject prefix is wrong. Please use something more consistent with existing patches, in this case: "drm/msm: ..." or "drm/msm/adreno: ..." > The release_firmware() 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/gpu/drm/msm/adreno/adreno_gpu.c | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/drivers/gpu/drm/msm/adreno/adreno_gpu.c b/drivers/gpu/drm/msm/adreno/adreno_gpu.c > index 655ce5b..757052c 100644 > --- a/drivers/gpu/drm/msm/adreno/adreno_gpu.c > +++ b/drivers/gpu/drm/msm/adreno/adreno_gpu.c > @@ -404,9 +404,7 @@ void adreno_gpu_cleanup(struct adreno_gpu *gpu) > msm_gem_put_iova(gpu->memptrs_bo, gpu->base.id); > drm_gem_object_unreference(gpu->memptrs_bo); > } > - if (gpu->pm4) > - release_firmware(gpu->pm4); > - if (gpu->pfp) > - release_firmware(gpu->pfp); > + release_firmware(gpu->pm4); > + release_firmware(gpu->pfp); > msm_gpu_cleanup(&gpu->base); > } Besides the subject prefix, Reviewed-by: Thierry Reding <treding@nvidia.com> [-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]
[-- Attachment #1: Type: text/plain, Size: 988 bytes --] On Tue, Nov 25, 2014 at 02:33:53PM +0100, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Tue, 25 Nov 2014 14:30:28 +0100 > > The functions framebuffer_release() and vunmap() perform 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/gpu/drm/msm/msm_fbdev.c | 3 +-- > drivers/gpu/drm/msm/msm_gem.c | 3 +-- > 2 files changed, 2 insertions(+), 4 deletions(-) This needs the same fix for the subject prefix that I mentioned for your other patch, otherwise: Reviewed-by: Thierry Reding <treding@nvidia.com> Perhaps a good idea would be to send all of these patches with the subject prefix fixed up as a second version and threaded in a series. That makes it easier for people to pick them up (assuming Dave will take them directly). Thierry [-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]
On Mon, Dec 1, 2014 at 11:04 AM, Thierry Reding <thierry.reding@gmail.com> wrote: > On Tue, Nov 25, 2014 at 02:33:53PM +0100, SF Markus Elfring wrote: >> From: Markus Elfring <elfring@users.sourceforge.net> >> Date: Tue, 25 Nov 2014 14:30:28 +0100 >> >> The functions framebuffer_release() and vunmap() perform 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/gpu/drm/msm/msm_fbdev.c | 3 +-- >> drivers/gpu/drm/msm/msm_gem.c | 3 +-- >> 2 files changed, 2 insertions(+), 4 deletions(-) > > This needs the same fix for the subject prefix that I mentioned for your > other patch, otherwise: > > Reviewed-by: Thierry Reding <treding@nvidia.com> > > Perhaps a good idea would be to send all of these patches with the > subject prefix fixed up as a second version and threaded in a series. > That makes it easier for people to pick them up (assuming Dave will take > them directly). > no worries, I'll fix up the subject lines when I apply.. BR, -R > Thierry > > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > http://lists.freedesktop.org/mailman/listinfo/dri-devel >
btw, I have these two queued up on msm-next, thanks
BR,
-R
On Tue, Nov 25, 2014 at 8:33 AM, SF Markus Elfring
<elfring@users.sourceforge.net> wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Tue, 25 Nov 2014 14:30:28 +0100
>
> The functions framebuffer_release() and vunmap() perform 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/gpu/drm/msm/msm_fbdev.c | 3 +--
> drivers/gpu/drm/msm/msm_gem.c | 3 +--
> 2 files changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/msm/msm_fbdev.c b/drivers/gpu/drm/msm/msm_fbdev.c
> index ab5bfd2..fd5a6f3 100644
> --- a/drivers/gpu/drm/msm/msm_fbdev.c
> +++ b/drivers/gpu/drm/msm/msm_fbdev.c
> @@ -193,8 +193,7 @@ fail_unlock:
> fail:
>
> if (ret) {
> - if (fbi)
> - framebuffer_release(fbi);
> + framebuffer_release(fbi);
> if (fb) {
> drm_framebuffer_unregister_private(fb);
> drm_framebuffer_remove(fb);
> diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
> index 4b1b82a..157cf21 100644
> --- a/drivers/gpu/drm/msm/msm_gem.c
> +++ b/drivers/gpu/drm/msm/msm_gem.c
> @@ -543,8 +543,7 @@ void msm_gem_free_object(struct drm_gem_object *obj)
> drm_free_large(msm_obj->pages);
>
> } else {
> - if (msm_obj->vaddr)
> - vunmap(msm_obj->vaddr);
> + vunmap(msm_obj->vaddr);
> put_pages(obj);
> }
>
> --
> 2.1.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
On 12/01/2014 06:00 PM, SF Markus Elfring wrote: >>> diff --git a/drivers/net/ppp/ppp_mppe.c b/drivers/net/ppp/ppp_mppe.c >>> index 911b216..7e44212 100644 >>> --- a/drivers/net/ppp/ppp_mppe.c >>> +++ b/drivers/net/ppp/ppp_mppe.c >>> @@ -238,8 +238,7 @@ static void *mppe_alloc(unsigned char *options, int optlen) >>> return (void *)state; >>> >>> out_free: >>> - if (state->sha1_digest) >>> - kfree(state->sha1_digest); >>> + kfree(state->sha1_digest); >> Please keep this line aligned to the others. > Can it be that the previous source code contained unwanted space > characters at this place? Yes, it seems so. > Do you want indentation fixes as a separate update step? Yes, that would be better to keep it separate. > Regards, > Markus WBR, Sergei
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 1 Dec 2014 18:15:46 +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> --- drivers/block/skd_main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/block/skd_main.c b/drivers/block/skd_main.c index 1e46eb2..c4b0259 100644 --- a/drivers/block/skd_main.c +++ b/drivers/block/skd_main.c @@ -3998,8 +3998,7 @@ static int skd_acquire_msix(struct skd_device *skdev) return 0; msix_out: - if (entries) - kfree(entries); + kfree(entries); skd_release_msix(skdev); return rc; } -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 1 Dec 2014 19:19:25 +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/block/rsxx/dma.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/block/rsxx/dma.c b/drivers/block/rsxx/dma.c index cf8cd29..0181387 100644 --- a/drivers/block/rsxx/dma.c +++ b/drivers/block/rsxx/dma.c @@ -960,8 +960,7 @@ failed_dma_setup: ctrl->done_wq = NULL; } - if (ctrl->trackers) - vfree(ctrl->trackers); + vfree(ctrl->trackers); if (ctrl->status.buf) pci_free_consistent(card->dev, STATUS_BUFFER_SIZE8, -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 1 Dec 2014 19:49:39 +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/staging/media/lirc/lirc_zilog.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/staging/media/lirc/lirc_zilog.c b/drivers/staging/media/lirc/lirc_zilog.c index 3259aac..50b255a 100644 --- a/drivers/staging/media/lirc/lirc_zilog.c +++ b/drivers/staging/media/lirc/lirc_zilog.c @@ -729,11 +729,9 @@ static int send_boot_data(struct IR_tx *tx) static void fw_unload_locked(void) { if (tx_data) { - if (tx_data->code_sets) - vfree(tx_data->code_sets); + vfree(tx_data->code_sets); - if (tx_data->datap) - vfree(tx_data->datap); + vfree(tx_data->datap); vfree(tx_data); tx_data = NULL; -- 2.1.3
On Mon, Dec 01, 2014 at 04:30:44PM +0100, SF Markus Elfring wrote:
> > Meanwhile Markus's error labels are absolutely useless. They give no
> > indication of what going to the label does.
>
> Which names would be better acceptable for you?
You named it after the goto location but the label name should be based
on the label location to say what the goto does. Something like
"err_put_fsinfo", "err_put_fat", and "err_unload" or like that.
regards,
dan carpenter
[-- Attachment #1: Type: text/plain, Size: 402 bytes --] On Sat, Nov 29, 2014 at 06:40:28PM +0100, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sat, 29 Nov 2014 18:34:20 +0100 > > The clk_disable() function tests whether its argument is NULL and then > returns immediately. Thus the test around the call is not needed. Applied, but please do try to use subject lines matching the style for the subsystem. [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 473 bytes --]
On Mon, 2014-12-01 at 02:34 +0100, SF Markus Elfring wrote: > > Some of those NULL pointer checks on input parameters may have been > > added subsequently to functions. So there may be older kernel versions > > out there in which those checks dont exists in some cases. If some of > > the now "cleaned up" code is backported to such a kernel chances are > > good that those missing checks are overseen. And then neither caller nor > > callee is doing the NULL pointer check. > I assume that a few backporters can tell you more about their corresponding > software development experiences. > http://www.do-not-panic.com/2014/04/automatic-linux-kernel-backporting-with-coccinelle.html In such cases we just provide an appropriate wrapper and replace callers of the original function by callers of the wrapper, typically with a #define. So this kind of evolution is no problem for the (automated) backports using the backports project - although it can be difficult to detect such a thing is needed. johannes
On Mon, 1 Dec 2014, Johannes Berg wrote:
> On Mon, 2014-12-01 at 02:34 +0100, SF Markus Elfring wrote:
>
> > > Some of those NULL pointer checks on input parameters may have been
> > > added subsequently to functions. So there may be older kernel versions
> > > out there in which those checks dont exists in some cases. If some of
> > > the now "cleaned up" code is backported to such a kernel chances are
> > > good that those missing checks are overseen. And then neither caller nor
> > > callee is doing the NULL pointer check.
>
> > I assume that a few backporters can tell you more about their corresponding
> > software development experiences.
> > http://www.do-not-panic.com/2014/04/automatic-linux-kernel-backporting-with-coccinelle.html
>
> In such cases we just provide an appropriate wrapper and replace callers
> of the original function by callers of the wrapper, typically with a
> #define.
>
> So this kind of evolution is no problem for the (automated) backports
> using the backports project - although it can be difficult to detect
> such a thing is needed.
That is exactly the problem...
julia
On Sat, Nov 29, 2014 at 10:00 AM, SF Markus Elfring
<elfring@users.sourceforge.net> wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 29 Nov 2014 18:55:40 +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>
For this particular case:
Acked-by: Olof Johansson <olof@lixom.net>
Note that the "this might cause problems with backports" case is
mostly academic in the scope of _this particular driver_. It's still a
very valid discussion and issue though.
So I'll be happy to give the ack on this driver, but the larger
problem needs consideration still.
-Olof
>> Which names would be better acceptable for you? > > You named it after the goto location but the label name should be based > on the label location to say what the goto does. I find it easier occasionally to name a label similarly to the jump target. It seems that there are a few variations used for the affected identifiers. > Something like "err_put_fsinfo", "err_put_fat", and "err_unload" or like that. How do you think about to provide a patch with your preferred names if my chances are lower to suggest the pleasing ones directly in my first tries? Regards, Markus
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 1 Dec 2014 23:16:34 +0100 Another update suggestion was taken into account after a patch was applied from static source code analysis. Markus Elfring (2): Deletion of an unnecessary check before the function call "release_firmware" One function call less in mn88473_init() after error detection drivers/staging/media/mn88473/mn88473.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 1 Dec 2014 22:55:29 +0100 The release_firmware() 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/staging/media/mn88473/mn88473.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/staging/media/mn88473/mn88473.c b/drivers/staging/media/mn88473/mn88473.c index 1659335..52180bb 100644 --- a/drivers/staging/media/mn88473/mn88473.c +++ b/drivers/staging/media/mn88473/mn88473.c @@ -262,8 +262,7 @@ static int mn88473_init(struct dvb_frontend *fe) return 0; err: - if (fw) - release_firmware(fw); + release_firmware(fw); dev_dbg(&client->dev, "failed=%d\n", ret); return ret; -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 1 Dec 2014 23:15:20 +0100 The release_firmware() function was called by the mn88473_init() function even if a previous function call "request_firmware" failed. This implementation detail could be improved by the introduction of another jump label. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/staging/media/mn88473/mn88473.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/staging/media/mn88473/mn88473.c b/drivers/staging/media/mn88473/mn88473.c index 52180bb..a333744 100644 --- a/drivers/staging/media/mn88473/mn88473.c +++ b/drivers/staging/media/mn88473/mn88473.c @@ -225,7 +225,7 @@ static int mn88473_init(struct dvb_frontend *fe) ret = request_firmware(&fw, fw_file, &client->dev); if (ret) { dev_err(&client->dev, "firmare file '%s' not found\n", fw_file); - goto err; + goto err_request_firmware; } dev_info(&client->dev, "downloading firmware from file '%s'\n", @@ -261,9 +261,10 @@ static int mn88473_init(struct dvb_frontend *fe) dev->warm = true; return 0; + err: release_firmware(fw); - +err_request_firmware: dev_dbg(&client->dev, "failed=%d\n", ret); return ret; } -- 2.1.3
On Sat, Nov 29, 2014 at 7:30 AM, SF Markus Elfring <elfring@users.sourceforge.net> wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sat, 29 Nov 2014 16:23:20 +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> Acked-by: Mahesh Bandewar <maheshb@google.com> > --- > drivers/net/ipvlan/ipvlan_main.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/net/ipvlan/ipvlan_main.c b/drivers/net/ipvlan/ipvlan_main.c > index 96b71b0..feb1853 100644 > --- a/drivers/net/ipvlan/ipvlan_main.c > +++ b/drivers/net/ipvlan/ipvlan_main.c > @@ -125,8 +125,7 @@ static void ipvlan_uninit(struct net_device *dev) > struct ipvl_dev *ipvlan = netdev_priv(dev); > struct ipvl_port *port = ipvlan->port; > > - if (ipvlan->pcpu_stats) > - free_percpu(ipvlan->pcpu_stats); > + free_percpu(ipvlan->pcpu_stats); > > port->count -= 1; > if (!port->count) > -- > 2.1.3 > > -- > To unsubscribe from this list: send the line "unsubscribe netdev" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html
On Mon, Dec 01, 2014 at 10:22:38PM +0100, SF Markus Elfring wrote: > >> Which names would be better acceptable for you? > > > > You named it after the goto location but the label name should be based > > on the label location to say what the goto does. > > I find it easier occasionally to name a label similarly to the jump target. That is a useless thing to do. > It seems that there are a few variations used for the affected identifiers. There is a lot of crap code in the kernel, yes. regards, dan carpenter
On Tue, 2 Dec 2014, Dan Carpenter wrote:
> On Mon, Dec 01, 2014 at 10:22:38PM +0100, SF Markus Elfring wrote:
> > >> Which names would be better acceptable for you?
> > >
> > > You named it after the goto location but the label name should be based
> > > on the label location to say what the goto does.
> >
> > I find it easier occasionally to name a label similarly to the jump target.
>
> That is a useless thing to do.
>
> > It seems that there are a few variations used for the affected identifiers.
>
> There is a lot of crap code in the kernel, yes.
Does the label naming strategy appear in the conding style documentation
anywhere? There are so many variants that just from looking at the code,
it is hard to guess what is the best strategy. For example, out1, out2,
etc are pretty uninformative, but they are concise and easy to spell
correctly.
julia
I added a paragraph on choosing label names, and updated the example code to use a better label name. I also cleaned up the example code to more modern style by moving the allocation out of the initializer and changing the NULL check. Perhaps the most common type of error handling bug in the kernel is "one err bugs". CodingStyle already says that we should "avoid nesting" by using error labels and one err style error handling tends to have multiple indent levels, so this was already bad style. But I've added a new paragraph explaining how to avoid one err bugs by using multiple error labels which is, hopefully, more clear. Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle index 9f28b14..9c8a234 100644 --- a/Documentation/CodingStyle +++ b/Documentation/CodingStyle @@ -392,7 +392,12 @@ The goto statement comes in handy when a function exits from multiple locations and some common work such as cleanup has to be done. If there is no cleanup needed then just return directly. -The rationale is: +Choose label names which say what the goto does or why the goto exists. An +example of a good name could be "out_buffer:" if the goto frees "buffer". Avoid +using GW-BASIC names like "err1:" and "err2:". Also don't name them after the +goto location like "err_kmalloc_failed:" + +The rationale for using gotos is: - unconditional statements are easier to understand and follow - nesting is reduced @@ -403,9 +408,10 @@ The rationale is: int fun(int a) { int result = 0; - char *buffer = kmalloc(SIZE); + char *buffer; - if (buffer = NULL) + buffer = kmalloc(SIZE); + if (!buffer) return -ENOMEM; if (condition1) { @@ -413,14 +419,25 @@ int fun(int a) ... } result = 1; - goto out; + goto out_buffer; } ... -out: +out_buffer: kfree(buffer); return result; } +A common type of bug to be aware of it "one err bugs" which look like this: + +err: + kfree(foo->bar); + kfree(foo); + return ret; + +The bug in this code is that on some exit paths "foo" is NULL. Normally the +fix for this is to split it up into two error labels "err_bar:" and "err_foo:". + + Chapter 8: Commenting Comments are good, but there is also a danger of over-commenting. NEVER
> @@ -403,9 +408,10 @@ The rationale is: > int fun(int a) > { > int result = 0; > - char *buffer = kmalloc(SIZE); > + char *buffer; > > - if (buffer = NULL) > + buffer = kmalloc(SIZE); kmalloc actually takes two arguments. Perhaps it would be better to show something that looks like a valid call. Otherwise, Acked-by: Julia Lawall <julia.lawall@lip6.fr> julia > + if (!buffer) > return -ENOMEM; > > if (condition1) { > @@ -413,14 +419,25 @@ int fun(int a) > ... > } > result = 1; > - goto out; > + goto out_buffer; > } > ... > -out: > +out_buffer: > kfree(buffer); > return result; > } > > +A common type of bug to be aware of it "one err bugs" which look like this: > + > +err: > + kfree(foo->bar); > + kfree(foo); > + return ret; > + > +The bug in this code is that on some exit paths "foo" is NULL. Normally the > +fix for this is to split it up into two error labels "err_bar:" and "err_foo:". > + > + > Chapter 8: Commenting > > Comments are good, but there is also a danger of over-commenting. NEVER > -- > To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >
[-- Attachment #1: Type: text/plain, Size: 736 bytes --] On Sun, Nov 23, 2014 at 07:39:23PM +0100, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sun, 23 Nov 2014 18:48:15 +0100 > > The functions ion_heap_destroy() and vfree() perform 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/staging/android/ion/ion.c | 6 ++---- > drivers/staging/android/ion/ion_dummy_driver.c | 6 ++---- > drivers/staging/android/ion/tegra/tegra_ion.c | 6 ++---- > 3 files changed, 6 insertions(+), 12 deletions(-) Acked-by: Thierry Reding <treding@nvidia.com> [-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 2 Dec 2014 11:40:33 +0100 The functions free_ll_remote_perm(), free_rmtperm_hash() and iput() test whether their argument is NULL and then return immediately. Thus the test around their calls is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/staging/lustre/lustre/llite/remote_perm.c | 5 ++--- drivers/staging/lustre/lustre/llite/statahead.c | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/staging/lustre/lustre/llite/remote_perm.c b/drivers/staging/lustre/lustre/llite/remote_perm.c index c05a912..a581826 100644 --- a/drivers/staging/lustre/lustre/llite/remote_perm.c +++ b/drivers/staging/lustre/lustre/llite/remote_perm.c @@ -194,7 +194,7 @@ int ll_update_remote_perm(struct inode *inode, struct mdt_remote_perm *perm) if (!lli->lli_remote_perms) lli->lli_remote_perms = perm_hash; - else if (perm_hash) + else free_rmtperm_hash(perm_hash); head = lli->lli_remote_perms + remote_perm_hashfunc(perm->rp_uid); @@ -209,8 +209,7 @@ again: continue; if (tmp->lrp_fsgid != perm->rp_fsgid) continue; - if (lrp) - free_ll_remote_perm(lrp); + free_ll_remote_perm(lrp); lrp = tmp; break; } diff --git a/drivers/staging/lustre/lustre/llite/statahead.c b/drivers/staging/lustre/lustre/llite/statahead.c index 227854b..6ad9dd0 100644 --- a/drivers/staging/lustre/lustre/llite/statahead.c +++ b/drivers/staging/lustre/lustre/llite/statahead.c @@ -334,8 +334,7 @@ static void ll_sa_entry_put(struct ll_statahead_info *sai, LASSERT(ll_sa_entry_unhashed(entry)); ll_sa_entry_cleanup(sai, entry); - if (entry->se_inode) - iput(entry->se_inode); + iput(entry->se_inode); OBD_FREE(entry, entry->se_size); atomic_dec(&sai->sai_cache_count); -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 2 Dec 2014 13:54:00 +0100 The of_node_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> --- drivers/of/unittest.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index cc0c5ec..06ebe9d 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -486,8 +486,7 @@ static void __init of_selftest_changeset(void) /* Make sure node names are constructed correctly */ selftest((np = of_find_node_by_path("/testcase-data/changeset/n2/n21")), "'%s' not added\n", n21->full_name); - if (np) - of_node_put(np); + of_node_put(np); mutex_lock(&of_mutex); selftest(!of_changeset_revert(&chgset), "revert failed\n"); -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 2 Dec 2014 14:34:30 +0100 The clk_disable() 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/soc/sh/fsi.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/sound/soc/sh/fsi.c b/sound/soc/sh/fsi.c index 88e5df4..8869971 100644 --- a/sound/soc/sh/fsi.c +++ b/sound/soc/sh/fsi.c @@ -842,12 +842,9 @@ static int fsi_clk_disable(struct device *dev, return -EINVAL; if (1 = clock->count--) { - if (clock->xck) - clk_disable(clock->xck); - if (clock->ick) - clk_disable(clock->ick); - if (clock->div) - clk_disable(clock->div); + clk_disable(clock->xck); + clk_disable(clock->ick); + clk_disable(clock->div); } return 0; -- 2.1.3
On Tue, 2 Dec 2014 10:09:02 +0100 (CET)
Julia Lawall <julia.lawall@lip6.fr> wrote:
> kmalloc actually takes two arguments. Perhaps it would be better to show
> something that looks like a valid call.
Agreed; I took the liberty of sticking in a GFP_KERNEL as I applied the
patch with Julia's ack.
Thanks,
jon
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 2 Dec 2014 17:15:11 +0100 The of_node_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/soc/ux500/mop500.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sound/soc/ux500/mop500.c b/sound/soc/ux500/mop500.c index 7f7093b..4e0c0e5 100644 --- a/sound/soc/ux500/mop500.c +++ b/sound/soc/ux500/mop500.c @@ -63,10 +63,8 @@ static void mop500_of_node_put(void) int i; for (i = 0; i < 2; i++) { - if (mop500_dai_links[i].cpu_of_node) - of_node_put(mop500_dai_links[i].cpu_of_node); - if (mop500_dai_links[i].codec_of_node) - of_node_put(mop500_dai_links[i].codec_of_node); + of_node_put(mop500_dai_links[i].cpu_of_node); + of_node_put(mop500_dai_links[i].codec_of_node); } } -- 2.1.3
On Mon, 2014-12-01 at 21:34 +0100, Julia Lawall wrote:
> > So this kind of evolution is no problem for the (automated) backports
> > using the backports project - although it can be difficult to detect
> > such a thing is needed.
>
> That is exactly the problem...
I'm not convinced though that it should stop such progress in mainline.
johannes
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 2 Dec 2014 18:05:32 +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/asihpi/hpioctl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sound/pci/asihpi/hpioctl.c b/sound/pci/asihpi/hpioctl.c index e457eb8..6aa677e 100644 --- a/sound/pci/asihpi/hpioctl.c +++ b/sound/pci/asihpi/hpioctl.c @@ -547,8 +547,7 @@ void asihpi_adapter_remove(struct pci_dev *pci_dev) if (pa->irq) free_irq(pa->irq, pa); - if (pa->p_buffer) - vfree(pa->p_buffer); + vfree(pa->p_buffer); if (1) dev_info(&pci_dev->dev, -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 2 Dec 2014 18:34:45 +0100 The release_and_free_resource() 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/echoaudio/echoaudio.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c index 60e4003..21228ad 100644 --- a/sound/pci/echoaudio/echoaudio.c +++ b/sound/pci/echoaudio/echoaudio.c @@ -1875,8 +1875,7 @@ static int snd_echo_free(struct echoaudio *chip) if (chip->dsp_registers) iounmap(chip->dsp_registers); - if (chip->iores) - release_and_free_resource(chip->iores); + release_and_free_resource(chip->iores); pci_disable_device(chip->pci); -- 2.1.3
At Tue, 02 Dec 2014 18:11:02 +0100, SF Markus Elfring wrote: > > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Tue, 2 Dec 2014 18:05:32 +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> Applied, thanks. Takashi > --- > sound/pci/asihpi/hpioctl.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/sound/pci/asihpi/hpioctl.c b/sound/pci/asihpi/hpioctl.c > index e457eb8..6aa677e 100644 > --- a/sound/pci/asihpi/hpioctl.c > +++ b/sound/pci/asihpi/hpioctl.c > @@ -547,8 +547,7 @@ void asihpi_adapter_remove(struct pci_dev *pci_dev) > if (pa->irq) > free_irq(pa->irq, pa); > > - if (pa->p_buffer) > - vfree(pa->p_buffer); > + vfree(pa->p_buffer); > > if (1) > dev_info(&pci_dev->dev, > -- > 2.1.3 >
At Tue, 02 Dec 2014 18:38:25 +0100, SF Markus Elfring wrote: > > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Tue, 2 Dec 2014 18:34:45 +0100 > > The release_and_free_resource() 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> Thanks, applied. Takashi > --- > sound/pci/echoaudio/echoaudio.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c > index 60e4003..21228ad 100644 > --- a/sound/pci/echoaudio/echoaudio.c > +++ b/sound/pci/echoaudio/echoaudio.c > @@ -1875,8 +1875,7 @@ static int snd_echo_free(struct echoaudio *chip) > if (chip->dsp_registers) > iounmap(chip->dsp_registers); > > - if (chip->iores) > - release_and_free_resource(chip->iores); > + release_and_free_resource(chip->iores); > > > pci_disable_device(chip->pci); > -- > 2.1.3 >
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 2 Dec 2014 18:52:21 +0100 The snd_util_memhdr_free() 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/trident/trident_main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sound/pci/trident/trident_main.c b/sound/pci/trident/trident_main.c index da875dc..57cd757 100644 --- a/sound/pci/trident/trident_main.c +++ b/sound/pci/trident/trident_main.c @@ -3702,8 +3702,7 @@ static int snd_trident_free(struct snd_trident *trident) free_irq(trident->irq, trident); if (trident->tlb.buffer.area) { outl(0, TRID_REG(trident, NX_TLBC)); - if (trident->tlb.memhdr) - snd_util_memhdr_free(trident->tlb.memhdr); + snd_util_memhdr_free(trident->tlb.memhdr); if (trident->tlb.silent_page.area) snd_dma_free_pages(&trident->tlb.silent_page); vfree(trident->tlb.shadow_entries); -- 2.1.3
On Tue, Dec 02, 2014 at 05:53:28PM +0100, Johannes Berg wrote:
> On Mon, 2014-12-01 at 21:34 +0100, Julia Lawall wrote:
>
> > > So this kind of evolution is no problem for the (automated) backports
> > > using the backports project - although it can be difficult to detect
> > > such a thing is needed.
> >
> > That is exactly the problem...
>
> I'm not convinced though that it should stop such progress in mainline.
Is it progress? These patches match the code look simpler by passing
hiding the NULL check inside a function call. Calling pci_dev_put(NULL)
doesn't make sense. Just because a sanity check exists doesn't mean we
should do insane things.
It's easy enough to store which functions have a sanity check in a
database, but to rememember all that as a human being trying to read the
code is impossible.
If we really wanted to make this code cleaner we would introduce more
error labels with better names.
regards,
dan carpenter
On Tue, Dec 2, 2014 at 11:53 AM, Johannes Berg
<johannes@sipsolutions.net> wrote:
> On Mon, 2014-12-01 at 21:34 +0100, Julia Lawall wrote:
>
>> > So this kind of evolution is no problem for the (automated) backports
>> > using the backports project - although it can be difficult to detect
>> > such a thing is needed.
>>
>> That is exactly the problem...
>
> I'm not convinced though that it should stop such progress in mainline.
I believe this case requires a bit more information explained as to
why it was explained. The "form" of change this patch has is of the
type that can crash systems if the NULL pointer check on the caller
implementation was only added later. We might be able to grammatically
check for this situation in the future if we had a white list / black
list / kernel revision where the NULL check was added but for now we
don't have that and as such care is just required on the developer in
consideration for backports.
It should be up to the maintainer to appreciate the gains of doing
something differently to make it easier for backporting. I obviously
think its a good thing to consider, its extra work though, so only if
the maintainer has some appreciation for backporting would this make
sense.
In this particular case I've reviewed Julia's concern and I've
determined that the patch is safe up to at least v2.6.12-rc2 (which is
where our git history begins on Linus' tree), this is because the
check for NULL has been there since then:
git show 1da177e drivers/pci/pci-driver.c
+void pci_dev_put(struct pci_dev *dev)
+{
+ if (dev)
+ put_device(&dev->dev);
+}
So this type of wide collateral evolution should not cause panics.
Because of this:
Acked-by: Luis R. Rodriguez <mcgrof@suse.com>
But note -- I still think its only good for us to vet these, if we
can't why not? If the maintainer doesn't give a shit that's different,
but if there are folks out there willing to help with vetting then
well, why not :)
PS. Including something like historical vetting as I did above on the
commit log should help folks.
Luis
At Tue, 02 Dec 2014 18:56:30 +0100, SF Markus Elfring wrote: > > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Tue, 2 Dec 2014 18:52:21 +0100 > > The snd_util_memhdr_free() 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> Applied, thanks. Takashi > --- > sound/pci/trident/trident_main.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/sound/pci/trident/trident_main.c b/sound/pci/trident/trident_main.c > index da875dc..57cd757 100644 > --- a/sound/pci/trident/trident_main.c > +++ b/sound/pci/trident/trident_main.c > @@ -3702,8 +3702,7 @@ static int snd_trident_free(struct snd_trident *trident) > free_irq(trident->irq, trident); > if (trident->tlb.buffer.area) { > outl(0, TRID_REG(trident, NX_TLBC)); > - if (trident->tlb.memhdr) > - snd_util_memhdr_free(trident->tlb.memhdr); > + snd_util_memhdr_free(trident->tlb.memhdr); > if (trident->tlb.silent_page.area) > snd_dma_free_pages(&trident->tlb.silent_page); > vfree(trident->tlb.shadow_entries); > -- > 2.1.3 >
On Tue, Dec 02, 2014 at 09:35:09PM +0300, Dan Carpenter wrote: > On Tue, Dec 02, 2014 at 05:53:28PM +0100, Johannes Berg wrote: > > On Mon, 2014-12-01 at 21:34 +0100, Julia Lawall wrote: > > > > > > So this kind of evolution is no problem for the (automated) backports > > > > using the backports project - although it can be difficult to detect > > > > such a thing is needed. > > > > > > That is exactly the problem... > > > > I'm not convinced though that it should stop such progress in mainline. > > Is it progress? I like to think of progress as using tools to help fix code where we know it can be made simpler with a small ammendment: if you can extend the tools to also vet for safety for backports to avoid crashes even better. So its a small evolution but we can do better, which is the point you and Julia are making. > These patches match the code look simpler by passing > hiding the NULL check inside a function call. Calling pci_dev_put(NULL) > doesn't make sense. Just because a sanity check exists doesn't mean we > should do insane things. It'd crash the system if the function call didn't have the check in place but having the code in question call pci_dev_put(NULL) is also ludicrious. Either way in this case I think we shouldn't go beyond analyzing the function call and if the error check was present before as it is a real case that has introduced crashes before which Julia wanted to flag. > It's easy enough to store which functions have a sanity check in a > database, This is easy but it adds complexities which I'd prefer to keep on some other people's workstations. For the developer I think we should strive to only have: a) git b) Coccinelle c) smatch. > but to rememember all that as a human being trying to read the > code is impossible. Agreed. The problem statement presented by Julia is part of the effort of addressing the "how do we evolve faster" problem on Linux kernel development, what you describe adds to the mix of the complexities, and while Oleg does note that part of this is academic there are those of us who are making things which are academic immediately practical and a reality for Linux. This is also how we evolve faster :) > If we really wanted to make this code cleaner we would introduce more > error labels with better names. Can you describe a bit more what you mean here? If we had a label *in code* on the caller, perhaps a comment, I can see tool-wise how it'd remove the requirement for a database for immediate analysis for safety here, ie, we hunt for a label on the code; but other than that its unclear what you mean here. If you folks agree with my simplication tool analsysi for safety can we devise a tag for whitelisting this check for a series of routines? Where would we put it, in the kernel or a tools package? If in the kernel we could end up sharing it, so I think that's be better. Perhaps scripts/safety/ ? Maybe use a header that describes the safety check that is vetted by the rule present, followed by a list of routines vetted? Then the Cocci file can preload this and a rule that wants this paranoid check can include this db file for safety ? The safety here would require vetting thirough history in git that the routine has a check in place throughout the routines's history up to a certain point. I propose we only care up to what kernels are listed on kernel.org as supported. Luis
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 2 Dec 2014 20:35:41 +0100 Another update suggestion was taken into account after a patch was applied from static source code analysis. Markus Elfring (2): Deletion of an unnecessary check before the function call "kfree" One function call less in get_daio_rsc() after error detection sound/pci/ctxfi/ctdaio.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 2 Dec 2014 20:00:33 +0100 The kfree() 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/ctxfi/ctdaio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/pci/ctxfi/ctdaio.c b/sound/pci/ctxfi/ctdaio.c index c1c3f88..1712332 100644 --- a/sound/pci/ctxfi/ctdaio.c +++ b/sound/pci/ctxfi/ctdaio.c @@ -577,7 +577,7 @@ static int get_daio_rsc(struct daio_mgr *mgr, error: if (dao) kfree(dao); - else if (dai) + else kfree(dai); spin_lock_irqsave(&mgr->mgr_lock, flags); -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 2 Dec 2014 20:33:51 +0100 The kfree() function was called in two cases by the get_daio_rsc() function during error handling even if the passed variable contained still a null pointer. This implementation detail could be improved by adjustments for jump labels. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- sound/pci/ctxfi/ctdaio.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/sound/pci/ctxfi/ctdaio.c b/sound/pci/ctxfi/ctdaio.c index 1712332..a12489e 100644 --- a/sound/pci/ctxfi/ctdaio.c +++ b/sound/pci/ctxfi/ctdaio.c @@ -549,22 +549,22 @@ static int get_daio_rsc(struct daio_mgr *mgr, dao = kzalloc(sizeof(*dao), GFP_KERNEL); if (!dao) { err = -ENOMEM; - goto error; + goto alloc_error; } err = dao_rsc_init(dao, desc, mgr); if (err) - goto error; + goto dao_init_error; *rdaio = &dao->daio; } else { dai = kzalloc(sizeof(*dai), GFP_KERNEL); if (!dai) { err = -ENOMEM; - goto error; + goto alloc_error; } err = dai_rsc_init(dai, desc, mgr); if (err) - goto error; + goto dai_init_error; *rdaio = &dai->daio; } @@ -574,12 +574,12 @@ static int get_daio_rsc(struct daio_mgr *mgr, return 0; -error: - if (dao) - kfree(dao); - else - kfree(dai); - +dao_init_error: + kfree(dao); + goto alloc_error; +dai_init_error: + kfree(dai); +alloc_error: spin_lock_irqsave(&mgr->mgr_lock, flags); daio_mgr_put_rsc(&mgr->mgr, desc->type); spin_unlock_irqrestore(&mgr->mgr_lock, flags); -- 2.1.3
On Tue, 2014-12-02 at 21:55 +0100, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Tue, 2 Dec 2014 20:00:33 +0100 > > The kfree() 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/ctxfi/ctdaio.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/sound/pci/ctxfi/ctdaio.c b/sound/pci/ctxfi/ctdaio.c > index c1c3f88..1712332 100644 > --- a/sound/pci/ctxfi/ctdaio.c > +++ b/sound/pci/ctxfi/ctdaio.c > @@ -577,7 +577,7 @@ static int get_daio_rsc(struct daio_mgr *mgr, > error: > if (dao) > kfree(dao); > - else if (dai) > + else > kfree(dai); > > spin_lock_irqsave(&mgr->mgr_lock, flags); I think this not nice and would prefer something like: --- sound/pci/ctxfi/ctdaio.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/sound/pci/ctxfi/ctdaio.c b/sound/pci/ctxfi/ctdaio.c index c1c3f88..9b87dd2 100644 --- a/sound/pci/ctxfi/ctdaio.c +++ b/sound/pci/ctxfi/ctdaio.c @@ -528,8 +528,6 @@ static int get_daio_rsc(struct daio_mgr *mgr, struct daio **rdaio) { int err; - struct dai *dai = NULL; - struct dao *dao = NULL; unsigned long flags; *rdaio = NULL; @@ -544,27 +542,30 @@ static int get_daio_rsc(struct daio_mgr *mgr, return err; } + err = -ENOMEM; /* Allocate mem for daio resource */ if (desc->type <= DAIO_OUT_MAX) { - dao = kzalloc(sizeof(*dao), GFP_KERNEL); - if (!dao) { - err = -ENOMEM; + struct dao *dao = kzalloc(sizeof(*dao), GFP_KERNEL); + if (!dao) goto error; - } + err = dao_rsc_init(dao, desc, mgr); - if (err) + if (err) { + kfree(dao); goto error; + } *rdaio = &dao->daio; } else { - dai = kzalloc(sizeof(*dai), GFP_KERNEL); - if (!dai) { - err = -ENOMEM; + struct dai *dai = kzalloc(sizeof(*dai), GFP_KERNEL); + if (!dai) goto error; - } + err = dai_rsc_init(dai, desc, mgr); - if (err) + if (err) { + kfree(dai); goto error; + } *rdaio = &dai->daio; } @@ -575,11 +576,6 @@ static int get_daio_rsc(struct daio_mgr *mgr, return 0; error: - if (dao) - kfree(dao); - else if (dai) - kfree(dai); - spin_lock_irqsave(&mgr->mgr_lock, flags); daio_mgr_put_rsc(&mgr->mgr, desc->type); spin_unlock_irqrestore(&mgr->mgr_lock, flags);
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 2 Dec 2014 22:50:24 +0100 The release_and_free_resource() 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/aoa/soundbus/i2sbus/core.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sound/aoa/soundbus/i2sbus/core.c b/sound/aoa/soundbus/i2sbus/core.c index a80d5ea..4e2b4fb 100644 --- a/sound/aoa/soundbus/i2sbus/core.c +++ b/sound/aoa/soundbus/i2sbus/core.c @@ -79,8 +79,7 @@ static void i2sbus_release_dev(struct device *dev) if (i2sdev->out.dbdma) iounmap(i2sdev->out.dbdma); if (i2sdev->in.dbdma) iounmap(i2sdev->in.dbdma); for (i = aoa_resource_i2smmio; i <= aoa_resource_rxdbdma; i++) - if (i2sdev->allocated_resource[i]) - release_and_free_resource(i2sdev->allocated_resource[i]); + release_and_free_resource(i2sdev->allocated_resource[i]); free_dbdma_descriptor_ring(i2sdev, &i2sdev->out.dbdma_ring); free_dbdma_descriptor_ring(i2sdev, &i2sdev->in.dbdma_ring); for (i = aoa_resource_i2smmio; i <= aoa_resource_rxdbdma; i++) @@ -323,8 +322,7 @@ static int i2sbus_add_dev(struct macio_dev *macio, if (dev->out.dbdma) iounmap(dev->out.dbdma); if (dev->in.dbdma) iounmap(dev->in.dbdma); for (i=0;i<3;i++) - if (dev->allocated_resource[i]) - release_and_free_resource(dev->allocated_resource[i]); + release_and_free_resource(dev->allocated_resource[i]); mutex_destroy(&dev->lock); kfree(dev); return 0; -- 2.1.3
At Tue, 02 Dec 2014 21:50:26 +0100,
SF Markus Elfring wrote:
>
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Tue, 2 Dec 2014 20:35:41 +0100
>
> Another update suggestion was taken into account after a patch was applied
> from static source code analysis.
>
> Markus Elfring (2):
> Deletion of an unnecessary check before the function call "kfree"
> One function call less in get_daio_rsc() after error detection
In these cases, the changes aren't so straightforward, and they don't
improve the readability.
Takashi
At Tue, 02 Dec 2014 22:55:57 +0100, SF Markus Elfring wrote: > > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Tue, 2 Dec 2014 22:50:24 +0100 > > The release_and_free_resource() 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> Thanks, applied. Takashi > --- > sound/aoa/soundbus/i2sbus/core.c | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/sound/aoa/soundbus/i2sbus/core.c b/sound/aoa/soundbus/i2sbus/core.c > index a80d5ea..4e2b4fb 100644 > --- a/sound/aoa/soundbus/i2sbus/core.c > +++ b/sound/aoa/soundbus/i2sbus/core.c > @@ -79,8 +79,7 @@ static void i2sbus_release_dev(struct device *dev) > if (i2sdev->out.dbdma) iounmap(i2sdev->out.dbdma); > if (i2sdev->in.dbdma) iounmap(i2sdev->in.dbdma); > for (i = aoa_resource_i2smmio; i <= aoa_resource_rxdbdma; i++) > - if (i2sdev->allocated_resource[i]) > - release_and_free_resource(i2sdev->allocated_resource[i]); > + release_and_free_resource(i2sdev->allocated_resource[i]); > free_dbdma_descriptor_ring(i2sdev, &i2sdev->out.dbdma_ring); > free_dbdma_descriptor_ring(i2sdev, &i2sdev->in.dbdma_ring); > for (i = aoa_resource_i2smmio; i <= aoa_resource_rxdbdma; i++) > @@ -323,8 +322,7 @@ static int i2sbus_add_dev(struct macio_dev *macio, > if (dev->out.dbdma) iounmap(dev->out.dbdma); > if (dev->in.dbdma) iounmap(dev->in.dbdma); > for (i=0;i<3;i++) > - if (dev->allocated_resource[i]) > - release_and_free_resource(dev->allocated_resource[i]); > + release_and_free_resource(dev->allocated_resource[i]); > mutex_destroy(&dev->lock); > kfree(dev); > return 0; > -- > 2.1.3 >
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 3 Dec 2014 09:01:33 +0100 The __clk_disable() 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> --- arch/arm/mach-davinci/clock.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/arm/mach-davinci/clock.c b/arch/arm/mach-davinci/clock.c index c70bb0a..8f2c2d8 100644 --- a/arch/arm/mach-davinci/clock.c +++ b/arch/arm/mach-davinci/clock.c @@ -55,8 +55,7 @@ static void __clk_disable(struct clk *clk) else if (clk->clk_disable) clk->clk_disable(clk); } - if (clk->parent) - __clk_disable(clk->parent); + __clk_disable(clk->parent); } int davinci_clk_reset(struct clk *clk, bool reset) -- 2.1.3
> The __clk_disable() function tests whether its argument is NULL and then > returns immediately. Thus the test around the call is not needed. I was a bit too quick to send you this notification. I stumbled once more on the detail that my source code analysis approach is incomplete for static functions so far. https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/arch/arm/mach-davinci/clock.c?id§ca2bcf2d2ef15c343a12f2a4c2e06380a0f495#n47 https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/drivers/clk/clk.c?idMc7ed32f398fa76b9e1d243a852420b1dad0150#n846 I would like to apologise for confusion I introduced here. Regards, Markus -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
>> Deletion of an unnecessary check before the function call "kfree"
>> One function call less in get_daio_rsc() after error detection
>
> In these cases, the changes aren't so straightforward, and they don't
> improve the readability.
How do you prefer to improve the affected source code here?
Regards,
Markus
> diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle
> index 9f28b14..9c8a234 100644
> --- a/Documentation/CodingStyle
> +++ b/Documentation/CodingStyle
> @@ -392,7 +392,12 @@ The goto statement comes in handy when a function exits from multiple
> locations and some common work such as cleanup has to be done. If there is no
> cleanup needed then just return directly.
>
> -The rationale is:
> +Choose label names which say what the goto does or why the goto exists. An
> +[...] Avoid
> +using GW-BASIC names like "err1:" and "err2:". Also don't name them after the
> +goto location like "err_kmalloc_failed:"
I find this documentation approach not safe and clear enough so far.
* How should the reference to an other programming language help in the understanding
of the recommended naming convention for jump labels?
* To which source code place should the word "location" refer to?
- jump source
- jump target
Regards,
Markus
On 12/03/14 13:31, SF Markus Elfring wrote: >> diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle >> index 9f28b14..9c8a234 100644 >> --- a/Documentation/CodingStyle >> +++ b/Documentation/CodingStyle >> @@ -392,7 +392,12 @@ The goto statement comes in handy when a function exits from multiple >> locations and some common work such as cleanup has to be done. If there is no >> cleanup needed then just return directly. >> >> -The rationale is: >> +Choose label names which say what the goto does or why the goto exists. An >> +[...] Avoid >> +using GW-BASIC names like "err1:" and "err2:". Also don't name them after the >> +goto location like "err_kmalloc_failed:" > > I find this documentation approach not safe and clear enough so far. > > * How should the reference to an other programming language help in the understanding > of the recommended naming convention for jump labels? > > * To which source code place should the word "location" refer to? > - jump source > - jump target I think you digested the paragraph in too small bits. The term "goto location" looks synonymous to "jump source" to me. Regards, Arend > Regards, > Markus > -- > To unsubscribe from this list: send the line "unsubscribe backports" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html
At Wed, 03 Dec 2014 12:38:51 +0100,
SF Markus Elfring wrote:
>
> >> Deletion of an unnecessary check before the function call "kfree"
> >> One function call less in get_daio_rsc() after error detection
> >
> > In these cases, the changes aren't so straightforward, and they don't
> > improve the readability.
>
> How do you prefer to improve the affected source code here?
Don't touch then. There are no bugs to fix there.
Takashi
On Wed, Dec 03, 2014 at 01:31:19PM +0100, SF Markus Elfring wrote:
>
> * To which source code place should the word "location" refer to?
> - jump source
> - jump target
jump target.
regards,
dan carpenter
>> * To which source code place should the word "location" refer to? >> - jump source >> - jump target > > I think you digested the paragraph in too small bits. I would prefer to reduce the probability for misunderstandings of the proposed wording a bit more. > The term "goto location" looks synonymous to "jump source" to me. I would interpret it differently because of the specific placement of this key word before an other term. Regards, Markus
On Wed, 3 Dec 2014, Dan Carpenter wrote:
> On Wed, Dec 03, 2014 at 01:31:19PM +0100, SF Markus Elfring wrote:
> >
> > * To which source code place should the word "location" refer to?
> > - jump source
> > - jump target
>
> jump target.
I think you mean source? Or it really is ambiguous. The example was
err_kmalloc_failed, which seems source-related.
julia
>> * To which source code place should the word "location" refer to?
>> - jump source
>> - jump target
>
> jump target.
Thanks for the clarification of your intention.
I wonder then why I got the feedback "That is a useless thing to do."
from you yesterday.
I hope that we can still clarify our different opinions about specific
implementation details in constructive ways.
Regards,
Markus
On Wed, Dec 03, 2014 at 01:52:53PM +0100, Julia Lawall wrote:
> On Wed, 3 Dec 2014, Dan Carpenter wrote:
>
> > On Wed, Dec 03, 2014 at 01:31:19PM +0100, SF Markus Elfring wrote:
> > >
> > > * To which source code place should the word "location" refer to?
> > > - jump source
> > > - jump target
> >
> > jump target.
>
> I think you mean source? Or it really is ambiguous. The example was
> err_kmalloc_failed, which seems source-related.
Yeah. You're right. I misread Markus's email. The goto location is
where the goto is. The label location is where the label is.
regards,
dan carpenter
Sorry. I misread your email. If the code looks like this: foo = kmalloc(); if (!foo) goto kmalloc_failed; The "kmalloc_failed" doesn't add any information. We can see that kmalloc failed from the context. regards, dan carpenter
> Sorry. I misread your email. If the code looks like this: > > foo = kmalloc(); > if (!foo) > goto kmalloc_failed; > > The "kmalloc_failed" doesn't add any information. I find that this such a name approach would fit to your expectation of a source-oriented labeling of these identifiers. > We can see that kmalloc failed from the context. Which name pattern do you find more appropriate in such an use case? Regards, Markus
On 12/03/14 14:24, SF Markus Elfring wrote: >> Sorry. I misread your email. If the code looks like this: >> >> foo = kmalloc(); >> if (!foo) >> goto kmalloc_failed; >> >> The "kmalloc_failed" doesn't add any information. > > I find that this such a name approach would fit to your > expectation of a source-oriented labeling of these identifiers. > > >> We can see that kmalloc failed from the context. > > Which name pattern do you find more appropriate in such > an use case? I think Dan wants the label to be descriptive about the tasks needed in the exception handling itself. This makes sense as the exception handling steps may be reused for different failures in the code. void foo(void) { if (check_a()) goto do_bar; sub_foo1(); if (checck_b()) goto do_bar; sub_foo2(); return; do_bar: bar(); } Regards, Arend > Regards, > Markus > -- > To unsubscribe from this list: send the line "unsubscribe backports" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html
>> Which name pattern do you find more appropriate in such >> an use case? > > I think Dan wants the label to be descriptive about the tasks > needed in the exception handling itself. I would usually prefer also such a target-oriented labelling for the affected identifiers. How are the chances to express an expectation in this direction unambiguously for the proposed coding style update? > This makes sense as the exception handling steps may be reused > for different failures in the code. I would stress a different reason from my point of view. Regards, Markus
On Tue, 02 Dec 2014 14:00:51 +0100 , SF Markus Elfring <elfring@users.sourceforge.net> wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Tue, 2 Dec 2014 13:54:00 +0100 > > The of_node_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> Applied, thanks. g. > --- > drivers/of/unittest.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c > index cc0c5ec..06ebe9d 100644 > --- a/drivers/of/unittest.c > +++ b/drivers/of/unittest.c > @@ -486,8 +486,7 @@ static void __init of_selftest_changeset(void) > /* Make sure node names are constructed correctly */ > selftest((np = of_find_node_by_path("/testcase-data/changeset/n2/n21")), > "'%s' not added\n", n21->full_name); > - if (np) > - of_node_put(np); > + of_node_put(np); > > mutex_lock(&of_mutex); > selftest(!of_changeset_revert(&chgset), "revert failed\n"); > -- > 2.1.3 >
On Wed, 2014-12-03 at 13:41 +0100, Takashi Iwai wrote: > At Wed, 03 Dec 2014 12:38:51 +0100, > SF Markus Elfring wrote: > > > > >> Deletion of an unnecessary check before the function call "kfree" > > >> One function call less in get_daio_rsc() after error detection > > > > > > In these cases, the changes aren't so straightforward, and they don't > > > improve the readability. > > > > How do you prefer to improve the affected source code here? > > Don't touch then. There are no bugs to fix there. Takashi, what did you think of this? https://lkml.org/lkml/2014/12/2/771 Just unnecessary?
At Wed, 03 Dec 2014 09:14:48 -0800,
Joe Perches wrote:
>
> On Wed, 2014-12-03 at 13:41 +0100, Takashi Iwai wrote:
> > At Wed, 03 Dec 2014 12:38:51 +0100,
> > SF Markus Elfring wrote:
> > >
> > > >> Deletion of an unnecessary check before the function call "kfree"
> > > >> One function call less in get_daio_rsc() after error detection
> > > >
> > > > In these cases, the changes aren't so straightforward, and they don't
> > > > improve the readability.
> > >
> > > How do you prefer to improve the affected source code here?
> >
> > Don't touch then. There are no bugs to fix there.
>
> Takashi, what did you think of this?
> https://lkml.org/lkml/2014/12/2/771
>
> Just unnecessary?
Well, this one looks more consistent. But honestly speaking, it's
rather a matter of taste. So I'm not so much inclined to merge the
stuff, too, sorry. If it's proven to reduce the compiled size, etc,
I'll happily apply it, though.
FWIW, what wasn't good in the original patch was to break the balance.
It removed only the check for dai, and not for dao. One would wonder
why there is a check only for one.
It could be two simple kfree() calls instead. But then this won't be
an improvement, as it gets one more function call, which is more
expensive than a conditional.
Takashi
Move the pointer declarations into the blocks that use them. Neaten the kfree calls when the _init functions fail. Trivially reduces object size (defconfig x86-64) $ size sound/pci/ctxfi/ctdaio.o.* text data bss dec hex filename 5287 224 0 5511 1587 sound/pci/ctxfi/ctdaio.o.new 5319 224 0 5543 15a7 sound/pci/ctxfi/ctdaio.o.old Signed-off-by: Joe Perches <joe@perches.com> Noticed-by: Markus Elfring <elfring@users.sourceforge.net> --- On Wed, 2014-12-03 at 18:30 +0100, Takashi Iwai wrote: > At Wed, 03 Dec 2014 09:14:48 -0800, Joe Perches wrote: > > On Wed, 2014-12-03 at 13:41 +0100, Takashi Iwai wrote: > > Takashi, what did you think of this? > > https://lkml.org/lkml/2014/12/2/771 > > > > Just unnecessary? > > Well, this one looks more consistent. But honestly speaking, it's > rather a matter of taste. So I'm not so much inclined to merge the > stuff, too, sorry. If it's proven to reduce the compiled size, etc, > I'll happily apply it, though. sound/pci/ctxfi/ctdaio.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/sound/pci/ctxfi/ctdaio.c b/sound/pci/ctxfi/ctdaio.c index c1c3f88..9b87dd2 100644 --- a/sound/pci/ctxfi/ctdaio.c +++ b/sound/pci/ctxfi/ctdaio.c @@ -528,8 +528,6 @@ static int get_daio_rsc(struct daio_mgr *mgr, struct daio **rdaio) { int err; - struct dai *dai = NULL; - struct dao *dao = NULL; unsigned long flags; *rdaio = NULL; @@ -544,27 +542,30 @@ static int get_daio_rsc(struct daio_mgr *mgr, return err; } + err = -ENOMEM; /* Allocate mem for daio resource */ if (desc->type <= DAIO_OUT_MAX) { - dao = kzalloc(sizeof(*dao), GFP_KERNEL); - if (!dao) { - err = -ENOMEM; + struct dao *dao = kzalloc(sizeof(*dao), GFP_KERNEL); + if (!dao) goto error; - } + err = dao_rsc_init(dao, desc, mgr); - if (err) + if (err) { + kfree(dao); goto error; + } *rdaio = &dao->daio; } else { - dai = kzalloc(sizeof(*dai), GFP_KERNEL); - if (!dai) { - err = -ENOMEM; + struct dai *dai = kzalloc(sizeof(*dai), GFP_KERNEL); + if (!dai) goto error; - } + err = dai_rsc_init(dai, desc, mgr); - if (err) + if (err) { + kfree(dai); goto error; + } *rdaio = &dai->daio; } @@ -575,11 +576,6 @@ static int get_daio_rsc(struct daio_mgr *mgr, return 0; error: - if (dao) - kfree(dao); - else if (dai) - kfree(dai); - spin_lock_irqsave(&mgr->mgr_lock, flags); daio_mgr_put_rsc(&mgr->mgr, desc->type); spin_unlock_irqrestore(&mgr->mgr_lock, flags);
[-- Attachment #1: Type: text/plain, Size: 331 bytes --] On Tue, Dec 02, 2014 at 02:41:47PM +0100, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Tue, 2 Dec 2014 14:34:30 +0100 > > The clk_disable() function tests whether its argument is NULL and then > returns immediately. Thus the test around the call is not needed. Applied, thanks. [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 473 bytes --]
[-- Attachment #1: Type: text/plain, Size: 380 bytes --] On Tue, Dec 02, 2014 at 05:40:11PM +0100, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Tue, 2 Dec 2014 17:15:11 +0100 > > The of_node_put() function tests whether its argument is NULL and then > returns immediately. Thus the test around the call is not needed. This doesn't apply against current code, please check and resend. [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 473 bytes --]
[-- Attachment #1: Type: text/plain, Size: 373 bytes --] On Tue, Dec 02, 2014 at 05:40:11PM +0100, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Tue, 2 Dec 2014 17:15:11 +0100 > > The of_node_put() function tests whether its argument is NULL and then > returns immediately. Thus the test around the call is not needed. Sorry, realised what the dependency was - applied, thanks. [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 473 bytes --]
On 12/03/14 17:00, SF Markus Elfring wrote:
>>> Which name pattern do you find more appropriate in such
>>> an use case?
>>
>> I think Dan wants the label to be descriptive about the tasks
>> needed in the exception handling itself.
>
> I would usually prefer also such a target-oriented labelling
> for the affected identifiers.
> How are the chances to express an expectation in this direction
> unambiguously for the proposed coding style update?
>
>
>> This makes sense as the exception handling steps may be reused
>> for different failures in the code.
>
> I would stress a different reason from my point of view.
I meant as apposed to using a goto-/source-oriented labelling. Please
provide your point of view. That way the explanations given in this
email exchange might be incorporated in the next round of the proposed
update or at least be used as input.
Regards,
Arend
At Wed, 03 Dec 2014 09:59:31 -0800, Joe Perches wrote: > > Move the pointer declarations into the blocks that use them. > Neaten the kfree calls when the _init functions fail. > > Trivially reduces object size (defconfig x86-64) > > $ size sound/pci/ctxfi/ctdaio.o.* > text data bss dec hex filename > 5287 224 0 5511 1587 sound/pci/ctxfi/ctdaio.o.new > 5319 224 0 5543 15a7 sound/pci/ctxfi/ctdaio.o.old > > Signed-off-by: Joe Perches <joe@perches.com> > Noticed-by: Markus Elfring <elfring@users.sourceforge.net> > --- > On Wed, 2014-12-03 at 18:30 +0100, Takashi Iwai wrote: > > At Wed, 03 Dec 2014 09:14:48 -0800, Joe Perches wrote: > > > On Wed, 2014-12-03 at 13:41 +0100, Takashi Iwai wrote: > > > Takashi, what did you think of this? > > > https://lkml.org/lkml/2014/12/2/771 > > > > > > Just unnecessary? > > > > Well, this one looks more consistent. But honestly speaking, it's > > rather a matter of taste. So I'm not so much inclined to merge the > > stuff, too, sorry. If it's proven to reduce the compiled size, etc, > > I'll happily apply it, though. Thanks, applied now. Takashi > > sound/pci/ctxfi/ctdaio.c | 30 +++++++++++++----------------- > 1 file changed, 13 insertions(+), 17 deletions(-) > > diff --git a/sound/pci/ctxfi/ctdaio.c b/sound/pci/ctxfi/ctdaio.c > index c1c3f88..9b87dd2 100644 > --- a/sound/pci/ctxfi/ctdaio.c > +++ b/sound/pci/ctxfi/ctdaio.c > @@ -528,8 +528,6 @@ static int get_daio_rsc(struct daio_mgr *mgr, > struct daio **rdaio) > { > int err; > - struct dai *dai = NULL; > - struct dao *dao = NULL; > unsigned long flags; > > *rdaio = NULL; > @@ -544,27 +542,30 @@ static int get_daio_rsc(struct daio_mgr *mgr, > return err; > } > > + err = -ENOMEM; > /* Allocate mem for daio resource */ > if (desc->type <= DAIO_OUT_MAX) { > - dao = kzalloc(sizeof(*dao), GFP_KERNEL); > - if (!dao) { > - err = -ENOMEM; > + struct dao *dao = kzalloc(sizeof(*dao), GFP_KERNEL); > + if (!dao) > goto error; > - } > + > err = dao_rsc_init(dao, desc, mgr); > - if (err) > + if (err) { > + kfree(dao); > goto error; > + } > > *rdaio = &dao->daio; > } else { > - dai = kzalloc(sizeof(*dai), GFP_KERNEL); > - if (!dai) { > - err = -ENOMEM; > + struct dai *dai = kzalloc(sizeof(*dai), GFP_KERNEL); > + if (!dai) > goto error; > - } > + > err = dai_rsc_init(dai, desc, mgr); > - if (err) > + if (err) { > + kfree(dai); > goto error; > + } > > *rdaio = &dai->daio; > } > @@ -575,11 +576,6 @@ static int get_daio_rsc(struct daio_mgr *mgr, > return 0; > > error: > - if (dao) > - kfree(dao); > - else if (dai) > - kfree(dai); > - > spin_lock_irqsave(&mgr->mgr_lock, flags); > daio_mgr_put_rsc(&mgr->mgr, desc->type); > spin_unlock_irqrestore(&mgr->mgr_lock, flags); > >
> Please provide your point of view.
I would like to interpret the key word "goto" from the C programming
language a bit more here so that a better common understanding can
eventually be achieved.
Strong opinions might be floating around for the consistent naming
of jump labels. My reasoning works like the following.
This key word could also be interpreted as two items "go" and "to",
couldn't it?
How much does this variation stress its meaning in a specific direction?
Some software developers would like to express the reason about
an unexpected event at the jump source. But I guess that this approach
increases the risk for a popular story like "goto fail;", doesn't it?
I would prefer not to specify "go to failure".
So I find that there are more variants possible to stress the jump target.
Examples:
* Failure_exit
* out_memory_release
* unregister_item
Regards,
Markus
[-- Attachment #1: Type: text/plain, Size: 1170 bytes --] Hi, On 22/11/14 18:00, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sat, 22 Nov 2014 16:51:31 +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/video/fbdev/sh_mobile_lcdcfb.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c > index 2bcc84a..cfde21d 100644 > --- a/drivers/video/fbdev/sh_mobile_lcdcfb.c > +++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c > @@ -2181,8 +2181,7 @@ sh_mobile_lcdc_channel_fb_cleanup(struct sh_mobile_lcdc_chan *ch) > if (!info || !info->device) > return; > > - if (ch->sglist) > - vfree(ch->sglist); > + vfree(ch->sglist); > > fb_dealloc_cmap(&info->cmap); > framebuffer_release(info); Thanks, I've applied the fbdev patches. Next time, please use git-format-patch and git-send-email to send a proper patch series. Tomi [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 819 bytes --]
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 4 Dec 2014 22:50:28 +0100 Further update suggestions were taken into account before and after a patch was applied from static source code analysis. Markus Elfring (6): Replacement of a printk() call by pr_warn() in mppe_rekey() Fix indentation Deletion of unnecessary checks before the function call "kfree" Less function calls in mppe_alloc() after error detection Delete an unnecessary assignment in mppe_alloc() Delete another unnecessary assignment in mppe_alloc() drivers/net/ppp/ppp_mppe.c | 49 +++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 29 deletions(-) -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 4 Dec 2014 18:28:52 +0100 The mppe_rekey() function contained a few update candidates. * Curly brackets were still used around a single function call "printk". * Unwanted space characters Let us improve these implementation details according to the current Linux coding style convention. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/net/ppp/ppp_mppe.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/net/ppp/ppp_mppe.c b/drivers/net/ppp/ppp_mppe.c index 911b216..84b7bce 100644 --- a/drivers/net/ppp/ppp_mppe.c +++ b/drivers/net/ppp/ppp_mppe.c @@ -172,9 +172,8 @@ static void mppe_rekey(struct ppp_mppe_state * state, int initial_key) setup_sg(sg_in, state->sha1_digest, state->keylen); setup_sg(sg_out, state->session_key, state->keylen); if (crypto_blkcipher_encrypt(&desc, sg_out, sg_in, - state->keylen) != 0) { - printk(KERN_WARNING "mppe_rekey: cipher_encrypt failed\n"); - } + state->keylen) != 0) + pr_warn("mppe_rekey: cipher_encrypt failed\n"); } else { memcpy(state->session_key, state->sha1_digest, state->keylen); } -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 4 Dec 2014 22:15:20 +0100 The implementations of the functions "mppe_alloc" and "mppe_free" contained unwanted space characters. Let us improve the indentation according to the Linux coding style convention. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/net/ppp/ppp_mppe.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/net/ppp/ppp_mppe.c b/drivers/net/ppp/ppp_mppe.c index 84b7bce..b80af29 100644 --- a/drivers/net/ppp/ppp_mppe.c +++ b/drivers/net/ppp/ppp_mppe.c @@ -236,15 +236,15 @@ static void *mppe_alloc(unsigned char *options, int optlen) return (void *)state; - out_free: - if (state->sha1_digest) +out_free: + if (state->sha1_digest) kfree(state->sha1_digest); - if (state->sha1) + if (state->sha1) crypto_free_hash(state->sha1); - if (state->arc4) + if (state->arc4) crypto_free_blkcipher(state->arc4); - kfree(state); - out: + kfree(state); +out: return NULL; } @@ -255,13 +255,13 @@ static void mppe_free(void *arg) { struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg; if (state) { - if (state->sha1_digest) - kfree(state->sha1_digest); - if (state->sha1) - crypto_free_hash(state->sha1); - if (state->arc4) - crypto_free_blkcipher(state->arc4); - kfree(state); + if (state->sha1_digest) + kfree(state->sha1_digest); + if (state->sha1) + crypto_free_hash(state->sha1); + if (state->arc4) + crypto_free_blkcipher(state->arc4); + kfree(state); } } -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 4 Dec 2014 22:22:23 +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> --- drivers/net/ppp/ppp_mppe.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/net/ppp/ppp_mppe.c b/drivers/net/ppp/ppp_mppe.c index b80af29..94ff216 100644 --- a/drivers/net/ppp/ppp_mppe.c +++ b/drivers/net/ppp/ppp_mppe.c @@ -237,8 +237,7 @@ static void *mppe_alloc(unsigned char *options, int optlen) return (void *)state; out_free: - if (state->sha1_digest) - kfree(state->sha1_digest); + kfree(state->sha1_digest); if (state->sha1) crypto_free_hash(state->sha1); if (state->arc4) @@ -255,8 +254,7 @@ static void mppe_free(void *arg) { struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg; if (state) { - if (state->sha1_digest) - kfree(state->sha1_digest); + kfree(state->sha1_digest); if (state->sha1) crypto_free_hash(state->sha1); if (state->arc4) -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 4 Dec 2014 22:30:20 +0100 The functions crypto_free_blkcipher((), crypto_free_hash() and kfree() could be called in some cases by the mppe_alloc() function during error handling even if the passed data structure element contained still a null pointer. This implementation detail could be improved by adjustments for jump labels. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/net/ppp/ppp_mppe.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/drivers/net/ppp/ppp_mppe.c b/drivers/net/ppp/ppp_mppe.c index 94ff216..c82198f 100644 --- a/drivers/net/ppp/ppp_mppe.c +++ b/drivers/net/ppp/ppp_mppe.c @@ -196,11 +196,11 @@ static void *mppe_alloc(unsigned char *options, int optlen) if (optlen != CILEN_MPPE + sizeof(state->master_key) || options[0] != CI_MPPE || options[1] != CILEN_MPPE) - goto out; + return NULL; state = kzalloc(sizeof(*state), GFP_KERNEL); if (state = NULL) - goto out; + return NULL; state->arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC); @@ -212,16 +212,16 @@ static void *mppe_alloc(unsigned char *options, int optlen) state->sha1 = crypto_alloc_hash("sha1", 0, CRYPTO_ALG_ASYNC); if (IS_ERR(state->sha1)) { state->sha1 = NULL; - goto out_free; + goto out_free_blkcipher; } digestsize = crypto_hash_digestsize(state->sha1); if (digestsize < MPPE_MAX_KEY_LEN) - goto out_free; + goto out_free_hash; state->sha1_digest = kmalloc(digestsize, GFP_KERNEL); if (!state->sha1_digest) - goto out_free; + goto out_free_hash; /* Save keys. */ memcpy(state->master_key, &options[CILEN_MPPE], @@ -236,14 +236,12 @@ static void *mppe_alloc(unsigned char *options, int optlen) return (void *)state; +out_free_hash: + crypto_free_hash(state->sha1); +out_free_blkcipher: + crypto_free_blkcipher(state->arc4); out_free: - kfree(state->sha1_digest); - if (state->sha1) - crypto_free_hash(state->sha1); - if (state->arc4) - crypto_free_blkcipher(state->arc4); kfree(state); -out: return NULL; } -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 4 Dec 2014 22:33:34 +0100 The data structure element "arc4" was assigned a null pointer by the mppe_alloc() function if a previous function call "crypto_alloc_blkcipher" failed. This assignment became unnecessary with previous source code adjustments. Let us delete it from the affected implementation because the element "arc4" will not be accessible outside the function after the detected allocation failure. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/net/ppp/ppp_mppe.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/net/ppp/ppp_mppe.c b/drivers/net/ppp/ppp_mppe.c index c82198f..b7db4b1 100644 --- a/drivers/net/ppp/ppp_mppe.c +++ b/drivers/net/ppp/ppp_mppe.c @@ -204,10 +204,8 @@ static void *mppe_alloc(unsigned char *options, int optlen) state->arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC); - if (IS_ERR(state->arc4)) { - state->arc4 = NULL; + if (IS_ERR(state->arc4)) goto out_free; - } state->sha1 = crypto_alloc_hash("sha1", 0, CRYPTO_ALG_ASYNC); if (IS_ERR(state->sha1)) { -- 2.1.3
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 4 Dec 2014 22:42:30 +0100 The data structure element "sha1" was assigned a null pointer by the mppe_alloc() after a function call "crypto_alloc_hash" failed. It was determined that this element was not accessed by the implementation of the crypto_free_blkcipher() function. Let us delete it from the affected implementation because the element "sha1" will not be accessible outside the function after the detected allocation failure. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/net/ppp/ppp_mppe.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/net/ppp/ppp_mppe.c b/drivers/net/ppp/ppp_mppe.c index b7db4b1..32cb054 100644 --- a/drivers/net/ppp/ppp_mppe.c +++ b/drivers/net/ppp/ppp_mppe.c @@ -208,10 +208,8 @@ static void *mppe_alloc(unsigned char *options, int optlen) goto out_free; state->sha1 = crypto_alloc_hash("sha1", 0, CRYPTO_ALG_ASYNC); - if (IS_ERR(state->sha1)) { - state->sha1 = NULL; + if (IS_ERR(state->sha1)) goto out_free_blkcipher; - } digestsize = crypto_hash_digestsize(state->sha1); if (digestsize < MPPE_MAX_KEY_LEN) -- 2.1.3
On Thu, 2014-12-04 at 23:10 +0100, SF Markus Elfring wrote: > The mppe_rekey() function contained a few update candidates. > * Curly brackets were still used around a single function call "printk". > * Unwanted space characters > > Let us improve these implementation details according to the current Linux > coding style convention. trivia: > diff --git a/drivers/net/ppp/ppp_mppe.c b/drivers/net/ppp/ppp_mppe.c [] > @@ -172,9 +172,8 @@ static void mppe_rekey(struct ppp_mppe_state * state, int initial_key) > setup_sg(sg_in, state->sha1_digest, state->keylen); > setup_sg(sg_out, state->session_key, state->keylen); > if (crypto_blkcipher_encrypt(&desc, sg_out, sg_in, > - state->keylen) != 0) { > - printk(KERN_WARNING "mppe_rekey: cipher_encrypt failed\n"); > - } > + state->keylen) != 0) > + pr_warn("mppe_rekey: cipher_encrypt failed\n"); It's generally nicer to replace embedded function names with "%s: ", __func__ pr_warn("%s: cipher_encrypt failed\n", __func__);
>> diff --git a/drivers/net/ppp/ppp_mppe.c b/drivers/net/ppp/ppp_mppe.c
> []
>> @@ -172,9 +172,8 @@ static void mppe_rekey(struct ppp_mppe_state * state, int initial_key)
>> setup_sg(sg_in, state->sha1_digest, state->keylen);
>> setup_sg(sg_out, state->session_key, state->keylen);
>> if (crypto_blkcipher_encrypt(&desc, sg_out, sg_in,
>> - state->keylen) != 0) {
>> - printk(KERN_WARNING "mppe_rekey: cipher_encrypt failed\n");
>> - }
>> + state->keylen) != 0)
>> + pr_warn("mppe_rekey: cipher_encrypt failed\n");
>
> It's generally nicer to replace embedded function names
> with "%s: ", __func__
>
> pr_warn("%s: cipher_encrypt failed\n", __func__);
Do you want that I send a third patch series for the fine-tuning of these parameters?
Regards,
Martkus
On Thu, 2014-12-04 at 23:27 +0100, SF Markus Elfring wrote:
> >> diff --git a/drivers/net/ppp/ppp_mppe.c b/drivers/net/ppp/ppp_mppe.c
> > []
> >> @@ -172,9 +172,8 @@ static void mppe_rekey(struct ppp_mppe_state * state, int initial_key)
> >> setup_sg(sg_in, state->sha1_digest, state->keylen);
> >> setup_sg(sg_out, state->session_key, state->keylen);
> >> if (crypto_blkcipher_encrypt(&desc, sg_out, sg_in,
> >> - state->keylen) != 0) {
> >> - printk(KERN_WARNING "mppe_rekey: cipher_encrypt failed\n");
> >> - }
> >> + state->keylen) != 0)
> >> + pr_warn("mppe_rekey: cipher_encrypt failed\n");
> >
> > It's generally nicer to replace embedded function names
> > with "%s: ", __func__
> >
> > pr_warn("%s: cipher_encrypt failed\n", __func__);
>
> Do you want that I send a third patch series for the fine-tuning of these parameters?
If you want.
I just wanted you to be aware of it for future patches.
On Thu, 4 Dec 2014, Joe Perches wrote:
> On Thu, 2014-12-04 at 23:27 +0100, SF Markus Elfring wrote:
> > >> diff --git a/drivers/net/ppp/ppp_mppe.c b/drivers/net/ppp/ppp_mppe.c
> > > []
> > >> @@ -172,9 +172,8 @@ static void mppe_rekey(struct ppp_mppe_state * state, int initial_key)
> > >> setup_sg(sg_in, state->sha1_digest, state->keylen);
> > >> setup_sg(sg_out, state->session_key, state->keylen);
> > >> if (crypto_blkcipher_encrypt(&desc, sg_out, sg_in,
> > >> - state->keylen) != 0) {
> > >> - printk(KERN_WARNING "mppe_rekey: cipher_encrypt failed\n");
> > >> - }
> > >> + state->keylen) != 0)
> > >> + pr_warn("mppe_rekey: cipher_encrypt failed\n");
> > >
> > > It's generally nicer to replace embedded function names
> > > with "%s: ", __func__
> > >
> > > pr_warn("%s: cipher_encrypt failed\n", __func__);
> >
> > Do you want that I send a third patch series for the fine-tuning of these parameters?
>
> If you want.
>
> I just wanted you to be aware of it for future patches.
Markus, are you sure that you cannot use netdev_warn in this case?
julia
>>> It's generally nicer to replace embedded function names >>> with "%s: ", __func__ >>> >>> pr_warn("%s: cipher_encrypt failed\n", __func__); >> >> Do you want that I send a third patch series for the fine-tuning of these parameters? > > If you want. Would "a committer" fix such a small source code adjustment also without a resend of a patch series? > I just wanted you to be aware of it for future patches. Thanks for your tip. Does it make sense to express such implementation details in the Linux coding style documentation more explicitly (besides the fact that this update suggestion was also triggered by a warning from the script "checkpatch.pl"). Regards, Markus
On Thu, 4 Dec 2014, Joe Perches wrote:
> On Thu, 2014-12-04 at 23:10 +0100, SF Markus Elfring wrote:
> > The mppe_rekey() function contained a few update candidates.
> > * Curly brackets were still used around a single function call "printk".
> > * Unwanted space characters
> >
> > Let us improve these implementation details according to the current Linux
> > coding style convention.
>
> trivia:
>
> > diff --git a/drivers/net/ppp/ppp_mppe.c b/drivers/net/ppp/ppp_mppe.c
> []
> > @@ -172,9 +172,8 @@ static void mppe_rekey(struct ppp_mppe_state * state, int initial_key)
> > setup_sg(sg_in, state->sha1_digest, state->keylen);
> > setup_sg(sg_out, state->session_key, state->keylen);
> > if (crypto_blkcipher_encrypt(&desc, sg_out, sg_in,
> > - state->keylen) != 0) {
> > - printk(KERN_WARNING "mppe_rekey: cipher_encrypt failed\n");
> > - }
> > + state->keylen) != 0)
> > + pr_warn("mppe_rekey: cipher_encrypt failed\n");
>
> It's generally nicer to replace embedded function names
> with "%s: ", __func__
>
> pr_warn("%s: cipher_encrypt failed\n", __func__);
Doing so may potentially allow some strings to be shared, thus saving a
little space. Perhaps not in this case, though.
julia
On Fri, 2014-12-05 at 08:21 +0100, Julia Lawall wrote:
> On Thu, 4 Dec 2014, Joe Perches wrote:
> > It's generally nicer to replace embedded function names
> > with "%s: ", __func__
> >
> > pr_warn("%s: cipher_encrypt failed\n", __func__);
>
> Doing so may potentially allow some strings to be shared, thus saving a
> little space. Perhaps not in this case, though.
It's not necessarily a code size savings in any case.
It can be, but the real benefits are stylistic
consistency and lack of mismatch between function
name and message.
If the code is refactored or copy/pasted into another
function, a moderately common defect is not modifying
the embedded function name in the message.
There may be some smallish savings if ever these
__func__ uses were converted to use %pf via some
internal standardized mechanism.
A negative to that approach is inlined functions would
take the function name of the parent not keep the
inlined function name.
On Fri, 2014-12-05 at 08:18 +0100, SF Markus Elfring wrote: > >>> It's generally nicer to replace embedded function names > >>> with "%s: ", __func__ > >>> > >>> pr_warn("%s: cipher_encrypt failed\n", __func__); > >> > >> Do you want that I send a third patch series for the fine-tuning of these parameters? > > > > If you want. > > Would "a committer" fix such a small source code adjustment also without a resend of > a patch series? Depends on the committer. Some might, most wouldn't. drivers/net/ppp doesn't have a specific maintainer. The networking maintainer generally asks for resends of patches that don't suit his taste, but lots of non-perfect patches still get applied there. It's a process, and it's not immediate. Wait to see if these get applied as-is. If the embedded function name use, which is trivial, bothers you, send another patch later on that changes it. > Does it make sense to express such implementation details in the Linux coding > style documentation more explicitly (besides the fact that this update suggestion > was also triggered by a warning from the script "checkpatch.pl"). Probably not. Overly formalized coding style rules are perhaps more of a barrier to entry than most want.
> Markus, are you sure that you cannot use netdev_warn in this case?
No. - I did not become familiar enough with the software infrastructure around
the mppe_rekey() function.
I do not see so far how I could determine a pointer for the first parameter there.
The data structure "ppp_mppe_state" (which is referenced by the input variable
"state") does not contain corresponding context information, does it?
Regards,
Markus
On Fri, 5 Dec 2014, SF Markus Elfring wrote:
> > Markus, are you sure that you cannot use netdev_warn in this case?
>
> No. - I did not become familiar enough with the software infrastructure around
> the mppe_rekey() function.
>
> I do not see so far how I could determine a pointer for the first parameter there.
> The data structure "ppp_mppe_state" (which is referenced by the input variable
> "state") does not contain corresponding context information, does it?
Indeed, I also don't see anything promising.
julia
> It's a process, and it's not immediate. Wait to see > if these get applied as-is. Thanks for your constructive feedback. > If the embedded function name use, which is trivial, bothers you, > send another patch later on that changes it. Not really at the moment ... I guess that I would prefer a general development of another semantic patch approach according to your request with the topic "Finding embedded function names?" a moment ago. https://systeme.lip6.fr/pipermail/cocci/2014-December/001517.html http://article.gmane.org/gmane.comp.version-control.coccinelle/4399 Regards, Markus
On Thu, Dec 04, 2014 at 11:18:41PM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 4 Dec 2014 22:33:34 +0100
>
> The data structure element "arc4" was assigned a null pointer by the
> mppe_alloc() function if a previous function call "crypto_alloc_blkcipher"
> failed.
No. crypto_alloc_blkcipher() returns error pointers and not NULL.
This patch creates a bug.
regards,
dan carpenter
On Thu, Dec 04, 2014 at 11:20:21PM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 4 Dec 2014 22:42:30 +0100
>
> The data structure element "sha1" was assigned a null pointer by the
> mppe_alloc() after a function call "crypto_alloc_hash" failed.
This patch is also buggy.
regards,
dan carpenter
>> The data structure element "arc4" was assigned a null pointer by the >> mppe_alloc() function if a previous function call "crypto_alloc_blkcipher" >> failed. > > crypto_alloc_blkcipher() returns error pointers and not NULL. That is true. > This patch creates a bug. Please explain: How? Did you notice that the data structure element "arc4" was reset to a null pointer if a failure was detected for the function call "crypto_alloc_blkcipher"? Do you find this specific assignment still necessary for exception handling in the implementation of mppe_alloc() function? Regards, Markus
>> The data structure element "sha1" was assigned a null pointer by the
>> mppe_alloc() after a function call "crypto_alloc_hash" failed.
>
> This patch is also buggy.
Do you really want to keep a variable reset after a detected failure?
Regards,
Markus
On Fri, Dec 05, 2014 at 01:44:30PM +0100, SF Markus Elfring wrote:
> >> The data structure element "arc4" was assigned a null pointer by the
> >> mppe_alloc() function if a previous function call "crypto_alloc_blkcipher"
> >> failed.
> >
> > crypto_alloc_blkcipher() returns error pointers and not NULL.
>
> That is true.
>
Oh. In that case, I misunderstood what you wrote. Looking at it now,
this patch is actually ok.
regards,
dan carpenter
On Fri, Dec 05, 2014 at 03:23:15PM +0300, Dan Carpenter wrote:
> On Thu, Dec 04, 2014 at 11:20:21PM +0100, SF Markus Elfring wrote:
> > From: Markus Elfring <elfring@users.sourceforge.net>
> > Date: Thu, 4 Dec 2014 22:42:30 +0100
> >
> > The data structure element "sha1" was assigned a null pointer by the
> > mppe_alloc() after a function call "crypto_alloc_hash" failed.
>
> This patch is also buggy.
Actually it's ok. I was just confused by the changelog.
Sorry about that, Markus.
regards,
dan carpenter
>> That is true. > > In that case, I misunderstood what you wrote. I find it a bit interesting how this misunderstanding could happen here somehow. > Looking at it now, this patch is actually ok. Does that mean that you would like to add any tag like "Acked-by" or "Reviewed-by" to any of the proposed six update steps? Regards, Markus
... ciao: : on "12-4-2014" "Joe Perches" writ: : > Does it make sense to express such implementation details in the Linux : > coding style documentation more explicitly (besides the fact that this : > update suggestion was also triggered by a warning from the script : > "checkpatch.pl". : : Probably not. : : Overly formalized coding style rules are perhaps : more of a barrier to entry than most want. funny you should mention that. as nothing more than a casual observer, i'm noticing a "TIRED" sensation reading this thread. i have "0" confidence a "SERIOUS" participant's enthusiasm would remain untested. however, the "checkpatch.pl" warning suggests an assumed 'custom'. i can't tell if this a 'serious' issue, or "pickin' fly shit out of pepper". but from my reading of it, the "CODE" , and the "logic" driving it, is not the problem. season's best ... -- ... it's not what you see , but in stead , notice ...
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 29 Nov 2014 15:05:33 +0100
> 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>
Applied.
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 29 Nov 2014 16:30:27 +0100
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 29 Nov 2014 16:23:20 +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>
Applied.
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 29 Nov 2014 19:00:17 +0100
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 29 Nov 2014 18:55:40 +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>
Applied.
> A negative to that approach is inlined functions would
> take the function name of the parent not keep the
> inlined function name.
I tried the following:
#include <stdio.h>
inline int foo() {
printf("%s %x\n",__func__,0x12345);
}
int main () {
foo();
}
The assembly code generated for main is:
0000000000400470 <main>:
400470: b9 45 23 01 00 mov $0x12345,%ecx
400475: ba 4b 06 40 00 mov $0x40064b,%edx
40047a: be 44 06 40 00 mov $0x400644,%esi
40047f: bf 01 00 00 00 mov $0x1,%edi
400484: 31 c0 xor %eax,%eax
400486: e9 d5 ff ff ff jmpq 400460 <__printf_chk@plt>
That is, the call to foo seems tom be inlined.
But the output is:
foo 12345
So it seems that __func__ is determined before inlining.
julia
On Sun, 2014-12-07 at 11:44 +0100, Julia Lawall wrote:
> > A negative to that approach is inlined functions would
> > take the function name of the parent not keep the
> > inlined function name.
>
> I tried the following:
>
> #include <stdio.h>
>
> inline int foo() {
> printf("%s %x\n",__func__,0x12345);
> }
>
> int main () {
> foo();
> }
>
> The assembly code generated for main is:
>
> 0000000000400470 <main>:
> 400470: b9 45 23 01 00 mov $0x12345,%ecx
> 400475: ba 4b 06 40 00 mov $0x40064b,%edx
> 40047a: be 44 06 40 00 mov $0x400644,%esi
> 40047f: bf 01 00 00 00 mov $0x1,%edi
> 400484: 31 c0 xor %eax,%eax
> 400486: e9 d5 ff ff ff jmpq 400460 <__printf_chk@plt>
>
> That is, the call to foo seems tom be inlined.
>
> But the output is:
>
> foo 12345
>
> So it seems that __func__ is determined before inlining.
True, and that's what I intended to describe.
If you did that with a kernel module and replaced
"%s, __func__" with "%pf, __builtin_return_address(0)"
when built with kallsyms you should get:
"modname 12345" when most would expect "foo 12345"
when built without kallsyms, that output should be
"<address> 12345"
but the object code should be smaller.
On Sun, 7 Dec 2014, Joe Perches wrote:
> On Sun, 2014-12-07 at 11:44 +0100, Julia Lawall wrote:
> > > A negative to that approach is inlined functions would
> > > take the function name of the parent not keep the
> > > inlined function name.
> >
> > I tried the following:
> >
> > #include <stdio.h>
> >
> > inline int foo() {
> > printf("%s %x\n",__func__,0x12345);
> > }
> >
> > int main () {
> > foo();
> > }
> >
> > The assembly code generated for main is:
> >
> > 0000000000400470 <main>:
> > 400470: b9 45 23 01 00 mov $0x12345,%ecx
> > 400475: ba 4b 06 40 00 mov $0x40064b,%edx
> > 40047a: be 44 06 40 00 mov $0x400644,%esi
> > 40047f: bf 01 00 00 00 mov $0x1,%edi
> > 400484: 31 c0 xor %eax,%eax
> > 400486: e9 d5 ff ff ff jmpq 400460 <__printf_chk@plt>
> >
> > That is, the call to foo seems tom be inlined.
> >
> > But the output is:
> >
> > foo 12345
> >
> > So it seems that __func__ is determined before inlining.
>
> True, and that's what I intended to describe.
>
> If you did that with a kernel module and replaced
> "%s, __func__" with "%pf, __builtin_return_address(0)"
> when built with kallsyms you should get:
>
> "modname 12345" when most would expect "foo 12345"
>
> when built without kallsyms, that output should be
> "<address> 12345"
>
> but the object code should be smaller.
OK. But the semantic patch is only using __func__ and only in cases where
the string wanted is similar to the name of the current function, so I
think it should be OK?
julia
On Sun, 2014-12-07 at 13:36 +0100, Julia Lawall wrote:
> the semantic patch is only using __func__ and only in cases where
> the string wanted is similar to the name of the current function, so I
> think it should be OK?
Yes, it'd be a good thing.
On Mon, 2014-12-01 at 05:50 +0100, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Mon, 1 Dec 2014 05:45:42 +0100 > > The thermal_zone_device_unregister() 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> applied. thanks, rui > --- > drivers/thermal/int340x_thermal/int3403_thermal.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/thermal/int340x_thermal/int3403_thermal.c b/drivers/thermal/int340x_thermal/int3403_thermal.c > index 6e9fb62..790b8f6 100644 > --- a/drivers/thermal/int340x_thermal/int3403_thermal.c > +++ b/drivers/thermal/int340x_thermal/int3403_thermal.c > @@ -293,8 +293,7 @@ static int int3403_sensor_add(struct int3403_priv *priv) > return 0; > > err_free_obj: > - if (obj->tzone) > - thermal_zone_device_unregister(obj->tzone); > + thermal_zone_device_unregister(obj->tzone); > return result; > } >
On Mon, Dec 01, 2014 at 06:12:21AM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Mon, 1 Dec 2014 06:06:57 +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.
Please make sure you use the right subsystem name
Applied, thanks
--
~Vinod
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 04 Dec 2014 23:03:30 +0100
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 4 Dec 2014 22:50:28 +0100
>
> Further update suggestions were taken into account before and after a patch
> was applied from static source code analysis.
Generally speaking, it is advisable to not leave error pointers in data
structures, even if they are about to be free'd up in an error path
anyways.
Therefore I do not like some of the patches in this series.
Sorry.
On Thu, Nov 20, 2014 at 05:47:29PM +0100, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Thu, 20 Nov 2014 17:42:23 +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> Applied to next-pci/misc for v3.19, thanks. This branch will be rebased when v3.19-rc1 is released. Bjorn > --- > drivers/pci/hotplug/cpci_hotplug_core.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/pci/hotplug/cpci_hotplug_core.c b/drivers/pci/hotplug/cpci_hotplug_core.c > index e09cf78..82c969b 100644 > --- a/drivers/pci/hotplug/cpci_hotplug_core.c > +++ b/drivers/pci/hotplug/cpci_hotplug_core.c > @@ -211,8 +211,7 @@ static void release_slot(struct hotplug_slot *hotplug_slot) > > kfree(slot->hotplug_slot->info); > kfree(slot->hotplug_slot); > - if (slot->dev) > - pci_dev_put(slot->dev); > + pci_dev_put(slot->dev); > kfree(slot); > } > > -- > 2.1.3 >
> Generally speaking, it is advisable to not leave error pointers in data
> structures, even if they are about to be free'd up in an error path anyways.
>
> Therefore I do not like some of the patches in this series.
Can you give any more concrete feedback here?
Regards,
Markus
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 12 Dec 2014 08:01:54 +0100
>> Generally speaking, it is advisable to not leave error pointers in data
>> structures, even if they are about to be free'd up in an error path anyways.
>>
>> Therefore I do not like some of the patches in this series.
>
> Can you give any more concrete feedback here?
I gave you very concrete feedback, I said exactly that I don't want
error pointers left in data structure members.
I cannot describe my requirements any more precisely than that.
> I gave you very concrete feedback, I said exactly that I don't want > error pointers left in data structure members. I find that your critique affects the proposed update steps four to six, doesn't it? Are the other steps acceptable in principle? > I cannot describe my requirements any more precisely than that. I hope that a bit more constructive suggestions will be contributed by involved software developers around the affected source code. Now it seems that a small code clean-up becomes a more challenging development task. How do you prefer to redesign corresponding data structures eventually? Regards, Markus
You are asking me to invest a lot of time for a very trivial set of changes. Why don't you just integrate the feedback you were given and resubmit your patch series, just like any other developer would?
> You are asking me to invest a lot of time for a very trivial > set of changes. I find the proposed six update steps also trivial so far. > Why don't you just integrate the feedback you were given and > resubmit your patch series, just like any other developer would? I find the requested redesign and reorganisation of involved data structures not so easy and therefore more challenging at the moment. Where should "the error pointers" be stored instead? Is such a software improvement even a kind of add-on to my patch series? Regards, Markus
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 12 Dec 2014 17:56:36 +0100
> Where should "the error pointers" be stored instead?
A local variable, before you assign it into the datastructure.
>> Where should "the error pointers" be stored instead?
> A local variable, before you assign it into the datastructure.
Will it be acceptable for you that anyone (or even me) will introduce
such a change with a seventh (and eventually eighth) update step here?
Do you want any other sequence for source code preparation of
the requested software improvement?
Regards,
Markus
> I hope that a bit more constructive suggestions will be contributed by
> involved
> software developers around the affected source code. Now it seems
> that a small code clean-up becomes a more challenging development task.
This is often the case. Doing something half way is not useful.
julia
On Fri, 2014-12-12 at 18:22 +0100, SF Markus Elfring wrote:
> Will it be acceptable for you that anyone (or even me) will introduce
> such a change with a seventh (and eventually eighth) update step here?
> Do you want any other sequence for source code preparation of
> the requested software improvement?
The thing is : We are in the merge window, tracking bugs added in latest
dev cycle.
Having to deal with patches like yours is adding pressure
on the maintainer (and other developers) at the wrong time.
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 12 Dec 2014 18:22:48 +0100
>>> Where should "the error pointers" be stored instead?
>> A local variable, before you assign it into the datastructure.
>
> Will it be acceptable for you that anyone (or even me) will introduce
> such a change with a seventh (and eventually eighth) update step here?
> Do you want any other sequence for source code preparation of
> the requested software improvement?
I'd like to honestly ask why you are being so difficult?
Everyone gets their code reviewed, everyone has to modify their
changes to adhere to the subsystem maintainer's wishes. You
are not being treated specially, and quite frankly nobody is
asking anything unreasonable of you.
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 21 Nov 2014 20:26:29 +0100
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 21 Nov 2014 20:22:32 +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>
Applied.
> We are in the merge window, tracking bugs added in latest dev cycle. I am also curious on the software evolution about how many improvements will arrive in the next Linux versions. > Having to deal with patches like yours is adding pressure > on the maintainer (and other developers) at the wrong time. You can relax a bit eventually. More merge windows will follow, won't they? It will be nice if a bunch of recent code clean-ups which were also triggered by static source code analysis will be integrated into Linux 3.19 already. More update suggestions will be considered later again as usual. Regards, Markus
> I'd like to honestly ask why you are being so difficult? There are several factors which contribute to your perception of difficulty here. 1. I try to extract from every feedback the information about the amount of acceptance or rejection for a specific update suggestion. A terse feedback (like yours for this issue) makes it occasionally harder to see the next useful steps. So another constructive discussion is evolving around the clarification of some implementation details. 2. I prefer also different communication styles at some points. 3. I reached a point where the desired software updates were not immediately obvious for me while other contributors might have achieved a better understanding for the affected issues already. 4. I am on the way at the moment to get my Linux software development system running again. https://forums.opensuse.org/showthread.php/503327-System-startup-does-not-continue-after-hard-disk-detection > Everyone gets their code reviewed, everyone has to modify their > changes to adhere to the subsystem maintainer's wishes. That is fine as usual. > You are not being treated specially, and quite frankly nobody > is asking anything unreasonable of you. That is also true as the software development process will be continued. Regards, Markus
>> Where should "the error pointers" be stored instead? > > A local variable, before you assign it into the datastructure. I have looked at the affected software infrastructure once more. Now I find still that your data reorgansisation wish can not be resolved in a simple way. I imagine that your update suggestion would mean that the corresponding pointers will be passed around by function parameters instead, wouldn't it? Two pointers were stored as the members "arc4" and "sha1" of the data structure "ppp_mppe_state" for a specific reason. A pointer to this structure is passed to the ppp_register_compressor() function. https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/include/linux/ppp-comp.h?id`7ca46e97a1b6594b29647d98a32d545c24bdff#n32 The data structure "compressor" manages some function pointers. I assume that this interface should not be changed at the moment, should it? Are further ideas needed here? Regards, Markus
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 18 Dec 2014 18:23:08 +0100
>>> Where should "the error pointers" be stored instead?
>>
>> A local variable, before you assign it into the datastructure.
>
> I have looked at the affected software infrastructure once more.
> Now I find still that your data reorgansisation wish can not be resolved
> in a simple way.
I'm saying to leave the code alone.
If it goes:
var = foo_that_returns_ptr_err()
if (IS_ERR(var))
return PTR_ERR(var);
p->bar = var;
or whatever, simply keep it that way!
I'm not engaging in this conversation any further, you have already
consumed way too much of my limited time on this incredibly trivial
matter.
>> Now I find still that your data reorgansisation wish can not be resolved >> in a simple way. > > I'm saying to leave the code alone. It seems that there might be a misunderstanding between us. > If it goes: > > var = foo_that_returns_ptr_err() > if (IS_ERR(var)) > return PTR_ERR(var); > > p->bar = var; > > or whatever, simply keep it that way! A simple return was not used by the mppe_alloc() function so far because a bit of memory clean-up will also be useful after error detection, won't it? > I'm not engaging in this conversation any further, you have already > consumed way too much of my limited time on this incredibly trivial matter. It can occasionally happen that a safe clarification of specific implementation details will need more efforts than you would like to invest at the moment. Regards, Markus
> I'm saying to leave the code alone. Do I need to try another interpretation out for your feedback? > If it goes: > > var = foo_that_returns_ptr_err() > if (IS_ERR(var)) > return PTR_ERR(var); > > p->bar = var; > > or whatever, simply keep it that way! Do you want to express here that a data structure member should only be set after a previous function call succeeded? > I'm not engaging in this conversation any further, you have > already consumed way too much of my limited time on this > incredibly trivial matter. I hope that you will find a bit time and patience again to clarify affected implementation details in a safer and unambiguous way. Regards, Markus
Hi Markus,
On 20.12.2014 15:45, SF Markus Elfring wrote:
>> I'm saying to leave the code alone.
>
> Do I need to try another interpretation out for your feedback?
>
>
>> If it goes:
>>
>> var = foo_that_returns_ptr_err()
>> if (IS_ERR(var))
>> return PTR_ERR(var);
>>
>> p->bar = var;
>>
>> or whatever, simply keep it that way!
>
> Do you want to express here that a data structure member should
> only be set after a previous function call succeeded?
>
I think what David said was pretty clear: If you see code like the above
there is no need to refactor it. That does not mean that this is the
_preferred_ way of error handling. Its just good enough to be left alone.
Regards,
Lino
> I think what David said was pretty clear: If you see code like the above > there is no need to refactor it. I can understand this view in principle. > That does not mean that this is the _preferred_ way of error handling. Can your feedback help in the clarification of suggestions around my update steps one to six for this Linux software module? Regards, Markus
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 20 Dec 2014 15:45:32 +0100
> I hope that you will find a bit time and patience again
> to clarify affected implementation details in a safer and
> unambiguous way.
Sorry, another developer will have to hold your hand, as I
said I already invested too much time into this.
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 28 Dec 2014 14:50:08 +0100 Further update suggestions were taken into account after a patch was applied from static source code analysis. Markus Elfring (8): Deletion of unnecessary checks before the function call "p9_client_clunk" One function call less in v9fs_create() after error detection One function call less in v9fs_vfs_atomic_open() after error detection One function call less in v9fs_fid_xattr_get() after error detection One function call less in v9fs_vfs_atomic_open_dotl() after error detection Less function calls in v9fs_vfs_mkdir_dotl() after error detection One function call less in v9fs_vfs_symlink_dotl() after error detection Less function calls in v9fs_vfs_mknod_dotl() after error detection fs/9p/vfs_dir.c | 3 +-- fs/9p/vfs_inode.c | 25 ++++++++++-------------- fs/9p/vfs_inode_dotl.c | 52 +++++++++++++++++++++----------------------------- fs/9p/xattr.c | 6 ++---- 4 files changed, 35 insertions(+), 51 deletions(-) -- 2.2.1
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 27 Dec 2014 09:34:39 +0100 The p9_client_clunk() 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/9p/vfs_dir.c | 3 +-- fs/9p/vfs_inode.c | 12 ++++-------- fs/9p/vfs_inode_dotl.c | 15 +++++---------- fs/9p/xattr.c | 3 +-- 4 files changed, 11 insertions(+), 22 deletions(-) diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c index 4f11510..9c13866 100644 --- a/fs/9p/vfs_dir.c +++ b/fs/9p/vfs_dir.c @@ -229,8 +229,7 @@ int v9fs_dir_release(struct inode *inode, struct file *filp) fid = filp->private_data; p9_debug(P9_DEBUG_VFS, "inode: %p filp: %p fid: %d\n", inode, filp, fid ? fid->fid : -1); - if (fid) - p9_client_clunk(fid); + p9_client_clunk(fid); return 0; } diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index 9ee5343..a787d4c 100644 --- a/fs/9p/vfs_inode.c +++ b/fs/9p/vfs_inode.c @@ -700,11 +700,9 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir, } return ofid; error: - if (ofid) - p9_client_clunk(ofid); + p9_client_clunk(ofid); - if (fid) - p9_client_clunk(fid); + p9_client_clunk(fid); return ERR_PTR(err); } @@ -768,8 +766,7 @@ static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode v9fs_invalidate_inode_attr(dir); } - if (fid) - p9_client_clunk(fid); + p9_client_clunk(fid); return err; } @@ -916,8 +913,7 @@ out: return err; error: - if (fid) - p9_client_clunk(fid); + p9_client_clunk(fid); goto out; } diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c index 6054c16b..3611b0f 100644 --- a/fs/9p/vfs_inode_dotl.c +++ b/fs/9p/vfs_inode_dotl.c @@ -363,11 +363,9 @@ out: return err; error: - if (fid) - p9_client_clunk(fid); + p9_client_clunk(fid); err_clunk_old_fid: - if (ofid) - p9_client_clunk(ofid); + p9_client_clunk(ofid); goto out; } @@ -464,8 +462,7 @@ static int v9fs_vfs_mkdir_dotl(struct inode *dir, inc_nlink(dir); v9fs_invalidate_inode_attr(dir); error: - if (fid) - p9_client_clunk(fid); + p9_client_clunk(fid); v9fs_put_acl(dacl, pacl); return err; } @@ -744,8 +741,7 @@ v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry, } error: - if (fid) - p9_client_clunk(fid); + p9_client_clunk(fid); return err; } @@ -896,8 +892,7 @@ v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, umode_t omode, d_instantiate(dentry, inode); } error: - if (fid) - p9_client_clunk(fid); + p9_client_clunk(fid); v9fs_put_acl(dacl, pacl); return err; } diff --git a/fs/9p/xattr.c b/fs/9p/xattr.c index f95e01e..8e72269 100644 --- a/fs/9p/xattr.c +++ b/fs/9p/xattr.c @@ -65,8 +65,7 @@ ssize_t v9fs_fid_xattr_get(struct p9_fid *fid, const char *name, /* Total read xattr bytes */ retval = offset; error: - if (attr_fid) - p9_client_clunk(attr_fid); + p9_client_clunk(attr_fid); return retval; } -- 2.2.1
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 28 Dec 2014 08:28:51 +0100 The p9_client_clunk() function was called in two cases by the v9fs_create() function during error handling even if the passed variable "fid" contained 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/9p/vfs_inode.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index a787d4c..81b945a 100644 --- a/fs/9p/vfs_inode.c +++ b/fs/9p/vfs_inode.c @@ -672,7 +672,7 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir, err = p9_client_fcreate(ofid, name, perm, mode, extension); if (err < 0) { p9_debug(P9_DEBUG_VFS, "p9_client_fcreate failed %d\n", err); - goto error; + goto ofid_clunk; } if (!(perm & P9_DMLINK)) { @@ -682,8 +682,7 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir, err = PTR_ERR(fid); p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); - fid = NULL; - goto error; + goto ofid_clunk; } /* * instantiate inode and assign the unopened fid to the dentry @@ -693,16 +692,17 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir, err = PTR_ERR(inode); p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n", err); - goto error; + goto fid_clunk; } v9fs_fid_add(dentry, fid); d_instantiate(dentry, inode); } return ofid; -error: - p9_client_clunk(ofid); +fid_clunk: p9_client_clunk(fid); +ofid_clunk: + p9_client_clunk(ofid); return ERR_PTR(err); } -- 2.2.1
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 28 Dec 2014 08:45:31 +0100 The p9_client_clunk() function was called in one case by the v9fs_vfs_atomic_open() function during error handling even if the passed variable "fid" contained a null pointer. This implementation detail could be improved by the adjustment of a jump target. Let us delete also an unnecessary variable assignment there. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- fs/9p/vfs_inode.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index 81b945a..f568427 100644 --- a/fs/9p/vfs_inode.c +++ b/fs/9p/vfs_inode.c @@ -873,8 +873,7 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry, v9fs_proto_dotu(v9ses))); if (IS_ERR(fid)) { err = PTR_ERR(fid); - fid = NULL; - goto error; + goto out; } v9fs_invalidate_inode_attr(dir); -- 2.2.1
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 28 Dec 2014 09:05:25 +0100 The p9_client_clunk() function was called in one case by the v9fs_fid_xattr_get() function during error handling even if the passed variable "attr_fid" contained a null pointer. Let us delete an unnecessary variable assignment there and return from this implementation directly after a failure detection for a p9_client_xattrwalk() call. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- fs/9p/xattr.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/9p/xattr.c b/fs/9p/xattr.c index 8e72269..05ef790 100644 --- a/fs/9p/xattr.c +++ b/fs/9p/xattr.c @@ -34,8 +34,7 @@ ssize_t v9fs_fid_xattr_get(struct p9_fid *fid, const char *name, retval = PTR_ERR(attr_fid); p9_debug(P9_DEBUG_VFS, "p9_client_attrwalk failed %zd\n", retval); - attr_fid = NULL; - goto error; + return retval; } if (!buffer_size) { /* request to get the attr_size */ -- 2.2.1
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 28 Dec 2014 09:29:40 +0100 The p9_client_clunk() function was called in three cases by the v9fs_vfs_atomic_open_dotl() function during error handling even if the passed variable "fid" contained a null pointer. This implementation detail could be improved by the adjustment of jump targets. Let us delete also an unnecessary variable assignment there. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- fs/9p/vfs_inode_dotl.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c index 3611b0f..ce1f5bb 100644 --- a/fs/9p/vfs_inode_dotl.c +++ b/fs/9p/vfs_inode_dotl.c @@ -297,14 +297,14 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry, if (err) { p9_debug(P9_DEBUG_VFS, "Failed to get acl values in creat %d\n", err); - goto error; + goto err_clunk_old_fid; } err = p9_client_create_dotl(ofid, name, v9fs_open_to_dotl_flags(flags), mode, gid, &qid); if (err < 0) { p9_debug(P9_DEBUG_VFS, "p9_client_open_dotl failed in creat %d\n", err); - goto error; + goto err_clunk_old_fid; } v9fs_invalidate_inode_attr(dir); @@ -313,8 +313,7 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry, if (IS_ERR(fid)) { err = PTR_ERR(fid); p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); - fid = NULL; - goto error; + goto err_clunk_old_fid; } inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb); if (IS_ERR(inode)) { -- 2.2.1
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 28 Dec 2014 12:44:22 +0100 The p9_client_clunk() function was called in some cases by the v9fs_vfs_mkdir_dotl() function during error handling even if the passed variable "fid" contained a null pointer. * Corresponding details could be improved by the introduction of another jump label. * Let us delete also two unnecessary variable assignments there. * Return from this implementation directly after failure detection for the function calls "v9fs_fid_lookup" and "v9fs_acl_mode". Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- fs/9p/vfs_inode_dotl.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c index ce1f5bb..672d84f 100644 --- a/fs/9p/vfs_inode_dotl.c +++ b/fs/9p/vfs_inode_dotl.c @@ -403,8 +403,7 @@ static int v9fs_vfs_mkdir_dotl(struct inode *dir, if (IS_ERR(dfid)) { err = PTR_ERR(dfid); p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err); - dfid = NULL; - goto error; + return err; } gid = v9fs_get_fsgid_for_create(dir); @@ -414,20 +413,19 @@ static int v9fs_vfs_mkdir_dotl(struct inode *dir, if (err) { p9_debug(P9_DEBUG_VFS, "Failed to get acl values in mkdir %d\n", err); - goto error; + return err; } name = (char *) dentry->d_name.name; err = p9_client_mkdir_dotl(dfid, name, mode, gid, &qid); if (err < 0) - goto error; + goto put_acl; fid = p9_client_walk(dfid, 1, &name, 1); if (IS_ERR(fid)) { err = PTR_ERR(fid); p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); - fid = NULL; - goto error; + goto put_acl; } /* instantiate inode and assign the unopened fid to the dentry */ @@ -462,6 +460,7 @@ static int v9fs_vfs_mkdir_dotl(struct inode *dir, v9fs_invalidate_inode_attr(dir); error: p9_client_clunk(fid); +put_acl: v9fs_put_acl(dacl, pacl); return err; } -- 2.2.1
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 28 Dec 2014 13:00:54 +0100 The p9_client_clunk() function was called in two cases by the v9fs_vfs_symlink_dotl() function during error handling even if the passed variable "fid" contained a null pointer. * This implementation detail could be improved by the introduction of another jump label. * Let us delete also an unnecessary variable assignment there. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- fs/9p/vfs_inode_dotl.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c index 672d84f..3b38dda 100644 --- a/fs/9p/vfs_inode_dotl.c +++ b/fs/9p/vfs_inode_dotl.c @@ -701,7 +701,7 @@ v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry, if (err < 0) { p9_debug(P9_DEBUG_VFS, "p9_client_symlink failed %d\n", err); - goto error; + goto exit; } v9fs_invalidate_inode_attr(dir); @@ -712,8 +712,7 @@ v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry, err = PTR_ERR(fid); p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); - fid = NULL; - goto error; + goto exit; } /* instantiate inode and assign the unopened fid to dentry */ @@ -740,7 +739,7 @@ v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry, error: p9_client_clunk(fid); - +exit: return err; } -- 2.2.1
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 28 Dec 2014 13:36:28 +0100 The p9_client_clunk() function was called in four cases by the v9fs_vfs_mknod_dotl() function during error handling even if the passed variable "fid" contained a null pointer. The v9fs_put_acl() function could also be unnecessarily called with null pointers. * This implementation detail could be improved by the introduction of two jump labels. * Let us delete also two unnecessary variable assignments there. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- fs/9p/vfs_inode_dotl.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c index 3b38dda..ff3c26a 100644 --- a/fs/9p/vfs_inode_dotl.c +++ b/fs/9p/vfs_inode_dotl.c @@ -832,8 +832,7 @@ v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, umode_t omode, if (IS_ERR(dfid)) { err = PTR_ERR(dfid); p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err); - dfid = NULL; - goto error; + goto exit; } gid = v9fs_get_fsgid_for_create(dir); @@ -843,13 +842,13 @@ v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, umode_t omode, if (err) { p9_debug(P9_DEBUG_VFS, "Failed to get acl values in mknod %d\n", err); - goto error; + goto exit; } name = (char *) dentry->d_name.name; err = p9_client_mknod_dotl(dfid, name, mode, rdev, gid, &qid); if (err < 0) - goto error; + goto put_acl; v9fs_invalidate_inode_attr(dir); fid = p9_client_walk(dfid, 1, &name, 1); @@ -857,8 +856,7 @@ v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, umode_t omode, err = PTR_ERR(fid); p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); - fid = NULL; - goto error; + goto put_acl; } /* instantiate inode and assign the unopened fid to the dentry */ @@ -890,7 +888,9 @@ v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, umode_t omode, } error: p9_client_clunk(fid); +put_acl: v9fs_put_acl(dacl, pacl); +exit: return err; } -- 2.2.1
> diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c > index 9ee5343..a787d4c 100644 > --- a/fs/9p/vfs_inode.c > +++ b/fs/9p/vfs_inode.c > @@ -700,11 +700,9 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir, > } > return ofid; > error: > - if (ofid) > - p9_client_clunk(ofid); > + p9_client_clunk(ofid); > > - if (fid) > - p9_client_clunk(fid); > + p9_client_clunk(fid); > > return ERR_PTR(err); > } This code seems rather sloppy. ofid could never be NULL at the point where it was tested. There is a useless definition of ofid to NULL at the top of the function. The error handling code could be rearranged with an extra error label so that p9_client_clunk is never called on fid when it it is not defined. The the two assignments of fid to NULL could also be removed. There is also a useless initialization of err to 0 at the beginning of the function. And the first two calls to ERR_PTR are not needed, as the types of dfid and ofid are the same as the return type of the function. > @@ -768,8 +766,7 @@ static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode > v9fs_invalidate_inode_attr(dir); > } > > - if (fid) > - p9_client_clunk(fid); > + p9_client_clunk(fid); > > return err; > } This function is also unnecessarily complex. The if above this one, that detects the error could just return PTR_ERR(fid);. The rest of the function could call inc_nlink, v9fs_invalidate_inode_attr, and p9_client_clunk, and the returnvalue could be 0, removing the need for the err variable. > @@ -916,8 +913,7 @@ out: > return err; > > error: > - if (fid) > - p9_client_clunk(fid); > + p9_client_clunk(fid); > goto out; > } In the case where fid is set to NULL, it could just goto out directly, instead of calling p9_client_clunk, testing fid, coming back, and going to out anyway. julia > diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c > index 6054c16b..3611b0f 100644 > --- a/fs/9p/vfs_inode_dotl.c > +++ b/fs/9p/vfs_inode_dotl.c > @@ -363,11 +363,9 @@ out: > return err; > > error: > - if (fid) > - p9_client_clunk(fid); > + p9_client_clunk(fid); > err_clunk_old_fid: > - if (ofid) > - p9_client_clunk(ofid); > + p9_client_clunk(ofid); > goto out; > } > > @@ -464,8 +462,7 @@ static int v9fs_vfs_mkdir_dotl(struct inode *dir, > inc_nlink(dir); > v9fs_invalidate_inode_attr(dir); > error: > - if (fid) > - p9_client_clunk(fid); > + p9_client_clunk(fid); > v9fs_put_acl(dacl, pacl); > return err; > } > @@ -744,8 +741,7 @@ v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry, > } > > error: > - if (fid) > - p9_client_clunk(fid); > + p9_client_clunk(fid); > > return err; > } > @@ -896,8 +892,7 @@ v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, umode_t omode, > d_instantiate(dentry, inode); > } > error: > - if (fid) > - p9_client_clunk(fid); > + p9_client_clunk(fid); > v9fs_put_acl(dacl, pacl); > return err; > } > diff --git a/fs/9p/xattr.c b/fs/9p/xattr.c > index f95e01e..8e72269 100644 > --- a/fs/9p/xattr.c > +++ b/fs/9p/xattr.c > @@ -65,8 +65,7 @@ ssize_t v9fs_fid_xattr_get(struct p9_fid *fid, const char *name, > /* Total read xattr bytes */ > retval = offset; > error: > - if (attr_fid) > - p9_client_clunk(attr_fid); > + p9_client_clunk(attr_fid); > return retval; > > } > -- > 2.2.1 > >
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 4 Jan 2015 11:50:12 +0100 Further update suggestions were taken into account after several patches were applied from static source code analysis. Markus Elfring (3): seq: Deletion of unnecessary checks before the function call "snd_midi_event_free" oss: Deletion of unnecessary checks before the function call "vfree" emu10k1: Delete an unnecessary check before the function call "kfree" oxygen: Delete an unnecessary check before the function call "snd_pcm_suspend" emux: Delete an unnecessary check before the function call "snd_sf_free" ASoC: Intel: Delete an unnecessary check before the function call "sst_dma_free" ASoC: fsi: Deletion of unnecessary checks before the function call "clk_enable" ASoC: Intel: Delete an unnecessary check before the function call "release_firmware" i2sbus: Delete an unnecessary check before the function call "snd_pcm_suspend_all" sb: Delete an unnecessary check before the function call "snd_emux_free" Deletion of checks before the function call "iounmap" msnd: One function call less in snd_msnd_attach() after error detection msnd: Fix centralized exiting from snd_msnd_attach() sound/aoa/soundbus/i2sbus/core.c | 13 ++++++------- sound/arm/aaci.c | 4 ++-- sound/drivers/ml403-ac97cr.c | 3 +-- sound/isa/msnd/msnd_pinnacle.c | 31 ++++++++++++++++--------------- sound/parisc/harmony.c | 4 +--- sound/pci/ad1889.c | 5 +---- sound/pci/asihpi/hpioctl.c | 6 ++---- sound/pci/atiixp.c | 3 +-- sound/pci/atiixp_modem.c | 3 +-- sound/pci/aw2/aw2-alsa.c | 4 +--- sound/pci/bt87x.c | 3 +-- sound/pci/cs4281.c | 6 ++---- sound/pci/cs46xx/cs46xx_lib.c | 4 ++-- sound/pci/ctxfi/cthw20k1.c | 5 +---- sound/pci/ctxfi/cthw20k2.c | 5 +---- sound/pci/echoaudio/echoaudio.c | 6 +----- sound/pci/hda/hda_intel.c | 3 +-- sound/pci/lola/lola.c | 6 ++---- sound/pci/mixart/mixart.c | 7 +++---- sound/pci/nm256/nm256.c | 6 ++---- sound/pci/rme9652/hdsp.c | 4 +--- sound/pci/rme9652/hdspm.c | 4 +--- sound/pci/rme9652/rme9652.c | 3 +-- sound/pci/sis7019.c | 5 +---- sound/pci/ymfpci/ymfpci_main.c | 3 +-- sound/ppc/pmac.c | 15 +++++---------- 26 files changed, 58 insertions(+), 103 deletions(-) -- 2.2.1
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 3 Jan 2015 14:54:56 +0100 The snd_midi_event_free() 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/core/seq/oss/seq_oss_midi.c | 6 ++---- sound/core/seq/seq_midi.c | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/sound/core/seq/oss/seq_oss_midi.c b/sound/core/seq/oss/seq_oss_midi.c index 3a45696..e79cc44 100644 --- a/sound/core/seq/oss/seq_oss_midi.c +++ b/sound/core/seq/oss/seq_oss_midi.c @@ -237,8 +237,7 @@ snd_seq_oss_midi_check_exit_port(int client, int port) spin_unlock_irqrestore(®ister_lock, flags); snd_use_lock_free(&mdev->use_lock); snd_use_lock_sync(&mdev->use_lock); - if (mdev->coder) - snd_midi_event_free(mdev->coder); + snd_midi_event_free(mdev->coder); kfree(mdev); } spin_lock_irqsave(®ister_lock, flags); @@ -265,8 +264,7 @@ snd_seq_oss_midi_clear_all(void) spin_lock_irqsave(®ister_lock, flags); for (i = 0; i < max_midi_devs; i++) { if ((mdev = midi_devs[i]) != NULL) { - if (mdev->coder) - snd_midi_event_free(mdev->coder); + snd_midi_event_free(mdev->coder); kfree(mdev); midi_devs[i] = NULL; } diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c index a1fd77a..68fec77 100644 --- a/sound/core/seq/seq_midi.c +++ b/sound/core/seq/seq_midi.c @@ -268,8 +268,7 @@ static void snd_seq_midisynth_delete(struct seq_midisynth *msynth) snd_seq_event_port_detach(msynth->seq_client, msynth->seq_port); } - if (msynth->parser) - snd_midi_event_free(msynth->parser); + snd_midi_event_free(msynth->parser); } /* register new midi synth port */ -- 2.2.1
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 3 Jan 2015 15:10:52 +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/oss/pss.c | 2 +- sound/oss/trix.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sound/oss/pss.c b/sound/oss/pss.c index ca0d6e9..81314f9 100644 --- a/sound/oss/pss.c +++ b/sound/oss/pss.c @@ -1228,7 +1228,7 @@ static void __exit cleanup_pss(void) { if(!pss_no_sound) { - if(fw_load && pss_synth) + if (fw_load) vfree(pss_synth); if(pssmss) unload_pss_mss(&cfg2); diff --git a/sound/oss/trix.c b/sound/oss/trix.c index 944e0c0..3c494dc 100644 --- a/sound/oss/trix.c +++ b/sound/oss/trix.c @@ -487,7 +487,7 @@ static int __init init_trix(void) static void __exit cleanup_trix(void) { - if (fw_load && trix_boot) + if (fw_load) vfree(trix_boot); if (sb) unload_trix_sb(&cfg2); -- 2.2.1
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 3 Jan 2015 17:06:04 +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> --- sound/pci/emu10k1/p16v.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/sound/pci/emu10k1/p16v.c b/sound/pci/emu10k1/p16v.c index b672755..3c60b43 100644 --- a/sound/pci/emu10k1/p16v.c +++ b/sound/pci/emu10k1/p16v.c @@ -166,11 +166,8 @@ static struct snd_pcm_hardware snd_p16v_capture_hw = { static void snd_p16v_pcm_free_substream(struct snd_pcm_runtime *runtime) { struct snd_emu10k1_pcm *epcm = runtime->private_data; - - if (epcm) { - /* dev_dbg(emu->card->dev, "epcm free: %p\n", epcm); */ - kfree(epcm); - } + + kfree(epcm); } /* open_playback callback */ -- 2.2.1
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 3 Jan 2015 17:37:28 +0100 The snd_pcm_suspend() 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/oxygen/oxygen_lib.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sound/pci/oxygen/oxygen_lib.c b/sound/pci/oxygen/oxygen_lib.c index b67e306..61a62c0 100644 --- a/sound/pci/oxygen/oxygen_lib.c +++ b/sound/pci/oxygen/oxygen_lib.c @@ -736,8 +736,7 @@ static int oxygen_pci_suspend(struct device *dev) snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); for (i = 0; i < PCM_COUNT; ++i) - if (chip->streams[i]) - snd_pcm_suspend(chip->streams[i]); + snd_pcm_suspend(chip->streams[i]); if (chip->model.suspend) chip->model.suspend(chip); -- 2.2.1
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 3 Jan 2015 18:28:21 +0100 The snd_sf_free() 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/synth/emux/emux.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/sound/synth/emux/emux.c b/sound/synth/emux/emux.c index 9352207..f27a1c8 100644 --- a/sound/synth/emux/emux.c +++ b/sound/synth/emux/emux.c @@ -160,12 +160,8 @@ int snd_emux_free(struct snd_emux *emu) snd_emux_detach_seq_oss(emu); #endif snd_emux_detach_seq(emu); - snd_emux_delete_hwdep(emu); - - if (emu->sflist) - snd_sf_free(emu->sflist); - + snd_sf_free(emu->sflist); kfree(emu->voices); kfree(emu->name); kfree(emu); -- 2.2.1
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 3 Jan 2015 19:03:55 +0100 The sst_dma_free() 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/soc/intel/sst-dsp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sound/soc/intel/sst-dsp.c b/sound/soc/intel/sst-dsp.c index 86e4108..64e9421 100644 --- a/sound/soc/intel/sst-dsp.c +++ b/sound/soc/intel/sst-dsp.c @@ -410,8 +410,7 @@ void sst_dsp_free(struct sst_dsp *sst) if (sst->ops->free) sst->ops->free(sst); - if (sst->dma) - sst_dma_free(sst->dma); + sst_dma_free(sst->dma); } EXPORT_SYMBOL_GPL(sst_dsp_free); -- 2.2.1
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 3 Jan 2015 19:25:55 +0100 The clk_enable() 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/soc/sh/fsi.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/sound/soc/sh/fsi.c b/sound/soc/sh/fsi.c index 8869971..d49f25f 100644 --- a/sound/soc/sh/fsi.c +++ b/sound/soc/sh/fsi.c @@ -820,12 +820,9 @@ static int fsi_clk_enable(struct device *dev, return ret; } - if (clock->xck) - clk_enable(clock->xck); - if (clock->ick) - clk_enable(clock->ick); - if (clock->div) - clk_enable(clock->div); + clk_enable(clock->xck); + clk_enable(clock->ick); + clk_enable(clock->div); clock->count++; } -- 2.2.1
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 3 Jan 2015 19:49:37 +0100 The release_firmware() 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/soc/intel/sst/sst_loader.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sound/soc/intel/sst/sst_loader.c b/sound/soc/intel/sst/sst_loader.c index b580f96..7888cd7 100644 --- a/sound/soc/intel/sst/sst_loader.c +++ b/sound/soc/intel/sst/sst_loader.c @@ -324,8 +324,7 @@ void sst_firmware_load_cb(const struct firmware *fw, void *context) if (ctx->sst_state != SST_RESET || ctx->fw_in_mem != NULL) { - if (fw != NULL) - release_firmware(fw); + release_firmware(fw); mutex_unlock(&ctx->sst_lock); return; } -- 2.2.1
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 3 Jan 2015 20:43:01 +0100 The snd_pcm_suspend_all() 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/aoa/soundbus/i2sbus/core.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sound/aoa/soundbus/i2sbus/core.c b/sound/aoa/soundbus/i2sbus/core.c index 4e2b4fb..837ba99 100644 --- a/sound/aoa/soundbus/i2sbus/core.c +++ b/sound/aoa/soundbus/i2sbus/core.c @@ -381,10 +381,8 @@ static int i2sbus_suspend(struct macio_dev* dev, pm_message_t state) list_for_each_entry(i2sdev, &control->list, item) { /* Notify Alsa */ - if (i2sdev->sound.pcm) { - /* Suspend PCM streams */ - snd_pcm_suspend_all(i2sdev->sound.pcm); - } + /* Suspend PCM streams */ + snd_pcm_suspend_all(i2sdev->sound.pcm); /* Notify codecs */ list_for_each_entry(cii, &i2sdev->sound.codec_list, list) { -- 2.2.1
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 3 Jan 2015 21:02:32 +0100 The snd_emux_free() 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/isa/sb/emu8000_synth.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c index 95b39be..72332df 100644 --- a/sound/isa/sb/emu8000_synth.c +++ b/sound/isa/sb/emu8000_synth.c @@ -103,8 +103,7 @@ static int snd_emu8000_delete_device(struct snd_seq_device *dev) hw = dev->driver_data; if (hw->pcm) snd_device_free(dev->card, hw->pcm); - if (hw->emu) - snd_emux_free(hw->emu); + snd_emux_free(hw->emu); snd_util_memhdr_free(hw->memhdr); hw->emu = NULL; hw->memhdr = NULL; -- 2.2.1
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 3 Jan 2015 22:55:54 +0100 The iounmap() 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/aoa/soundbus/i2sbus/core.c | 13 ++++++------- sound/arm/aaci.c | 4 ++-- sound/drivers/ml403-ac97cr.c | 3 +-- sound/isa/msnd/msnd_pinnacle.c | 3 +-- sound/parisc/harmony.c | 4 +--- sound/pci/ad1889.c | 5 +---- sound/pci/asihpi/hpioctl.c | 6 ++---- sound/pci/atiixp.c | 3 +-- sound/pci/atiixp_modem.c | 3 +-- sound/pci/aw2/aw2-alsa.c | 4 +--- sound/pci/bt87x.c | 3 +-- sound/pci/cs4281.c | 6 ++---- sound/pci/cs46xx/cs46xx_lib.c | 4 ++-- sound/pci/ctxfi/cthw20k1.c | 5 +---- sound/pci/ctxfi/cthw20k2.c | 5 +---- sound/pci/echoaudio/echoaudio.c | 6 +----- sound/pci/hda/hda_intel.c | 3 +-- sound/pci/lola/lola.c | 6 ++---- sound/pci/mixart/mixart.c | 7 +++---- sound/pci/nm256/nm256.c | 6 ++---- sound/pci/rme9652/hdsp.c | 4 +--- sound/pci/rme9652/hdspm.c | 4 +--- sound/pci/rme9652/rme9652.c | 3 +-- sound/pci/sis7019.c | 5 +---- sound/pci/ymfpci/ymfpci_main.c | 3 +-- sound/ppc/pmac.c | 15 +++++---------- 26 files changed, 43 insertions(+), 90 deletions(-) diff --git a/sound/aoa/soundbus/i2sbus/core.c b/sound/aoa/soundbus/i2sbus/core.c index 4e2b4fb..7835045 100644 --- a/sound/aoa/soundbus/i2sbus/core.c +++ b/sound/aoa/soundbus/i2sbus/core.c @@ -74,10 +74,9 @@ static void i2sbus_release_dev(struct device *dev) int i; i2sdev = container_of(dev, struct i2sbus_dev, sound.ofdev.dev); - - if (i2sdev->intfregs) iounmap(i2sdev->intfregs); - if (i2sdev->out.dbdma) iounmap(i2sdev->out.dbdma); - if (i2sdev->in.dbdma) iounmap(i2sdev->in.dbdma); + iounmap(i2sdev->intfregs); + iounmap(i2sdev->out.dbdma); + iounmap(i2sdev->in.dbdma); for (i = aoa_resource_i2smmio; i <= aoa_resource_rxdbdma; i++) release_and_free_resource(i2sdev->allocated_resource[i]); free_dbdma_descriptor_ring(i2sdev, &i2sdev->out.dbdma_ring); @@ -318,9 +317,9 @@ static int i2sbus_add_dev(struct macio_dev *macio, free_irq(dev->interrupts[i], dev); free_dbdma_descriptor_ring(dev, &dev->out.dbdma_ring); free_dbdma_descriptor_ring(dev, &dev->in.dbdma_ring); - if (dev->intfregs) iounmap(dev->intfregs); - if (dev->out.dbdma) iounmap(dev->out.dbdma); - if (dev->in.dbdma) iounmap(dev->in.dbdma); + iounmap(dev->intfregs); + iounmap(dev->out.dbdma); + iounmap(dev->in.dbdma); for (i=0;i<3;i++) release_and_free_resource(dev->allocated_resource[i]); mutex_destroy(&dev->lock); diff --git a/sound/arm/aaci.c b/sound/arm/aaci.c index 0e83a73..4140b1b 100644 --- a/sound/arm/aaci.c +++ b/sound/arm/aaci.c @@ -889,8 +889,8 @@ static int aaci_probe_ac97(struct aaci *aaci) static void aaci_free_card(struct snd_card *card) { struct aaci *aaci = card->private_data; - if (aaci->base) - iounmap(aaci->base); + + iounmap(aaci->base); } static struct aaci *aaci_init_card(struct amba_device *dev) diff --git a/sound/drivers/ml403-ac97cr.c b/sound/drivers/ml403-ac97cr.c index ec01de1..bdcb572 100644 --- a/sound/drivers/ml403-ac97cr.c +++ b/sound/drivers/ml403-ac97cr.c @@ -1094,8 +1094,7 @@ static int snd_ml403_ac97cr_free(struct snd_ml403_ac97cr *ml403_ac97cr) if (ml403_ac97cr->capture_irq >= 0) free_irq(ml403_ac97cr->capture_irq, ml403_ac97cr); /* give back "port" */ - if (ml403_ac97cr->port != NULL) - iounmap(ml403_ac97cr->port); + iounmap(ml403_ac97cr->port); kfree(ml403_ac97cr); PDEBUG(INIT_INFO, "free(): (done)\n"); return 0; diff --git a/sound/isa/msnd/msnd_pinnacle.c b/sound/isa/msnd/msnd_pinnacle.c index 65b3682..4c07266 100644 --- a/sound/isa/msnd/msnd_pinnacle.c +++ b/sound/isa/msnd/msnd_pinnacle.c @@ -627,8 +627,7 @@ static int snd_msnd_attach(struct snd_card *card) return 0; err_release_region: - if (chip->mappedbase) - iounmap(chip->mappedbase); + iounmap(chip->mappedbase); release_mem_region(chip->base, BUFFSIZE); release_region(chip->io, DSP_NUMIO); free_irq(chip->irq, chip); diff --git a/sound/parisc/harmony.c b/sound/parisc/harmony.c index 29604a2..f2350c1 100644 --- a/sound/parisc/harmony.c +++ b/sound/parisc/harmony.c @@ -893,9 +893,7 @@ snd_harmony_free(struct snd_harmony *h) if (h->irq >= 0) free_irq(h->irq, h); - if (h->iobase) - iounmap(h->iobase); - + iounmap(h->iobase); kfree(h); return 0; } diff --git a/sound/pci/ad1889.c b/sound/pci/ad1889.c index 547ee30..0de3129 100644 --- a/sound/pci/ad1889.c +++ b/sound/pci/ad1889.c @@ -853,12 +853,9 @@ snd_ad1889_free(struct snd_ad1889 *chip) free_irq(chip->irq, chip); skip_hw: - if (chip->iobase) - iounmap(chip->iobase); - + iounmap(chip->iobase); pci_release_regions(chip->pci); pci_disable_device(chip->pci); - kfree(chip); return 0; } diff --git a/sound/pci/asihpi/hpioctl.c b/sound/pci/asihpi/hpioctl.c index 72af66b..67d1133 100644 --- a/sound/pci/asihpi/hpioctl.c +++ b/sound/pci/asihpi/hpioctl.c @@ -541,10 +541,8 @@ void asihpi_adapter_remove(struct pci_dev *pci_dev) hpi_send_recv_ex(&hm, &hr, HOWNER_KERNEL); /* unmap PCI memory space, mapped during device init. */ - for (idx = 0; idx < HPI_MAX_ADAPTER_MEM_SPACES; idx++) { - if (pci.ap_mem_base[idx]) - iounmap(pci.ap_mem_base[idx]); - } + for (idx = 0; idx < HPI_MAX_ADAPTER_MEM_SPACES; ++idx) + iounmap(pci.ap_mem_base[idx]); if (pa->irq) free_irq(pa->irq, pa); diff --git a/sound/pci/atiixp.c b/sound/pci/atiixp.c index 9c1c445..d24188f 100644 --- a/sound/pci/atiixp.c +++ b/sound/pci/atiixp.c @@ -1585,8 +1585,7 @@ static int snd_atiixp_free(struct atiixp *chip) __hw_end: if (chip->irq >= 0) free_irq(chip->irq, chip); - if (chip->remap_addr) - iounmap(chip->remap_addr); + iounmap(chip->remap_addr); pci_release_regions(chip->pci); pci_disable_device(chip->pci); kfree(chip); diff --git a/sound/pci/atiixp_modem.c b/sound/pci/atiixp_modem.c index b2f63e0..c321a97 100644 --- a/sound/pci/atiixp_modem.c +++ b/sound/pci/atiixp_modem.c @@ -1211,8 +1211,7 @@ static int snd_atiixp_free(struct atiixp_modem *chip) __hw_end: if (chip->irq >= 0) free_irq(chip->irq, chip); - if (chip->remap_addr) - iounmap(chip->remap_addr); + iounmap(chip->remap_addr); pci_release_regions(chip->pci); pci_disable_device(chip->pci); kfree(chip); diff --git a/sound/pci/aw2/aw2-alsa.c b/sound/pci/aw2/aw2-alsa.c index e1cf019..8d2fee7 100644 --- a/sound/pci/aw2/aw2-alsa.c +++ b/sound/pci/aw2/aw2-alsa.c @@ -229,9 +229,7 @@ static int snd_aw2_dev_free(struct snd_device *device) if (chip->irq >= 0) free_irq(chip->irq, (void *)chip); /* release the i/o ports & memory */ - if (chip->iobase_virt) - iounmap(chip->iobase_virt); - + iounmap(chip->iobase_virt); pci_release_regions(chip->pci); /* disable the PCI entry */ pci_disable_device(chip->pci); diff --git a/sound/pci/bt87x.c b/sound/pci/bt87x.c index 058b997..e82ceac 100644 --- a/sound/pci/bt87x.c +++ b/sound/pci/bt87x.c @@ -690,8 +690,7 @@ static int snd_bt87x_free(struct snd_bt87x *chip) snd_bt87x_stop(chip); if (chip->irq >= 0) free_irq(chip->irq, chip); - if (chip->mmio) - iounmap(chip->mmio); + iounmap(chip->mmio); pci_release_regions(chip->pci); pci_disable_device(chip->pci); kfree(chip); diff --git a/sound/pci/cs4281.c b/sound/pci/cs4281.c index 05a4337..ea33911 100644 --- a/sound/pci/cs4281.c +++ b/sound/pci/cs4281.c @@ -1316,10 +1316,8 @@ static int snd_cs4281_free(struct cs4281 *chip) if (chip->irq >= 0) free_irq(chip->irq, chip); - if (chip->ba0) - iounmap(chip->ba0); - if (chip->ba1) - iounmap(chip->ba1); + iounmap(chip->ba0); + iounmap(chip->ba1); pci_release_regions(chip->pci); pci_disable_device(chip->pci); diff --git a/sound/pci/cs46xx/cs46xx_lib.c b/sound/pci/cs46xx/cs46xx_lib.c index dfec84e..128bbfe 100644 --- a/sound/pci/cs46xx/cs46xx_lib.c +++ b/sound/pci/cs46xx/cs46xx_lib.c @@ -2949,8 +2949,8 @@ static int snd_cs46xx_free(struct snd_cs46xx *chip) for (idx = 0; idx < 5; idx++) { struct snd_cs46xx_region *region = &chip->region.idx[idx]; - if (region->remap_addr) - iounmap(region->remap_addr); + + iounmap(region->remap_addr); release_and_free_resource(region->resource); } diff --git a/sound/pci/ctxfi/cthw20k1.c b/sound/pci/ctxfi/cthw20k1.c index b425aa8..b8b0d8e 100644 --- a/sound/pci/ctxfi/cthw20k1.c +++ b/sound/pci/ctxfi/cthw20k1.c @@ -1985,10 +1985,7 @@ static int hw_card_shutdown(struct hw *hw) free_irq(hw->irq, hw); hw->irq = -1; - - if (hw->mem_base) - iounmap(hw->mem_base); - + iounmap(hw->mem_base); hw->mem_base = NULL; if (hw->io_base) diff --git a/sound/pci/ctxfi/cthw20k2.c b/sound/pci/ctxfi/cthw20k2.c index 253899d..4e16b4d 100644 --- a/sound/pci/ctxfi/cthw20k2.c +++ b/sound/pci/ctxfi/cthw20k2.c @@ -2110,10 +2110,7 @@ static int hw_card_shutdown(struct hw *hw) free_irq(hw->irq, hw); hw->irq = -1; - - if (hw->mem_base) - iounmap(hw->mem_base); - + iounmap(hw->mem_base); hw->mem_base = NULL; if (hw->io_base) diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c index 21228ad..98d4f35 100644 --- a/sound/pci/echoaudio/echoaudio.c +++ b/sound/pci/echoaudio/echoaudio.c @@ -1872,12 +1872,8 @@ static int snd_echo_free(struct echoaudio *chip) if (chip->comm_page) snd_dma_free_pages(&chip->commpage_dma_buf); - if (chip->dsp_registers) - iounmap(chip->dsp_registers); - + iounmap(chip->dsp_registers); release_and_free_resource(chip->iores); - - pci_disable_device(chip->pci); /* release chip data */ diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index d426a0b..a971425 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -1138,8 +1138,7 @@ static int azx_free(struct azx *chip) free_irq(chip->irq, (void*)chip); if (chip->msi) pci_disable_msi(chip->pci); - if (chip->remap_addr) - iounmap(chip->remap_addr); + iounmap(chip->remap_addr); azx_free_stream_pages(chip); if (chip->region_requested) diff --git a/sound/pci/lola/lola.c b/sound/pci/lola/lola.c index 4cf4be5..9ff60008 100644 --- a/sound/pci/lola/lola.c +++ b/sound/pci/lola/lola.c @@ -551,10 +551,8 @@ static void lola_free(struct lola *chip) lola_free_mixer(chip); if (chip->irq >= 0) free_irq(chip->irq, (void *)chip); - if (chip->bar[0].remap_addr) - iounmap(chip->bar[0].remap_addr); - if (chip->bar[1].remap_addr) - iounmap(chip->bar[1].remap_addr); + iounmap(chip->bar[0].remap_addr); + iounmap(chip->bar[1].remap_addr); if (chip->rb.area) snd_dma_free_pages(&chip->rb); pci_release_regions(chip->pci); diff --git a/sound/pci/mixart/mixart.c b/sound/pci/mixart/mixart.c index 1faf47e..c3a9f39 100644 --- a/sound/pci/mixart/mixart.c +++ b/sound/pci/mixart/mixart.c @@ -1114,10 +1114,9 @@ static int snd_mixart_free(struct mixart_mgr *mgr) } /* release the i/o ports */ - for (i = 0; i < 2; i++) { - if (mgr->mem[i].virt) - iounmap(mgr->mem[i].virt); - } + for (i = 0; i < 2; ++i) + iounmap(mgr->mem[i].virt); + pci_release_regions(mgr->pci); /* free flowarray */ diff --git a/sound/pci/nm256/nm256.c b/sound/pci/nm256/nm256.c index 4e41a4e..3f52a44 100644 --- a/sound/pci/nm256/nm256.c +++ b/sound/pci/nm256/nm256.c @@ -1460,10 +1460,8 @@ static int snd_nm256_free(struct nm256 *chip) if (chip->irq >= 0) free_irq(chip->irq, chip); - if (chip->cport) - iounmap(chip->cport); - if (chip->buffer) - iounmap(chip->buffer); + iounmap(chip->cport); + iounmap(chip->buffer); release_and_free_resource(chip->res_cport); release_and_free_resource(chip->res_buffer); diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c index cf5a6c8..fe66bcb 100644 --- a/sound/pci/rme9652/hdsp.c +++ b/sound/pci/rme9652/hdsp.c @@ -5309,9 +5309,7 @@ static int snd_hdsp_free(struct hdsp *hdsp) release_firmware(hdsp->firmware); vfree(hdsp->fw_uploaded); - - if (hdsp->iobase) - iounmap(hdsp->iobase); + iounmap(hdsp->iobase); if (hdsp->port) pci_release_regions(hdsp->pci); diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c index 3342705..8109b8e 100644 --- a/sound/pci/rme9652/hdspm.c +++ b/sound/pci/rme9652/hdspm.c @@ -6965,9 +6965,7 @@ static int snd_hdspm_free(struct hdspm * hdspm) free_irq(hdspm->irq, (void *) hdspm); kfree(hdspm->mixer); - - if (hdspm->iobase) - iounmap(hdspm->iobase); + iounmap(hdspm->iobase); if (hdspm->port) pci_release_regions(hdspm->pci); diff --git a/sound/pci/rme9652/rme9652.c b/sound/pci/rme9652/rme9652.c index 6521521..648911c 100644 --- a/sound/pci/rme9652/rme9652.c +++ b/sound/pci/rme9652/rme9652.c @@ -1756,8 +1756,7 @@ static int snd_rme9652_free(struct snd_rme9652 *rme9652) if (rme9652->irq >= 0) free_irq(rme9652->irq, (void *)rme9652); - if (rme9652->iobase) - iounmap(rme9652->iobase); + iounmap(rme9652->iobase); if (rme9652->port) pci_release_regions(rme9652->pci); diff --git a/sound/pci/sis7019.c b/sound/pci/sis7019.c index 7f6a0a0..5e9437b 100644 --- a/sound/pci/sis7019.c +++ b/sound/pci/sis7019.c @@ -1064,12 +1064,9 @@ static int sis_chip_free(struct sis7019 *sis) if (sis->irq >= 0) free_irq(sis->irq, sis); - if (sis->ioaddr) - iounmap(sis->ioaddr); - + iounmap(sis->ioaddr); pci_release_regions(sis->pci); pci_disable_device(sis->pci); - sis_free_suspend(sis); return 0; } diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c index f5581a9..de7f06f 100644 --- a/sound/pci/ymfpci/ymfpci_main.c +++ b/sound/pci/ymfpci/ymfpci_main.c @@ -2246,8 +2246,7 @@ static int snd_ymfpci_free(struct snd_ymfpci *chip) release_and_free_resource(chip->mpu_res); release_and_free_resource(chip->fm_res); snd_ymfpci_free_gameport(chip); - if (chip->reg_area_virt) - iounmap(chip->reg_area_virt); + iounmap(chip->reg_area_virt); if (chip->work_ptr.area) snd_dma_free_pages(&chip->work_ptr); diff --git a/sound/ppc/pmac.c b/sound/ppc/pmac.c index 5a13b22..d399df4 100644 --- a/sound/ppc/pmac.c +++ b/sound/ppc/pmac.c @@ -867,16 +867,11 @@ static int snd_pmac_free(struct snd_pmac *chip) snd_pmac_dbdma_free(chip, &chip->capture.cmd); snd_pmac_dbdma_free(chip, &chip->extra_dma); snd_pmac_dbdma_free(chip, &emergency_dbdma); - if (chip->macio_base) - iounmap(chip->macio_base); - if (chip->latch_base) - iounmap(chip->latch_base); - if (chip->awacs) - iounmap(chip->awacs); - if (chip->playback.dma) - iounmap(chip->playback.dma); - if (chip->capture.dma) - iounmap(chip->capture.dma); + iounmap(chip->macio_base); + iounmap(chip->latch_base); + iounmap(chip->awacs); + iounmap(chip->playback.dma); + iounmap(chip->capture.dma); if (chip->node) { int i; -- 2.2.1
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 4 Jan 2015 11:00:11 +0100 The iounmap() function was called in one case by the snd_msnd_attach() function even if a previous call of the ioremap_nocache() function failed. This implementation detail could be improved by the introduction of another jump label. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- sound/isa/msnd/msnd_pinnacle.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/sound/isa/msnd/msnd_pinnacle.c b/sound/isa/msnd/msnd_pinnacle.c index 4c07266..e2e940d 100644 --- a/sound/isa/msnd/msnd_pinnacle.c +++ b/sound/isa/msnd/msnd_pinnacle.c @@ -575,23 +575,23 @@ static int snd_msnd_attach(struct snd_card *card) err = snd_msnd_dsp_full_reset(card); if (err < 0) - goto err_release_region; + goto io_unmap; /* Register device */ err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); if (err < 0) - goto err_release_region; + goto io_unmap; err = snd_msnd_pcm(card, 0); if (err < 0) { printk(KERN_ERR LOGNAME ": error creating new PCM device\n"); - goto err_release_region; + goto io_unmap; } err = snd_msndmix_new(card); if (err < 0) { printk(KERN_ERR LOGNAME ": error creating new Mixer device\n"); - goto err_release_region; + goto io_unmap; } @@ -607,7 +607,7 @@ static int snd_msnd_attach(struct snd_card *card) if (err < 0) { printk(KERN_ERR LOGNAME ": error creating new Midi device\n"); - goto err_release_region; + goto io_unmap; } mpu = chip->rmidi->private_data; @@ -622,12 +622,13 @@ static int snd_msnd_attach(struct snd_card *card) err = snd_card_register(card); if (err < 0) - goto err_release_region; + goto io_unmap; return 0; -err_release_region: +io_unmap: iounmap(chip->mappedbase); +err_release_region: release_mem_region(chip->base, BUFFSIZE); release_region(chip->io, DSP_NUMIO); free_irq(chip->irq, chip); -- 2.2.1
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 4 Jan 2015 11:47:17 +0100 Two return statements were used by the snd_msnd_attach() function at source code places where the Linux coding style recommends an alternative approach. Let us improve the affected implementation details with adjustments for corresponding jump targets. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- sound/isa/msnd/msnd_pinnacle.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/sound/isa/msnd/msnd_pinnacle.c b/sound/isa/msnd/msnd_pinnacle.c index e2e940d..0e66e5e 100644 --- a/sound/isa/msnd/msnd_pinnacle.c +++ b/sound/isa/msnd/msnd_pinnacle.c @@ -552,17 +552,16 @@ static int snd_msnd_attach(struct snd_card *card) return err; } if (request_region(chip->io, DSP_NUMIO, card->shortname) = NULL) { - free_irq(chip->irq, chip); - return -EBUSY; + err = -EBUSY; + goto free_an_irq; } if (!request_mem_region(chip->base, BUFFSIZE, card->shortname)) { printk(KERN_ERR LOGNAME ": unable to grab memory region 0x%lx-0x%lx\n", chip->base, chip->base + BUFFSIZE - 1); - release_region(chip->io, DSP_NUMIO); - free_irq(chip->irq, chip); - return -EBUSY; + err = -EBUSY; + goto release_resource_region; } chip->mappedbase = ioremap_nocache(chip->base, 0x8000); if (!chip->mappedbase) { @@ -570,7 +569,7 @@ static int snd_msnd_attach(struct snd_card *card) ": unable to map memory region 0x%lx-0x%lx\n", chip->base, chip->base + BUFFSIZE - 1); err = -EIO; - goto err_release_region; + goto release_memory_region; } err = snd_msnd_dsp_full_reset(card); @@ -628,9 +627,11 @@ static int snd_msnd_attach(struct snd_card *card) io_unmap: iounmap(chip->mappedbase); -err_release_region: +release_memory_region: release_mem_region(chip->base, BUFFSIZE); +release_resource_region: release_region(chip->io, DSP_NUMIO); +free_an_irq: free_irq(chip->irq, chip); return err; } -- 2.2.1
At Sun, 04 Jan 2015 14:38:38 +0100, SF Markus Elfring wrote: > > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sun, 4 Jan 2015 11:00:11 +0100 > > The iounmap() function was called in one case by the snd_msnd_attach() function > even if a previous call of the ioremap_nocache() function failed. > > This implementation detail could be improved by the introduction of another > jump label. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> I didn't apply this and the next one. Using goto label isn't bad for the error paths in general, but using too much nested labels worsens the readability significantly. (Though, it's almost a matter of taste, so I don't want to spend my time for discussing this.) thanks, Takashi > --- > sound/isa/msnd/msnd_pinnacle.c | 15 ++++++++------- > 1 file changed, 8 insertions(+), 7 deletions(-) > > diff --git a/sound/isa/msnd/msnd_pinnacle.c b/sound/isa/msnd/msnd_pinnacle.c > index 4c07266..e2e940d 100644 > --- a/sound/isa/msnd/msnd_pinnacle.c > +++ b/sound/isa/msnd/msnd_pinnacle.c > @@ -575,23 +575,23 @@ static int snd_msnd_attach(struct snd_card *card) > > err = snd_msnd_dsp_full_reset(card); > if (err < 0) > - goto err_release_region; > + goto io_unmap; > > /* Register device */ > err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); > if (err < 0) > - goto err_release_region; > + goto io_unmap; > > err = snd_msnd_pcm(card, 0); > if (err < 0) { > printk(KERN_ERR LOGNAME ": error creating new PCM device\n"); > - goto err_release_region; > + goto io_unmap; > } > > err = snd_msndmix_new(card); > if (err < 0) { > printk(KERN_ERR LOGNAME ": error creating new Mixer device\n"); > - goto err_release_region; > + goto io_unmap; > } > > > @@ -607,7 +607,7 @@ static int snd_msnd_attach(struct snd_card *card) > if (err < 0) { > printk(KERN_ERR LOGNAME > ": error creating new Midi device\n"); > - goto err_release_region; > + goto io_unmap; > } > mpu = chip->rmidi->private_data; > > @@ -622,12 +622,13 @@ static int snd_msnd_attach(struct snd_card *card) > > err = snd_card_register(card); > if (err < 0) > - goto err_release_region; > + goto io_unmap; > > return 0; > > -err_release_region: > +io_unmap: > iounmap(chip->mappedbase); > +err_release_region: > release_mem_region(chip->base, BUFFSIZE); > release_region(chip->io, DSP_NUMIO); > free_irq(chip->irq, chip); > -- > 2.2.1 >
At Sun, 04 Jan 2015 13:43:11 +0100, SF Markus Elfring wrote: > > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sun, 4 Jan 2015 11:50:12 +0100 > > Further update suggestions were taken into account after several patches > were applied from static source code analysis. > > Markus Elfring (3): > seq: Deletion of unnecessary checks before the function call "snd_midi_event_free" > oss: Deletion of unnecessary checks before the function call "vfree" > emu10k1: Delete an unnecessary check before the function call "kfree" > oxygen: Delete an unnecessary check before the function call "snd_pcm_suspend" > emux: Delete an unnecessary check before the function call "snd_sf_free" > ASoC: Intel: Delete an unnecessary check before the function call "sst_dma_free" > ASoC: fsi: Deletion of unnecessary checks before the function call "clk_enable" > ASoC: Intel: Delete an unnecessary check before the function call "release_firmware" > i2sbus: Delete an unnecessary check before the function call "snd_pcm_suspend_all" > sb: Delete an unnecessary check before the function call "snd_emux_free" > Deletion of checks before the function call "iounmap" > msnd: One function call less in snd_msnd_attach() after error detection > msnd: Fix centralized exiting from snd_msnd_attach() I applied most of them now but leave patches 6-8 left to Mark applying through his tree. As posted in another mail patches 12 and 13 are dropped. BTW, when you sending a new patch series, you should drop the old references tags. thanks, Takashi > > sound/aoa/soundbus/i2sbus/core.c | 13 ++++++------- > sound/arm/aaci.c | 4 ++-- > sound/drivers/ml403-ac97cr.c | 3 +-- > sound/isa/msnd/msnd_pinnacle.c | 31 ++++++++++++++++--------------- > sound/parisc/harmony.c | 4 +--- > sound/pci/ad1889.c | 5 +---- > sound/pci/asihpi/hpioctl.c | 6 ++---- > sound/pci/atiixp.c | 3 +-- > sound/pci/atiixp_modem.c | 3 +-- > sound/pci/aw2/aw2-alsa.c | 4 +--- > sound/pci/bt87x.c | 3 +-- > sound/pci/cs4281.c | 6 ++---- > sound/pci/cs46xx/cs46xx_lib.c | 4 ++-- > sound/pci/ctxfi/cthw20k1.c | 5 +---- > sound/pci/ctxfi/cthw20k2.c | 5 +---- > sound/pci/echoaudio/echoaudio.c | 6 +----- > sound/pci/hda/hda_intel.c | 3 +-- > sound/pci/lola/lola.c | 6 ++---- > sound/pci/mixart/mixart.c | 7 +++---- > sound/pci/nm256/nm256.c | 6 ++---- > sound/pci/rme9652/hdsp.c | 4 +--- > sound/pci/rme9652/hdspm.c | 4 +--- > sound/pci/rme9652/rme9652.c | 3 +-- > sound/pci/sis7019.c | 5 +---- > sound/pci/ymfpci/ymfpci_main.c | 3 +-- > sound/ppc/pmac.c | 15 +++++---------- > 26 files changed, 58 insertions(+), 103 deletions(-) > > -- > 2.2.1 >
On Sun, Dec 28, 2014 at 09:40:25PM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 27 Dec 2014 09:34:39 +0100
>
> The p9_client_clunk() function tests whether its argument is NULL
> and then returns immediately. Thus the test around the call is not needed.
>
Not true. You are not allowed to call p9_client_clunk(NULL). I assume
this patch adds a bug. You have tried to introduce several of these
kinds of bugs. You are not careful enough.
regards,
dan carpenter
On Sun, Jan 04, 2015 at 02:36:01PM +0100, SF Markus Elfring wrote:
> /* unmap PCI memory space, mapped during device init. */
> - for (idx = 0; idx < HPI_MAX_ADAPTER_MEM_SPACES; idx++) {
> - if (pci.ap_mem_base[idx])
> - iounmap(pci.ap_mem_base[idx]);
> - }
> + for (idx = 0; idx < HPI_MAX_ADAPTER_MEM_SPACES; ++idx)
> + iounmap(pci.ap_mem_base[idx]);
>
Don't do the gratuitous idx++ to ++idx changes. You do it a couple
other places as well. It belongs in a separate patch if you really feel
it is worth doing. (It is not a clean up and it is not worth doing).
regards,
dan carpenter
[-- Attachment #1: Type: text/plain, Size: 368 bytes --] On Sun, Jan 04, 2015 at 02:08:42PM +0100, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sat, 3 Jan 2015 19:03:55 +0100 > > The sst_dma_free() function tests whether its argument is NULL and then > returns immediately. Thus the test around the call is not needed. I'm missing aptches 1-5, are there any dependencies? [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 473 bytes --]
At Mon, 5 Jan 2015 14:35:51 +0000,
Mark Brown wrote:
>
> On Sun, Jan 04, 2015 at 02:08:42PM +0100, SF Markus Elfring wrote:
> > From: Markus Elfring <elfring@users.sourceforge.net>
> > Date: Sat, 3 Jan 2015 19:03:55 +0100
> >
> > The sst_dma_free() function tests whether its argument is NULL and then
> > returns immediately. Thus the test around the call is not needed.
>
> I'm missing aptches 1-5, are there any dependencies?
No, all individual fixes.
Takashi
[-- Attachment #1: Type: text/plain, Size: 306 bytes --] On Mon, Jan 05, 2015 at 04:18:07PM +0100, Takashi Iwai wrote: > Mark Brown wrote: > > I'm missing aptches 1-5, are there any dependencies? > No, all individual fixes. OK. SF, in future please always send at least the cover letter to everyone getting patches in the series so they know what's going on. [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 473 bytes --]
[-- Attachment #1: Type: text/plain, Size: 332 bytes --] On Sun, Jan 04, 2015 at 02:08:42PM +0100, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sat, 3 Jan 2015 19:03:55 +0100 > > The sst_dma_free() function tests whether its argument is NULL and then > returns immediately. Thus the test around the call is not needed. Applied, thanks. [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 473 bytes --]
[-- Attachment #1: Type: text/plain, Size: 330 bytes --] On Sun, Jan 04, 2015 at 02:11:58PM +0100, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sat, 3 Jan 2015 19:25:55 +0100 > > The clk_enable() function tests whether its argument is NULL and then > returns immediately. Thus the test around the call is not needed. Applied, thanks. [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 473 bytes --]
[-- Attachment #1: Type: text/plain, Size: 336 bytes --] On Sun, Jan 04, 2015 at 02:14:37PM +0100, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sat, 3 Jan 2015 19:49:37 +0100 > > The release_firmware() function tests whether its argument is NULL and then > returns immediately. Thus the test around the call is not needed. Applied, thanks. [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 473 bytes --]
>> The p9_client_clunk() function tests whether its argument is NULL >> and then returns immediately. Thus the test around the call is not needed. >> > > Not true. You are not allowed to call p9_client_clunk(NULL). I find that it will work in principle if we refer to the same function implementation. https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/net/9p/client.c?idØ282ea05ad119247122de23db7d48ad6098cfa2#n1448 http://lxr.free-electrons.com/source/net/9p/client.c#L1448 > I assume this patch adds a bug. It can happen that you will not like a corresponding error message if the callers will still pass null pointers eventually. ... Trying to clunk with NULL ... > I assume this patch adds a bug. You have tried to introduce several of these > kinds of bugs. Do any other contributors want to reject my update suggestions around software components for "fs/9p"? Regards, Markus -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Mon, 5 Jan 2015, SF Markus Elfring wrote: > >> The p9_client_clunk() function tests whether its argument is NULL > >> and then returns immediately. Thus the test around the call is not needed. > >> > > > > Not true. You are not allowed to call p9_client_clunk(NULL). > > I find that it will work in principle if we refer to the same > function implementation. > https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/net/9p/client.c?idØ282ea05ad119247122de23db7d48ad6098cfa2#n1448 > http://lxr.free-electrons.com/source/net/9p/client.c#L1448 What do you mean by "work in principle"? One possible issue is the return value - I don't have the original patch so I don't know what is the call site, so I don't know if that is an issue. But you don't want to do a dump_stack for no reason. That would at best be very misleading, and I would imagine be quite expensive. julia -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
>> https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/net/9p/client.c?idØ282ea05ad119247122de23db7d48ad6098cfa2#n1448 >> http://lxr.free-electrons.com/source/net/9p/client.c#L1448 > > What do you mean by "work in principle"? If I do not stumble on an unexpected name space issue from my static source analysis again, then I would see the linked function as relevant here. Its implementation provides a clear input parameter validation. > But you don't want to do a dump_stack for no reason. That would at best > be very misleading, and I would imagine be quite expensive. The error response is clear. Are any software developments efforts expected to clean-up the call stack for unwanted null pointers even more? Regards, Markus -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
> The error response is clear. Are any software developments efforts expected
> to clean-up the call stack for unwanted null pointers even more?
I found the original patch and looked at the call sites. None of them
calls dump_stack. The behavior is thus not the same. With your change,
something that was previously treated in an orderly manner will be
converted to something that looks like an oops. I assume that the cost of
the dump_stack will also be huge.
julia
On Mon, Jan 05, 2015 at 10:32:35PM +0100, SF Markus Elfring wrote:
> > I assume this patch adds a bug. You have tried to introduce several of these
> > kinds of bugs.
>
> Do any other contributors want to reject my update suggestions
> around software components for "fs/9p"?
Some of the 9p patches actually seem like bug fixes so I like those
ones. It would be better if the bug fixes had a correct changelog, of
course.
regards,
dan carpenter
Hi, Julia Lawall wrote on Mon, Jan 05, 2015 at 11:01:55PM +0100: > > The error response is clear. Are any software developments efforts expected > > to clean-up the call stack for unwanted null pointers even more? > > I found the original patch and looked at the call sites. None of them > calls dump_stack. The behavior is thus not the same. With your change, > something that was previously treated in an orderly manner will be > converted to something that looks like an oops. I assume that the cost of > the dump_stack will also be huge. I definitely agree there, this will create unwanted dump_stack messages. Simple example, without even looking at the multiple possible interactions with multiple clients hammering the server, can be taken from v9fs_create in fs/9p/vfs_inode.c https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/fs/9p/vfs_inode.c?idØ282ea05ad119247122de23db7d48ad6098cfa2#n652 jumping to label error from a failure in p9_client_fcreate (e.g. EPERM or something perfectly valid) will, with your patch, call clunk with fid = NULL and thus generate a stack trace, while it is a perfectly normal code path that should only return to userspace with EPERM. (admitedly, the linux vfs will do checks first to ensure that the function is likely to succeed, but some servers can implement their own security model on top) Other patches in the set look good at first glance, but I'll need a bit to find time to look through implications they may have. -- Dominique Martinet, CEA -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Dominique Martinet wrote on Tue, Jan 06, 2015 at 09:12:53AM +0100: > Simple example, without even looking at the multiple possible > interactions with multiple clients hammering the server, can be taken > from v9fs_create in fs/9p/vfs_inode.c > https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/fs/9p/vfs_inode.c?idØ282ea05ad119247122de23db7d48ad6098cfa2#n652 > > jumping to label error from a failure in p9_client_fcreate (e.g. EPERM > or something perfectly valid) will, with your patch, call clunk with fid > = NULL and thus generate a stack trace, while it is a perfectly normal > code path that should only return to userspace with EPERM. Actually just seen that this precise example is fixed along with more similar code paths in subsequents (!) patchs of the set. It could actually be interesting to see if we could get all such paths "fixed". If so, I believe this way will ultimately lead to cleaner code, but I'd rather see taken all other patches first and keep this one in v9fs-devel branch for a bit longer if this makes sense... Well, I guess there is a test window before the merge to linus tree anyway, but given the number of active 9P users it could be useful. (All other patches in the set look good to me at second glance, now. To answer Dan's mail, none of these are bug fix as far as I've seen, just avoiding unnecessary checks for null or calls+check/warn depending on whether you apply patch #1 first) -- Dominique Martinet, CEA -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Tue, Jan 06, 2015 at 10:27:19AM +0100, Dominique Martinet wrote:
> (All other patches in the set look good to me at second glance, now.
> To answer Dan's mail, none of these are bug fix as far as I've seen,
> just avoiding unnecessary checks for null or calls+check/warn depending
> on whether you apply patch #1 first)
You're right. The patch set introduces bugs then fixes them later.
regards,
dan carpenter
>> jumping to label error from a failure in p9_client_fcreate (e.g. EPERM >> or something perfectly valid) will, with your patch, call clunk with fid >> = NULL and thus generate a stack trace, while it is a perfectly normal >> code path that should only return to userspace with EPERM. > > Actually just seen that this precise example is fixed along with more > similar code paths in subsequents (!) patchs of the set. Do you refer to my update suggestions with a subject like "One function call less in v9fs_…" here? > It could actually be interesting to see if we could get all such > paths "fixed". Would you like to see any more specific source code clean-up? Which kind of fine-tuning have you got in mind? Regards, Markus -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
SF Markus Elfring wrote on Tue, Jan 06, 2015 at 03:34:08PM +0100: > > Actually just seen that this precise example is fixed along with more > > similar code paths in subsequents (!) patchs of the set. > > Do you refer to my update suggestions with a subject like "One function > call less in v9fs_…" here? Yes. Looking at the patchset as a whole (and under the assumption that calling p9_client_clunk with NULL is harmful), your patchset first introduces many such calls then proceeds onto fixing them. Thinking a bit more, I think that instead of just changing the order of patches the cleanest way would be to submit this as "reworking jump labels, making NULL checks useless in the process". Still only looking at v9fs_create, with your patch#2 reflowing, p9_client_clunk can't be called with NULL unless a bug happened (either p9_client_fcreate or p9_client_walk returning non-error but leaving ofid or fid NULL), so it'd actually make sense to remove the quiet check in favor of the warn/stack dump check at this point. Is what I'm saying making sense? > > It could actually be interesting to see if we could get all such > > paths "fixed". > > Would you like to see any more specific source code clean-up? > Which kind of fine-tuning have you got in mind? I was really just thinking that if the code flow is thought out the if's can be removed harmlessly, but that it actually needs to be done the other way around. I honestly am not involved enough in kernel coding style changes or 9p code as a whole to suggest anything else, sorry :) Thanks, -- Dominique Martinet, CEA -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 5 Feb 2015 17:54: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>
> ---
> drivers/iommu/tegra-gart.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/iommu/tegra-gart.c b/drivers/iommu/tegra-gart.c
> index f722a0c..07a795a 100644
> --- a/drivers/iommu/tegra-gart.c
> +++ b/drivers/iommu/tegra-gart.c
> @@ -404,8 +404,7 @@ static int tegra_gart_remove(struct platform_device *pdev)
> struct gart_device *gart = platform_get_drvdata(pdev);
>
> writel(0, gart->regs + GART_CONFIG);
> - if (gart->savedata)
> - vfree(gart->savedata);
> + vfree(gart->savedata);
> gart_handle = NULL;
> return 0;
> }
>
Would you like to integrate this update suggestion
into another source code repository?
Regards,
Markus
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 18 Jan 2015 14:50:06 +0100 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. Markus Elfring (3): cciss: Deletion of an unnecessary check before the function call "put_disk" z2ram: Delete an unnecessary check before the function call "kfree" Deletion of checks before the function call "iounmap" drivers/block/cciss.c | 18 ++++++------------ drivers/block/mg_disk.c | 3 +-- drivers/block/skd_main.c | 6 ++---- 3 files changed, 9 insertions(+), 18 deletions(-) -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 18 Jan 2015 11:14:16 +0100 The put_disk() 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/block/cciss.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c index ff20f19..4be0de0 100644 --- a/drivers/block/cciss.c +++ b/drivers/block/cciss.c @@ -4424,8 +4424,7 @@ static void free_hba(ctlr_info_t *h) hba[h->ctlr] = NULL; for (i = 0; i < h->highest_lun + 1; i++) - if (h->gendisk[i] != NULL) - put_disk(h->gendisk[i]); + put_disk(h->gendisk[i]); kfree(h); } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 18 Jan 2015 12:28:27 +0100 The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/block/z2ram.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/block/z2ram.c b/drivers/block/z2ram.c index 968f9e5..c32f248 100644 --- a/drivers/block/z2ram.c +++ b/drivers/block/z2ram.c @@ -404,10 +404,7 @@ static void __exit z2_exit(void) } } - if ( z2ram_map != NULL ) - { - kfree( z2ram_map ); - } + kfree(z2ram_map); } return; -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 18 Jan 2015 13:33:25 +0100 The iounmap() 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/block/cciss.c | 18 ++++++------------ drivers/block/mg_disk.c | 3 +-- drivers/block/skd_main.c | 6 ++---- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c index ff20f19..d13ef0f 100644 --- a/drivers/block/cciss.c +++ b/drivers/block/cciss.c @@ -4382,12 +4382,9 @@ err_out_free_res: * Deliberately omit pci_disable_device(): it does something nasty to * Smart Array controllers that pci_enable_device does not undo */ - if (h->transtable) - iounmap(h->transtable); - if (h->cfgtable) - iounmap(h->cfgtable); - if (h->vaddr) - iounmap(h->vaddr); + iounmap(h->transtable); + iounmap(h->cfgtable); + iounmap(h->vaddr); pci_release_regions(h->pdev); return err; } @@ -4939,12 +4936,9 @@ static void cciss_undo_allocations_after_kdump_soft_reset(ctlr_info_t *h) if (h->reply_pool) pci_free_consistent(h->pdev, h->max_commands * sizeof(__u64), h->reply_pool, h->reply_pool_dhandle); - if (h->transtable) - iounmap(h->transtable); - if (h->cfgtable) - iounmap(h->cfgtable); - if (h->vaddr) - iounmap(h->vaddr); + iounmap(h->transtable); + iounmap(h->cfgtable); + iounmap(h->vaddr); unregister_blkdev(h->major, h->devname); cciss_destroy_hba_sysfs_entry(h); pci_release_regions(h->pdev); diff --git a/drivers/block/mg_disk.c b/drivers/block/mg_disk.c index 145ce2a..9f738ee 100644 --- a/drivers/block/mg_disk.c +++ b/drivers/block/mg_disk.c @@ -1068,8 +1068,7 @@ static int mg_remove(struct platform_device *plat_dev) gpio_free(host->rst); /* unmap io */ - if (host->dev_base) - iounmap(host->dev_base); + iounmap(host->dev_base); /* free mg_host */ kfree(host); diff --git a/drivers/block/skd_main.c b/drivers/block/skd_main.c index 1e46eb2..d4c7c4b 100644 --- a/drivers/block/skd_main.c +++ b/drivers/block/skd_main.c @@ -4944,8 +4944,7 @@ err_out_timer: err_out_iounmap: for (i = 0; i < SKD_MAX_BARS; i++) - if (skdev->mem_map[i]) - iounmap(skdev->mem_map[i]); + iounmap(skdev->mem_map[i]); if (skdev->pcie_error_reporting_is_enabled) pci_disable_pcie_error_reporting(pdev); @@ -5108,8 +5107,7 @@ err_out_timer: err_out_iounmap: for (i = 0; i < SKD_MAX_BARS; i++) - if (skdev->mem_map[i]) - iounmap(skdev->mem_map[i]); + iounmap(skdev->mem_map[i]); if (skdev->pcie_error_reporting_is_enabled) pci_disable_pcie_error_reporting(pdev); -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 18 Jan 2015 17:30:23 +0100 The iounmap() 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/mtd/maps/latch-addr-flash.c | 3 +-- drivers/mtd/maps/pci.c | 6 ++---- drivers/mtd/maps/physmap_of.c | 3 +-- drivers/mtd/maps/plat-ram.c | 3 +-- drivers/mtd/maps/pxa2xx-flash.c | 6 ++---- drivers/mtd/maps/sa1100-flash.c | 3 +-- drivers/mtd/nand/fsl_elbc_nand.c | 3 +-- drivers/mtd/nand/fsl_ifc_nand.c | 3 +-- drivers/mtd/nand/mpc5121_nfc.c | 3 +-- drivers/mtd/onenand/samsung.c | 12 ++++-------- 10 files changed, 15 insertions(+), 30 deletions(-) diff --git a/drivers/mtd/maps/latch-addr-flash.c b/drivers/mtd/maps/latch-addr-flash.c index cadfbe0..60496cd 100644 --- a/drivers/mtd/maps/latch-addr-flash.c +++ b/drivers/mtd/maps/latch-addr-flash.c @@ -109,8 +109,7 @@ static int latch_addr_flash_remove(struct platform_device *dev) map_destroy(info->mtd); } - if (info->map.virt != NULL) - iounmap(info->map.virt); + iounmap(info->map.virt); if (info->res != NULL) release_mem_region(info->res->start, resource_size(info->res)); diff --git a/drivers/mtd/maps/pci.c b/drivers/mtd/maps/pci.c index eb0242e..0006794 100644 --- a/drivers/mtd/maps/pci.c +++ b/drivers/mtd/maps/pci.c @@ -118,8 +118,7 @@ intel_iq80310_init(struct pci_dev *dev, struct map_pci_info *map) static void intel_iq80310_exit(struct pci_dev *dev, struct map_pci_info *map) { - if (map->base) - iounmap(map->base); + iounmap(map->base); pci_write_config_dword(dev, 0x44, map->map.map_priv_2); } @@ -202,8 +201,7 @@ intel_dc21285_init(struct pci_dev *dev, struct map_pci_info *map) static void intel_dc21285_exit(struct pci_dev *dev, struct map_pci_info *map) { - if (map->base) - iounmap(map->base); + iounmap(map->base); /* * We need to undo the PCI BAR2/PCI ROM BAR address alteration. diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c index f35cd20..89f5d42 100644 --- a/drivers/mtd/maps/physmap_of.c +++ b/drivers/mtd/maps/physmap_of.c @@ -57,8 +57,7 @@ static int of_flash_remove(struct platform_device *dev) if (info->list[i].mtd) map_destroy(info->list[i].mtd); - if (info->list[i].map.virt) - iounmap(info->list[i].map.virt); + iounmap(info->list[i].map.virt); if (info->list[i].res) { release_resource(info->list[i].res); diff --git a/drivers/mtd/maps/plat-ram.c b/drivers/mtd/maps/plat-ram.c index 4b65c08..da09274 100644 --- a/drivers/mtd/maps/plat-ram.c +++ b/drivers/mtd/maps/plat-ram.c @@ -104,8 +104,7 @@ static int platram_remove(struct platform_device *pdev) kfree(info->area); } - if (info->map.virt != NULL) - iounmap(info->map.virt); + iounmap(info->map.virt); kfree(info); diff --git a/drivers/mtd/maps/pxa2xx-flash.c b/drivers/mtd/maps/pxa2xx-flash.c index 12fa75d..a5f27b9 100644 --- a/drivers/mtd/maps/pxa2xx-flash.c +++ b/drivers/mtd/maps/pxa2xx-flash.c @@ -89,8 +89,7 @@ static int pxa2xx_flash_probe(struct platform_device *pdev) if (!info->mtd) { iounmap((void *)info->map.virt); - if (info->map.cached) - iounmap(info->map.cached); + iounmap(info->map.cached); return -EIO; } info->mtd->owner = THIS_MODULE; @@ -110,8 +109,7 @@ static int pxa2xx_flash_remove(struct platform_device *dev) map_destroy(info->mtd); iounmap(info->map.virt); - if (info->map.cached) - iounmap(info->map.cached); + iounmap(info->map.cached); kfree(info); return 0; } diff --git a/drivers/mtd/maps/sa1100-flash.c b/drivers/mtd/maps/sa1100-flash.c index ea69720..22e5d7d 100644 --- a/drivers/mtd/maps/sa1100-flash.c +++ b/drivers/mtd/maps/sa1100-flash.c @@ -58,8 +58,7 @@ static void sa1100_destroy_subdev(struct sa_subdev_info *subdev) { if (subdev->mtd) map_destroy(subdev->mtd); - if (subdev->map.virt) - iounmap(subdev->map.virt); + iounmap(subdev->map.virt); release_mem_region(subdev->map.phys, subdev->map.size); } diff --git a/drivers/mtd/nand/fsl_elbc_nand.c b/drivers/mtd/nand/fsl_elbc_nand.c index 04b22fd..a0f2a91 100644 --- a/drivers/mtd/nand/fsl_elbc_nand.c +++ b/drivers/mtd/nand/fsl_elbc_nand.c @@ -801,8 +801,7 @@ static int fsl_elbc_chip_remove(struct fsl_elbc_mtd *priv) kfree(priv->mtd.name); - if (priv->vbase) - iounmap(priv->vbase); + iounmap(priv->vbase); elbc_fcm_ctrl->chips[priv->bank] = NULL; kfree(priv); diff --git a/drivers/mtd/nand/fsl_ifc_nand.c b/drivers/mtd/nand/fsl_ifc_nand.c index 4c05f4f..360d9a3 100644 --- a/drivers/mtd/nand/fsl_ifc_nand.c +++ b/drivers/mtd/nand/fsl_ifc_nand.c @@ -995,8 +995,7 @@ static int fsl_ifc_chip_remove(struct fsl_ifc_mtd *priv) kfree(priv->mtd.name); - if (priv->vbase) - iounmap(priv->vbase); + iounmap(priv->vbase); ifc_nand_ctrl->chips[priv->bank] = NULL; diff --git a/drivers/mtd/nand/mpc5121_nfc.c b/drivers/mtd/nand/mpc5121_nfc.c index 1f12e5b..34fa6db 100644 --- a/drivers/mtd/nand/mpc5121_nfc.c +++ b/drivers/mtd/nand/mpc5121_nfc.c @@ -621,8 +621,7 @@ static void mpc5121_nfc_free(struct device *dev, struct mtd_info *mtd) if (prv->clk) clk_disable_unprepare(prv->clk); - if (prv->csreg) - iounmap(prv->csreg); + iounmap(prv->csreg); } static int mpc5121_nfc_probe(struct platform_device *op) diff --git a/drivers/mtd/onenand/samsung.c b/drivers/mtd/onenand/samsung.c index 19cfb97..24ac4cb 100644 --- a/drivers/mtd/onenand/samsung.c +++ b/drivers/mtd/onenand/samsung.c @@ -1001,8 +1001,7 @@ static int s3c_onenand_probe(struct platform_device *pdev) return 0; scan_failed: - if (onenand->dma_addr) - iounmap(onenand->dma_addr); + iounmap(onenand->dma_addr); dma_ioremap_failed: if (onenand->dma_res) release_mem_region(onenand->dma_res->start, @@ -1011,8 +1010,7 @@ dma_ioremap_failed: oob_buf_fail: kfree(onenand->page_buf); page_buf_fail: - if (onenand->ahb_addr) - iounmap(onenand->ahb_addr); + iounmap(onenand->ahb_addr); ahb_ioremap_failed: if (onenand->ahb_res) release_mem_region(onenand->ahb_res->start, @@ -1036,13 +1034,11 @@ static int s3c_onenand_remove(struct platform_device *pdev) struct mtd_info *mtd = platform_get_drvdata(pdev); onenand_release(mtd); - if (onenand->ahb_addr) - iounmap(onenand->ahb_addr); + iounmap(onenand->ahb_addr); if (onenand->ahb_res) release_mem_region(onenand->ahb_res->start, resource_size(onenand->ahb_res)); - if (onenand->dma_addr) - iounmap(onenand->dma_addr); + iounmap(onenand->dma_addr); if (onenand->dma_res) release_mem_region(onenand->dma_res->start, resource_size(onenand->dma_res)); -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 18 Jan 2015 19:49:16 +0100 Another update suggestion was taken into account after a patch was applied from static source code analysis. Markus Elfring (2): Deletion of checks before the function call "iounmap" Less function calls in bcm63xx_drv_pcmcia_probe() after error detection drivers/pcmcia/bcm63xx_pcmcia.c | 20 ++++++++++---------- drivers/pcmcia/cistpl.c | 3 +-- drivers/pcmcia/electra_cf.c | 6 ++---- drivers/pcmcia/yenta_socket.c | 3 +-- 4 files changed, 14 insertions(+), 18 deletions(-) -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 18 Jan 2015 18:48:09 +0100 The iounmap() 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/pcmcia/bcm63xx_pcmcia.c | 6 ++---- drivers/pcmcia/cistpl.c | 3 +-- drivers/pcmcia/electra_cf.c | 6 ++---- drivers/pcmcia/yenta_socket.c | 3 +-- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/pcmcia/bcm63xx_pcmcia.c b/drivers/pcmcia/bcm63xx_pcmcia.c index 0802e0b..9e7ad1b 100644 --- a/drivers/pcmcia/bcm63xx_pcmcia.c +++ b/drivers/pcmcia/bcm63xx_pcmcia.c @@ -426,10 +426,8 @@ static int bcm63xx_drv_pcmcia_probe(struct platform_device *pdev) return 0; err: - if (skt->io_base) - iounmap(skt->io_base); - if (skt->base) - iounmap(skt->base); + iounmap(skt->io_base); + iounmap(skt->base); if (skt->reg_res) release_mem_region(skt->reg_res->start, regmem_size); kfree(skt); diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c index 884a984..662462e 100644 --- a/drivers/pcmcia/cistpl.c +++ b/drivers/pcmcia/cistpl.c @@ -115,8 +115,7 @@ static void __iomem *set_cis_map(struct pcmcia_socket *s, } if (s->features & SS_CAP_STATIC_MAP) { - if (s->cis_virt) - iounmap(s->cis_virt); + iounmap(s->cis_virt); s->cis_virt = ioremap(mem->static_start, s->map_size); } diff --git a/drivers/pcmcia/electra_cf.c b/drivers/pcmcia/electra_cf.c index 7f9950d..3fb78d6 100644 --- a/drivers/pcmcia/electra_cf.c +++ b/drivers/pcmcia/electra_cf.c @@ -316,10 +316,8 @@ fail1: if (cf->io_virt) __iounmap_at(cf->io_virt, cf->io_size); - if (cf->mem_base) - iounmap(cf->mem_base); - if (cf->gpio_base) - iounmap(cf->gpio_base); + iounmap(cf->mem_base); + iounmap(cf->gpio_base); device_init_wakeup(&ofdev->dev, 0); kfree(cf); return status; diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c index 8a23ccb..5ea1d49 100644 --- a/drivers/pcmcia/yenta_socket.c +++ b/drivers/pcmcia/yenta_socket.c @@ -802,8 +802,7 @@ static void yenta_close(struct pci_dev *dev) else del_timer_sync(&sock->poll_timer); - if (sock->base) - iounmap(sock->base); + iounmap(sock->base); yenta_free_resources(sock); pci_release_regions(dev); -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 18 Jan 2015 19:45:45 +0100 The functions "iounmap", "kfree" and "release_mem_region" were called in some cases by the bcm63xx_drv_pcmcia_probe() function during error handling even if the passed variable contained a null pointer. * Corresponding details could be improved by adjustments for jump labels. * Let us delete also another unnecessary check for the data structure member "reg_res" there. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/pcmcia/bcm63xx_pcmcia.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/pcmcia/bcm63xx_pcmcia.c b/drivers/pcmcia/bcm63xx_pcmcia.c index 9e7ad1b..9848d91a2 100644 --- a/drivers/pcmcia/bcm63xx_pcmcia.c +++ b/drivers/pcmcia/bcm63xx_pcmcia.c @@ -346,7 +346,7 @@ static int bcm63xx_drv_pcmcia_probe(struct platform_device *pdev) skt->pd = pdev->dev.platform_data; if (!skt->common_res || !skt->attr_res || !irq_res || !skt->pd) { ret = -EINVAL; - goto err; + goto free_memory; } /* remap pcmcia registers */ @@ -354,14 +354,14 @@ static int bcm63xx_drv_pcmcia_probe(struct platform_device *pdev) regmem_size = resource_size(res); if (!request_mem_region(res->start, regmem_size, "bcm63xx_pcmcia")) { ret = -EINVAL; - goto err; + goto free_memory; } skt->reg_res = res; skt->base = ioremap(res->start, regmem_size); if (!skt->base) { ret = -ENOMEM; - goto err; + goto release_memory_region; } /* remap io registers */ @@ -370,7 +370,7 @@ static int bcm63xx_drv_pcmcia_probe(struct platform_device *pdev) skt->io_base = ioremap(res->start, iomem_size); if (!skt->io_base) { ret = -ENOMEM; - goto err; + goto io_unmap_base; } /* resources are static */ @@ -427,9 +427,11 @@ static int bcm63xx_drv_pcmcia_probe(struct platform_device *pdev) err: iounmap(skt->io_base); +io_unmap_base: iounmap(skt->base); - if (skt->reg_res) - release_mem_region(skt->reg_res->start, regmem_size); +release_memory_region: + release_mem_region(skt->reg_res->start, regmem_size); +free_memory: kfree(skt); return ret; } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 19 Jan 2015 17:57:25 +0100 Further update suggestions were taken into account after a patch was applied from static source code analysis. Markus Elfring (9): fbdev: Deletion of checks before the function call "iounmap" One function call less in tdfxfb_probe() after error detection One function call less in vesafb_probe() after error detection Add check for return value of ioremap() in cirrusfb_pci_register() Less function calls in trident_pci_probe() after error detection One function call less in pvr2fb_common_init() after error detection One function call less in tgafb_register() after error detection Less function calls in valkyriefb_init() after error detection Less function calls in w100fb_probe() after error detection drivers/video/fbdev/aty/atyfb_base.c | 15 +++++-------- drivers/video/fbdev/cirrusfb.c | 10 ++++++--- drivers/video/fbdev/controlfb.c | 6 ++--- drivers/video/fbdev/efifb.c | 3 +-- drivers/video/fbdev/hgafb.c | 3 +-- drivers/video/fbdev/hpfb.c | 3 +-- drivers/video/fbdev/i810/i810_main.c | 6 ++--- drivers/video/fbdev/macfb.c | 15 +++++-------- drivers/video/fbdev/offb.c | 3 +-- drivers/video/fbdev/pvr2fb.c | 15 ++++++------- drivers/video/fbdev/s1d13xxxfb.c | 3 +-- drivers/video/fbdev/s3fb.c | 6 ++--- drivers/video/fbdev/sh_mobile_hdmi.c | 6 ++--- drivers/video/fbdev/sh_mobile_lcdcfb.c | 3 +-- drivers/video/fbdev/simplefb.c | 3 +-- drivers/video/fbdev/stifb.c | 3 +-- drivers/video/fbdev/tdfxfb.c | 22 +++++++++---------- drivers/video/fbdev/tgafb.c | 20 ++++++++--------- drivers/video/fbdev/tridentfb.c | 15 +++++++------ drivers/video/fbdev/valkyriefb.c | 37 ++++++++++++++++++------------- drivers/video/fbdev/vesafb.c | 11 +++++----- drivers/video/fbdev/w100fb.c | 40 +++++++++++++++++----------------- 22 files changed, 116 insertions(+), 132 deletions(-) -- 2.2.2
On Sun, Jan 18, 2015 at 06:08:12PM +0100, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sun, 18 Jan 2015 17:30:23 +0100 > > The iounmap() function performs also input parameter validation. > Thus the test around the call is not needed. Is this guaranteed for all arch'es? I expect that it would be, but I see that, for instance, ARM allows replaceable iounmap() for subarchitectures. Also, I see checks for various sorts of static mappings in ARM and x86; these likely (always?) cover the NULL case, but they're not always straightforward. Anyway, I'm essentially saying that I'd like to be 100% sure we have a guarantee before dropping all these. > This issue was detected by using the Coccinelle software. What script? Hand-rolled I guess? Brian
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 18 Jan 2015 22:45:39 +0100 The iounmap() 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/video/fbdev/aty/atyfb_base.c | 15 +++++---------- drivers/video/fbdev/cirrusfb.c | 3 +-- drivers/video/fbdev/controlfb.c | 6 ++---- drivers/video/fbdev/efifb.c | 3 +-- drivers/video/fbdev/hgafb.c | 3 +-- drivers/video/fbdev/hpfb.c | 3 +-- drivers/video/fbdev/i810/i810_main.c | 6 ++---- drivers/video/fbdev/macfb.c | 15 +++++---------- drivers/video/fbdev/offb.c | 3 +-- drivers/video/fbdev/pvr2fb.c | 3 +-- drivers/video/fbdev/s1d13xxxfb.c | 3 +-- drivers/video/fbdev/s3fb.c | 6 ++---- drivers/video/fbdev/sh_mobile_hdmi.c | 6 ++---- drivers/video/fbdev/sh_mobile_lcdcfb.c | 3 +-- drivers/video/fbdev/simplefb.c | 3 +-- drivers/video/fbdev/stifb.c | 3 +-- drivers/video/fbdev/tdfxfb.c | 6 ++---- drivers/video/fbdev/tgafb.c | 3 +-- drivers/video/fbdev/tridentfb.c | 6 ++---- drivers/video/fbdev/valkyriefb.c | 9 +++------ drivers/video/fbdev/vesafb.c | 6 ++---- drivers/video/fbdev/w100fb.c | 9 +++------ 22 files changed, 41 insertions(+), 82 deletions(-) diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c index 37ec09b..0f4b147 100644 --- a/drivers/video/fbdev/aty/atyfb_base.c +++ b/drivers/video/fbdev/aty/atyfb_base.c @@ -3605,10 +3605,8 @@ err_release_io: #ifdef __sparc__ kfree(par->mmap_map); #else - if (par->ati_regbase) - iounmap(par->ati_regbase); - if (info->screen_base) - iounmap(info->screen_base); + iounmap(par->ati_regbase); + iounmap(info->screen_base); #endif err_release_mem: if (par->aux_start) @@ -3733,13 +3731,10 @@ static void atyfb_remove(struct fb_info *info) } #endif #ifndef __sparc__ - if (par->ati_regbase) - iounmap(par->ati_regbase); - if (info->screen_base) - iounmap(info->screen_base); + iounmap(par->ati_regbase); + iounmap(info->screen_base); #ifdef __BIG_ENDIAN - if (info->sprite.addr) - iounmap(info->sprite.addr); + iounmap(info->sprite.addr); #endif #endif #ifdef __sparc__ diff --git a/drivers/video/fbdev/cirrusfb.c b/drivers/video/fbdev/cirrusfb.c index d992aa5..d8b3359 100644 --- a/drivers/video/fbdev/cirrusfb.c +++ b/drivers/video/fbdev/cirrusfb.c @@ -2164,8 +2164,7 @@ err_release_regions: #endif pci_release_regions(pdev); err_release_fb: - if (cinfo->laguna_mmio != NULL) - iounmap(cinfo->laguna_mmio); + iounmap(cinfo->laguna_mmio); framebuffer_release(info); err_out: return ret; diff --git a/drivers/video/fbdev/controlfb.c b/drivers/video/fbdev/controlfb.c index 080fdd2..d386fed 100644 --- a/drivers/video/fbdev/controlfb.c +++ b/drivers/video/fbdev/controlfb.c @@ -1068,10 +1068,8 @@ static void control_cleanup(void) if (!p) return; - if (p->cmap_regs) - iounmap(p->cmap_regs); - if (p->control_regs) - iounmap(p->control_regs); + iounmap(p->cmap_regs); + iounmap(p->control_regs); if (p->frame_buffer) { if (p->control_use_bank2) p->frame_buffer -= 0x600000; diff --git a/drivers/video/fbdev/efifb.c b/drivers/video/fbdev/efifb.c index 4bfff34..a6d08f0 100644 --- a/drivers/video/fbdev/efifb.c +++ b/drivers/video/fbdev/efifb.c @@ -65,8 +65,7 @@ static int efifb_setcolreg(unsigned regno, unsigned red, unsigned green, static void efifb_destroy(struct fb_info *info) { - if (info->screen_base) - iounmap(info->screen_base); + iounmap(info->screen_base); if (request_mem_succeeded) release_mem_region(info->apertures->ranges[0].base, info->apertures->ranges[0].size); diff --git a/drivers/video/fbdev/hgafb.c b/drivers/video/fbdev/hgafb.c index 5ff9fe2..76b231e 100644 --- a/drivers/video/fbdev/hgafb.c +++ b/drivers/video/fbdev/hgafb.c @@ -552,8 +552,7 @@ static int hgafb_probe(struct platform_device *pdev) if (! hga_card_detect()) { printk(KERN_INFO "hgafb: HGA card not detected.\n"); - if (hga_vram) - iounmap(hga_vram); + iounmap(hga_vram); return -EINVAL; } diff --git a/drivers/video/fbdev/hpfb.c b/drivers/video/fbdev/hpfb.c index a1b7e5f..9b47102 100644 --- a/drivers/video/fbdev/hpfb.c +++ b/drivers/video/fbdev/hpfb.c @@ -355,8 +355,7 @@ static void hpfb_remove_one(struct dio_dev *d) iounmap((void *)fb_regs); release_mem_region(d->resource.start, resource_size(&d->resource)); fb_dealloc_cmap(&fb_info.cmap); - if (fb_info.screen_base) - iounmap(fb_info.screen_base); + iounmap(fb_info.screen_base); } static struct dio_device_id hpfb_dio_tbl[] = { diff --git a/drivers/video/fbdev/i810/i810_main.c b/drivers/video/fbdev/i810/i810_main.c index bb674e4..ce3a585 100644 --- a/drivers/video/fbdev/i810/i810_main.c +++ b/drivers/video/fbdev/i810/i810_main.c @@ -2105,10 +2105,8 @@ static void i810fb_release_resource(struct fb_info *info, if (par->i810_gtt.i810_fb_memory) agp_free_memory(gtt->i810_fb_memory); - if (par->mmio_start_virtual) - iounmap(par->mmio_start_virtual); - if (par->aperture.virtual) - iounmap(par->aperture.virtual); + iounmap(par->mmio_start_virtual); + iounmap(par->aperture.virtual); kfree(par->edid); if (par->res_flags & FRAMEBUFFER_REQ) release_mem_region(par->aperture.physical, diff --git a/drivers/video/fbdev/macfb.c b/drivers/video/fbdev/macfb.c index cda7587..dde0520 100644 --- a/drivers/video/fbdev/macfb.c +++ b/drivers/video/fbdev/macfb.c @@ -541,16 +541,11 @@ static void __init macfb_setup(char *options) static void __init iounmap_macfb(void) { - if (dafb_cmap_regs) - iounmap(dafb_cmap_regs); - if (v8_brazil_cmap_regs) - iounmap(v8_brazil_cmap_regs); - if (rbv_cmap_regs) - iounmap(rbv_cmap_regs); - if (civic_cmap_regs) - iounmap(civic_cmap_regs); - if (csc_cmap_regs) - iounmap(csc_cmap_regs); + iounmap(dafb_cmap_regs); + iounmap(v8_brazil_cmap_regs); + iounmap(rbv_cmap_regs); + iounmap(civic_cmap_regs); + iounmap(csc_cmap_regs); } static int __init macfb_init(void) diff --git a/drivers/video/fbdev/offb.c b/drivers/video/fbdev/offb.c index 43a0a52..5efce99 100644 --- a/drivers/video/fbdev/offb.c +++ b/drivers/video/fbdev/offb.c @@ -281,8 +281,7 @@ static int offb_set_par(struct fb_info *info) static void offb_destroy(struct fb_info *info) { - if (info->screen_base) - iounmap(info->screen_base); + iounmap(info->screen_base); release_mem_region(info->apertures->ranges[0].base, info->apertures->ranges[0].size); framebuffer_release(info); } diff --git a/drivers/video/fbdev/pvr2fb.c b/drivers/video/fbdev/pvr2fb.c index 7c74f58..7aa4ef1 100644 --- a/drivers/video/fbdev/pvr2fb.c +++ b/drivers/video/fbdev/pvr2fb.c @@ -841,8 +841,7 @@ static int pvr2fb_common_init(void) return 0; out_err: - if (fb_info->screen_base) - iounmap(fb_info->screen_base); + iounmap(fb_info->screen_base); if (par->mmio_base) iounmap((void *)par->mmio_base); diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c index 83433cb..dff38b7 100644 --- a/drivers/video/fbdev/s1d13xxxfb.c +++ b/drivers/video/fbdev/s1d13xxxfb.c @@ -750,8 +750,7 @@ s1d13xxxfb_remove(struct platform_device *pdev) fb_dealloc_cmap(&info->cmap); - if (info->screen_base) - iounmap(info->screen_base); + iounmap(info->screen_base); framebuffer_release(info); } diff --git a/drivers/video/fbdev/s3fb.c b/drivers/video/fbdev/s3fb.c index f0ae61a..3d9d45f 100644 --- a/drivers/video/fbdev/s3fb.c +++ b/drivers/video/fbdev/s3fb.c @@ -1382,8 +1382,7 @@ err_find_mode: #ifdef CONFIG_FB_S3_DDC if (par->ddc_registered) i2c_del_adapter(&par->ddc_adapter); - if (par->mmio) - iounmap(par->mmio); + iounmap(par->mmio); #endif pci_iounmap(dev, info->screen_base); err_iomap: @@ -1419,8 +1418,7 @@ static void s3_pci_remove(struct pci_dev *dev) #ifdef CONFIG_FB_S3_DDC if (par->ddc_registered) i2c_del_adapter(&par->ddc_adapter); - if (par->mmio) - iounmap(par->mmio); + iounmap(par->mmio); #endif pci_iounmap(dev, info->screen_base); diff --git a/drivers/video/fbdev/sh_mobile_hdmi.c b/drivers/video/fbdev/sh_mobile_hdmi.c index 7c72a3f..2a7187d 100644 --- a/drivers/video/fbdev/sh_mobile_hdmi.c +++ b/drivers/video/fbdev/sh_mobile_hdmi.c @@ -1397,8 +1397,7 @@ static int __init sh_hdmi_probe(struct platform_device *pdev) ecodec: free_irq(irq, hdmi); ereqirq: - if (hdmi->htop1) - iounmap(hdmi->htop1); + iounmap(hdmi->htop1); emap_htop1: pm_runtime_put(&pdev->dev); pm_runtime_disable(&pdev->dev); @@ -1428,8 +1427,7 @@ static int __exit sh_hdmi_remove(struct platform_device *pdev) pm_runtime_disable(&pdev->dev); clk_disable_unprepare(hdmi->hdmi_clk); clk_put(hdmi->hdmi_clk); - if (hdmi->htop1) - iounmap(hdmi->htop1); + iounmap(hdmi->htop1); iounmap(hdmi->base); release_mem_region(res->start, resource_size(res)); diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c index d3013cd..4f9a25b 100644 --- a/drivers/video/fbdev/sh_mobile_lcdcfb.c +++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c @@ -2489,8 +2489,7 @@ static int sh_mobile_lcdc_remove(struct platform_device *pdev) clk_put(priv->dot_clk); } - if (priv->base) - iounmap(priv->base); + iounmap(priv->base); if (priv->irq) free_irq(priv->irq, priv); diff --git a/drivers/video/fbdev/simplefb.c b/drivers/video/fbdev/simplefb.c index 92cac80..40e6b33 100644 --- a/drivers/video/fbdev/simplefb.c +++ b/drivers/video/fbdev/simplefb.c @@ -72,8 +72,7 @@ static int simplefb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, static void simplefb_destroy(struct fb_info *info) { - if (info->screen_base) - iounmap(info->screen_base); + iounmap(info->screen_base); } static struct fb_ops simplefb_ops = { diff --git a/drivers/video/fbdev/stifb.c b/drivers/video/fbdev/stifb.c index 86621fa..ea12305 100644 --- a/drivers/video/fbdev/stifb.c +++ b/drivers/video/fbdev/stifb.c @@ -1374,8 +1374,7 @@ stifb_cleanup(void) unregister_framebuffer(sti->info); release_mem_region(info->fix.mmio_start, info->fix.mmio_len); release_mem_region(info->fix.smem_start, info->fix.smem_len); - if (info->screen_base) - iounmap(info->screen_base); + iounmap(info->screen_base); fb_dealloc_cmap(&info->cmap); framebuffer_release(info); } diff --git a/drivers/video/fbdev/tdfxfb.c b/drivers/video/fbdev/tdfxfb.c index f761fe3..69d4062 100644 --- a/drivers/video/fbdev/tdfxfb.c +++ b/drivers/video/fbdev/tdfxfb.c @@ -1572,15 +1572,13 @@ out_err_iobase: release_region(pci_resource_start(pdev, 2), pci_resource_len(pdev, 2)); out_err_screenbase: - if (info->screen_base) - iounmap(info->screen_base); + iounmap(info->screen_base); release_mem_region(info->fix.smem_start, pci_resource_len(pdev, 1)); out_err_regbase: /* * Cleanup after anything that was remapped/allocated. */ - if (default_par->regbase_virt) - iounmap(default_par->regbase_virt); + iounmap(default_par->regbase_virt); release_mem_region(info->fix.mmio_start, info->fix.mmio_len); out_err: framebuffer_release(info); diff --git a/drivers/video/fbdev/tgafb.c b/drivers/video/fbdev/tgafb.c index 65ba992..b6fb7e8 100644 --- a/drivers/video/fbdev/tgafb.c +++ b/drivers/video/fbdev/tgafb.c @@ -1520,8 +1520,7 @@ static int tgafb_register(struct device *dev) err2: fb_dealloc_cmap(&info->cmap); err1: - if (mem_base) - iounmap(mem_base); + iounmap(mem_base); release_mem_region(bar0_start, bar0_len); err0: framebuffer_release(info); diff --git a/drivers/video/fbdev/tridentfb.c b/drivers/video/fbdev/tridentfb.c index 7ed9a22..71567401 100644 --- a/drivers/video/fbdev/tridentfb.c +++ b/drivers/video/fbdev/tridentfb.c @@ -1531,13 +1531,11 @@ static int trident_pci_probe(struct pci_dev *dev, out_unmap2: kfree(info->pixmap.addr); - if (info->screen_base) - iounmap(info->screen_base); + iounmap(info->screen_base); release_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len); disable_mmio(info->par); out_unmap1: - if (default_par->io_virt) - iounmap(default_par->io_virt); + iounmap(default_par->io_virt); release_mem_region(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len); framebuffer_release(info); return err; diff --git a/drivers/video/fbdev/valkyriefb.c b/drivers/video/fbdev/valkyriefb.c index 275fb98..2a9213b 100644 --- a/drivers/video/fbdev/valkyriefb.c +++ b/drivers/video/fbdev/valkyriefb.c @@ -400,12 +400,9 @@ int __init valkyriefb_init(void) out_cmap_free: fb_dealloc_cmap(&p->info.cmap); out_free: - if (p->frame_buffer) - iounmap(p->frame_buffer); - if (p->cmap_regs) - iounmap(p->cmap_regs); - if (p->valkyrie_regs) - iounmap(p->valkyrie_regs); + iounmap(p->frame_buffer); + iounmap(p->cmap_regs); + iounmap(p->valkyrie_regs); kfree(p); return err; } diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c index d79a0ac..693d18e 100644 --- a/drivers/video/fbdev/vesafb.c +++ b/drivers/video/fbdev/vesafb.c @@ -176,8 +176,7 @@ static int vesafb_setcolreg(unsigned regno, unsigned red, unsigned green, static void vesafb_destroy(struct fb_info *info) { fb_dealloc_cmap(&info->cmap); - if (info->screen_base) - iounmap(info->screen_base); + iounmap(info->screen_base); release_mem_region(info->apertures->ranges[0].base, info->apertures->ranges[0].size); } @@ -492,8 +491,7 @@ static int vesafb_probe(struct platform_device *dev) fb_info(info, "%s frame buffer device\n", info->fix.id); return 0; err: - if (info->screen_base) - iounmap(info->screen_base); + iounmap(info->screen_base); framebuffer_release(info); release_mem_region(vesafb_fix.smem_start, size_total); return err; diff --git a/drivers/video/fbdev/w100fb.c b/drivers/video/fbdev/w100fb.c index 10951c8..aeb53eb 100644 --- a/drivers/video/fbdev/w100fb.c +++ b/drivers/video/fbdev/w100fb.c @@ -770,12 +770,9 @@ out: fb_dealloc_cmap(&info->cmap); kfree(info->pseudo_palette); } - if (remapped_fbuf != NULL) - iounmap(remapped_fbuf); - if (remapped_regs != NULL) - iounmap(remapped_regs); - if (remapped_base != NULL) - iounmap(remapped_base); + iounmap(remapped_fbuf); + iounmap(remapped_regs); + iounmap(remapped_base); if (info) framebuffer_release(info); return err; -- 2.2.2
> Anyway, I'm essentially saying that I'd like to be 100% sure we have a > guarantee before dropping all these. You can not be absolutely sure. There are various implementation details which will eventually need further considerations. I hope that a reasonable confidence can be achieved here. >> This issue was detected by using the Coccinelle software. > > What script? I published scripts for static source code analysis in March 2004. > Hand-rolled I guess? An extended version found some update candidates in source files for Linux according to the software development status of "next-20141226". My approach is still incomplete at the moment. Regards, Markus
The sparc iounmap() implementation in arch/sparc/kernel/ioport.c looks it prints an error message if you pass a NULL pointer. regards, dan carpenter
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 18 Jan 2015 23:30:41 +0100 The iounmap() function could be called in two cases by the tdfxfb_probe() function during error handling even if the passed data structure element contained still a null pointer. This implementation detail could be improved by adjustments for jump labels. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/video/fbdev/tdfxfb.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/video/fbdev/tdfxfb.c b/drivers/video/fbdev/tdfxfb.c index 69d4062..c280a3b 100644 --- a/drivers/video/fbdev/tdfxfb.c +++ b/drivers/video/fbdev/tdfxfb.c @@ -1438,20 +1438,20 @@ static int tdfxfb_probe(struct pci_dev *pdev, const struct pci_device_id *id) if (!default_par->regbase_virt) { printk(KERN_ERR "fb: Can't remap %s register area.\n", info->fix.id); - goto out_err_regbase; + goto release_memory_region_regbase; } info->fix.smem_start = pci_resource_start(pdev, 1); info->fix.smem_len = do_lfb_size(default_par, pdev->device); if (!info->fix.smem_len) { printk(KERN_ERR "fb: Can't count %s memory.\n", info->fix.id); - goto out_err_regbase; + goto io_unmap_regbase; } if (!request_mem_region(info->fix.smem_start, pci_resource_len(pdev, 1), "tdfx smem")) { printk(KERN_ERR "tdfxfb: Can't reserve smem\n"); - goto out_err_regbase; + goto io_unmap_regbase; } info->screen_base = ioremap_nocache(info->fix.smem_start, @@ -1459,7 +1459,7 @@ static int tdfxfb_probe(struct pci_dev *pdev, const struct pci_device_id *id) if (!info->screen_base) { printk(KERN_ERR "fb: Can't remap %s framebuffer.\n", info->fix.id); - goto out_err_screenbase; + goto release_memory_region_screenbase; } default_par->iobase = pci_resource_start(pdev, 2); @@ -1467,7 +1467,7 @@ static int tdfxfb_probe(struct pci_dev *pdev, const struct pci_device_id *id) if (!request_region(pci_resource_start(pdev, 2), pci_resource_len(pdev, 2), "tdfx iobase")) { printk(KERN_ERR "tdfxfb: Can't reserve iobase\n"); - goto out_err_screenbase; + goto io_unmap_screenbase; } printk(KERN_INFO "fb: %s memory = %dK\n", info->fix.id, @@ -1571,14 +1571,16 @@ out_err_iobase: info->fix.smem_len); release_region(pci_resource_start(pdev, 2), pci_resource_len(pdev, 2)); -out_err_screenbase: +io_unmap_screenbase: iounmap(info->screen_base); +release_memory_region_screenbase: release_mem_region(info->fix.smem_start, pci_resource_len(pdev, 1)); -out_err_regbase: +io_unmap_regbase: /* * Cleanup after anything that was remapped/allocated. */ iounmap(default_par->regbase_virt); +release_memory_region_regbase: release_mem_region(info->fix.mmio_start, info->fix.mmio_len); out_err: framebuffer_release(info); -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 19 Jan 2015 11:30:33 +0100 The iounmap() function could be called in two cases by the vesafb_probe() function during error handling even if the passed data structure element contained still a null pointer. This implementation detail could be improved by adjustments for jump labels. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/video/fbdev/vesafb.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c index 693d18e..de7cad0 100644 --- a/drivers/video/fbdev/vesafb.c +++ b/drivers/video/fbdev/vesafb.c @@ -303,7 +303,7 @@ static int vesafb_probe(struct platform_device *dev) info->apertures = alloc_apertures(1); if (!info->apertures) { err = -ENOMEM; - goto err; + goto release_framebuffer; } info->apertures->ranges[0].base = screen_info.lfb_base; info->apertures->ranges[0].size = size_total; @@ -462,7 +462,7 @@ static int vesafb_probe(struct platform_device *dev) "vesafb: abort, cannot ioremap video memory 0x%x @ 0x%lx\n", vesafb_fix.smem_len, vesafb_fix.smem_start); err = -EIO; - goto err; + goto release_framebuffer; } printk(KERN_INFO "vesafb: framebuffer at 0x%lx, mapped to 0x%p, " @@ -492,6 +492,7 @@ static int vesafb_probe(struct platform_device *dev) return 0; err: iounmap(info->screen_base); +release_framebuffer: framebuffer_release(info); release_mem_region(vesafb_fix.smem_start, size_total); return err; -- 2.2.2
On Mon, Jan 19, 2015 at 07:19:34PM +0100, SF Markus Elfring wrote: > > Anyway, I'm essentially saying that I'd like to be 100% sure we have a > > guarantee before dropping all these. > > You can not be absolutely sure. There are various implementation details > which will eventually need further considerations. Let's consider them first. We don't ship code that is missing the implementation details. (At least, we try not to!) > I hope that a reasonable confidence can be achieved here. > > > >> This issue was detected by using the Coccinelle software. > > > > What script? > > I published scripts for static source code analysis in March 2004. I didn't ask "when?"; where? > > Hand-rolled I guess? > > An extended version found some update candidates in source files for Linux > according to the software development status of "next-20141226". > > My approach is still incomplete at the moment. Then please complete it. Thanks, Brian
On Mon, Jan 19, 2015 at 09:20:47PM +0300, Dan Carpenter wrote:
> The sparc iounmap() implementation in arch/sparc/kernel/ioport.c looks
> it prints an error message if you pass a NULL pointer.
Seems that way. Thanks.
Nak to the patch then.
Brian
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 19 Jan 2015 13:18:50 +0100 The return value from a call of the ioremap() function was not checked by the implementation of the cirrusfb_pci_register() function. Let us complete the corresponding error detection and exception handling at this source code place. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/video/fbdev/cirrusfb.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/video/fbdev/cirrusfb.c b/drivers/video/fbdev/cirrusfb.c index d8b3359..aa4050c 100644 --- a/drivers/video/fbdev/cirrusfb.c +++ b/drivers/video/fbdev/cirrusfb.c @@ -2111,6 +2111,10 @@ static int cirrusfb_pci_register(struct pci_dev *pdev, /* FIXME: this forces VGA. alternatives? */ cinfo->regbase = NULL; cinfo->laguna_mmio = ioremap(info->fix.mmio_start, 0x1000); + if (!cinfo->laguna_mmio) { + ret = -EIO; + goto err_release_fb; + } dev_dbg(info->device, "Board address: 0x%lx, register address: 0x%lx\n", board_addr, info->fix.mmio_start); @@ -2122,7 +2126,7 @@ static int cirrusfb_pci_register(struct pci_dev *pdev, if (ret < 0) { dev_err(info->device, "cannot reserve region 0x%lx, abort\n", board_addr); - goto err_release_fb; + goto io_unmap_laguna; } #if 0 /* if the system didn't claim this region, we would... */ if (!request_mem_region(0xA0000, 65535, "cirrusfb")) { @@ -2163,8 +2167,9 @@ err_release_legacy: err_release_regions: #endif pci_release_regions(pdev); -err_release_fb: +io_unmap_laguna: iounmap(cinfo->laguna_mmio); +err_release_fb: framebuffer_release(info); err_out: return ret; -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 19 Jan 2015 14:18:47 +0100 The functions "iounmap" and "kfree" could be called in a few cases by the trident_pci_probe() function during error handling even if the passed data structure element contained still a null pointer. This implementation detail could be improved by adjustments for jump labels. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/video/fbdev/tridentfb.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/video/fbdev/tridentfb.c b/drivers/video/fbdev/tridentfb.c index 71567401..86d4733 100644 --- a/drivers/video/fbdev/tridentfb.c +++ b/drivers/video/fbdev/tridentfb.c @@ -1436,7 +1436,7 @@ static int trident_pci_probe(struct pci_dev *dev, if (!default_par->io_virt) { debug("ioremap failed\n"); err = -1; - goto out_unmap1; + goto release_memory_region_mmio; } enable_mmio(default_par); @@ -1459,7 +1459,7 @@ static int trident_pci_probe(struct pci_dev *dev, if (!info->screen_base) { debug("ioremap failed\n"); err = -1; - goto out_unmap2; + goto release_memory_region_smem; } default_par->flatpanel = is_flatpanel(default_par); @@ -1485,7 +1485,7 @@ static int trident_pci_probe(struct pci_dev *dev, info->pixmap.addr = kmalloc(4096, GFP_KERNEL); if (!info->pixmap.addr) { err = -ENOMEM; - goto out_unmap2; + goto io_unmap_screenbase; } info->pixmap.size = 4096; @@ -1531,11 +1531,14 @@ static int trident_pci_probe(struct pci_dev *dev, out_unmap2: kfree(info->pixmap.addr); +io_unmap_screenbase: iounmap(info->screen_base); +release_memory_region_smem: release_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len); disable_mmio(info->par); out_unmap1: iounmap(default_par->io_virt); +release_memory_region_mmio: release_mem_region(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len); framebuffer_release(info); return err; -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 19 Jan 2015 14:50:44 +0100 The iounmap() function could be called in two cases by the pvr2fb_common_init() function during error handling even if the passed data structure element contained still a null pointer. This implementation detail could be improved by adjustments for jump labels. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/video/fbdev/pvr2fb.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/video/fbdev/pvr2fb.c b/drivers/video/fbdev/pvr2fb.c index 7aa4ef1..9fb8bbf 100644 --- a/drivers/video/fbdev/pvr2fb.c +++ b/drivers/video/fbdev/pvr2fb.c @@ -773,14 +773,14 @@ static int pvr2fb_common_init(void) if (!fb_info->screen_base) { printk(KERN_ERR "pvr2fb: Failed to remap smem space\n"); - goto out_err; + return -ENXIO; } par->mmio_base = (unsigned long)ioremap_nocache(pvr2_fix.mmio_start, pvr2_fix.mmio_len); if (!par->mmio_base) { printk(KERN_ERR "pvr2fb: Failed to remap mmio space\n"); - goto out_err; + goto io_unmap_screen; } fb_memset(fb_info->screen_base, 0, pvr2_fix.smem_len); @@ -807,7 +807,7 @@ static int pvr2fb_common_init(void) fb_alloc_cmap(&fb_info->cmap, 256, 0); if (register_framebuffer(fb_info) < 0) - goto out_err; + goto io_unmap_mmio; /*Must write PIXDEPTH to register before anything is displayed - so force init */ pvr2_init_display(fb_info); @@ -840,10 +840,10 @@ static int pvr2fb_common_init(void) return 0; -out_err: +io_unmap_mmio: + iounmap((void *)par->mmio_base); +io_unmap_screen: iounmap(fb_info->screen_base); - if (par->mmio_base) - iounmap((void *)par->mmio_base); return -ENXIO; } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 19 Jan 2015 15:30:45 +0100 The iounmap() function could be called in one case by the tgafb_register() function during error handling even if the passed variable "mem_base" contained still a null pointer. This implementation detail could be improved by adjustments for jump labels (according also to current Linux coding style). Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/video/fbdev/tgafb.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/video/fbdev/tgafb.c b/drivers/video/fbdev/tgafb.c index b6fb7e8..a3cd0ef 100644 --- a/drivers/video/fbdev/tgafb.c +++ b/drivers/video/fbdev/tgafb.c @@ -1436,14 +1436,14 @@ static int tgafb_register(struct device *dev) } if (!request_mem_region (bar0_start, bar0_len, "tgafb")) { printk(KERN_ERR "tgafb: cannot reserve FB region\n"); - goto err0; + goto release_framebuffer; } /* Map the framebuffer. */ mem_base = ioremap_nocache(bar0_start, bar0_len); if (!mem_base) { printk(KERN_ERR "tgafb: Cannot map MMIO\n"); - goto err1; + goto release_memory_region; } /* Grab info about the card. */ @@ -1484,13 +1484,13 @@ static int tgafb_register(struct device *dev) if (ret = 0 || ret = 4) { printk(KERN_ERR "tgafb: Could not find valid video mode\n"); ret = -EINVAL; - goto err1; + goto io_unmap; } if (fb_alloc_cmap(&info->cmap, 256, 0)) { printk(KERN_ERR "tgafb: Could not allocate color map\n"); ret = -ENOMEM; - goto err1; + goto io_unmap; } tgafb_set_par(info); @@ -1498,7 +1498,7 @@ static int tgafb_register(struct device *dev) if (register_framebuffer(info) < 0) { printk(KERN_ERR "tgafb: Could not register framebuffer\n"); ret = -EINVAL; - goto err2; + goto dealloc_cmap; } if (tga_bus_pci) { @@ -1517,12 +1517,13 @@ static int tgafb_register(struct device *dev) return 0; - err2: +dealloc_cmap: fb_dealloc_cmap(&info->cmap); - err1: +io_unmap: iounmap(mem_base); +release_memory_region: release_mem_region(bar0_start, bar0_len); - err0: +release_framebuffer: framebuffer_release(info); return ret; } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 19 Jan 2015 17:01:25 +0100 The iounmap() function could be called in three cases by the valkyriefb_init() function during error handling even if the passed data structure element contained still a null pointer. This implementation detail could be improved by adjustments for jump labels (according also to current Linux coding style) and error messages. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/video/fbdev/valkyriefb.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/drivers/video/fbdev/valkyriefb.c b/drivers/video/fbdev/valkyriefb.c index 2a9213b..a81a0f1 100644 --- a/drivers/video/fbdev/valkyriefb.c +++ b/drivers/video/fbdev/valkyriefb.c @@ -369,40 +369,50 @@ int __init valkyriefb_init(void) } p->total_vram = 0x100000; p->frame_buffer_phys = frame_buffer_phys; + err = -ENOMEM; p->frame_buffer = __ioremap(frame_buffer_phys, p->total_vram, flags); + if (p->frame_buffer = NULL) { + pr_err("%s: %s failed\n", __func__, "Frame buffer mapping"); + goto free_memory; + } p->cmap_regs_phys = cmap_regs_phys; p->cmap_regs = ioremap(p->cmap_regs_phys, 0x1000); + if (p->cmap_regs = NULL) { + pr_err("%s: %s failed\n", __func__, "cmap"); + goto io_unmap_framebuffer; + } p->valkyrie_regs_phys = cmap_regs_phys+0x6000; p->valkyrie_regs = ioremap(p->valkyrie_regs_phys, 0x1000); - err = -ENOMEM; - if (p->frame_buffer = NULL || p->cmap_regs = NULL - || p->valkyrie_regs = NULL) { - printk(KERN_ERR "valkyriefb: couldn't map resources\n"); - goto out_free; + if (p->valkyrie_regs = NULL) { + pr_err("%s: %s failed\n", __func__, "ioremap"); + goto io_unmap_cmap; } valkyrie_choose_mode(p); mac_vmode_to_var(default_vmode, default_cmode, &p->info.var); err = valkyrie_init_info(&p->info, p); if (err < 0) - goto out_free; + goto io_unmap_valkyrie; valkyrie_init_fix(&p->info.fix, p); if (valkyriefb_set_par(&p->info)) /* "can't happen" */ printk(KERN_ERR "valkyriefb: can't set default video mode\n"); if ((err = register_framebuffer(&p->info)) != 0) - goto out_cmap_free; + goto dealloc_cmap; fb_info(&p->info, "valkyrie frame buffer device\n"); return 0; - out_cmap_free: +dealloc_cmap: fb_dealloc_cmap(&p->info.cmap); - out_free: - iounmap(p->frame_buffer); - iounmap(p->cmap_regs); +io_unmap_valkyrie: iounmap(p->valkyrie_regs); +io_unmap_cmap: + iounmap(p->cmap_regs); +io_unmap_framebuffer: + iounmap(p->frame_buffer); +free_memory: kfree(p); return err; } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 19 Jan 2015 17:56:11 +0100 The iounmap() function could be called in three cases by the w100fb_probe() function during error handling even if the passed data structure element contained still a null pointer. * This implementation detail could be improved by adjustments for jump labels. * Let us also delete two unnecessary null pointer checks for the variable "info". Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/video/fbdev/w100fb.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/drivers/video/fbdev/w100fb.c b/drivers/video/fbdev/w100fb.c index aeb53eb..67ddc57 100644 --- a/drivers/video/fbdev/w100fb.c +++ b/drivers/video/fbdev/w100fb.c @@ -645,12 +645,12 @@ int w100fb_probe(struct platform_device *pdev) /* Remap the chip base address */ remapped_base = ioremap_nocache(mem->start+W100_CFG_BASE, W100_CFG_LEN); if (remapped_base = NULL) - goto out; + goto exit; /* Map the register space */ remapped_regs = ioremap_nocache(mem->start+W100_REG_BASE, W100_REG_LEN); if (remapped_regs = NULL) - goto out; + goto io_unmap_base; /* Identify the chip */ printk("Found "); @@ -662,19 +662,19 @@ int w100fb_probe(struct platform_device *pdev) default: printk("Unknown imageon chip ID\n"); err = -ENODEV; - goto out; + goto io_unmap_regs; } printk(" at 0x%08lx.\n", (unsigned long) mem->start+W100_CFG_BASE); /* Remap the framebuffer */ remapped_fbuf = ioremap_nocache(mem->start+MEM_WINDOW_BASE, MEM_WINDOW_SIZE); if (remapped_fbuf = NULL) - goto out; + goto io_unmap_regs; info=framebuffer_alloc(sizeof(struct w100fb_par), &pdev->dev); if (!info) { err = -ENOMEM; - goto out; + goto io_unmap_framebuffer; } par = info->par; @@ -690,13 +690,13 @@ int w100fb_probe(struct platform_device *pdev) if (!par->pll_table) { printk(KERN_ERR "No matching Xtal definition found\n"); err = -EINVAL; - goto out; + goto release_framebuffer; } info->pseudo_palette = kmalloc(sizeof (u32) * MAX_PALETTES, GFP_KERNEL); if (!info->pseudo_palette) { err = -ENOMEM; - goto out; + goto release_framebuffer; } info->fbops = &w100fb_ops; @@ -716,7 +716,7 @@ int w100fb_probe(struct platform_device *pdev) if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) { err = -ENOMEM; - goto out; + goto free_palette; } par->mode = &inf->modelist[0]; @@ -766,15 +766,18 @@ int w100fb_probe(struct platform_device *pdev) fb_info(info, "%s frame buffer device\n", info->fix.id); return 0; out: - if (info) { - fb_dealloc_cmap(&info->cmap); - kfree(info->pseudo_palette); - } + fb_dealloc_cmap(&info->cmap); +free_palette: + kfree(info->pseudo_palette); +release_framebuffer: + framebuffer_release(info); +io_unmap_framebuffer: iounmap(remapped_fbuf); +io_unmap_regs: iounmap(remapped_regs); +io_unmap_base: iounmap(remapped_base); - if (info) - framebuffer_release(info); +exit: return err; } -- 2.2.2
>> I published scripts for static source code analysis in March 2004. > > I didn't ask "when?"; where? https://lkml.org/lkml/2014/3/5/356 http://article.gmane.org/gmane.comp.version-control.coccinelle/3513/ https://systeme.lip6.fr/pipermail/cocci/2014-March/000676.html Do you get further ideas from this software analysis approach? Regards, Markus
On Mon, Jan 19, 2015 at 08:07:34PM +0100, SF Markus Elfring wrote: > >> I published scripts for static source code analysis in March 2004. ^^ That would be March 2014, not March 2004. > > I didn't ask "when?"; where? > > https://lkml.org/lkml/2014/3/5/356 > http://article.gmane.org/gmane.comp.version-control.coccinelle/3513/ > https://systeme.lip6.fr/pipermail/cocci/2014-March/000676.html > > Do you get further ideas from this software analysis approach? I suppose. I've gotten the idea that I can generate a ton of patches using an automated tool, not test or research them, possibly add bugs to the kernel, and still get a good percentage of my patches merged. Now, have *you* learned anything from this approach? Brian
> Now, have *you* learned anything from this approach?
Yes, of course. ;-)
How would we like to tackle any corresponding software development challenges?
Regards,
Markus
Replying, against my better judgment... On Mon, Jan 19, 2015 at 2:00 PM, SF Markus Elfring <elfring@users.sourceforge.net> wrote: >> Now, have *you* learned anything from this approach? > > Yes, of course. ;-) Do you have any evidence of this? Details? The only evidence I see is a long thread of similar patches from the last several months, of varying (though not increasing) quality. Prior objections to your approach were met with a distinct lack of self-awareness on your part. > How would we like to tackle any corresponding software development challenges? I don't really see many challenges here to tackle, except for the social issue of dealing with patch bots like you. Your automated patches are generally not solving real problems, but they are at times introducing bugs. So the most efficient "solution" to this "challenge" may simply be to ignore your patches. Brian
> The only evidence I see is a long thread of similar patches from > the last several months, of varying (though not increasing) quality. I find it acceptable that some of my update suggestions do not fit to your quality expectations at the moment. > Prior objections to your approach were met with a distinct lack > of self-awareness on your part. I guess that a bit more clarification of this view will help to resolve some open issues, won't it? > I don't really see many challenges here to tackle, except for the > social issue of dealing with patch bots like you. I hope that you will like other automatic source code analysis results. > Your automated patches are generally not solving real problems, I try to clean-up Linux source files a bit. Problem solving with a higher value might follow ... > but they are at times introducing bugs. There are the usual different opinions and disagreements which might be still waiting for a constructive solution. Regards, Markus
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 31 Jan 2015 17:18:48 +0100 The meta_delete() function could be called in four cases by the em_meta_change() function during error handling even if the passed variable "meta" contained still a null pointer. * This implementation detail could be improved by adjustments for jump labels. * Let us return immediately after the first failed function call according to the current Linux coding style convention. * Let us delete also unnecessary checks for the variables "err" and "meta" there. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- net/sched/em_meta.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/net/sched/em_meta.c b/net/sched/em_meta.c index b5294ce..2aa67b1 100644 --- a/net/sched/em_meta.c +++ b/net/sched/em_meta.c @@ -866,23 +866,23 @@ static int em_meta_change(struct net *net, void *data, int len, err = nla_parse(tb, TCA_EM_META_MAX, data, len, meta_policy); if (err < 0) - goto errout; + return err; err = -EINVAL; if (tb[TCA_EM_META_HDR] = NULL) - goto errout; + goto exit; hdr = nla_data(tb[TCA_EM_META_HDR]); if (TCF_META_TYPE(hdr->left.kind) != TCF_META_TYPE(hdr->right.kind) || TCF_META_TYPE(hdr->left.kind) > TCF_META_TYPE_MAX || TCF_META_ID(hdr->left.kind) > TCF_META_ID_MAX || TCF_META_ID(hdr->right.kind) > TCF_META_ID_MAX) - goto errout; + goto exit; meta = kzalloc(sizeof(*meta), GFP_KERNEL); if (meta = NULL) { err = -ENOMEM; - goto errout; + goto exit; } memcpy(&meta->lvalue.hdr, &hdr->left, sizeof(hdr->left)); @@ -891,20 +891,20 @@ static int em_meta_change(struct net *net, void *data, int len, if (!meta_is_supported(&meta->lvalue) || !meta_is_supported(&meta->rvalue)) { err = -EOPNOTSUPP; - goto errout; + goto delete_meta; } if (meta_change_data(&meta->lvalue, tb[TCA_EM_META_LVALUE]) < 0 || meta_change_data(&meta->rvalue, tb[TCA_EM_META_RVALUE]) < 0) - goto errout; + goto delete_meta; m->datalen = sizeof(*meta); m->data = (unsigned long) meta; - err = 0; -errout: - if (err && meta) - meta_delete(meta); + return 0; +delete_meta: + meta_delete(meta); +exit: return err; } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 31 Jan 2015 18:10:03 +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/sctp/associola.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/sctp/associola.c b/net/sctp/associola.c index f791edd..3c2aefc 100644 --- a/net/sctp/associola.c +++ b/net/sctp/associola.c @@ -391,8 +391,7 @@ void sctp_association_free(struct sctp_association *asoc) sctp_asconf_queue_teardown(asoc); /* Free pending address space being deleted */ - if (asoc->asconf_addr_del_pending != NULL) - kfree(asoc->asconf_addr_del_pending); + kfree(asoc->asconf_addr_del_pending); /* AUTH - Free the endpoint shared keys */ sctp_auth_destroy_keys(&asoc->endpoint_shared_keys); -- 2.2.2
Hi,
On 31.01.2015 17:34, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 31 Jan 2015 17:18:48 +0100
>
> The meta_delete() function could be called in four cases by the
> em_meta_change() function during error handling even if the passed
> variable "meta" contained still a null pointer.
>
> * This implementation detail could be improved by adjustments for jump labels.
>
> * Let us return immediately after the first failed function call according to
> the current Linux coding style convention.
>
> * Let us delete also unnecessary checks for the variables "err" and
> "meta" there.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> net/sched/em_meta.c | 20 ++++++++++----------
> 1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/net/sched/em_meta.c b/net/sched/em_meta.c
> index b5294ce..2aa67b1 100644
> --- a/net/sched/em_meta.c
> +++ b/net/sched/em_meta.c
> @@ -866,23 +866,23 @@ static int em_meta_change(struct net *net, void *data, int len,
>
> err = nla_parse(tb, TCA_EM_META_MAX, data, len, meta_policy);
> if (err < 0)
> - goto errout;
> + return err;
>
> err = -EINVAL;
> if (tb[TCA_EM_META_HDR] = NULL)
> - goto errout;
> + goto exit;
> hdr = nla_data(tb[TCA_EM_META_HDR]);
>
> if (TCF_META_TYPE(hdr->left.kind) != TCF_META_TYPE(hdr->right.kind) ||
> TCF_META_TYPE(hdr->left.kind) > TCF_META_TYPE_MAX ||
> TCF_META_ID(hdr->left.kind) > TCF_META_ID_MAX ||
> TCF_META_ID(hdr->right.kind) > TCF_META_ID_MAX)
> - goto errout;
> + goto exit;
>
> meta = kzalloc(sizeof(*meta), GFP_KERNEL);
> if (meta = NULL) {
> err = -ENOMEM;
> - goto errout;
> + goto exit;
> }
>
> memcpy(&meta->lvalue.hdr, &hdr->left, sizeof(hdr->left));
> @@ -891,20 +891,20 @@ static int em_meta_change(struct net *net, void *data, int len,
> if (!meta_is_supported(&meta->lvalue) ||
> !meta_is_supported(&meta->rvalue)) {
> err = -EOPNOTSUPP;
> - goto errout;
> + goto delete_meta;
> }
>
> if (meta_change_data(&meta->lvalue, tb[TCA_EM_META_LVALUE]) < 0 ||
> meta_change_data(&meta->rvalue, tb[TCA_EM_META_RVALUE]) < 0)
> - goto errout;
> + goto delete_meta;
>
> m->datalen = sizeof(*meta);
> m->data = (unsigned long) meta;
>
> - err = 0;
> -errout:
> - if (err && meta)
> - meta_delete(meta);
> + return 0;
> +delete_meta:
> + meta_delete(meta);
> +exit:
> return err;
> }
Why do you use that exit label if it does nothing more than returning
the error value? Also if nla_parse fails you dont use it but return the
error directly. While using a label which is used only to return an
error may be a matter of taste, its at least inconsistent to do both in
a function, use such a label in one case and return immediately in
another, isnt it?
Regards,
Lino
On 31.01.2015 17:34, SF Markus Elfring wrote:
> -errout:
> - if (err && meta)
> - meta_delete(meta);
Since this patch seems to be about optimization and cleanup you should
probably also remove the now unnecessary initialization of "meta" with
NULL at the beginning of the function...
Regards,
Lino
On Sat, Jan 31, 2015 at 06:15:59PM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 31 Jan 2015 18:10:03 +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/sctp/associola.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/net/sctp/associola.c b/net/sctp/associola.c
> index f791edd..3c2aefc 100644
> --- a/net/sctp/associola.c
> +++ b/net/sctp/associola.c
> @@ -391,8 +391,7 @@ void sctp_association_free(struct sctp_association *asoc)
> sctp_asconf_queue_teardown(asoc);
>
> /* Free pending address space being deleted */
> - if (asoc->asconf_addr_del_pending != NULL)
> - kfree(asoc->asconf_addr_del_pending);
> + kfree(asoc->asconf_addr_del_pending);
>
> /* AUTH - Free the endpoint shared keys */
> sctp_auth_destroy_keys(&asoc->endpoint_shared_keys);
> --
> 2.2.2
>
>
Sure, seems reasonable
Acked-By: Neil Horman <nhorman@tuxdriver.com>
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 31 Jan 2015 22:00:14 +0100 Further update suggestions were taken into account after patches were applied from static source code analysis. Markus Elfring (3): Deletion of an unnecessary check before the function call "cipso_v4_doi_putdef" Deletion of an unnecessary check before the function call "cipso_v4_doi_free" Less function calls in netlbl_mgmt_add_common() after error detection net/netlabel/netlabel_cipso_v4.c | 3 +-- net/netlabel/netlabel_mgmt.c | 47 ++++++++++++++++++++-------------------- 2 files changed, 24 insertions(+), 26 deletions(-) -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 31 Jan 2015 19:09:50 +0100 The cipso_v4_doi_putdef() 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/netlabel/netlabel_mgmt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/netlabel/netlabel_mgmt.c b/net/netlabel/netlabel_mgmt.c index 8b3b789..f5807f5 100644 --- a/net/netlabel/netlabel_mgmt.c +++ b/net/netlabel/netlabel_mgmt.c @@ -242,8 +242,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, return 0; add_failure: - if (cipsov4) - cipso_v4_doi_putdef(cipsov4); + cipso_v4_doi_putdef(cipsov4); if (entry) kfree(entry->domain); kfree(addrmap); -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 31 Jan 2015 19:35:59 +0100 The cipso_v4_doi_free() 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/netlabel/netlabel_cipso_v4.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/netlabel/netlabel_cipso_v4.c b/net/netlabel/netlabel_cipso_v4.c index 1796253..7fd1104 100644 --- a/net/netlabel/netlabel_cipso_v4.c +++ b/net/netlabel/netlabel_cipso_v4.c @@ -324,8 +324,7 @@ static int netlbl_cipsov4_add_std(struct genl_info *info, return 0; add_std_failure: - if (doi_def) - cipso_v4_doi_free(doi_def); + cipso_v4_doi_free(doi_def); return ret_val; } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 31 Jan 2015 21:55:48 +0100 The functions "cipso_v4_doi_putdef" and "kfree" could be called in some cases by the netlbl_mgmt_add_common() function during error handling even if the passed variables contained still a null pointer. * This implementation detail could be improved by adjustments for jump labels. * Let us return immediately after the first failed function call according to the current Linux coding style convention. * Let us delete also an unnecessary check for the variable "entry" there. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- net/netlabel/netlabel_mgmt.c | 46 ++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/net/netlabel/netlabel_mgmt.c b/net/netlabel/netlabel_mgmt.c index f5807f5..17f1ed5 100644 --- a/net/netlabel/netlabel_mgmt.c +++ b/net/netlabel/netlabel_mgmt.c @@ -99,17 +99,15 @@ static int netlbl_mgmt_add_common(struct genl_info *info, u32 tmp_val; entry = kzalloc(sizeof(*entry), GFP_KERNEL); - if (entry = NULL) { - ret_val = -ENOMEM; - goto add_failure; - } + if (!entry) + return -ENOMEM; entry->def.type = nla_get_u32(info->attrs[NLBL_MGMT_A_PROTOCOL]); if (info->attrs[NLBL_MGMT_A_DOMAIN]) { size_t tmp_size = nla_len(info->attrs[NLBL_MGMT_A_DOMAIN]); entry->domain = kmalloc(tmp_size, GFP_KERNEL); if (entry->domain = NULL) { ret_val = -ENOMEM; - goto add_failure; + goto free_entry; } nla_strlcpy(entry->domain, info->attrs[NLBL_MGMT_A_DOMAIN], tmp_size); @@ -125,16 +123,16 @@ static int netlbl_mgmt_add_common(struct genl_info *info, break; case NETLBL_NLTYPE_CIPSOV4: if (!info->attrs[NLBL_MGMT_A_CV4DOI]) - goto add_failure; + goto free_domain; tmp_val = nla_get_u32(info->attrs[NLBL_MGMT_A_CV4DOI]); cipsov4 = cipso_v4_doi_getdef(tmp_val); if (cipsov4 = NULL) - goto add_failure; + goto free_domain; entry->def.cipso = cipsov4; break; default: - goto add_failure; + goto free_domain; } if (info->attrs[NLBL_MGMT_A_IPV4ADDR]) { @@ -145,7 +143,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL); if (addrmap = NULL) { ret_val = -ENOMEM; - goto add_failure; + goto doi_put_def; } INIT_LIST_HEAD(&addrmap->list4); INIT_LIST_HEAD(&addrmap->list6); @@ -153,12 +151,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info, if (nla_len(info->attrs[NLBL_MGMT_A_IPV4ADDR]) ! sizeof(struct in_addr)) { ret_val = -EINVAL; - goto add_failure; + goto free_address_map; } if (nla_len(info->attrs[NLBL_MGMT_A_IPV4MASK]) ! sizeof(struct in_addr)) { ret_val = -EINVAL; - goto add_failure; + goto free_address_map; } addr = nla_data(info->attrs[NLBL_MGMT_A_IPV4ADDR]); mask = nla_data(info->attrs[NLBL_MGMT_A_IPV4MASK]); @@ -166,7 +164,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, map = kzalloc(sizeof(*map), GFP_KERNEL); if (map = NULL) { ret_val = -ENOMEM; - goto add_failure; + goto free_address_map; } map->list.addr = addr->s_addr & mask->s_addr; map->list.mask = mask->s_addr; @@ -178,7 +176,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, ret_val = netlbl_af4list_add(&map->list, &addrmap->list4); if (ret_val != 0) { kfree(map); - goto add_failure; + goto free_address_map; } entry->def.type = NETLBL_NLTYPE_ADDRSELECT; @@ -192,7 +190,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL); if (addrmap = NULL) { ret_val = -ENOMEM; - goto add_failure; + goto doi_put_def; } INIT_LIST_HEAD(&addrmap->list4); INIT_LIST_HEAD(&addrmap->list6); @@ -200,12 +198,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info, if (nla_len(info->attrs[NLBL_MGMT_A_IPV6ADDR]) ! sizeof(struct in6_addr)) { ret_val = -EINVAL; - goto add_failure; + goto free_address_map; } if (nla_len(info->attrs[NLBL_MGMT_A_IPV6MASK]) ! sizeof(struct in6_addr)) { ret_val = -EINVAL; - goto add_failure; + goto free_address_map; } addr = nla_data(info->attrs[NLBL_MGMT_A_IPV6ADDR]); mask = nla_data(info->attrs[NLBL_MGMT_A_IPV6MASK]); @@ -213,7 +211,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, map = kzalloc(sizeof(*map), GFP_KERNEL); if (map = NULL) { ret_val = -ENOMEM; - goto add_failure; + goto free_address_map; } map->list.addr = *addr; map->list.addr.s6_addr32[0] &= mask->s6_addr32[0]; @@ -227,7 +225,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, ret_val = netlbl_af6list_add(&map->list, &addrmap->list6); if (ret_val != 0) { kfree(map); - goto add_failure; + goto free_address_map; } entry->def.type = NETLBL_NLTYPE_ADDRSELECT; @@ -237,15 +235,17 @@ static int netlbl_mgmt_add_common(struct genl_info *info, ret_val = netlbl_domhsh_add(entry, audit_info); if (ret_val != 0) - goto add_failure; + goto free_address_map; return 0; -add_failure: - cipso_v4_doi_putdef(cipsov4); - if (entry) - kfree(entry->domain); +free_address_map: kfree(addrmap); +doi_put_def: + cipso_v4_doi_putdef(cipsov4); +free_domain: + kfree(entry->domain); +free_entry: kfree(entry); return ret_val; } -- 2.2.2
>> +exit:
>> return err;
>> }
>
> Why do you use that exit label if it does nothing more than returning
> the error value? Also if nla_parse fails you dont use it but return the
> error directly. While using a label which is used only to return an
> error may be a matter of taste, its at least inconsistent to do both in
> a function, use such a label in one case and return immediately in
> another, isnt it?
I find that all these cases correspond to the current Linux coding
style documentation, doesn't it?
Regards,
Markus
>> -errout:
>> - if (err && meta)
>> - meta_delete(meta);
>
> Since this patch seems to be about optimization and cleanup you should
> probably also remove the now unnecessary initialization of "meta" with
> NULL at the beginning of the function...
Will the optimiser of the C compiler drop any remaining unnecessary
variable initialisations?
Do you want another update step here?
Regards,
Markus
On 31.01.2015 22:52, SF Markus Elfring wrote: >>> -errout: >>> - if (err && meta) >>> - meta_delete(meta); >> >> Since this patch seems to be about optimization and cleanup you should >> probably also remove the now unnecessary initialization of "meta" with >> NULL at the beginning of the function... > > Will the optimiser of the C compiler drop any remaining unnecessary > variable initialisations? > I dont know if that matters, since the code is not only used by compilers but also read by humans. > Do you want another update step here? > I am not the one who decides if this patch is acceptable or not. But I vote for a removal of that assignment (as a part of the same patch). Regards, Lino
On 31.01.2015 22:48, SF Markus Elfring wrote:
>
> I find that all these cases correspond to the current Linux coding
> style documentation, doesn't it?
>
Sure, I think it does. But it was not coding style violation what I was
reffering to.
Regards,
Lino
>> I find that all these cases correspond to the current Linux coding >> style documentation, doesn't it? > > Sure, I think it does. Thanks for your acknowledgement. > But it was not coding style violation what I was reffering to. Do you suggest any fine-tuning for the affected documentation so that I would tweak my update suggestion once more? Regards, Markus
On 31.01.2015 23:20, SF Markus Elfring wrote:
>>> I find that all these cases correspond to the current Linux coding
>>> style documentation, doesn't it?
>>
>> Sure, I think it does.
>
> Thanks for your acknowledgement.
>
>
>> But it was not coding style violation what I was reffering to.
>
> Do you suggest any fine-tuning for the affected documentation
> so that I would tweak my update suggestion once more?
>
No I dont think that any documentation has to be adjusted. If you agree
with me you should adjust the patch accordingly and resend it. Otherwise
keep it as it is.
Regards,
Lino
On Sat, Jan 31, 2015 at 4:34 PM, SF Markus Elfring <elfring@users.sourceforge.net> wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sat, 31 Jan 2015 19:09:50 +0100 > > The cipso_v4_doi_putdef() 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/netlabel/netlabel_mgmt.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) Acked-by: Paul Moore <paul@paul-moore.com> > diff --git a/net/netlabel/netlabel_mgmt.c b/net/netlabel/netlabel_mgmt.c > index 8b3b789..f5807f5 100644 > --- a/net/netlabel/netlabel_mgmt.c > +++ b/net/netlabel/netlabel_mgmt.c > @@ -242,8 +242,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, > return 0; > > add_failure: > - if (cipsov4) > - cipso_v4_doi_putdef(cipsov4); > + cipso_v4_doi_putdef(cipsov4); > if (entry) > kfree(entry->domain); > kfree(addrmap); > -- > 2.2.2 > -- paul moore www.paul-moore.com
On Sat, Jan 31, 2015 at 4:36 PM, SF Markus Elfring <elfring@users.sourceforge.net> wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sat, 31 Jan 2015 19:35:59 +0100 > > The cipso_v4_doi_free() 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/netlabel/netlabel_cipso_v4.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) Acked-by: Paul Moore <paul@paul-moore.com> > diff --git a/net/netlabel/netlabel_cipso_v4.c b/net/netlabel/netlabel_cipso_v4.c > index 1796253..7fd1104 100644 > --- a/net/netlabel/netlabel_cipso_v4.c > +++ b/net/netlabel/netlabel_cipso_v4.c > @@ -324,8 +324,7 @@ static int netlbl_cipsov4_add_std(struct genl_info *info, > return 0; > > add_std_failure: > - if (doi_def) > - cipso_v4_doi_free(doi_def); > + cipso_v4_doi_free(doi_def); > return ret_val; > } > > -- > 2.2.2 > -- paul moore www.paul-moore.com
On Sat, Jan 31, 2015 at 4:38 PM, SF Markus Elfring <elfring@users.sourceforge.net> wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sat, 31 Jan 2015 21:55:48 +0100 > > The functions "cipso_v4_doi_putdef" and "kfree" could be called in some cases > by the netlbl_mgmt_add_common() function during error handling even if the > passed variables contained still a null pointer. > > * This implementation detail could be improved by adjustments for jump labels. > > * Let us return immediately after the first failed function call according to > the current Linux coding style convention. > > * Let us delete also an unnecessary check for the variable "entry" there. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > net/netlabel/netlabel_mgmt.c | 46 ++++++++++++++++++++++---------------------- > 1 file changed, 23 insertions(+), 23 deletions(-) > > diff --git a/net/netlabel/netlabel_mgmt.c b/net/netlabel/netlabel_mgmt.c > index f5807f5..17f1ed5 100644 > --- a/net/netlabel/netlabel_mgmt.c > +++ b/net/netlabel/netlabel_mgmt.c ... > @@ -237,15 +235,17 @@ static int netlbl_mgmt_add_common(struct genl_info *info, > > ret_val = netlbl_domhsh_add(entry, audit_info); > if (ret_val != 0) > - goto add_failure; > + goto free_address_map; > > return 0; > > -add_failure: > - cipso_v4_doi_putdef(cipsov4); > - if (entry) > - kfree(entry->domain); > +free_address_map: > kfree(addrmap); > +doi_put_def: > + cipso_v4_doi_putdef(cipsov4); > +free_domain: > + kfree(entry->domain); > +free_entry: > kfree(entry); > return ret_val; > } It would be nice if you could stick with the goto label naming style in the rest of the file, e.g. "add_free_addrmap"/"add_put_doi_def"/"add_free_domain"/"add_free_entry". -- paul moore www.paul-moore.com
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 1 Feb 2015 11:11:29 +0100 The functions "cipso_v4_doi_putdef" and "kfree" could be called in some cases by the netlbl_mgmt_add_common() function during error handling even if the passed variables contained still a null pointer. * This implementation detail could be improved by adjustments for jump labels. * Let us return immediately after the first failed function call according to the current Linux coding style convention. * Let us delete also an unnecessary check for the variable "entry" there. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- net/netlabel/netlabel_mgmt.c | 49 ++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/net/netlabel/netlabel_mgmt.c b/net/netlabel/netlabel_mgmt.c index f5807f5..7044074 100644 --- a/net/netlabel/netlabel_mgmt.c +++ b/net/netlabel/netlabel_mgmt.c @@ -93,23 +93,20 @@ static int netlbl_mgmt_add_common(struct genl_info *info, struct netlbl_audit *audit_info) { int ret_val = -EINVAL; - struct netlbl_dom_map *entry = NULL; struct netlbl_domaddr_map *addrmap = NULL; struct cipso_v4_doi *cipsov4 = NULL; u32 tmp_val; + struct netlbl_dom_map *entry = kzalloc(sizeof(*entry), GFP_KERNEL); - entry = kzalloc(sizeof(*entry), GFP_KERNEL); - if (entry = NULL) { - ret_val = -ENOMEM; - goto add_failure; - } + if (!entry) + return -ENOMEM; entry->def.type = nla_get_u32(info->attrs[NLBL_MGMT_A_PROTOCOL]); if (info->attrs[NLBL_MGMT_A_DOMAIN]) { size_t tmp_size = nla_len(info->attrs[NLBL_MGMT_A_DOMAIN]); entry->domain = kmalloc(tmp_size, GFP_KERNEL); if (entry->domain = NULL) { ret_val = -ENOMEM; - goto add_failure; + goto add_free_entry; } nla_strlcpy(entry->domain, info->attrs[NLBL_MGMT_A_DOMAIN], tmp_size); @@ -125,16 +122,16 @@ static int netlbl_mgmt_add_common(struct genl_info *info, break; case NETLBL_NLTYPE_CIPSOV4: if (!info->attrs[NLBL_MGMT_A_CV4DOI]) - goto add_failure; + goto add_free_domain; tmp_val = nla_get_u32(info->attrs[NLBL_MGMT_A_CV4DOI]); cipsov4 = cipso_v4_doi_getdef(tmp_val); if (cipsov4 = NULL) - goto add_failure; + goto add_free_domain; entry->def.cipso = cipsov4; break; default: - goto add_failure; + goto add_free_domain; } if (info->attrs[NLBL_MGMT_A_IPV4ADDR]) { @@ -145,7 +142,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL); if (addrmap = NULL) { ret_val = -ENOMEM; - goto add_failure; + goto add_doi_put_def; } INIT_LIST_HEAD(&addrmap->list4); INIT_LIST_HEAD(&addrmap->list6); @@ -153,12 +150,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info, if (nla_len(info->attrs[NLBL_MGMT_A_IPV4ADDR]) ! sizeof(struct in_addr)) { ret_val = -EINVAL; - goto add_failure; + goto add_free_addrmap; } if (nla_len(info->attrs[NLBL_MGMT_A_IPV4MASK]) ! sizeof(struct in_addr)) { ret_val = -EINVAL; - goto add_failure; + goto add_free_addrmap; } addr = nla_data(info->attrs[NLBL_MGMT_A_IPV4ADDR]); mask = nla_data(info->attrs[NLBL_MGMT_A_IPV4MASK]); @@ -166,7 +163,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, map = kzalloc(sizeof(*map), GFP_KERNEL); if (map = NULL) { ret_val = -ENOMEM; - goto add_failure; + goto add_free_addrmap; } map->list.addr = addr->s_addr & mask->s_addr; map->list.mask = mask->s_addr; @@ -178,7 +175,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, ret_val = netlbl_af4list_add(&map->list, &addrmap->list4); if (ret_val != 0) { kfree(map); - goto add_failure; + goto add_free_addrmap; } entry->def.type = NETLBL_NLTYPE_ADDRSELECT; @@ -192,7 +189,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL); if (addrmap = NULL) { ret_val = -ENOMEM; - goto add_failure; + goto add_doi_put_def; } INIT_LIST_HEAD(&addrmap->list4); INIT_LIST_HEAD(&addrmap->list6); @@ -200,12 +197,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info, if (nla_len(info->attrs[NLBL_MGMT_A_IPV6ADDR]) ! sizeof(struct in6_addr)) { ret_val = -EINVAL; - goto add_failure; + goto add_free_addrmap; } if (nla_len(info->attrs[NLBL_MGMT_A_IPV6MASK]) ! sizeof(struct in6_addr)) { ret_val = -EINVAL; - goto add_failure; + goto add_free_addrmap; } addr = nla_data(info->attrs[NLBL_MGMT_A_IPV6ADDR]); mask = nla_data(info->attrs[NLBL_MGMT_A_IPV6MASK]); @@ -213,7 +210,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, map = kzalloc(sizeof(*map), GFP_KERNEL); if (map = NULL) { ret_val = -ENOMEM; - goto add_failure; + goto add_free_addrmap; } map->list.addr = *addr; map->list.addr.s6_addr32[0] &= mask->s6_addr32[0]; @@ -227,7 +224,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, ret_val = netlbl_af6list_add(&map->list, &addrmap->list6); if (ret_val != 0) { kfree(map); - goto add_failure; + goto add_free_addrmap; } entry->def.type = NETLBL_NLTYPE_ADDRSELECT; @@ -237,15 +234,17 @@ static int netlbl_mgmt_add_common(struct genl_info *info, ret_val = netlbl_domhsh_add(entry, audit_info); if (ret_val != 0) - goto add_failure; + goto add_free_addrmap; return 0; -add_failure: - cipso_v4_doi_putdef(cipsov4); - if (entry) - kfree(entry->domain); +add_free_addrmap: kfree(addrmap); +add_doi_put_def: + cipso_v4_doi_putdef(cipsov4); +add_free_domain: + kfree(entry->domain); +add_free_entry: kfree(entry); return ret_val; } -- 2.2.2
On Sun, Feb 1, 2015 at 5:15 AM, SF Markus Elfring <elfring@users.sourceforge.net> wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sun, 1 Feb 2015 11:11:29 +0100 > > The functions "cipso_v4_doi_putdef" and "kfree" could be called in some cases > by the netlbl_mgmt_add_common() function during error handling even if the > passed variables contained still a null pointer. > > * This implementation detail could be improved by adjustments for jump labels. > > * Let us return immediately after the first failed function call according to > the current Linux coding style convention. > > * Let us delete also an unnecessary check for the variable "entry" there. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > net/netlabel/netlabel_mgmt.c | 49 ++++++++++++++++++++++---------------------- > 1 file changed, 24 insertions(+), 25 deletions(-) Thanks for fixing the label names. Acked-by: Paul Moore <paul@paul-moore.com> > diff --git a/net/netlabel/netlabel_mgmt.c b/net/netlabel/netlabel_mgmt.c > index f5807f5..7044074 100644 > --- a/net/netlabel/netlabel_mgmt.c > +++ b/net/netlabel/netlabel_mgmt.c > @@ -93,23 +93,20 @@ static int netlbl_mgmt_add_common(struct genl_info *info, > struct netlbl_audit *audit_info) > { > int ret_val = -EINVAL; > - struct netlbl_dom_map *entry = NULL; > struct netlbl_domaddr_map *addrmap = NULL; > struct cipso_v4_doi *cipsov4 = NULL; > u32 tmp_val; > + struct netlbl_dom_map *entry = kzalloc(sizeof(*entry), GFP_KERNEL); > > - entry = kzalloc(sizeof(*entry), GFP_KERNEL); > - if (entry = NULL) { > - ret_val = -ENOMEM; > - goto add_failure; > - } > + if (!entry) > + return -ENOMEM; > entry->def.type = nla_get_u32(info->attrs[NLBL_MGMT_A_PROTOCOL]); > if (info->attrs[NLBL_MGMT_A_DOMAIN]) { > size_t tmp_size = nla_len(info->attrs[NLBL_MGMT_A_DOMAIN]); > entry->domain = kmalloc(tmp_size, GFP_KERNEL); > if (entry->domain = NULL) { > ret_val = -ENOMEM; > - goto add_failure; > + goto add_free_entry; > } > nla_strlcpy(entry->domain, > info->attrs[NLBL_MGMT_A_DOMAIN], tmp_size); > @@ -125,16 +122,16 @@ static int netlbl_mgmt_add_common(struct genl_info *info, > break; > case NETLBL_NLTYPE_CIPSOV4: > if (!info->attrs[NLBL_MGMT_A_CV4DOI]) > - goto add_failure; > + goto add_free_domain; > > tmp_val = nla_get_u32(info->attrs[NLBL_MGMT_A_CV4DOI]); > cipsov4 = cipso_v4_doi_getdef(tmp_val); > if (cipsov4 = NULL) > - goto add_failure; > + goto add_free_domain; > entry->def.cipso = cipsov4; > break; > default: > - goto add_failure; > + goto add_free_domain; > } > > if (info->attrs[NLBL_MGMT_A_IPV4ADDR]) { > @@ -145,7 +142,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, > addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL); > if (addrmap = NULL) { > ret_val = -ENOMEM; > - goto add_failure; > + goto add_doi_put_def; > } > INIT_LIST_HEAD(&addrmap->list4); > INIT_LIST_HEAD(&addrmap->list6); > @@ -153,12 +150,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info, > if (nla_len(info->attrs[NLBL_MGMT_A_IPV4ADDR]) !> sizeof(struct in_addr)) { > ret_val = -EINVAL; > - goto add_failure; > + goto add_free_addrmap; > } > if (nla_len(info->attrs[NLBL_MGMT_A_IPV4MASK]) !> sizeof(struct in_addr)) { > ret_val = -EINVAL; > - goto add_failure; > + goto add_free_addrmap; > } > addr = nla_data(info->attrs[NLBL_MGMT_A_IPV4ADDR]); > mask = nla_data(info->attrs[NLBL_MGMT_A_IPV4MASK]); > @@ -166,7 +163,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, > map = kzalloc(sizeof(*map), GFP_KERNEL); > if (map = NULL) { > ret_val = -ENOMEM; > - goto add_failure; > + goto add_free_addrmap; > } > map->list.addr = addr->s_addr & mask->s_addr; > map->list.mask = mask->s_addr; > @@ -178,7 +175,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, > ret_val = netlbl_af4list_add(&map->list, &addrmap->list4); > if (ret_val != 0) { > kfree(map); > - goto add_failure; > + goto add_free_addrmap; > } > > entry->def.type = NETLBL_NLTYPE_ADDRSELECT; > @@ -192,7 +189,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, > addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL); > if (addrmap = NULL) { > ret_val = -ENOMEM; > - goto add_failure; > + goto add_doi_put_def; > } > INIT_LIST_HEAD(&addrmap->list4); > INIT_LIST_HEAD(&addrmap->list6); > @@ -200,12 +197,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info, > if (nla_len(info->attrs[NLBL_MGMT_A_IPV6ADDR]) !> sizeof(struct in6_addr)) { > ret_val = -EINVAL; > - goto add_failure; > + goto add_free_addrmap; > } > if (nla_len(info->attrs[NLBL_MGMT_A_IPV6MASK]) !> sizeof(struct in6_addr)) { > ret_val = -EINVAL; > - goto add_failure; > + goto add_free_addrmap; > } > addr = nla_data(info->attrs[NLBL_MGMT_A_IPV6ADDR]); > mask = nla_data(info->attrs[NLBL_MGMT_A_IPV6MASK]); > @@ -213,7 +210,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, > map = kzalloc(sizeof(*map), GFP_KERNEL); > if (map = NULL) { > ret_val = -ENOMEM; > - goto add_failure; > + goto add_free_addrmap; > } > map->list.addr = *addr; > map->list.addr.s6_addr32[0] &= mask->s6_addr32[0]; > @@ -227,7 +224,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, > ret_val = netlbl_af6list_add(&map->list, &addrmap->list6); > if (ret_val != 0) { > kfree(map); > - goto add_failure; > + goto add_free_addrmap; > } > > entry->def.type = NETLBL_NLTYPE_ADDRSELECT; > @@ -237,15 +234,17 @@ static int netlbl_mgmt_add_common(struct genl_info *info, > > ret_val = netlbl_domhsh_add(entry, audit_info); > if (ret_val != 0) > - goto add_failure; > + goto add_free_addrmap; > > return 0; > > -add_failure: > - cipso_v4_doi_putdef(cipsov4); > - if (entry) > - kfree(entry->domain); > +add_free_addrmap: > kfree(addrmap); > +add_doi_put_def: > + cipso_v4_doi_putdef(cipsov4); > +add_free_domain: > + kfree(entry->domain); > +add_free_entry: > kfree(entry); > return ret_val; > } > -- > 2.2.2 > -- paul moore www.paul-moore.com
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 1 Feb 2015 17:00:24 +0100 The unload_nls() 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/jfs/super.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/jfs/super.c b/fs/jfs/super.c index 16c3a95..5d30c56 100644 --- a/fs/jfs/super.c +++ b/fs/jfs/super.c @@ -619,8 +619,7 @@ out_mount_failed: iput(sbi->direct_inode); sbi->direct_inode = NULL; out_unload: - if (sbi->nls_tab) - unload_nls(sbi->nls_tab); + unload_nls(sbi->nls_tab); out_kfree: kfree(sbi); return ret; -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 1 Feb 2015 18:28:33 +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> --- drivers/staging/gdm72xx/gdm_wimax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/staging/gdm72xx/gdm_wimax.c b/drivers/staging/gdm72xx/gdm_wimax.c index 9cab54b..ac901e6 100644 --- a/drivers/staging/gdm72xx/gdm_wimax.c +++ b/drivers/staging/gdm72xx/gdm_wimax.c @@ -362,7 +362,7 @@ static int gdm_wimax_close(struct net_device *dev) static void kdelete(void **buf) { - if (buf && *buf) { + if (buf) { kfree(*buf); *buf = NULL; } -- 2.2.2
On Sun, Feb 01, 2015 at 06:42:53PM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sun, 1 Feb 2015 18:28:33 +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>
> ---
> drivers/staging/gdm72xx/gdm_wimax.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/staging/gdm72xx/gdm_wimax.c b/drivers/staging/gdm72xx/gdm_wimax.c
> index 9cab54b..ac901e6 100644
> --- a/drivers/staging/gdm72xx/gdm_wimax.c
> +++ b/drivers/staging/gdm72xx/gdm_wimax.c
> @@ -362,7 +362,7 @@ static int gdm_wimax_close(struct net_device *dev)
>
> static void kdelete(void **buf)
> {
> - if (buf && *buf) {
> + if (buf) {
> kfree(*buf);
> *buf = NULL;
> }
Instead we should delete this function and have the driver use the
"correct" kfree calls instead, right? That extra setting the buffer to
NULL is a waste for most of these calls.
thanks,
greg k-h
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 1 Feb 2015 20:00:17 +0100 Another update suggestion was taken into account after a patch was applied from static source code analysis. Markus Elfring (2): Deletion of an unnecessary check before the function call "release_firmware" One function call less in mn88472_init() after error detection drivers/staging/media/mn88472/mn88472.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 1 Feb 2015 19:12:56 +0100 The release_firmware() 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/staging/media/mn88472/mn88472.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/staging/media/mn88472/mn88472.c b/drivers/staging/media/mn88472/mn88472.c index 52de8f8..e7874ae 100644 --- a/drivers/staging/media/mn88472/mn88472.c +++ b/drivers/staging/media/mn88472/mn88472.c @@ -315,8 +315,7 @@ static int mn88472_init(struct dvb_frontend *fe) return 0; err: - if (fw) - release_firmware(fw); + release_firmware(fw); dev_dbg(&client->dev, "failed=%d\n", ret); return ret; -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 1 Feb 2015 19:34:37 +0100 The release_firmware() function was called in three cases by the mn88472_init() function during error handling even if the passed variable "fw" 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> --- drivers/staging/media/mn88472/mn88472.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/staging/media/mn88472/mn88472.c b/drivers/staging/media/mn88472/mn88472.c index e7874ae..3975a57 100644 --- a/drivers/staging/media/mn88472/mn88472.c +++ b/drivers/staging/media/mn88472/mn88472.c @@ -286,7 +286,7 @@ static int mn88472_init(struct dvb_frontend *fe) ret = regmap_write(dev->regmap[0], 0xf5, 0x03); if (ret) - goto err; + goto firmware_release; for (remaining = fw->size; remaining > 0; remaining -= (dev->i2c_wr_max - 1)) { @@ -299,13 +299,13 @@ static int mn88472_init(struct dvb_frontend *fe) if (ret) { dev_err(&client->dev, "firmware download failed=%d\n", ret); - goto err; + goto firmware_release; } } ret = regmap_write(dev->regmap[0], 0xf5, 0x00); if (ret) - goto err; + goto firmware_release; release_firmware(fw); fw = NULL; @@ -314,9 +314,9 @@ static int mn88472_init(struct dvb_frontend *fe) dev->warm = true; return 0; -err: +firmware_release: release_firmware(fw); - +err: dev_dbg(&client->dev, "failed=%d\n", ret); return ret; } -- 2.2.2
When you post a new version of a patch within a series, you must repost the entire series, not just the patch which is changing. Thanks.
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 2 Feb 2015 11:15:56 +0100 Further update suggestions were taken into account after patches were applied from static source code analysis. Markus Elfring (3): Deletion of an unnecessary check before the function call "cipso_v4_doi_putdef" Deletion of an unnecessary check before the function call "cipso_v4_doi_free" Less function calls in netlbl_mgmt_add_common() after error detection net/netlabel/netlabel_cipso_v4.c | 3 +-- net/netlabel/netlabel_mgmt.c | 50 +++++++++++++++++++--------------------- 2 files changed, 25 insertions(+), 28 deletions(-) -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 2 Feb 2015 10:01:45 +0100 The cipso_v4_doi_putdef() 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 Moore <paul@paul-moore.com> --- net/netlabel/netlabel_mgmt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/netlabel/netlabel_mgmt.c b/net/netlabel/netlabel_mgmt.c index 8b3b789..f5807f5 100644 --- a/net/netlabel/netlabel_mgmt.c +++ b/net/netlabel/netlabel_mgmt.c @@ -242,8 +242,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, return 0; add_failure: - if (cipsov4) - cipso_v4_doi_putdef(cipsov4); + cipso_v4_doi_putdef(cipsov4); if (entry) kfree(entry->domain); kfree(addrmap); -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 2 Feb 2015 10:40:30 +0100 The cipso_v4_doi_free() 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 Moore <paul@paul-moore.com> --- net/netlabel/netlabel_cipso_v4.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/netlabel/netlabel_cipso_v4.c b/net/netlabel/netlabel_cipso_v4.c index 1796253..7fd1104 100644 --- a/net/netlabel/netlabel_cipso_v4.c +++ b/net/netlabel/netlabel_cipso_v4.c @@ -324,8 +324,7 @@ static int netlbl_cipsov4_add_std(struct genl_info *info, return 0; add_std_failure: - if (doi_def) - cipso_v4_doi_free(doi_def); + cipso_v4_doi_free(doi_def); return ret_val; } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 2 Feb 2015 11:00:24 +0100 The functions "cipso_v4_doi_putdef" and "kfree" could be called in some cases by the netlbl_mgmt_add_common() function during error handling even if the passed variables contained still a null pointer. * This implementation detail could be improved by adjustments for jump labels. * Let us return immediately after the first failed function call according to the current Linux coding style convention. * Let us delete also an unnecessary check for the variable "entry" there. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> Acked-by: Paul Moore <paul@paul-moore.com> --- net/netlabel/netlabel_mgmt.c | 49 ++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/net/netlabel/netlabel_mgmt.c b/net/netlabel/netlabel_mgmt.c index f5807f5..7044074 100644 --- a/net/netlabel/netlabel_mgmt.c +++ b/net/netlabel/netlabel_mgmt.c @@ -93,23 +93,20 @@ static int netlbl_mgmt_add_common(struct genl_info *info, struct netlbl_audit *audit_info) { int ret_val = -EINVAL; - struct netlbl_dom_map *entry = NULL; struct netlbl_domaddr_map *addrmap = NULL; struct cipso_v4_doi *cipsov4 = NULL; u32 tmp_val; + struct netlbl_dom_map *entry = kzalloc(sizeof(*entry), GFP_KERNEL); - entry = kzalloc(sizeof(*entry), GFP_KERNEL); - if (entry = NULL) { - ret_val = -ENOMEM; - goto add_failure; - } + if (!entry) + return -ENOMEM; entry->def.type = nla_get_u32(info->attrs[NLBL_MGMT_A_PROTOCOL]); if (info->attrs[NLBL_MGMT_A_DOMAIN]) { size_t tmp_size = nla_len(info->attrs[NLBL_MGMT_A_DOMAIN]); entry->domain = kmalloc(tmp_size, GFP_KERNEL); if (entry->domain = NULL) { ret_val = -ENOMEM; - goto add_failure; + goto add_free_entry; } nla_strlcpy(entry->domain, info->attrs[NLBL_MGMT_A_DOMAIN], tmp_size); @@ -125,16 +122,16 @@ static int netlbl_mgmt_add_common(struct genl_info *info, break; case NETLBL_NLTYPE_CIPSOV4: if (!info->attrs[NLBL_MGMT_A_CV4DOI]) - goto add_failure; + goto add_free_domain; tmp_val = nla_get_u32(info->attrs[NLBL_MGMT_A_CV4DOI]); cipsov4 = cipso_v4_doi_getdef(tmp_val); if (cipsov4 = NULL) - goto add_failure; + goto add_free_domain; entry->def.cipso = cipsov4; break; default: - goto add_failure; + goto add_free_domain; } if (info->attrs[NLBL_MGMT_A_IPV4ADDR]) { @@ -145,7 +142,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL); if (addrmap = NULL) { ret_val = -ENOMEM; - goto add_failure; + goto add_doi_put_def; } INIT_LIST_HEAD(&addrmap->list4); INIT_LIST_HEAD(&addrmap->list6); @@ -153,12 +150,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info, if (nla_len(info->attrs[NLBL_MGMT_A_IPV4ADDR]) ! sizeof(struct in_addr)) { ret_val = -EINVAL; - goto add_failure; + goto add_free_addrmap; } if (nla_len(info->attrs[NLBL_MGMT_A_IPV4MASK]) ! sizeof(struct in_addr)) { ret_val = -EINVAL; - goto add_failure; + goto add_free_addrmap; } addr = nla_data(info->attrs[NLBL_MGMT_A_IPV4ADDR]); mask = nla_data(info->attrs[NLBL_MGMT_A_IPV4MASK]); @@ -166,7 +163,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, map = kzalloc(sizeof(*map), GFP_KERNEL); if (map = NULL) { ret_val = -ENOMEM; - goto add_failure; + goto add_free_addrmap; } map->list.addr = addr->s_addr & mask->s_addr; map->list.mask = mask->s_addr; @@ -178,7 +175,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, ret_val = netlbl_af4list_add(&map->list, &addrmap->list4); if (ret_val != 0) { kfree(map); - goto add_failure; + goto add_free_addrmap; } entry->def.type = NETLBL_NLTYPE_ADDRSELECT; @@ -192,7 +189,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL); if (addrmap = NULL) { ret_val = -ENOMEM; - goto add_failure; + goto add_doi_put_def; } INIT_LIST_HEAD(&addrmap->list4); INIT_LIST_HEAD(&addrmap->list6); @@ -200,12 +197,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info, if (nla_len(info->attrs[NLBL_MGMT_A_IPV6ADDR]) ! sizeof(struct in6_addr)) { ret_val = -EINVAL; - goto add_failure; + goto add_free_addrmap; } if (nla_len(info->attrs[NLBL_MGMT_A_IPV6MASK]) ! sizeof(struct in6_addr)) { ret_val = -EINVAL; - goto add_failure; + goto add_free_addrmap; } addr = nla_data(info->attrs[NLBL_MGMT_A_IPV6ADDR]); mask = nla_data(info->attrs[NLBL_MGMT_A_IPV6MASK]); @@ -213,7 +210,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, map = kzalloc(sizeof(*map), GFP_KERNEL); if (map = NULL) { ret_val = -ENOMEM; - goto add_failure; + goto add_free_addrmap; } map->list.addr = *addr; map->list.addr.s6_addr32[0] &= mask->s6_addr32[0]; @@ -227,7 +224,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, ret_val = netlbl_af6list_add(&map->list, &addrmap->list6); if (ret_val != 0) { kfree(map); - goto add_failure; + goto add_free_addrmap; } entry->def.type = NETLBL_NLTYPE_ADDRSELECT; @@ -237,15 +234,17 @@ static int netlbl_mgmt_add_common(struct genl_info *info, ret_val = netlbl_domhsh_add(entry, audit_info); if (ret_val != 0) - goto add_failure; + goto add_free_addrmap; return 0; -add_failure: - cipso_v4_doi_putdef(cipsov4); - if (entry) - kfree(entry->domain); +add_free_addrmap: kfree(addrmap); +add_doi_put_def: + cipso_v4_doi_putdef(cipsov4); +add_free_domain: + kfree(entry->domain); +add_free_entry: kfree(entry); return ret_val; } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 2 Feb 2015 13:20:23 +0100 The video_unregister_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/staging/media/bcm2048/radio-bcm2048.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/staging/media/bcm2048/radio-bcm2048.c b/drivers/staging/media/bcm2048/radio-bcm2048.c index 60a57b2..f308078 100644 --- a/drivers/staging/media/bcm2048/radio-bcm2048.c +++ b/drivers/staging/media/bcm2048/radio-bcm2048.c @@ -2684,9 +2684,7 @@ static int __exit bcm2048_i2c_driver_remove(struct i2c_client *client) vd = bdev->videodev; bcm2048_sysfs_unregister_properties(bdev, ARRAY_SIZE(attrs)); - - if (vd) - video_unregister_device(vd); + video_unregister_device(vd); if (bdev->power_state) bcm2048_set_power_state(bdev, BCM2048_POWER_OFF); -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 2 Feb 2015 15:51:43 +0100 Further update suggestions were taken into account together with results from static source code analysis. Markus Elfring (3): dm snapshot: Deletion of unnecessary checks before the function call "vfree" md/bitmap: Delete an unnecessary check before the function call "kfree" dm ioctl: Delete an unnecessary check before the function call "dm_table_destroy" drivers/md/bitmap.c | 10 +++++----- drivers/md/dm-ioctl.c | 3 +-- drivers/md/dm-snap-persistent.c | 14 ++++---------- 3 files changed, 10 insertions(+), 17 deletions(-) -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 2 Feb 2015 14:38:29 +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/md/dm-snap-persistent.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/md/dm-snap-persistent.c b/drivers/md/dm-snap-persistent.c index d6e8817..808b841 100644 --- a/drivers/md/dm-snap-persistent.c +++ b/drivers/md/dm-snap-persistent.c @@ -200,16 +200,11 @@ err_area: static void free_area(struct pstore *ps) { - if (ps->area) - vfree(ps->area); + vfree(ps->area); ps->area = NULL; - - if (ps->zero_area) - vfree(ps->zero_area); + vfree(ps->zero_area); ps->zero_area = NULL; - - if (ps->header_area) - vfree(ps->header_area); + vfree(ps->header_area); ps->header_area = NULL; } @@ -605,8 +600,7 @@ static void persistent_dtr(struct dm_exception_store *store) free_area(ps); /* Allocated in persistent_read_metadata */ - if (ps->callbacks) - vfree(ps->callbacks); + vfree(ps->callbacks); kfree(ps); } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 2 Feb 2015 15:10:57 +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. * Let us also move an assignment for the variable "pages" to the place directly before it is really needed for a loop. * Let us also move another kfree() call into a block which should belong to a previous check for the variable "bp". Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/md/bitmap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c index da3604e..47d72df 100644 --- a/drivers/md/bitmap.c +++ b/drivers/md/bitmap.c @@ -1586,15 +1586,15 @@ static void bitmap_free(struct bitmap *bitmap) bitmap_file_unmap(&bitmap->storage); bp = bitmap->counts.bp; - pages = bitmap->counts.pages; /* free all allocated memory */ - - if (bp) /* deallocate the page memory */ + if (bp) { /* deallocate the page memory */ + pages = bitmap->counts.pages; for (k = 0; k < pages; k++) - if (bp[k].map && !bp[k].hijacked) + if (!bp[k].hijacked) kfree(bp[k].map); - kfree(bp); + kfree(bp); + } kfree(bitmap); } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 2 Feb 2015 15:30:37 +0100 The dm_table_destroy() 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/md/dm-ioctl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c index 73f791b..4fac6cf 100644 --- a/drivers/md/dm-ioctl.c +++ b/drivers/md/dm-ioctl.c @@ -1053,8 +1053,7 @@ static int do_resume(struct dm_ioctl *param) * Since dm_swap_table synchronizes RCU, nobody should be in * read-side critical section already. */ - if (old_map) - dm_table_destroy(old_map); + dm_table_destroy(old_map); if (!r) __dev_status(md, param); -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 2 Feb 2015 18:26:34 +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> --- drivers/edac/i82443bxgx_edac.c | 4 +--- drivers/edac/i82860_edac.c | 9 ++------- drivers/edac/i82875p_edac.c | 4 +--- drivers/edac/i82975x_edac.c | 4 +--- 4 files changed, 5 insertions(+), 16 deletions(-) diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c index b4705d9..38d6406 100644 --- a/drivers/edac/i82443bxgx_edac.c +++ b/drivers/edac/i82443bxgx_edac.c @@ -445,9 +445,7 @@ fail1: pci_unregister_driver(&i82443bxgx_edacmc_driver); fail0: - if (mci_pdev != NULL) - pci_dev_put(mci_pdev); - + pci_dev_put(mci_pdev); return pci_rc; } diff --git a/drivers/edac/i82860_edac.c b/drivers/edac/i82860_edac.c index 4382343..ee1078c 100644 --- a/drivers/edac/i82860_edac.c +++ b/drivers/edac/i82860_edac.c @@ -343,20 +343,15 @@ fail1: pci_unregister_driver(&i82860_driver); fail0: - if (mci_pdev != NULL) - pci_dev_put(mci_pdev); - + pci_dev_put(mci_pdev); return pci_rc; } static void __exit i82860_exit(void) { edac_dbg(3, "\n"); - pci_unregister_driver(&i82860_driver); - - if (mci_pdev != NULL) - pci_dev_put(mci_pdev); + pci_dev_put(mci_pdev); } module_init(i82860_init); diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c index 64b6832..c26a513 100644 --- a/drivers/edac/i82875p_edac.c +++ b/drivers/edac/i82875p_edac.c @@ -576,9 +576,7 @@ fail1: pci_unregister_driver(&i82875p_driver); fail0: - if (mci_pdev != NULL) - pci_dev_put(mci_pdev); - + pci_dev_put(mci_pdev); return pci_rc; } diff --git a/drivers/edac/i82975x_edac.c b/drivers/edac/i82975x_edac.c index 10b1052..35ab66c 100644 --- a/drivers/edac/i82975x_edac.c +++ b/drivers/edac/i82975x_edac.c @@ -685,9 +685,7 @@ fail1: pci_unregister_driver(&i82975x_driver); fail0: - if (mci_pdev != NULL) - pci_dev_put(mci_pdev); - + pci_dev_put(mci_pdev); return pci_rc; } -- 2.2.2
[-- Attachment #1: Type: text/plain, Size: 2388 bytes --] On Mon, 02 Feb 2015 16:20:42 +0100 SF Markus Elfring <elfring@users.sourceforge.net> wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Mon, 2 Feb 2015 15:10:57 +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. > > * Let us also move an assignment for the variable "pages" to the place > directly before it is really needed for a loop. > > * Let us also move another kfree() call into a block which should belong > to a previous check for the variable "bp". > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > drivers/md/bitmap.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c > index da3604e..47d72df 100644 > --- a/drivers/md/bitmap.c > +++ b/drivers/md/bitmap.c > @@ -1586,15 +1586,15 @@ static void bitmap_free(struct bitmap *bitmap) > bitmap_file_unmap(&bitmap->storage); > > bp = bitmap->counts.bp; > - pages = bitmap->counts.pages; > > /* free all allocated memory */ > - > - if (bp) /* deallocate the page memory */ > + if (bp) { /* deallocate the page memory */ > + pages = bitmap->counts.pages; > for (k = 0; k < pages; k++) > - if (bp[k].map && !bp[k].hijacked) > + if (!bp[k].hijacked) > kfree(bp[k].map); > - kfree(bp); > + kfree(bp); > + } > kfree(bitmap); > } > Hi, I'm somewhat amused that you removed a test for one kfree, but imposed a test on another. I realised the second test was already there, but why not just: diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c index da3604e73e8a..ad13b2e1bf1f 100644 --- a/drivers/md/bitmap.c +++ b/drivers/md/bitmap.c @@ -1592,7 +1592,7 @@ static void bitmap_free(struct bitmap *bitmap) if (bp) /* deallocate the page memory */ for (k = 0; k < pages; k++) - if (bp[k].map && !bp[k].hijacked) + if (!bp[k].hijacked) kfree(bp[k].map); kfree(bp); kfree(bitmap); It makes the intention of the patch much clearer. I'd probably prefer to leave the code as it is. I don't think either patch is really an improvement in readability, and readability trumps performance in places like this. Thanks, NeilBrown [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 811 bytes --]
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 2 Feb 2015 22:08:29 +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> --- drivers/ata/pata_cs5530.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/ata/pata_cs5530.c b/drivers/ata/pata_cs5530.c index 48ae4b4..f9ca72e 100644 --- a/drivers/ata/pata_cs5530.c +++ b/drivers/ata/pata_cs5530.c @@ -276,10 +276,8 @@ static int cs5530_init_chip(void) pci_dev_put(cs5530_0); return 0; fail_put: - if (master_0) - pci_dev_put(master_0); - if (cs5530_0) - pci_dev_put(cs5530_0); + pci_dev_put(master_0); + pci_dev_put(cs5530_0); return -ENODEV; } -- 2.2.2
On 02/01/2015 10:15 AM, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sun, 1 Feb 2015 17:00:24 +0100 > > The unload_nls() 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> Thanks! I'll push this upstream. Dave > --- > fs/jfs/super.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/fs/jfs/super.c b/fs/jfs/super.c > index 16c3a95..5d30c56 100644 > --- a/fs/jfs/super.c > +++ b/fs/jfs/super.c > @@ -619,8 +619,7 @@ out_mount_failed: > iput(sbi->direct_inode); > sbi->direct_inode = NULL; > out_unload: > - if (sbi->nls_tab) > - unload_nls(sbi->nls_tab); > + unload_nls(sbi->nls_tab); > out_kfree: > kfree(sbi); > return ret; >
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 31 Jan 2015 18:15:59 +0100
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 31 Jan 2015 18:10:03 +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>
Applied to net-next, thanks.
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 3 Feb 2015 09:12:22 +0100 Another update suggestion was taken into account after a patch was applied from static source code analysis. Markus Elfring (2): Delete unnecessary checks before the function call "phy_power_off" More error handling for phy_power_off() in mv_platform_remove() drivers/ata/sata_mv.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 2 Feb 2015 22:55:53 +0100 The phy_power_off() 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/ata/sata_mv.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c index f9a0e34..f8c33e3 100644 --- a/drivers/ata/sata_mv.c +++ b/drivers/ata/sata_mv.c @@ -4185,8 +4185,7 @@ err: clk_disable_unprepare(hpriv->port_clks[port]); clk_put(hpriv->port_clks[port]); } - if (hpriv->port_phys[port]) - phy_power_off(hpriv->port_phys[port]); + phy_power_off(hpriv->port_phys[port]); } return rc; @@ -4216,8 +4215,7 @@ static int mv_platform_remove(struct platform_device *pdev) clk_disable_unprepare(hpriv->port_clks[port]); clk_put(hpriv->port_clks[port]); } - if (hpriv->port_phys[port]) - phy_power_off(hpriv->port_phys[port]); + phy_power_off(hpriv->port_phys[port]); } return 0; } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 2 Feb 2015 23:30:34 +0100 The return value from the phy_power_off() function was not used by the mv_platform_remove() function. Let us improve error detection and eventually return a corresponding failure code. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/ata/sata_mv.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c index f8c33e3..4f9bc33 100644 --- a/drivers/ata/sata_mv.c +++ b/drivers/ata/sata_mv.c @@ -4203,7 +4203,7 @@ static int mv_platform_remove(struct platform_device *pdev) { struct ata_host *host = platform_get_drvdata(pdev); struct mv_host_priv *hpriv = host->private_data; - int port; + int port, rc; ata_host_detach(host); if (!IS_ERR(hpriv->clk)) { @@ -4215,7 +4215,9 @@ static int mv_platform_remove(struct platform_device *pdev) clk_disable_unprepare(hpriv->port_clks[port]); clk_put(hpriv->port_clks[port]); } - phy_power_off(hpriv->port_phys[port]); + rc = phy_power_off(hpriv->port_phys[port]); + if (rc) + return rc; } return 0; } -- 2.2.2
Am 02.02.2015 20:46, schrieb NeilBrown:
> On Mon, 02 Feb 2015 16:20:42 +0100 SF Markus Elfring
> <elfring@users.sourceforge.net> wrote:
>
>> From: Markus Elfring <elfring@users.sourceforge.net>
>> Date: Mon, 2 Feb 2015 15:10:57 +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.
>>
>> * Let us also move an assignment for the variable "pages" to the place
>> directly before it is really needed for a loop.
>>
>> * Let us also move another kfree() call into a block which should belong
>> to a previous check for the variable "bp".
>>
>> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
>> ---
>> drivers/md/bitmap.c | 10 +++++-----
>> 1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
>> index da3604e..47d72df 100644
>> --- a/drivers/md/bitmap.c
>> +++ b/drivers/md/bitmap.c
>> @@ -1586,15 +1586,15 @@ static void bitmap_free(struct bitmap *bitmap)
>> bitmap_file_unmap(&bitmap->storage);
>>
>> bp = bitmap->counts.bp;
>> - pages = bitmap->counts.pages;
>>
>> /* free all allocated memory */
>> -
>> - if (bp) /* deallocate the page memory */
>> + if (bp) { /* deallocate the page memory */
>> + pages = bitmap->counts.pages;
>> for (k = 0; k < pages; k++)
>> - if (bp[k].map && !bp[k].hijacked)
>> + if (!bp[k].hijacked)
>> kfree(bp[k].map);
>> - kfree(bp);
>> + kfree(bp);
>> + }
>> kfree(bitmap);
>> }
>>
>
> Hi,
> I'm somewhat amused that you removed a test for one kfree, but imposed a
> test on another. I realised the second test was already there, but why not
> just:
>
> diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
> index da3604e73e8a..ad13b2e1bf1f 100644
> --- a/drivers/md/bitmap.c
> +++ b/drivers/md/bitmap.c
> @@ -1592,7 +1592,7 @@ static void bitmap_free(struct bitmap *bitmap)
>
> if (bp) /* deallocate the page memory */
> for (k = 0; k < pages; k++)
> - if (bp[k].map && !bp[k].hijacked)
> + if (!bp[k].hijacked)
> kfree(bp[k].map);
> kfree(bp);
> kfree(bitmap);
>
>
> It makes the intention of the patch much clearer.
>
> I'd probably prefer to leave the code as it is. I don't think either patch
> is really an improvement in readability, and readability trumps performance
> in places like this.
>
hello Neil,
just for my curiosity.
is it possible that a bp[k] exists but bp[k].hijacked is 0 ?
if that case: kfree(bp) would free an object in use.
otherwise hijacked seems useless here as it is possible to free
everything.
re,
wh
[-- Attachment #1: Type: text/plain, Size: 3341 bytes --] On Tue, 03 Feb 2015 09:48:01 +0100 walter harms <wharms@bfs.de> wrote: > > > Am 02.02.2015 20:46, schrieb NeilBrown: > > On Mon, 02 Feb 2015 16:20:42 +0100 SF Markus Elfring > > <elfring@users.sourceforge.net> wrote: > > > >> From: Markus Elfring <elfring@users.sourceforge.net> > >> Date: Mon, 2 Feb 2015 15:10:57 +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. > >> > >> * Let us also move an assignment for the variable "pages" to the place > >> directly before it is really needed for a loop. > >> > >> * Let us also move another kfree() call into a block which should belong > >> to a previous check for the variable "bp". > >> > >> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > >> --- > >> drivers/md/bitmap.c | 10 +++++----- > >> 1 file changed, 5 insertions(+), 5 deletions(-) > >> > >> diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c > >> index da3604e..47d72df 100644 > >> --- a/drivers/md/bitmap.c > >> +++ b/drivers/md/bitmap.c > >> @@ -1586,15 +1586,15 @@ static void bitmap_free(struct bitmap *bitmap) > >> bitmap_file_unmap(&bitmap->storage); > >> > >> bp = bitmap->counts.bp; > >> - pages = bitmap->counts.pages; > >> > >> /* free all allocated memory */ > >> - > >> - if (bp) /* deallocate the page memory */ > >> + if (bp) { /* deallocate the page memory */ > >> + pages = bitmap->counts.pages; > >> for (k = 0; k < pages; k++) > >> - if (bp[k].map && !bp[k].hijacked) > >> + if (!bp[k].hijacked) > >> kfree(bp[k].map); > >> - kfree(bp); > >> + kfree(bp); > >> + } > >> kfree(bitmap); > >> } > >> > > > > Hi, > > I'm somewhat amused that you removed a test for one kfree, but imposed a > > test on another. I realised the second test was already there, but why not > > just: > > > > diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c > > index da3604e73e8a..ad13b2e1bf1f 100644 > > --- a/drivers/md/bitmap.c > > +++ b/drivers/md/bitmap.c > > @@ -1592,7 +1592,7 @@ static void bitmap_free(struct bitmap *bitmap) > > > > if (bp) /* deallocate the page memory */ > > for (k = 0; k < pages; k++) > > - if (bp[k].map && !bp[k].hijacked) > > + if (!bp[k].hijacked) > > kfree(bp[k].map); > > kfree(bp); > > kfree(bitmap); > > > > > > It makes the intention of the patch much clearer. > > > > I'd probably prefer to leave the code as it is. I don't think either patch > > is really an improvement in readability, and readability trumps performance > > in places like this. > > > > > hello Neil, > just for my curiosity. > is it possible that a bp[k] exists but bp[k].hijacked is 0 ? > if that case: kfree(bp) would free an object in use. > otherwise hijacked seems useless here as it is possible to free > everything. > > re, > wh If .hijacked is 0, the .map is a pointer (that would need to be freed) or is NULL. If .hijacked is 1, then .map has been re-tasked as 2 16-bit counters. They are probably bother zero at this point, but I think it is safer to completely skip the 'free' if 'hijacked' is set as in that case 'map' isn't a pointer. NeilBrown [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 811 bytes --]
Am 03.02.2015 10:07, schrieb NeilBrown:
> On Tue, 03 Feb 2015 09:48:01 +0100 walter harms <wharms@bfs.de> wrote:
>
>>
>>
>> Am 02.02.2015 20:46, schrieb NeilBrown:
>>> On Mon, 02 Feb 2015 16:20:42 +0100 SF Markus Elfring
>>> <elfring@users.sourceforge.net> wrote:
>>>
>>>> From: Markus Elfring <elfring@users.sourceforge.net>
>>>> Date: Mon, 2 Feb 2015 15:10:57 +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.
>>>>
>>>> * Let us also move an assignment for the variable "pages" to the place
>>>> directly before it is really needed for a loop.
>>>>
>>>> * Let us also move another kfree() call into a block which should belong
>>>> to a previous check for the variable "bp".
>>>>
>>>> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
>>>> ---
>>>> drivers/md/bitmap.c | 10 +++++-----
>>>> 1 file changed, 5 insertions(+), 5 deletions(-)
>>>>
>>>> diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
>>>> index da3604e..47d72df 100644
>>>> --- a/drivers/md/bitmap.c
>>>> +++ b/drivers/md/bitmap.c
>>>> @@ -1586,15 +1586,15 @@ static void bitmap_free(struct bitmap *bitmap)
>>>> bitmap_file_unmap(&bitmap->storage);
>>>>
>>>> bp = bitmap->counts.bp;
>>>> - pages = bitmap->counts.pages;
>>>>
>>>> /* free all allocated memory */
>>>> -
>>>> - if (bp) /* deallocate the page memory */
>>>> + if (bp) { /* deallocate the page memory */
>>>> + pages = bitmap->counts.pages;
>>>> for (k = 0; k < pages; k++)
>>>> - if (bp[k].map && !bp[k].hijacked)
>>>> + if (!bp[k].hijacked)
>>>> kfree(bp[k].map);
>>>> - kfree(bp);
>>>> + kfree(bp);
>>>> + }
>>>> kfree(bitmap);
>>>> }
>>>>
>>>
>>> Hi,
>>> I'm somewhat amused that you removed a test for one kfree, but imposed a
>>> test on another. I realised the second test was already there, but why not
>>> just:
>>>
>>> diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
>>> index da3604e73e8a..ad13b2e1bf1f 100644
>>> --- a/drivers/md/bitmap.c
>>> +++ b/drivers/md/bitmap.c
>>> @@ -1592,7 +1592,7 @@ static void bitmap_free(struct bitmap *bitmap)
>>>
>>> if (bp) /* deallocate the page memory */
>>> for (k = 0; k < pages; k++)
>>> - if (bp[k].map && !bp[k].hijacked)
>>> + if (!bp[k].hijacked)
>>> kfree(bp[k].map);
>>> kfree(bp);
>>> kfree(bitmap);
>>>
>>>
>>> It makes the intention of the patch much clearer.
>>>
>>> I'd probably prefer to leave the code as it is. I don't think either patch
>>> is really an improvement in readability, and readability trumps performance
>>> in places like this.
>>>
>>
>>
>> hello Neil,
>> just for my curiosity.
>> is it possible that a bp[k] exists but bp[k].hijacked is 0 ?
>> if that case: kfree(bp) would free an object in use.
>> otherwise hijacked seems useless here as it is possible to free
>> everything.
>>
>> re,
>> wh
>
> If .hijacked is 0, the .map is a pointer (that would need to be freed) or is
> NULL.
> If .hijacked is 1, then .map has been re-tasked as 2 16-bit counters. They
> are probably bother zero at this point, but I think it is safer to completely
> skip the 'free' if 'hijacked' is set as in that case 'map' isn't a pointer.
>
It seems i was not clear enough, sorry about that.
we have a loop to kfree(bp[k].map), thats fine how it is done.
I am wondering about the kfree(bp) after the loop.
if bp[k].map is not freed for what ever reason how can it be freed later
after a kfree(bp) ?
what is what i am missing ? Is there a hidden copy ?
re,
wh
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 3 Feb 2015 11:15:14 +0100 The cpufreq_cooling_unregister() 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/thermal/ti-soc-thermal/ti-thermal-common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c index 3fb054a..a38c175 100644 --- a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c +++ b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c @@ -429,7 +429,7 @@ int ti_thermal_unregister_cpu_cooling(struct ti_bandgap *bgp, int id) data = ti_bandgap_get_sensor_data(bgp, id); - if (data && data->cool_dev) + if (data) cpufreq_cooling_unregister(data->cool_dev); return 0; -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 3 Feb 2015 11:54:28 +0100 The of_node_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> --- drivers/pwm/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 966497d..810aef3 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -192,7 +192,7 @@ static void of_pwmchip_add(struct pwm_chip *chip) static void of_pwmchip_remove(struct pwm_chip *chip) { - if (chip->dev && chip->dev->of_node) + if (chip->dev) of_node_put(chip->dev->of_node); } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 3 Feb 2015 12:40: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> --- arch/x86/kernel/cpu/perf_event_intel_uncore_snbep.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore_snbep.c b/arch/x86/kernel/cpu/perf_event_intel_uncore_snbep.c index 21af6149e..12d9548 100644 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore_snbep.c +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore_snbep.c @@ -1132,8 +1132,7 @@ static int snbep_pci2phy_map_init(int devid) } } - if (ubox_dev) - pci_dev_put(ubox_dev); + pci_dev_put(ubox_dev); return err ? pcibios_err_to_errno(err) : 0; } -- 2.2.2
[-- Attachment #1: Type: text/plain, Size: 965 bytes --] On Tue, Feb 03, 2015 at 11:58:29AM +0100, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Tue, 3 Feb 2015 11:54:28 +0100 > > The of_node_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> > --- > drivers/pwm/core.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c > index 966497d..810aef3 100644 > --- a/drivers/pwm/core.c > +++ b/drivers/pwm/core.c > @@ -192,7 +192,7 @@ static void of_pwmchip_add(struct pwm_chip *chip) > > static void of_pwmchip_remove(struct pwm_chip *chip) > { > - if (chip->dev && chip->dev->of_node) > + if (chip->dev) > of_node_put(chip->dev->of_node); > } > Applied, thanks. Thierry [-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]
On Mon, Feb 02, 2015 at 10:22:32PM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Mon, 2 Feb 2015 22:08:29 +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>
Applied to libata/for-3.20.
Thanks.
--
tejun
On Tue, Feb 03, 2015 at 09:33:53AM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Mon, 2 Feb 2015 22:55:53 +0100
>
> The phy_power_off() 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>
Applied to libata/for-3.20.
Thanks.
--
tejun
On Tue, Feb 03, 2015 at 09:36:01AM +0100, SF Markus Elfring wrote:
...
> @@ -4215,7 +4215,9 @@ static int mv_platform_remove(struct platform_device *pdev)
> clk_disable_unprepare(hpriv->port_clks[port]);
> clk_put(hpriv->port_clks[port]);
> }
> - phy_power_off(hpriv->port_phys[port]);
> + rc = phy_power_off(hpriv->port_phys[port]);
> + if (rc)
> + return rc;
So, this is a removal function which is ignoring failure from turning
off phy, which seems like the right thing to do. The same thing with
suspend routines. If something auxliary which isn't strictly
necessary in reaching suspend state fails, the failure should be
ignored.
Running static code analysis to locate trivial irregularities and
performing identity transformations is fine, even great, but you're
changing the behavior here without actually understanding what's going
on. Please don't do these things automatically.
Thanks.
--
tejun
Am 03.02.2015 13:10, schrieb Tejun Heo:
> On Tue, Feb 03, 2015 at 09:36:01AM +0100, SF Markus Elfring wrote:
> ...
>> @@ -4215,7 +4215,9 @@ static int mv_platform_remove(struct platform_device *pdev)
>> clk_disable_unprepare(hpriv->port_clks[port]);
>> clk_put(hpriv->port_clks[port]);
>> }
>> - phy_power_off(hpriv->port_phys[port]);
>> + rc = phy_power_off(hpriv->port_phys[port]);
>> + if (rc)
>> + return rc;
>
> So, this is a removal function which is ignoring failure from turning
> off phy, which seems like the right thing to do. The same thing with
> suspend routines. If something auxliary which isn't strictly
> necessary in reaching suspend state fails, the failure should be
> ignored.
>
> Running static code analysis to locate trivial irregularities and
> performing identity transformations is fine, even great, but you're
> changing the behavior here without actually understanding what's going
> on. Please don't do these things automatically.
>
> Thanks.
>
maybe this can be changed into
(void) phy_power_off(hpriv->port_phys[port]);
that would tell the compiler and other readers that this is intentional.
On Tue, Feb 03, 2015 at 01:32:10PM +0100, walter harms wrote:
> maybe this can be changed into
> (void) phy_power_off(hpriv->port_phys[port]);
>
> that would tell the compiler and other readers that this is intentional.
That's too anal to be helpful and too spurious to become even remotely
consistent. Things like that are actualy harmful. Note that we have
an annotation marking the other way - __must_check. Balance is to be
found towards that direction, not this, so please stop.
Thanks.
--
tejun
On Tue, Feb 03, 2015 at 07:48:14AM -0500, Tejun Heo wrote:
> That's too anal to be helpful and too spurious to become even remotely
Let me clarify the "too anal" part a bit. Let's say people push this
like crazy and we successfully mark all places to either check the
return value or have (void) in front. It's not difficult to realize
that that would be the exact same situation as right now just with
more visual clutter. That's the problem when these things become
obsessive - they become indisciminate and thus meaningless. Annotate
the exceptionals, not the other way around.
Thanks.
--
tejun
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 3 Feb 2015 13:55:53 +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> --- arch/powerpc/platforms/cell/celleb_pci.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/platforms/cell/celleb_pci.c b/arch/powerpc/platforms/cell/celleb_pci.c index 3ce70de..9b11b5d 100644 --- a/arch/powerpc/platforms/cell/celleb_pci.c +++ b/arch/powerpc/platforms/cell/celleb_pci.c @@ -393,11 +393,10 @@ static int __init celleb_setup_fake_pci_device(struct device_node *node, error: if (mem_init_done) { - if (config && *config) + if (config) kfree(*config); - if (res && *res) + if (res) kfree(*res); - } else { if (config && *config) { size = 256; -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 3 Feb 2015 14:34:10 +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> --- arch/powerpc/lib/rheap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/lib/rheap.c b/arch/powerpc/lib/rheap.c index a1060a8..69abf84 100644 --- a/arch/powerpc/lib/rheap.c +++ b/arch/powerpc/lib/rheap.c @@ -284,7 +284,7 @@ EXPORT_SYMBOL_GPL(rh_create); */ void rh_destroy(rh_info_t * info) { - if ((info->flags & RHIF_STATIC_BLOCK) = 0 && info->block != NULL) + if ((info->flags & RHIF_STATIC_BLOCK) = 0) kfree(info->block); if ((info->flags & RHIF_STATIC_INFO) = 0) -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 3 Feb 2015 15:05:26 +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> --- drivers/media/dvb-frontends/sp2.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/media/dvb-frontends/sp2.c b/drivers/media/dvb-frontends/sp2.c index cc1ef96..8fd4276 100644 --- a/drivers/media/dvb-frontends/sp2.c +++ b/drivers/media/dvb-frontends/sp2.c @@ -413,11 +413,8 @@ static int sp2_remove(struct i2c_client *client) struct sp2 *s = i2c_get_clientdata(client); dev_dbg(&client->dev, "\n"); - sp2_exit(client); - if (s != NULL) - kfree(s); - + kfree(s); return 0; } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 3 Feb 2015 15:27:38 +0100 The media_entity_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> --- drivers/media/v4l2-core/v4l2-subdev.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index 543631c..b9ff7fd 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -93,8 +93,7 @@ static int subdev_open(struct file *file) err: #if defined(CONFIG_MEDIA_CONTROLLER) - if (entity) - media_entity_put(entity); + media_entity_put(entity); #endif v4l2_fh_del(&subdev_fh->vfh); v4l2_fh_exit(&subdev_fh->vfh); -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 3 Feb 2015 16:50:07 +0100 Another update suggestion was taken into account after a patch was applied from static source code analysis. Markus Elfring (2): Delete an unnecessary check before the function call "dvb_unregister_device" Less function calls in dvb_ca_en50221_init() after error detection drivers/media/dvb-core/dvb_ca_en50221.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 3 Feb 2015 16:01:40 +0100 The dvb_unregister_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/media/dvb-core/dvb_ca_en50221.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/media/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb-core/dvb_ca_en50221.c index 0aac309..b999689 100644 --- a/drivers/media/dvb-core/dvb_ca_en50221.c +++ b/drivers/media/dvb-core/dvb_ca_en50221.c @@ -1726,8 +1726,7 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter, error: if (ca != NULL) { - if (ca->dvbdev != NULL) - dvb_unregister_device(ca->dvbdev); + dvb_unregister_device(ca->dvbdev); kfree(ca->slot_info); kfree(ca); } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 3 Feb 2015 16:47:48 +0100 The functions "dvb_unregister_device" and "kfree" could still be called by the dvb_ca_en50221_init() function in the case that a previous resource allocation failed. * Corresponding details could be improved by adjustments for jump targets. * Let us delete also an unnecessary check for the variable "ca" there. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/media/dvb-core/dvb_ca_en50221.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/media/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb-core/dvb_ca_en50221.c index b999689..9842fd1 100644 --- a/drivers/media/dvb-core/dvb_ca_en50221.c +++ b/drivers/media/dvb-core/dvb_ca_en50221.c @@ -1676,14 +1676,14 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter, /* initialise the system data */ if ((ca = kzalloc(sizeof(struct dvb_ca_private), GFP_KERNEL)) = NULL) { ret = -ENOMEM; - goto error; + goto exit; } ca->pub = pubca; ca->flags = flags; ca->slot_count = slot_count; if ((ca->slot_info = kcalloc(slot_count, sizeof(struct dvb_ca_slot), GFP_KERNEL)) = NULL) { ret = -ENOMEM; - goto error; + goto free_ca; } init_waitqueue_head(&ca->wait_queue); ca->open = 0; @@ -1694,7 +1694,7 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter, /* register the DVB device */ ret = dvb_register_device(dvb_adapter, &ca->dvbdev, &dvbdev_ca, ca, DVB_DEVICE_CA); if (ret) - goto error; + goto free_slot_info; /* now initialise each slot */ for (i = 0; i < slot_count; i++) { @@ -1709,7 +1709,7 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter, if (signal_pending(current)) { ret = -EINTR; - goto error; + goto unregister_device; } mb(); @@ -1720,16 +1720,17 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter, ret = PTR_ERR(ca->thread); printk("dvb_ca_init: failed to start kernel_thread (%d)\n", ret); - goto error; + goto unregister_device; } return 0; -error: - if (ca != NULL) { - dvb_unregister_device(ca->dvbdev); - kfree(ca->slot_info); - kfree(ca); - } +unregister_device: + dvb_unregister_device(ca->dvbdev); +free_slot_info: + kfree(ca->slot_info); +free_ca: + kfree(ca); +exit: pubca->private = NULL; return ret; } -- 2.2.2
On Mon, Feb 02, 2015 at 07:25:48PM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Mon, 2 Feb 2015 18:26:34 +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>
Queued for 3.21, thanks.
--
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 3 Feb 2015 18:36:35 +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/media/usb/stkwebcam/stk-webcam.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/media/usb/stkwebcam/stk-webcam.c b/drivers/media/usb/stkwebcam/stk-webcam.c index 3588dc3..3686c4e 100644 --- a/drivers/media/usb/stkwebcam/stk-webcam.c +++ b/drivers/media/usb/stkwebcam/stk-webcam.c @@ -556,10 +556,8 @@ static int stk_free_sio_buffers(struct stk_camera *dev) nbufs = dev->n_sbufs; dev->n_sbufs = 0; spin_unlock_irqrestore(&dev->spinlock, flags); - for (i = 0; i < nbufs; i++) { - if (dev->sio_bufs[i].buffer != NULL) - vfree(dev->sio_bufs[i].buffer); - } + for (i = 0; i < nbufs; i++) + vfree(dev->sio_bufs[i].buffer); kfree(dev->sio_bufs); dev->sio_bufs = NULL; return 0; -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 3 Feb 2015 19:00:25 +0100 The video_unregister_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/media/usb/au0828/au0828-video.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c index 5f337b1..e593fb5 100644 --- a/drivers/media/usb/au0828/au0828-video.c +++ b/drivers/media/usb/au0828/au0828-video.c @@ -870,12 +870,8 @@ void au0828_analog_unregister(struct au0828_dev *dev) { dprintk(1, "au0828_release_resources called\n"); mutex_lock(&au0828_sysfs_lock); - - if (dev->vdev) - video_unregister_device(dev->vdev); - if (dev->vbi_dev) - video_unregister_device(dev->vbi_dev); - + video_unregister_device(dev->vdev); + video_unregister_device(dev->vbi_dev); mutex_unlock(&au0828_sysfs_lock); } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 3 Feb 2015 19:21:21 +0100 The cpufreq_cooling_unregister() 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/cpufreq/cpufreq-dt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c index fde97d6..bab67db 100644 --- a/drivers/cpufreq/cpufreq-dt.c +++ b/drivers/cpufreq/cpufreq-dt.c @@ -320,8 +320,7 @@ static int cpufreq_exit(struct cpufreq_policy *policy) { struct private_data *priv = policy->driver_data; - if (priv->cdev) - cpufreq_cooling_unregister(priv->cdev); + cpufreq_cooling_unregister(priv->cdev); dev_pm_opp_free_cpufreq_table(priv->cpu_dev, &policy->freq_table); of_free_opp_table(priv->cpu_dev); clk_put(policy->clk); -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 3 Feb 2015 19:47:33 +0100 The of_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> --- drivers/net/ethernet/ibm/emac/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c index 9388a83..162762d 100644 --- a/drivers/net/ethernet/ibm/emac/core.c +++ b/drivers/net/ethernet/ibm/emac/core.c @@ -2367,7 +2367,7 @@ static int emac_wait_deps(struct emac_instance *dev) err = emac_check_deps(dev, deps) ? 0 : -ENODEV; for (i = 0; i < EMAC_DEP_COUNT; i++) { of_node_put(deps[i].node); - if (err && deps[i].ofdev) + if (err) of_dev_put(deps[i].ofdev); } if (err = 0) { -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 3 Feb 2015 20:12:25 +0100 The functions cpsw_ale_destroy() and of_dev_put() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/net/ethernet/ti/netcp_ethss.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/ti/netcp_ethss.c b/drivers/net/ethernet/ti/netcp_ethss.c index fa1041a..cbd6dde 100644 --- a/drivers/net/ethernet/ti/netcp_ethss.c +++ b/drivers/net/ethernet/ti/netcp_ethss.c @@ -2010,12 +2010,10 @@ static int gbe_probe(struct netcp_device *netcp_device, struct device *dev, quit: if (gbe_dev->hw_stats) devm_kfree(dev, gbe_dev->hw_stats); - if (gbe_dev->ale) - cpsw_ale_destroy(gbe_dev->ale); + cpsw_ale_destroy(gbe_dev->ale); if (gbe_dev->ss_regs) devm_iounmap(dev, gbe_dev->ss_regs); - if (interfaces) - of_node_put(interfaces); + of_node_put(interfaces); devm_kfree(dev, gbe_dev); return ret; } -- 2.2.2
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 31 Jan 2015 17:34:54 +0100
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 31 Jan 2015 17:18:48 +0100
>
> The meta_delete() function could be called in four cases by the
> em_meta_change() function during error handling even if the passed
> variable "meta" contained still a null pointer.
>
> * This implementation detail could be improved by adjustments for jump labels.
>
> * Let us return immediately after the first failed function call according to
> the current Linux coding style convention.
>
> * Let us delete also unnecessary checks for the variables "err" and
> "meta" there.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
I kind of like the way the code is now, branching to the end of the function
even when cleanups are not necessary.
Inter-function return statements make code harder to audit, for locking
errors, resource leaks, etc.
[-- Attachment #1: Type: text/plain, Size: 4304 bytes --] On Tue, 03 Feb 2015 11:19:58 +0100 walter harms <wharms@bfs.de> wrote: > > > Am 03.02.2015 10:07, schrieb NeilBrown: > > On Tue, 03 Feb 2015 09:48:01 +0100 walter harms <wharms@bfs.de> wrote: > > > >> > >> > >> Am 02.02.2015 20:46, schrieb NeilBrown: > >>> On Mon, 02 Feb 2015 16:20:42 +0100 SF Markus Elfring > >>> <elfring@users.sourceforge.net> wrote: > >>> > >>>> From: Markus Elfring <elfring@users.sourceforge.net> > >>>> Date: Mon, 2 Feb 2015 15:10:57 +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. > >>>> > >>>> * Let us also move an assignment for the variable "pages" to the place > >>>> directly before it is really needed for a loop. > >>>> > >>>> * Let us also move another kfree() call into a block which should belong > >>>> to a previous check for the variable "bp". > >>>> > >>>> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > >>>> --- > >>>> drivers/md/bitmap.c | 10 +++++----- > >>>> 1 file changed, 5 insertions(+), 5 deletions(-) > >>>> > >>>> diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c > >>>> index da3604e..47d72df 100644 > >>>> --- a/drivers/md/bitmap.c > >>>> +++ b/drivers/md/bitmap.c > >>>> @@ -1586,15 +1586,15 @@ static void bitmap_free(struct bitmap *bitmap) > >>>> bitmap_file_unmap(&bitmap->storage); > >>>> > >>>> bp = bitmap->counts.bp; > >>>> - pages = bitmap->counts.pages; > >>>> > >>>> /* free all allocated memory */ > >>>> - > >>>> - if (bp) /* deallocate the page memory */ > >>>> + if (bp) { /* deallocate the page memory */ > >>>> + pages = bitmap->counts.pages; > >>>> for (k = 0; k < pages; k++) > >>>> - if (bp[k].map && !bp[k].hijacked) > >>>> + if (!bp[k].hijacked) > >>>> kfree(bp[k].map); > >>>> - kfree(bp); > >>>> + kfree(bp); > >>>> + } > >>>> kfree(bitmap); > >>>> } > >>>> > >>> > >>> Hi, > >>> I'm somewhat amused that you removed a test for one kfree, but imposed a > >>> test on another. I realised the second test was already there, but why not > >>> just: > >>> > >>> diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c > >>> index da3604e73e8a..ad13b2e1bf1f 100644 > >>> --- a/drivers/md/bitmap.c > >>> +++ b/drivers/md/bitmap.c > >>> @@ -1592,7 +1592,7 @@ static void bitmap_free(struct bitmap *bitmap) > >>> > >>> if (bp) /* deallocate the page memory */ > >>> for (k = 0; k < pages; k++) > >>> - if (bp[k].map && !bp[k].hijacked) > >>> + if (!bp[k].hijacked) > >>> kfree(bp[k].map); > >>> kfree(bp); > >>> kfree(bitmap); > >>> > >>> > >>> It makes the intention of the patch much clearer. > >>> > >>> I'd probably prefer to leave the code as it is. I don't think either patch > >>> is really an improvement in readability, and readability trumps performance > >>> in places like this. > >>> > >> > >> > >> hello Neil, > >> just for my curiosity. > >> is it possible that a bp[k] exists but bp[k].hijacked is 0 ? > >> if that case: kfree(bp) would free an object in use. > >> otherwise hijacked seems useless here as it is possible to free > >> everything. > >> > >> re, > >> wh > > > > If .hijacked is 0, the .map is a pointer (that would need to be freed) or is > > NULL. > > If .hijacked is 1, then .map has been re-tasked as 2 16-bit counters. They > > are probably bother zero at this point, but I think it is safer to completely > > skip the 'free' if 'hijacked' is set as in that case 'map' isn't a pointer. > > > > It seems i was not clear enough, sorry about that. > > we have a loop to kfree(bp[k].map), thats fine how it is done. > > I am wondering about the kfree(bp) after the loop. > if bp[k].map is not freed for what ever reason how can it be freed later > after a kfree(bp) ? > > what is what i am missing ? Is there a hidden copy ? If bp[k].map is a pointer, it will be freed. If bp[k].map is not a pointer (because it has been hijacked), then there is nothing to free. So after the loop, all bp[k].maps that were allocated will have been freed. Does that help? NeilBrown > > re, > wh > > > [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 811 bytes --]
>> The meta_delete() function could be called in four cases by the
>> em_meta_change() function during error handling even if the passed
>> variable "meta" contained still a null pointer.
>>
>> * This implementation detail could be improved by adjustments for jump labels.
>>
>> * Let us return immediately after the first failed function call according to
>> the current Linux coding style convention.
>>
>> * Let us delete also unnecessary checks for the variables "err" and
>> "meta" there.
>
> I kind of like the way the code is now, branching to the end of the function
> even when cleanups are not necessary.
I would appreciate if the affected exception handling can become also
a bit more efficient.
Regards,
Markus
Am 04.02.2015 07:48, schrieb NeilBrown:
> On Tue, 03 Feb 2015 11:19:58 +0100 walter harms <wharms@bfs.de> wrote:
>
>>
>>
>> Am 03.02.2015 10:07, schrieb NeilBrown:
>>> On Tue, 03 Feb 2015 09:48:01 +0100 walter harms <wharms@bfs.de> wrote:
>>>
>>>>
>>>>
>>>> Am 02.02.2015 20:46, schrieb NeilBrown:
>>>>> On Mon, 02 Feb 2015 16:20:42 +0100 SF Markus Elfring
>>>>> <elfring@users.sourceforge.net> wrote:
>>>>>
>>>>>> From: Markus Elfring <elfring@users.sourceforge.net>
>>>>>> Date: Mon, 2 Feb 2015 15:10:57 +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.
>>>>>>
>>>>>> * Let us also move an assignment for the variable "pages" to the place
>>>>>> directly before it is really needed for a loop.
>>>>>>
>>>>>> * Let us also move another kfree() call into a block which should belong
>>>>>> to a previous check for the variable "bp".
>>>>>>
>>>>>> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
>>>>>> ---
>>>>>> drivers/md/bitmap.c | 10 +++++-----
>>>>>> 1 file changed, 5 insertions(+), 5 deletions(-)
>>>>>>
>>>>>> diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
>>>>>> index da3604e..47d72df 100644
>>>>>> --- a/drivers/md/bitmap.c
>>>>>> +++ b/drivers/md/bitmap.c
>>>>>> @@ -1586,15 +1586,15 @@ static void bitmap_free(struct bitmap *bitmap)
>>>>>> bitmap_file_unmap(&bitmap->storage);
>>>>>>
>>>>>> bp = bitmap->counts.bp;
>>>>>> - pages = bitmap->counts.pages;
>>>>>>
>>>>>> /* free all allocated memory */
>>>>>> -
>>>>>> - if (bp) /* deallocate the page memory */
>>>>>> + if (bp) { /* deallocate the page memory */
>>>>>> + pages = bitmap->counts.pages;
>>>>>> for (k = 0; k < pages; k++)
>>>>>> - if (bp[k].map && !bp[k].hijacked)
>>>>>> + if (!bp[k].hijacked)
>>>>>> kfree(bp[k].map);
>>>>>> - kfree(bp);
>>>>>> + kfree(bp);
>>>>>> + }
>>>>>> kfree(bitmap);
>>>>>> }
>>>>>>
>>>>>
>>>>> Hi,
>>>>> I'm somewhat amused that you removed a test for one kfree, but imposed a
>>>>> test on another. I realised the second test was already there, but why not
>>>>> just:
>>>>>
>>>>> diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
>>>>> index da3604e73e8a..ad13b2e1bf1f 100644
>>>>> --- a/drivers/md/bitmap.c
>>>>> +++ b/drivers/md/bitmap.c
>>>>> @@ -1592,7 +1592,7 @@ static void bitmap_free(struct bitmap *bitmap)
>>>>>
>>>>> if (bp) /* deallocate the page memory */
>>>>> for (k = 0; k < pages; k++)
>>>>> - if (bp[k].map && !bp[k].hijacked)
>>>>> + if (!bp[k].hijacked)
>>>>> kfree(bp[k].map);
>>>>> kfree(bp);
>>>>> kfree(bitmap);
>>>>>
>>>>>
>>>>> It makes the intention of the patch much clearer.
>>>>>
>>>>> I'd probably prefer to leave the code as it is. I don't think either patch
>>>>> is really an improvement in readability, and readability trumps performance
>>>>> in places like this.
>>>>>
>>>>
>>>>
>>>> hello Neil,
>>>> just for my curiosity.
>>>> is it possible that a bp[k] exists but bp[k].hijacked is 0 ?
>>>> if that case: kfree(bp) would free an object in use.
>>>> otherwise hijacked seems useless here as it is possible to free
>>>> everything.
>>>>
>>>> re,
>>>> wh
>>>
>>> If .hijacked is 0, the .map is a pointer (that would need to be freed) or is
>>> NULL.
>>> If .hijacked is 1, then .map has been re-tasked as 2 16-bit counters. They
>>> are probably bother zero at this point, but I think it is safer to completely
>>> skip the 'free' if 'hijacked' is set as in that case 'map' isn't a pointer.
>>>
>>
>> It seems i was not clear enough, sorry about that.
>>
>> we have a loop to kfree(bp[k].map), thats fine how it is done.
>>
>> I am wondering about the kfree(bp) after the loop.
>> if bp[k].map is not freed for what ever reason how can it be freed later
>> after a kfree(bp) ?
>>
>> what is what i am missing ? Is there a hidden copy ?
>
> If bp[k].map is a pointer, it will be freed.
> If bp[k].map is not a pointer (because it has been hijacked), then there is
> nothing to free.
>
> So after the loop, all bp[k].maps that were allocated will have been freed.
>
> Does that help?
>
> NeilBrown
>
thx for explanation,
i am happy now, no further questions.
re,
wh
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 4 Feb 2015 11:28:43 +0100 The release_firmware() 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/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c index 1147e1e..6d08b8c 100644 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c @@ -5129,8 +5129,7 @@ static int adap_init0(struct adapter *adap) state, &reset); /* Cleaning up */ - if (fw != NULL) - release_firmware(fw); + release_firmware(fw); t4_free_mem(card_fw); if (ret < 0) -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 4 Feb 2015 12:32:14 +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> --- drivers/net/ethernet/myricom/myri10ge/myri10ge.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/ethernet/myricom/myri10ge/myri10ge.c b/drivers/net/ethernet/myricom/myri10ge/myri10ge.c index 71af98b..1412f5a 100644 --- a/drivers/net/ethernet/myricom/myri10ge/myri10ge.c +++ b/drivers/net/ethernet/myricom/myri10ge/myri10ge.c @@ -4226,8 +4226,7 @@ static void myri10ge_remove(struct pci_dev *pdev) mtrr_del(mgp->mtrr, mgp->iomem_base, mgp->board_span); #endif myri10ge_free_slices(mgp); - if (mgp->msix_vectors != NULL) - kfree(mgp->msix_vectors); + kfree(mgp->msix_vectors); dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd), mgp->cmd, mgp->cmd_bus); -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 4 Feb 2015 12:56:42 +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> --- drivers/net/ethernet/freescale/fec_main.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c index 1c7a7e4..29fd7e3 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -2584,12 +2584,9 @@ static void fec_enet_free_queue(struct net_device *ndev) } for (i = 0; i < fep->num_rx_queues; i++) - if (fep->rx_queue[i]) - kfree(fep->rx_queue[i]); - + kfree(fep->rx_queue[i]); for (i = 0; i < fep->num_tx_queues; i++) - if (fep->tx_queue[i]) - kfree(fep->tx_queue[i]); + kfree(fep->tx_queue[i]); } static int fec_enet_alloc_queue(struct net_device *ndev) -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 4 Feb 2015 13:17:48 +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> --- drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c b/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c index a47fe67..7d1b524 100644 --- a/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c +++ b/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c @@ -176,9 +176,7 @@ netxen_alloc_sds_rings(struct netxen_recv_context *recv_ctx, int count) static void netxen_free_sds_rings(struct netxen_recv_context *recv_ctx) { - if (recv_ctx->sds_rings != NULL) - kfree(recv_ctx->sds_rings); - + kfree(recv_ctx->sds_rings); recv_ctx->sds_rings = NULL; } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 4 Feb 2015 14:07:56 +0100 The functions kfree() and vfree() perform also input parameter validation. Thus the test around their calls is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c | 24 ++++++++-------------- .../net/ethernet/qlogic/qlcnic/qlcnic_minidump.c | 3 +-- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c index 2528c3f..a430a34a 100644 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c @@ -294,9 +294,7 @@ int qlcnic_alloc_sds_rings(struct qlcnic_recv_context *recv_ctx, int count) void qlcnic_free_sds_rings(struct qlcnic_recv_context *recv_ctx) { - if (recv_ctx->sds_rings != NULL) - kfree(recv_ctx->sds_rings); - + kfree(recv_ctx->sds_rings); recv_ctx->sds_rings = NULL; } @@ -1257,8 +1255,7 @@ qlcnic_check_options(struct qlcnic_adapter *adapter) if (ahw->op_mode != QLCNIC_NON_PRIV_FUNC) { if (fw_dump->tmpl_hdr = NULL || adapter->fw_version > prev_fw_version) { - if (fw_dump->tmpl_hdr) - vfree(fw_dump->tmpl_hdr); + vfree(fw_dump->tmpl_hdr); if (!qlcnic_fw_cmd_get_minidump_temp(adapter)) dev_info(&pdev->dev, "Supports FW dump capability\n"); @@ -2374,13 +2371,12 @@ void qlcnic_free_tx_rings(struct qlcnic_adapter *adapter) for (ring = 0; ring < adapter->drv_tx_rings; ring++) { tx_ring = &adapter->tx_ring[ring]; - if (tx_ring && tx_ring->cmd_buf_arr != NULL) { + if (tx_ring) { vfree(tx_ring->cmd_buf_arr); tx_ring->cmd_buf_arr = NULL; } } - if (adapter->tx_ring != NULL) - kfree(adapter->tx_ring); + kfree(adapter->tx_ring); } int qlcnic_alloc_tx_rings(struct qlcnic_adapter *adapter, @@ -2758,13 +2754,9 @@ static void qlcnic_remove(struct pci_dev *pdev) } qlcnic_dcb_free(adapter->dcb); - qlcnic_detach(adapter); - - if (adapter->npars != NULL) - kfree(adapter->npars); - if (adapter->eswitch != NULL) - kfree(adapter->eswitch); + kfree(adapter->npars); + kfree(adapter->eswitch); if (qlcnic_82xx_check(adapter)) qlcnic_clr_all_drv_state(adapter, 0); @@ -2932,13 +2924,13 @@ void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter) static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter) { - if (adapter->fhash.fmax && adapter->fhash.fhead) + if (adapter->fhash.fmax) kfree(adapter->fhash.fhead); adapter->fhash.fhead = NULL; adapter->fhash.fmax = 0; - if (adapter->rx_fhash.fmax && adapter->rx_fhash.fhead) + if (adapter->rx_fhash.fmax) kfree(adapter->rx_fhash.fhead); adapter->rx_fhash.fmax = 0; diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c index c9f57fb..332bb8a 100644 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c @@ -1407,8 +1407,7 @@ void qlcnic_83xx_get_minidump_template(struct qlcnic_adapter *adapter) current_version = qlcnic_83xx_get_fw_version(adapter); if (fw_dump->tmpl_hdr = NULL || current_version > prev_version) { - if (fw_dump->tmpl_hdr) - vfree(fw_dump->tmpl_hdr); + vfree(fw_dump->tmpl_hdr); if (!qlcnic_fw_cmd_get_minidump_temp(adapter)) dev_info(&pdev->dev, "Supports FW dump capability\n"); } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 4 Feb 2015 15:17:00 +0100 The vunmap() 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/mellanox/mlx4/alloc.c | 2 +- drivers/net/ethernet/mellanox/mlx5/core/alloc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx4/alloc.c b/drivers/net/ethernet/mellanox/mlx4/alloc.c index 963dd7e..06faa51 100644 --- a/drivers/net/ethernet/mellanox/mlx4/alloc.c +++ b/drivers/net/ethernet/mellanox/mlx4/alloc.c @@ -660,7 +660,7 @@ void mlx4_buf_free(struct mlx4_dev *dev, int size, struct mlx4_buf *buf) dma_free_coherent(&dev->pdev->dev, size, buf->direct.buf, buf->direct.map); else { - if (BITS_PER_LONG = 64 && buf->direct.buf) + if (BITS_PER_LONG = 64) vunmap(buf->direct.buf); for (i = 0; i < buf->nbufs; ++i) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/alloc.c b/drivers/net/ethernet/mellanox/mlx5/core/alloc.c index 56779c1..201ca6d 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/alloc.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/alloc.c @@ -121,7 +121,7 @@ void mlx5_buf_free(struct mlx5_core_dev *dev, struct mlx5_buf *buf) dma_free_coherent(&dev->pdev->dev, buf->size, buf->direct.buf, buf->direct.map); else { - if (BITS_PER_LONG = 64 && buf->direct.buf) + if (BITS_PER_LONG = 64) vunmap(buf->direct.buf); for (i = 0; i < buf->nbufs; i++) -- 2.2.2
On Tuesday, February 03, 2015 07:25:39 PM SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Tue, 3 Feb 2015 19:21:21 +0100 > > The cpufreq_cooling_unregister() 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> Queued up for 3.20, thanks! > --- > drivers/cpufreq/cpufreq-dt.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c > index fde97d6..bab67db 100644 > --- a/drivers/cpufreq/cpufreq-dt.c > +++ b/drivers/cpufreq/cpufreq-dt.c > @@ -320,8 +320,7 @@ static int cpufreq_exit(struct cpufreq_policy *policy) > { > struct private_data *priv = policy->driver_data; > > - if (priv->cdev) > - cpufreq_cooling_unregister(priv->cdev); > + cpufreq_cooling_unregister(priv->cdev); > dev_pm_opp_free_cpufreq_table(priv->cpu_dev, &policy->freq_table); > of_free_opp_table(priv->cpu_dev); > clk_put(policy->clk); > -- I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Acked-by: Eli Cohen <eli@mellanox.com>
On Wed, Feb 04, 2015 at 03:22:33PM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 4 Feb 2015 15:17:00 +0100
>
> The vunmap() 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>
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 4 Feb 2015 15:56:58 +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> --- drivers/net/ethernet/cirrus/ep93xx_eth.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/cirrus/ep93xx_eth.c b/drivers/net/ethernet/cirrus/ep93xx_eth.c index 3a12c09..de9f7c9 100644 --- a/drivers/net/ethernet/cirrus/ep93xx_eth.c +++ b/drivers/net/ethernet/cirrus/ep93xx_eth.c @@ -475,8 +475,7 @@ static void ep93xx_free_buffers(struct ep93xx_priv *ep) if (d) dma_unmap_single(dev, d, PKT_BUF_SIZE, DMA_FROM_DEVICE); - if (ep->rx_buf[i] != NULL) - kfree(ep->rx_buf[i]); + kfree(ep->rx_buf[i]); } for (i = 0; i < TX_QUEUE_ENTRIES; i++) { @@ -486,8 +485,7 @@ static void ep93xx_free_buffers(struct ep93xx_priv *ep) if (d) dma_unmap_single(dev, d, PKT_BUF_SIZE, DMA_TO_DEVICE); - if (ep->tx_buf[i] != NULL) - kfree(ep->tx_buf[i]); + kfree(ep->tx_buf[i]); } dma_free_coherent(dev, sizeof(struct ep93xx_descs), ep->descs, -- 2.2.2
On Wednesday, February 04, 2015 8:01 AM, Markus Elfring wrote:
> 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>
> ---
> drivers/net/ethernet/cirrus/ep93xx_eth.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/ethernet/cirrus/ep93xx_eth.c b/drivers/net/ethernet/cirrus/ep93xx_eth.c
> index 3a12c09..de9f7c9 100644
> --- a/drivers/net/ethernet/cirrus/ep93xx_eth.c
> +++ b/drivers/net/ethernet/cirrus/ep93xx_eth.c
> @@ -475,8 +475,7 @@ static void ep93xx_free_buffers(struct ep93xx_priv *ep)
> if (d)
> dma_unmap_single(dev, d, PKT_BUF_SIZE, DMA_FROM_DEVICE);
>
> - if (ep->rx_buf[i] != NULL)
> - kfree(ep->rx_buf[i]);
> + kfree(ep->rx_buf[i]);
> }
>
> for (i = 0; i < TX_QUEUE_ENTRIES; i++) {
> @@ -486,8 +485,7 @@ static void ep93xx_free_buffers(struct ep93xx_priv *ep)
> if (d)
> dma_unmap_single(dev, d, PKT_BUF_SIZE, DMA_TO_DEVICE);
>
> - if (ep->tx_buf[i] != NULL)
> - kfree(ep->tx_buf[i]);
> + kfree(ep->tx_buf[i]);
> }
>
> dma_free_coherent(dev, sizeof(struct ep93xx_descs), ep->descs,
Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Thanks
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 4 Feb 2015 17:31:00 +0100 Another update suggestion was taken into account after a patch was applied from static source code analysis. Markus Elfring (2): Delete an unnecessary check before the function call "release_firmware" Less function calls in cw1200_load_firmware_cw1200() after error detection drivers/net/wireless/cw1200/fwio.c | 40 +++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 16 deletions(-) -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 4 Feb 2015 16:32:15 +0100 The release_firmware() 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/net/wireless/cw1200/fwio.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/wireless/cw1200/fwio.c b/drivers/net/wireless/cw1200/fwio.c index 6f1b9aa..581dfde 100644 --- a/drivers/net/wireless/cw1200/fwio.c +++ b/drivers/net/wireless/cw1200/fwio.c @@ -246,8 +246,7 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv) error: kfree(buf); - if (firmware) - release_firmware(firmware); + release_firmware(firmware); return ret; #undef APB_WRITE -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 4 Feb 2015 17:28:41 +0100 The functions kfree() and release_firmware() were called in a few cases by the cw1200_load_firmware_cw1200() function during error handling even if the passed variables contained still a null pointer. Corresponding implementation details could be improved by adjustments for jump targets. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/net/wireless/cw1200/fwio.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/drivers/net/wireless/cw1200/fwio.c b/drivers/net/wireless/cw1200/fwio.c index 581dfde..30e7646 100644 --- a/drivers/net/wireless/cw1200/fwio.c +++ b/drivers/net/wireless/cw1200/fwio.c @@ -66,25 +66,31 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv) do { \ ret = cw1200_apb_write_32(priv, CW1200_APB(reg), (val)); \ if (ret < 0) \ - goto error; \ + goto exit; \ + } while (0) +#define APB_WRITE2(reg, val) \ + do { \ + ret = cw1200_apb_write_32(priv, CW1200_APB(reg), (val)); \ + if (ret < 0) \ + goto free_buffer; \ } while (0) #define APB_READ(reg, val) \ do { \ ret = cw1200_apb_read_32(priv, CW1200_APB(reg), &(val)); \ if (ret < 0) \ - goto error; \ + goto free_buffer; \ } while (0) #define REG_WRITE(reg, val) \ do { \ ret = cw1200_reg_write_32(priv, (reg), (val)); \ if (ret < 0) \ - goto error; \ + goto exit; \ } while (0) #define REG_READ(reg, val) \ do { \ ret = cw1200_reg_read_32(priv, (reg), &(val)); \ if (ret < 0) \ - goto error; \ + goto exit; \ } while (0) switch (priv->hw_revision) { @@ -142,14 +148,14 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv) ret = request_firmware(&firmware, fw_path, priv->pdev); if (ret) { pr_err("Can't load firmware file %s.\n", fw_path); - goto error; + goto exit; } buf = kmalloc(DOWNLOAD_BLOCK_SIZE, GFP_KERNEL | GFP_DMA); if (!buf) { pr_err("Can't allocate firmware load buffer.\n"); ret = -ENOMEM; - goto error; + goto firmware_release; } /* Check if the bootloader is ready */ @@ -163,7 +169,7 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv) if (val32 != DOWNLOAD_I_AM_HERE) { pr_err("Bootloader is not ready.\n"); ret = -ETIMEDOUT; - goto error; + goto free_buffer; } /* Calculcate number of download blocks */ @@ -171,7 +177,7 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv) /* Updating the length in Download Ctrl Area */ val32 = firmware->size; /* Explicit cast from size_t to u32 */ - APB_WRITE(DOWNLOAD_IMAGE_SIZE_REG, val32); + APB_WRITE2(DOWNLOAD_IMAGE_SIZE_REG, val32); /* Firmware downloading loop */ for (block = 0; block < num_blocks; block++) { @@ -183,7 +189,7 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv) if (val32 != DOWNLOAD_PENDING) { pr_err("Bootloader reported error %d.\n", val32); ret = -EIO; - goto error; + goto free_buffer; } /* loop until put - get <= 24K */ @@ -198,7 +204,7 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv) if ((put - get) > (DOWNLOAD_FIFO_SIZE - DOWNLOAD_BLOCK_SIZE)) { pr_err("Timeout waiting for FIFO.\n"); ret = -ETIMEDOUT; - goto error; + goto free_buffer; } /* calculate the block size */ @@ -220,12 +226,12 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv) if (ret < 0) { pr_err("Can't write firmware block @ %d!\n", put & (DOWNLOAD_FIFO_SIZE - 1)); - goto error; + goto free_buffer; } /* update the put register */ put += block_size; - APB_WRITE(DOWNLOAD_PUT_REG, put); + APB_WRITE2(DOWNLOAD_PUT_REG, put); } /* End of firmware download loop */ /* Wait for the download completion */ @@ -238,18 +244,21 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv) if (val32 != DOWNLOAD_SUCCESS) { pr_err("Wait for download completion failed: 0x%.8X\n", val32); ret = -ETIMEDOUT; - goto error; + goto free_buffer; } else { pr_info("Firmware download completed.\n"); ret = 0; } -error: +free_buffer: kfree(buf); +firmware_release: release_firmware(firmware); +exit: return ret; #undef APB_WRITE +#undef APB_WRITE2 #undef APB_READ #undef REG_WRITE #undef REG_READ -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 4 Feb 2015 18:48:28 +0100 The relay_close() 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/net/wireless/ath/ath9k/common-spectral.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath9k/common-spectral.c b/drivers/net/wireless/ath/ath9k/common-spectral.c index ec93ddf..5cee231 100644 --- a/drivers/net/wireless/ath/ath9k/common-spectral.c +++ b/drivers/net/wireless/ath/ath9k/common-spectral.c @@ -582,7 +582,7 @@ static struct rchan_callbacks rfs_spec_scan_cb = { void ath9k_cmn_spectral_deinit_debug(struct ath_spec_scan_priv *spec_priv) { - if (config_enabled(CONFIG_ATH9K_DEBUGFS) && spec_priv->rfs_chan_spec_scan) { + if (config_enabled(CONFIG_ATH9K_DEBUGFS)) { relay_close(spec_priv->rfs_chan_spec_scan); spec_priv->rfs_chan_spec_scan = NULL; } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 4 Feb 2015 19:30:23 +0100 The release_firmware() 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/net/wireless/ath/ath10k/core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c index 2d0671e..45171ad 100644 --- a/drivers/net/wireless/ath/ath10k/core.c +++ b/drivers/net/wireless/ath/ath10k/core.c @@ -393,16 +393,16 @@ static int ath10k_download_fw(struct ath10k *ar, enum ath10k_firmware_mode mode) static void ath10k_core_free_firmware_files(struct ath10k *ar) { - if (ar->board && !IS_ERR(ar->board)) + if (!IS_ERR(ar->board)) release_firmware(ar->board); - if (ar->otp && !IS_ERR(ar->otp)) + if (!IS_ERR(ar->otp)) release_firmware(ar->otp); - if (ar->firmware && !IS_ERR(ar->firmware)) + if (!IS_ERR(ar->firmware)) release_firmware(ar->firmware); - if (ar->cal_file && !IS_ERR(ar->cal_file)) + if (!IS_ERR(ar->cal_file)) release_firmware(ar->cal_file); ar->board = NULL; -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 4 Feb 2015 19:53:11 +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> --- drivers/net/wireless/orinoco/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/orinoco/main.c b/drivers/net/wireless/orinoco/main.c index 38ec8d1..c410180 100644 --- a/drivers/net/wireless/orinoco/main.c +++ b/drivers/net/wireless/orinoco/main.c @@ -2342,7 +2342,7 @@ void free_orinocodev(struct orinoco_private *priv) list_for_each_entry_safe(sd, sdtemp, &priv->scan_list, list) { list_del(&sd->list); - if ((sd->len > 0) && sd->buf) + if (sd->len > 0) kfree(sd->buf); kfree(sd); } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 4 Feb 2015 20:06:39 +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> --- drivers/net/wireless/hostap/hostap_ap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/hostap/hostap_ap.c b/drivers/net/wireless/hostap/hostap_ap.c index 5965255..fd8d83d 100644 --- a/drivers/net/wireless/hostap/hostap_ap.c +++ b/drivers/net/wireless/hostap/hostap_ap.c @@ -145,7 +145,7 @@ static void ap_free_sta(struct ap_data *ap, struct sta_info *sta) if (sta->aid > 0) ap->sta_aid[sta->aid - 1] = NULL; - if (!sta->ap && sta->u.sta.challenge) + if (!sta->ap) kfree(sta->u.sta.challenge); del_timer_sync(&sta->timer); #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */ -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 4 Feb 2015 20:28:49 +0100 The functions brcmu_pkt_buf_free_skb() and usb_free_urb() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/net/wireless/brcm80211/brcmfmac/sdio.c | 3 +-- drivers/net/wireless/brcm80211/brcmfmac/usb.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/brcm80211/brcmfmac/sdio.c b/drivers/net/wireless/brcm80211/brcmfmac/sdio.c index 99a3776..5b5520b 100644 --- a/drivers/net/wireless/brcm80211/brcmfmac/sdio.c +++ b/drivers/net/wireless/brcm80211/brcmfmac/sdio.c @@ -2543,8 +2543,7 @@ static void brcmf_sdio_bus_stop(struct device *dev) brcmu_pktq_flush(&bus->txq, true, NULL, NULL); /* Clear any held glomming stuff */ - if (bus->glomd) - brcmu_pkt_buf_free_skb(bus->glomd); + brcmu_pkt_buf_free_skb(bus->glomd); brcmf_sdio_free_glom(bus); /* Clear rx control and wake any waiters */ diff --git a/drivers/net/wireless/brcm80211/brcmfmac/usb.c b/drivers/net/wireless/brcm80211/brcmfmac/usb.c index 4572def..10c684c 100644 --- a/drivers/net/wireless/brcm80211/brcmfmac/usb.c +++ b/drivers/net/wireless/brcm80211/brcmfmac/usb.c @@ -421,7 +421,7 @@ fail: brcmf_err("fail!\n"); while (!list_empty(q)) { req = list_entry(q->next, struct brcmf_usbreq, list); - if (req && req->urb) + if (req) usb_free_urb(req->urb); list_del(q->next); } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 4 Feb 2015 20:50:31 +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> --- drivers/misc/sgi-xp/xpc_partition.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/misc/sgi-xp/xpc_partition.c b/drivers/misc/sgi-xp/xpc_partition.c index 6956f7e..0e32431 100644 --- a/drivers/misc/sgi-xp/xpc_partition.c +++ b/drivers/misc/sgi-xp/xpc_partition.c @@ -98,8 +98,7 @@ xpc_get_rsvd_page_pa(int nasid) len = L1_CACHE_ALIGN(len); if (len > buf_len) { - if (buf_base != NULL) - kfree(buf_base); + kfree(buf_base); buf_len = L1_CACHE_ALIGN(len); buf = xpc_kmalloc_cacheline_aligned(buf_len, GFP_KERNEL, &buf_base); -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 4 Feb 2015 21:32:27 +0100 The of_node_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> --- drivers/macintosh/smu.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/macintosh/smu.c b/drivers/macintosh/smu.c index 10ae69b..d531f80 100644 --- a/drivers/macintosh/smu.c +++ b/drivers/macintosh/smu.c @@ -557,8 +557,7 @@ int __init smu_init (void) return 0; fail_msg_node: - if (smu->msg_node) - of_node_put(smu->msg_node); + of_node_put(smu->msg_node); fail_db_node: of_node_put(smu->db_node); fail_bootmem: -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 4 Feb 2015 21:54:45 +0100 The functions phy_power_on() and vunmap() perform also input parameter validation. Thus the test around their calls is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/gpu/drm/exynos/exynos_dp_core.c | 6 ++---- drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/exynos/exynos_dp_core.c b/drivers/gpu/drm/exynos/exynos_dp_core.c index 34d46aa..306cf1d 100644 --- a/drivers/gpu/drm/exynos/exynos_dp_core.c +++ b/drivers/gpu/drm/exynos/exynos_dp_core.c @@ -1057,14 +1057,12 @@ static int exynos_dp_create_connector(struct exynos_drm_display *display, static void exynos_dp_phy_init(struct exynos_dp_device *dp) { - if (dp->phy) - phy_power_on(dp->phy); + phy_power_on(dp->phy); } static void exynos_dp_phy_exit(struct exynos_dp_device *dp) { - if (dp->phy) - phy_power_off(dp->phy); + phy_power_off(dp->phy); } static void exynos_dp_poweron(struct exynos_drm_display *display) diff --git a/drivers/gpu/drm/exynos/exynos_drm_fbdev.c b/drivers/gpu/drm/exynos/exynos_drm_fbdev.c index e12ea90..0dd448a 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_fbdev.c +++ b/drivers/gpu/drm/exynos/exynos_drm_fbdev.c @@ -313,7 +313,7 @@ static void exynos_drm_fbdev_destroy(struct drm_device *dev, struct exynos_drm_gem_obj *exynos_gem_obj = exynos_fbd->exynos_gem_obj; struct drm_framebuffer *fb; - if (is_drm_iommu_supported(dev) && exynos_gem_obj->buffer->kvaddr) + if (is_drm_iommu_supported(dev)) vunmap(exynos_gem_obj->buffer->kvaddr); /* release drm framebuffer and real buffer */ -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 4 Feb 2015 22:22:36 +0100 The functions framebuffer_release() and vunmap() perform also input parameter validation. Thus the test around their calls is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/gpu/drm/omapdrm/omap_fbdev.c | 3 +-- drivers/gpu/drm/omapdrm/omap_gem.c | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/omapdrm/omap_fbdev.c b/drivers/gpu/drm/omapdrm/omap_fbdev.c index d292d24..fcc02b0 100644 --- a/drivers/gpu/drm/omapdrm/omap_fbdev.c +++ b/drivers/gpu/drm/omapdrm/omap_fbdev.c @@ -270,8 +270,7 @@ fail_unlock: fail: if (ret) { - if (fbi) - framebuffer_release(fbi); + framebuffer_release(fbi); if (fb) { drm_framebuffer_unregister_private(fb); drm_framebuffer_remove(fb); diff --git a/drivers/gpu/drm/omapdrm/omap_gem.c b/drivers/gpu/drm/omapdrm/omap_gem.c index aeb91ed..18a4137 100644 --- a/drivers/gpu/drm/omapdrm/omap_gem.c +++ b/drivers/gpu/drm/omapdrm/omap_gem.c @@ -1292,12 +1292,11 @@ void omap_gem_free_object(struct drm_gem_object *obj) if (omap_obj->pages) omap_gem_detach_pages(obj); - if (!is_shmem(obj)) { + if (!is_shmem(obj)) dma_free_writecombine(dev->dev, obj->size, omap_obj->vaddr, omap_obj->paddr); - } else if (omap_obj->vaddr) { + else vunmap(omap_obj->vaddr); - } } /* don't free externally allocated syncobj */ -- 2.2.2
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 03 Feb 2015 19:51:38 +0100
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Tue, 3 Feb 2015 19:47:33 +0100
>
> The of_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>
Applied.
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 03 Feb 2015 20:22:23 +0100
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Tue, 3 Feb 2015 20:12:25 +0100
>
> The functions cpsw_ale_destroy() and of_dev_put() test whether their argument
> is NULL and then return immediately. Thus the test around the call
> is not needed.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Applied.
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 04 Feb 2015 11:38:39 +0100
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 4 Feb 2015 11:28:43 +0100
>
> The release_firmware() 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>
Applied.
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 04 Feb 2015 12:36:02 +0100
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 4 Feb 2015 12:32:14 +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>
Applied.
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 04 Feb 2015 13:00:46 +0100
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 4 Feb 2015 12:56:42 +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>
Applied.
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 04 Feb 2015 13:21:29 +0100
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 4 Feb 2015 13:17:48 +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>
Applied.
Hi,
On 02/05/2015 06:00 AM, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 4 Feb 2015 21:54:45 +0100
>
> The functions phy_power_on() and vunmap() perform also input
> parameter validation. Thus the test around their calls is not needed.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> drivers/gpu/drm/exynos/exynos_dp_core.c | 6 ++----
> drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 2 +-
> 2 files changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/exynos/exynos_dp_core.c b/drivers/gpu/drm/exynos/exynos_dp_core.c
> index 34d46aa..306cf1d 100644
> --- a/drivers/gpu/drm/exynos/exynos_dp_core.c
> +++ b/drivers/gpu/drm/exynos/exynos_dp_core.c
> @@ -1057,14 +1057,12 @@ static int exynos_dp_create_connector(struct exynos_drm_display *display,
>
> static void exynos_dp_phy_init(struct exynos_dp_device *dp)
> {
> - if (dp->phy)
> - phy_power_on(dp->phy);
> + phy_power_on(dp->phy);
> }
>
> static void exynos_dp_phy_exit(struct exynos_dp_device *dp)
> {
> - if (dp->phy)
> - phy_power_off(dp->phy);
> + phy_power_off(dp->phy);
> }
>
> static void exynos_dp_poweron(struct exynos_drm_display *display)
> diff --git a/drivers/gpu/drm/exynos/exynos_drm_fbdev.c b/drivers/gpu/drm/exynos/exynos_drm_fbdev.c
> index e12ea90..0dd448a 100644
> --- a/drivers/gpu/drm/exynos/exynos_drm_fbdev.c
> +++ b/drivers/gpu/drm/exynos/exynos_drm_fbdev.c
> @@ -313,7 +313,7 @@ static void exynos_drm_fbdev_destroy(struct drm_device *dev,
> struct exynos_drm_gem_obj *exynos_gem_obj = exynos_fbd->exynos_gem_obj;
> struct drm_framebuffer *fb;
>
> - if (is_drm_iommu_supported(dev) && exynos_gem_obj->buffer->kvaddr)
> + if (is_drm_iommu_supported(dev))
> vunmap(exynos_gem_obj->buffer->kvaddr);
>
> /* release drm framebuffer and real buffer */
>
Acked-by: Joonyoung Shim <jy0922.shim@samsung.com>
Thanks.
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 04 Feb 2015 14:13:37 +0100
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 4 Feb 2015 14:07:56 +0100
>
> The functions kfree() and vfree() perform also input parameter validation.
> Thus the test around their calls is not needed.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Applied.
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 04 Feb 2015 15:22:33 +0100
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 4 Feb 2015 15:17:00 +0100
>
> The vunmap() 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>
This does not apply cleanly to the net-next tree, please respin.
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 04 Feb 2015 16:00:37 +0100
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 4 Feb 2015 15:56:58 +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>
Applied.
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Feb 2015 10:12:51 +0100 The vunmap() 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/gpu/drm/tegra/fb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/tegra/fb.c b/drivers/gpu/drm/tegra/fb.c index e9c715d..803598e 100644 --- a/drivers/gpu/drm/tegra/fb.c +++ b/drivers/gpu/drm/tegra/fb.c @@ -66,7 +66,7 @@ static void tegra_fb_destroy(struct drm_framebuffer *framebuffer) struct tegra_bo *bo = fb->planes[i]; if (bo) { - if (bo->pages && bo->vaddr) + if (bo->pages) vunmap(bo->vaddr); drm_gem_object_unreference_unlocked(&bo->gem); -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Feb 2015 11:48:26 +0100 The put_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/base/core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 97e2baf..9c6536f 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -1095,8 +1095,7 @@ done: kobject_del(&dev->kobj); Error: cleanup_device_parent(dev); - if (parent) - put_device(parent); + put_device(parent); name_error: kfree(dev->p); dev->p = NULL; -- 2.2.2
Hi Wingman, There are some bugs in this error handling. On Tue, Feb 03, 2015 at 08:22:23PM +0100, SF Markus Elfring wrote: > diff --git a/drivers/net/ethernet/ti/netcp_ethss.c b/drivers/net/ethernet/ti/netcp_ethss.c > index fa1041a..cbd6dde 100644 > --- a/drivers/net/ethernet/ti/netcp_ethss.c > +++ b/drivers/net/ethernet/ti/netcp_ethss.c > @@ -2010,12 +2010,10 @@ static int gbe_probe(struct netcp_device *netcp_device, struct device *dev, > quit: > if (gbe_dev->hw_stats) > devm_kfree(dev, gbe_dev->hw_stats); > - if (gbe_dev->ale) > - cpsw_ale_destroy(gbe_dev->ale); > + cpsw_ale_destroy(gbe_dev->ale); > if (gbe_dev->ss_regs) > devm_iounmap(dev, gbe_dev->ss_regs); > - if (interfaces) > - of_node_put(interfaces); > + of_node_put(interfaces); ^^^^^^^^^^ "interfaces" is sometimes unintialized in this code. I don't know why GCC doesn't catch this... :( This is a "one rrr bug", which is caused because you just have one error label "quit" which handles all the error handling. Please read my Google+ comment on error handling. https://plus.google.com/106378716002406849458/posts/dnanfhQ4mHQ > devm_kfree(dev, gbe_dev); ^^^^^^^^^^^^^^^^^^^^^^^^ This is not the right way to use the devm_ interface. These things are freed automatically on error or when we are done with them. This driver is double freeing pretty much everything. Grep for devm_kfree() and fix everything. I don't know why kbuild didn't catch this... regards dan carpenter
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Feb 2015 13:20:42 +0100 The srp_destroy_fr_pool() 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/infiniband/ulp/srp/ib_srp.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c index 0747c05..6f5dfa1 100644 --- a/drivers/infiniband/ulp/srp/ib_srp.c +++ b/drivers/infiniband/ulp/srp/ib_srp.c @@ -549,8 +549,7 @@ static int srp_create_ch_ib(struct srp_rdma_ch *ch) "FR pool allocation failed (%d)\n", ret); goto err_qp; } - if (ch->fr_pool) - srp_destroy_fr_pool(ch->fr_pool); + srp_destroy_fr_pool(ch->fr_pool); ch->fr_pool = fr_pool; } else if (!dev->use_fast_reg && dev->has_fmr) { fmr_pool = srp_alloc_fmr_pool(target); @@ -615,13 +614,12 @@ static void srp_free_ch_ib(struct srp_target_port *target, if (!ch->qp) return; - if (dev->use_fast_reg) { - if (ch->fr_pool) - srp_destroy_fr_pool(ch->fr_pool); - } else { + if (dev->use_fast_reg) + srp_destroy_fr_pool(ch->fr_pool); + else if (ch->fmr_pool) ib_destroy_fmr_pool(ch->fmr_pool); - } + srp_destroy_qp(ch); ib_destroy_cq(ch->send_cq); ib_destroy_cq(ch->recv_cq); -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Feb 2015 14:10:21 +0100 The functions clk_enable() and clk_disable() test whether their argument is NULL and then return immediately. Thus the test around the calls is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/video/fbdev/au1100fb.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/video/fbdev/au1100fb.c b/drivers/video/fbdev/au1100fb.c index 5956018..47ee023 100644 --- a/drivers/video/fbdev/au1100fb.c +++ b/drivers/video/fbdev/au1100fb.c @@ -605,11 +605,8 @@ int au1100fb_drv_suspend(struct platform_device *dev, pm_message_t state) /* Blank the LCD */ au1100fb_fb_blank(VESA_POWERDOWN, &fbdev->info); - if (fbdev->lcdclk) - clk_disable(fbdev->lcdclk); - + clk_disable(fbdev->lcdclk); memcpy(&fbregs, fbdev->regs, sizeof(struct au1100fb_regs)); - return 0; } @@ -621,13 +618,10 @@ int au1100fb_drv_resume(struct platform_device *dev) return 0; memcpy(fbdev->regs, &fbregs, sizeof(struct au1100fb_regs)); - - if (fbdev->lcdclk) - clk_enable(fbdev->lcdclk); + clk_enable(fbdev->lcdclk); /* Unblank the LCD */ au1100fb_fb_blank(VESA_NO_BLANKING, &fbdev->info); - return 0; } #else -- 2.2.2
On Thu, Feb 05, 2015 at 02:14:54PM +0100, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Thu, 5 Feb 2015 14:10:21 +0100 > > The functions clk_enable() and clk_disable() test whether their argument > is NULL and then return immediately. This isn't true for clk_enable(). "I find it acceptable that some of my update suggestions do not fit to your quality expectations at the moment." -- https://lkml.org/lkml/2015/1/22/446 It's frustrating that you make the same mistake over and over and you are fine with doing that. If you make a mistake and you are fixing a bug, then hopefully you fix more bugs than you introduce. If you make a mistake and you are doing a cleanup then you are really just introducing bugs and that's not helpful. I wish you would find something useful to do instead of sending these patches. :( regards, dan carpenter
>> The functions clk_enable() and clk_disable() test whether their argument >> is NULL and then return immediately. > > This isn't true for clk_enable(). I stumble on an interesting name space issue once more. > It's frustrating that you make the same mistake over and over > and you are fine with doing that. I admit that there can be also risks with my update suggestions in similar ways to contributions from other software developers. A specific function implementation exists which performs also input parameter validation. http://lxr.free-electrons.com/source/drivers/sh/clk/core.c#L291 Such variants might not fit to the functions au1100fb_drv_suspend() and au1100fb_drv_resume(). Do you want that I send a reduced patch? Regards, Markus
On 02/05/15 13:26, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 5 Feb 2015 13:20:42 +0100
>
> The srp_destroy_fr_pool() 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/infiniband/ulp/srp/ib_srp.c | 12 +++++-------
> 1 file changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
> index 0747c05..6f5dfa1 100644
> --- a/drivers/infiniband/ulp/srp/ib_srp.c
> +++ b/drivers/infiniband/ulp/srp/ib_srp.c
> @@ -549,8 +549,7 @@ static int srp_create_ch_ib(struct srp_rdma_ch *ch)
> "FR pool allocation failed (%d)\n", ret);
> goto err_qp;
> }
> - if (ch->fr_pool)
> - srp_destroy_fr_pool(ch->fr_pool);
> + srp_destroy_fr_pool(ch->fr_pool);
> ch->fr_pool = fr_pool;
> } else if (!dev->use_fast_reg && dev->has_fmr) {
> fmr_pool = srp_alloc_fmr_pool(target);
> @@ -615,13 +614,12 @@ static void srp_free_ch_ib(struct srp_target_port *target,
> if (!ch->qp)
> return;
>
> - if (dev->use_fast_reg) {
> - if (ch->fr_pool)
> - srp_destroy_fr_pool(ch->fr_pool);
> - } else {
> + if (dev->use_fast_reg)
> + srp_destroy_fr_pool(ch->fr_pool);
> + else
> if (ch->fmr_pool)
> ib_destroy_fmr_pool(ch->fmr_pool);
> - }
> +
> srp_destroy_qp(ch);
> ib_destroy_cq(ch->send_cq);
> ib_destroy_cq(ch->recv_cq);
This patch makes the code in srp_free_ch_ib() asymmetric which is
unfortunate. Please add a test in ib_destroy_fmr_pool() such that the
check before ib_destroy_fmr_pool() can also be eliminated.
Bart.
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Feb 2015 16:07:43 +0100 The backlight_device_unregister() 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/usb/misc/appledisplay.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c index b3d245e..a0a3827 100644 --- a/drivers/usb/misc/appledisplay.c +++ b/drivers/usb/misc/appledisplay.c @@ -329,7 +329,7 @@ error: pdata->urbdata, pdata->urb->transfer_dma); usb_free_urb(pdata->urb); } - if (pdata->bd && !IS_ERR(pdata->bd)) + if (!IS_ERR(pdata->bd)) backlight_device_unregister(pdata->bd); kfree(pdata->msgdata); } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Feb 2015 16:33:09 +0100 The release_firmware() 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/usb/atm/ueagle-atm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c index 5a45937..888998a 100644 --- a/drivers/usb/atm/ueagle-atm.c +++ b/drivers/usb/atm/ueagle-atm.c @@ -952,7 +952,7 @@ static void uea_load_page_e1(struct work_struct *work) int i; /* reload firmware when reboot start and it's loaded already */ - if (ovl = 0 && pageno = 0 && sc->dsp_firm) { + if (ovl = 0 && pageno = 0) { release_firmware(sc->dsp_firm); sc->dsp_firm = NULL; } @@ -1074,7 +1074,7 @@ static void uea_load_page_e4(struct work_struct *work) uea_dbg(INS_TO_USBDEV(sc), "sending DSP page %u\n", pageno); /* reload firmware when reboot start and it's loaded already */ - if (pageno = 0 && sc->dsp_firm) { + if (pageno = 0) { release_firmware(sc->dsp_firm); sc->dsp_firm = NULL; } -- 2.2.2
RGFuLA0KDQpUaGFua3MuICBXZSdsbCBsb29rIGludG8gaXQgYW5kIHNlbmQgYSBwYXRjaCBzb29u Lg0KDQpSZWdhcmRzLA0KV2luZ01hbg0KDQo+IC0tLS0tT3JpZ2luYWwgTWVzc2FnZS0tLS0tDQo+ IEZyb206IERhbiBDYXJwZW50ZXIgW21haWx0bzpkYW4uY2FycGVudGVyQG9yYWNsZS5jb21dDQo+ IFNlbnQ6IFRodXJzZGF5LCBGZWJydWFyeSAwNSwgMjAxNSA3OjAyIEFNDQo+IFRvOiBLd29rLCBX aW5nTWFuDQo+IENjOiBTRiBNYXJrdXMgRWxmcmluZzsgS2FyaWNoZXJpLCBNdXJhbGlkaGFyYW47 IEt3b2ssIFdpbmdNYW47DQo+IG5ldGRldkB2Z2VyLmtlcm5lbC5vcmc7IExLTUw7IGtlcm5lbC1q YW5pdG9yc0B2Z2VyLmtlcm5lbC5vcmc7IEp1bGlhIExhd2FsbA0KPiBTdWJqZWN0OiBSZTogW1BB VENIXSBOZXRDUDogRGVsZXRpb24gb2YgdW5uZWNlc3NhcnkgY2hlY2tzIGJlZm9yZSB0d28NCj4g ZnVuY3Rpb24gY2FsbHMNCj4gDQo+IEhpIFdpbmdtYW4sDQo+IA0KPiBUaGVyZSBhcmUgc29tZSBi dWdzIGluIHRoaXMgZXJyb3IgaGFuZGxpbmcuDQo+IA0KPiBPbiBUdWUsIEZlYiAwMywgMjAxNSBh dCAwODoyMjoyM1BNICswMTAwLCBTRiBNYXJrdXMgRWxmcmluZyB3cm90ZToNCj4gPiBkaWZmIC0t Z2l0IGEvZHJpdmVycy9uZXQvZXRoZXJuZXQvdGkvbmV0Y3BfZXRoc3MuYw0KPiBiL2RyaXZlcnMv bmV0L2V0aGVybmV0L3RpL25ldGNwX2V0aHNzLmMNCj4gPiBpbmRleCBmYTEwNDFhLi5jYmQ2ZGRl IDEwMDY0NA0KPiA+IC0tLSBhL2RyaXZlcnMvbmV0L2V0aGVybmV0L3RpL25ldGNwX2V0aHNzLmMN Cj4gPiArKysgYi9kcml2ZXJzL25ldC9ldGhlcm5ldC90aS9uZXRjcF9ldGhzcy5jDQo+ID4gQEAg LTIwMTAsMTIgKzIwMTAsMTAgQEAgc3RhdGljIGludCBnYmVfcHJvYmUoc3RydWN0IG5ldGNwX2Rl dmljZQ0KPiAqbmV0Y3BfZGV2aWNlLCBzdHJ1Y3QgZGV2aWNlICpkZXYsDQo+ID4gIHF1aXQ6DQo+ ID4gIAlpZiAoZ2JlX2Rldi0+aHdfc3RhdHMpDQo+ID4gIAkJZGV2bV9rZnJlZShkZXYsIGdiZV9k ZXYtPmh3X3N0YXRzKTsNCj4gPiAtCWlmIChnYmVfZGV2LT5hbGUpDQo+ID4gLQkJY3Bzd19hbGVf ZGVzdHJveShnYmVfZGV2LT5hbGUpOw0KPiA+ICsJY3Bzd19hbGVfZGVzdHJveShnYmVfZGV2LT5h bGUpOw0KPiA+ICAJaWYgKGdiZV9kZXYtPnNzX3JlZ3MpDQo+ID4gIAkJZGV2bV9pb3VubWFwKGRl diwgZ2JlX2Rldi0+c3NfcmVncyk7DQo+ID4gLQlpZiAoaW50ZXJmYWNlcykNCj4gPiAtCQlvZl9u b2RlX3B1dChpbnRlcmZhY2VzKTsNCj4gPiArCW9mX25vZGVfcHV0KGludGVyZmFjZXMpOw0KPiAg ICAgICAgICAgICAgICAgICAgIF5eXl5eXl5eXl4NCj4gImludGVyZmFjZXMiIGlzIHNvbWV0aW1l cyB1bmludGlhbGl6ZWQgaW4gdGhpcyBjb2RlLiAgSSBkb24ndCBrbm93IHdoeQ0KPiBHQ0MgZG9l c24ndCBjYXRjaCB0aGlzLi4uICA6KA0KPiANCj4gVGhpcyBpcyBhICJvbmUgcnJyIGJ1ZyIsIHdo aWNoIGlzIGNhdXNlZCBiZWNhdXNlIHlvdSBqdXN0IGhhdmUgb25lIGVycm9yDQo+IGxhYmVsICJx dWl0IiB3aGljaCBoYW5kbGVzIGFsbCB0aGUgZXJyb3IgaGFuZGxpbmcuICBQbGVhc2UgcmVhZCBt eQ0KPiBHb29nbGUrIGNvbW1lbnQgb24gZXJyb3IgaGFuZGxpbmcuDQo+IA0KPiBodHRwczovL3Bs dXMuZ29vZ2xlLmNvbS8xMDYzNzg3MTYwMDI0MDY4NDk0NTgvcG9zdHMvZG5hbmZoUTRtSFENCj4g DQo+ID4gIAlkZXZtX2tmcmVlKGRldiwgZ2JlX2Rldik7DQo+ICAgICAgICAgXl5eXl5eXl5eXl5e Xl5eXl5eXl5eXl5eDQo+IFRoaXMgaXMgbm90IHRoZSByaWdodCB3YXkgdG8gdXNlIHRoZSBkZXZt XyBpbnRlcmZhY2UuICBUaGVzZSB0aGluZ3MgYXJlDQo+IGZyZWVkIGF1dG9tYXRpY2FsbHkgb24g ZXJyb3Igb3Igd2hlbiB3ZSBhcmUgZG9uZSB3aXRoIHRoZW0uICBUaGlzIGRyaXZlcg0KPiBpcyBk b3VibGUgZnJlZWluZyBwcmV0dHkgbXVjaCBldmVyeXRoaW5nLiAgR3JlcCBmb3IgZGV2bV9rZnJl ZSgpIGFuZA0KPiBmaXggZXZlcnl0aGluZy4NCj4gDQo+IEkgZG9uJ3Qga25vdyB3aHkga2J1aWxk IGRpZG4ndCBjYXRjaCB0aGlzLi4uDQo+IA0KPiByZWdhcmRzDQo+IGRhbiBjYXJwZW50ZXINCg0K
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Feb 2015 16:54:12 +0100 The usb_put_hcd() 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/usb/host/whci/hcd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/usb/host/whci/hcd.c b/drivers/usb/host/whci/hcd.c index d7b363a..43626c4 100644 --- a/drivers/usb/host/whci/hcd.c +++ b/drivers/usb/host/whci/hcd.c @@ -313,8 +313,7 @@ error_wusbhc_create: uwb_rc_put(wusbhc->uwb_rc); error: whc_clean_up(whc); - if (usb_hcd) - usb_put_hcd(usb_hcd); + usb_put_hcd(usb_hcd); return ret; } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Feb 2015 17:35:35 +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/input/joystick/adi.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c index b784257..d09cefa 100644 --- a/drivers/input/joystick/adi.c +++ b/drivers/input/joystick/adi.c @@ -535,8 +535,7 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv) } } fail2: for (i = 0; i < 2; i++) - if (port->adi[i].dev) - input_free_device(port->adi[i].dev); + input_free_device(port->adi[i].dev); gameport_close(gameport); fail1: gameport_set_drvdata(gameport, NULL); kfree(port); -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Feb 2015 17:54: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> --- drivers/iommu/tegra-gart.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/iommu/tegra-gart.c b/drivers/iommu/tegra-gart.c index f722a0c..07a795a 100644 --- a/drivers/iommu/tegra-gart.c +++ b/drivers/iommu/tegra-gart.c @@ -404,8 +404,7 @@ static int tegra_gart_remove(struct platform_device *pdev) struct gart_device *gart = platform_get_drvdata(pdev); writel(0, gart->regs + GART_CONFIG); - if (gart->savedata) - vfree(gart->savedata); + vfree(gart->savedata); gart_handle = NULL; return 0; } -- 2.2.2
On Thu, Feb 05, 2015 at 03:20:27PM +0100, SF Markus Elfring wrote: > >> The functions clk_enable() and clk_disable() test whether their argument > >> is NULL and then return immediately. > > > > This isn't true for clk_enable(). > > I stumble on an interesting name space issue once more. > The "once more" is the problem in this statement. Other people would have stopped making the mistake by now. I am able to see your bugs so you should be able to see your bugs as well. > > > It's frustrating that you make the same mistake over and over > > and you are fine with doing that. > > I admit that there can be also risks with my update suggestions > in similar ways to contributions from other software developers. > At times, I have told other people to stop sending cleanups until they can at least fix a bugs to balance out the bugs they have introduced. It's unacceptable to only introduce bugs and never fix any. regards, dan carpenter
> It's unacceptable to only introduce bugs Such a view is generally fine. Would you like to point any more update candidates out from my suggestion collection? > and never fix any. Would you like to clarify any statistics around my update suggestions? Regards, Markus
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Feb 2015 21:40:29 +0100 The umc_device_unregister() 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/uwb/whci.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/uwb/whci.c b/drivers/uwb/whci.c index 46b7cfc..c3ee39a 100644 --- a/drivers/uwb/whci.c +++ b/drivers/uwb/whci.c @@ -133,8 +133,7 @@ static void whci_del_cap(struct whci_card *card, int n) { struct umc_dev *umc = card->devs[n]; - if (umc != NULL) - umc_device_unregister(umc); + umc_device_unregister(umc); } static int whci_n_caps(struct pci_dev *pci) -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Feb 2015 22:02: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> --- drivers/scsi/bfa/bfad.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/bfa/bfad.c b/drivers/scsi/bfa/bfad.c index e90a374..05c8ca0 100644 --- a/drivers/scsi/bfa/bfad.c +++ b/drivers/scsi/bfa/bfad.c @@ -1810,11 +1810,11 @@ bfad_load_fwimg(struct pci_dev *pdev) static void bfad_free_fwimg(void) { - if (bfi_image_ct2_size && bfi_image_ct2) + if (bfi_image_ct2_size) vfree(bfi_image_ct2); - if (bfi_image_ct_size && bfi_image_ct) + if (bfi_image_ct_size) vfree(bfi_image_ct); - if (bfi_image_cb_size && bfi_image_cb) + if (bfi_image_cb_size) vfree(bfi_image_cb); } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Feb 2015 22:23:48 +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> --- drivers/scsi/aic7xxx/aic7xxx_core.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/scsi/aic7xxx/aic7xxx_core.c b/drivers/scsi/aic7xxx/aic7xxx_core.c index 10172a3..98a5ed1 100644 --- a/drivers/scsi/aic7xxx/aic7xxx_core.c +++ b/drivers/scsi/aic7xxx/aic7xxx_core.c @@ -2200,8 +2200,7 @@ ahc_free_tstate(struct ahc_softc *ahc, u_int scsi_id, char channel, int force) if (channel = 'B') scsi_id += 8; tstate = ahc->enabled_targets[scsi_id]; - if (tstate != NULL) - kfree(tstate); + kfree(tstate); ahc->enabled_targets[scsi_id] = NULL; } #endif @@ -4482,8 +4481,7 @@ ahc_set_unit(struct ahc_softc *ahc, int unit) void ahc_set_name(struct ahc_softc *ahc, char *name) { - if (ahc->name != NULL) - kfree(ahc->name); + kfree(ahc->name); ahc->name = name; } @@ -4550,10 +4548,8 @@ ahc_free(struct ahc_softc *ahc) kfree(ahc->black_hole); } #endif - if (ahc->name != NULL) - kfree(ahc->name); - if (ahc->seep_config != NULL) - kfree(ahc->seep_config); + kfree(ahc->name); + kfree(ahc->seep_config); #ifndef __FreeBSD__ kfree(ahc); #endif @@ -4958,8 +4954,7 @@ ahc_fini_scbdata(struct ahc_softc *ahc) case 0: break; } - if (scb_data->scbarray != NULL) - kfree(scb_data->scbarray); + kfree(scb_data->scbarray); } static void -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Feb 2015 23:17:52 +0100 Another update suggestion was taken into account after a patch was applied from static source code analysis. Markus Elfring (2): Delete an unnecessary check before the function call "kfree" One function call less in lpfc_bsg_hba_set_event() after error detection drivers/scsi/lpfc/lpfc_bsg.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Feb 2015 22:45:02 +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> --- drivers/scsi/lpfc/lpfc_bsg.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c index a7bf359..1af783a 100644 --- a/drivers/scsi/lpfc/lpfc_bsg.c +++ b/drivers/scsi/lpfc/lpfc_bsg.c @@ -1261,9 +1261,7 @@ lpfc_bsg_hba_set_event(struct fc_bsg_job *job) return 0; /* call job done later */ job_error: - if (dd_data != NULL) - kfree(dd_data); - + kfree(dd_data); job->dd_data = NULL; return rc; } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Feb 2015 23:03:52 +0100 The kfree() function was called in two cases by the lpfc_bsg_hba_set_event() function during error handling even if the passed variable "dd_data" 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> --- drivers/scsi/lpfc/lpfc_bsg.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c index 1af783a..b8074cf 100644 --- a/drivers/scsi/lpfc/lpfc_bsg.c +++ b/drivers/scsi/lpfc/lpfc_bsg.c @@ -1240,7 +1240,7 @@ lpfc_bsg_hba_set_event(struct fc_bsg_job *job) "2617 Failed allocation of event " "waiter\n"); rc = -ENOMEM; - goto job_error; + goto free_data; } dd_data->type = TYPE_EVT; dd_data->set_job = NULL; @@ -1260,8 +1260,9 @@ lpfc_bsg_hba_set_event(struct fc_bsg_job *job) spin_unlock_irqrestore(&phba->ct_ev_lock, flags); return 0; /* call job done later */ -job_error: +free_data: kfree(dd_data); +job_error: job->dd_data = NULL; return rc; } -- 2.2.2
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 4 Feb 2015 16:32:15 +0100
>
> The release_firmware() 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>
Thanks, 2 patches applied to wireless-drivers-next.git:
df970d39b90e cw1200: Delete an unnecessary check before the function call "release_firmware"
ee4ddad82356 cw1200: Less function calls in cw1200_load_firmware_cw1200() after error detection
Kalle Valo
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 4 Feb 2015 18:48:28 +0100
>
> The relay_close() 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>
Thanks, applied to wireless-drivers-next.git.
Kalle Valo
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 4 Feb 2015 19:53:11 +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>
Thanks, applied to wireless-drivers-next.git.
Kalle Valo
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 4 Feb 2015 20:06:39 +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>
Thanks, applied to wireless-drivers-next.git.
Kalle Valo
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 4 Feb 2015 20:28:49 +0100
>
> The functions brcmu_pkt_buf_free_skb() and usb_free_urb() test whether
> their argument is NULL and then return immediately. Thus the test around
> the call is not needed.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Thanks, applied to wireless-drivers-next.git.
Kalle Valo
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 6 Feb 2015 18:08:53 +0100 Further update suggestions were taken into account after a patch was applied from static source code analysis. Markus Elfring (3): Deletion of unnecessary checks before the function call "vfree" Less function calls in scsi_debug_init() after error detection Fix exception handling for an alignment/granularity mismatch in scsi_debug_init() drivers/scsi/scsi_debug.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 6 Feb 2015 16:56:57 +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/scsi/scsi_debug.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 1132321..9e4add7 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -4969,12 +4969,9 @@ bus_unreg: dev_unreg: root_device_unregister(pseudo_primary); free_vm: - if (map_storep) - vfree(map_storep); - if (dif_storep) - vfree(dif_storep); + vfree(map_storep); + vfree(dif_storep); vfree(fake_storep); - return ret; } @@ -4989,10 +4986,7 @@ static void __exit scsi_debug_exit(void) driver_unregister(&sdebug_driverfs_driver); bus_unregister(&pseudo_lld_bus); root_device_unregister(pseudo_primary); - - if (dif_storep) - vfree(dif_storep); - + vfree(dif_storep); vfree(fake_storep); } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 6 Feb 2015 17:48:34 +0100 The vfree() function was called in two cases by the scsi_debug_init() function during error handling even if the passed variables "dif_storep" and "map_storep" contained null pointers eventually. This implementation detail could be improved by the introduction of two jump labels. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/scsi/scsi_debug.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 9e4add7..756b7be 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -4887,7 +4887,7 @@ static int __init scsi_debug_init(void) if (dif_storep = NULL) { pr_err("%s: out of mem. (DIX)\n", __func__); ret = -ENOMEM; - goto free_vm; + goto free_fake; } memset(dif_storep, 0xff, dif_size); @@ -4920,7 +4920,7 @@ static int __init scsi_debug_init(void) if (map_storep = NULL) { pr_err("%s: out of mem. (MAP)\n", __func__); ret = -ENOMEM; - goto free_vm; + goto free_dif; } bitmap_zero(map_storep, map_size); @@ -4934,7 +4934,7 @@ static int __init scsi_debug_init(void) if (IS_ERR(pseudo_primary)) { pr_warn("%s: root_device_register() error\n", __func__); ret = PTR_ERR(pseudo_primary); - goto free_vm; + goto free_map; } ret = bus_register(&pseudo_lld_bus); if (ret < 0) { @@ -4968,9 +4968,11 @@ bus_unreg: bus_unregister(&pseudo_lld_bus); dev_unreg: root_device_unregister(pseudo_primary); -free_vm: +free_map: vfree(map_storep); +free_dif: vfree(dif_storep); +free_fake: vfree(fake_storep); return ret; } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 6 Feb 2015 17:57:32 +0100 The scsi_debug_init() function returned directly if the data items "alignment" and "granularity" did not fit together. Let us improve the affected exception handling by replacing the return statement by a goto statement so that previously allocated resources will also be appropriately released. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/scsi/scsi_debug.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 756b7be..2c78663 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -4909,7 +4909,8 @@ static int __init scsi_debug_init(void) scsi_debug_unmap_alignment) { pr_err("%s: ERR: unmap_granularity <= unmap_alignment\n", __func__); - return -EINVAL; + ret = -EINVAL; + goto free_dif; } map_size = lba_to_map_index(sdebug_store_sectors - 1) + 1; -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 6 Feb 2015 19:10:25 +0100 The release_firmware() 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/scsi/csiostor/csio_hw.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/scsi/csiostor/csio_hw.c b/drivers/scsi/csiostor/csio_hw.c index 35c5f83..37fa8bf 100644 --- a/drivers/scsi/csiostor/csio_hw.c +++ b/drivers/scsi/csiostor/csio_hw.c @@ -2117,8 +2117,7 @@ csio_hw_flash_fw(struct csio_hw *hw, int *reset) hw->fw_state, reset); /* Cleaning up */ - if (fw != NULL) - release_firmware(fw); + release_firmware(fw); kfree(card_fw); return ret; } -- 2.2.2
On Mon, Feb 02 2015 at 10:23am -0500,
SF Markus Elfring <elfring@users.sourceforge.net> wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Mon, 2 Feb 2015 15:30:37 +0100
>
> The dm_table_destroy() 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.
Your proposed patch (while technically correct) hurts code clarity.
Nack.
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 6 Feb 2015 23:03:41 +0100 Further update suggestions were taken into account after a patch was applied from static source code analysis. Markus Elfring (4): Deletion of unnecessary checks before three function calls Less function calls in qla4xxx_is_session_exists() after error detection Less function calls in qla4xxx_is_flash_ddb_exists() after error detection Less function calls in qla4xxx_sysfs_ddb_logout() after error detection drivers/scsi/qla4xxx/ql4_mbx.c | 2 +- drivers/scsi/qla4xxx/ql4_os.c | 96 ++++++++++++++++++------------------------ 2 files changed, 42 insertions(+), 56 deletions(-) -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 6 Feb 2015 20:38:23 +0100 The following functions perform also input parameter validation. * iscsi_boot_destroy_kset * kfree * vfree Thus the test around their calls is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/scsi/qla4xxx/ql4_mbx.c | 2 +- drivers/scsi/qla4xxx/ql4_os.c | 31 ++++++++++--------------------- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/drivers/scsi/qla4xxx/ql4_mbx.c b/drivers/scsi/qla4xxx/ql4_mbx.c index c291fdf..2343c0f 100644 --- a/drivers/scsi/qla4xxx/ql4_mbx.c +++ b/drivers/scsi/qla4xxx/ql4_mbx.c @@ -2410,7 +2410,7 @@ exit_free_acb: dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk), acb, acb_dma); exit_config_acb: - if ((acb_config = ACB_CONFIG_SET) && ha->saved_acb) { + if (acb_config = ACB_CONFIG_SET) { kfree(ha->saved_acb); ha->saved_acb = NULL; } diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c index 6d25879..2a00fd3 100644 --- a/drivers/scsi/qla4xxx/ql4_os.c +++ b/drivers/scsi/qla4xxx/ql4_os.c @@ -4131,9 +4131,7 @@ static void qla4xxx_mem_free(struct scsi_qla_host *ha) dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues, ha->queues_dma); - if (ha->fw_dump) - vfree(ha->fw_dump); - + vfree(ha->fw_dump); ha->queues_len = 0; ha->queues = NULL; ha->queues_dma = 0; @@ -4155,8 +4153,7 @@ static void qla4xxx_mem_free(struct scsi_qla_host *ha) if (ha->chap_dma_pool) dma_pool_destroy(ha->chap_dma_pool); - if (ha->chap_list) - vfree(ha->chap_list); + vfree(ha->chap_list); ha->chap_list = NULL; if (ha->fw_ddb_dma_pool) @@ -4175,9 +4172,7 @@ static void qla4xxx_mem_free(struct scsi_qla_host *ha) iounmap(ha->reg); } - if (ha->reset_tmplt.buff) - vfree(ha->reset_tmplt.buff); - + vfree(ha->reset_tmplt.buff); pci_release_regions(ha->pdev); } @@ -6370,10 +6365,8 @@ static int qla4xxx_is_session_exists(struct scsi_qla_host *ha, } exit_check: - if (fw_tddb) - vfree(fw_tddb); - if (tmp_tddb) - vfree(tmp_tddb); + vfree(fw_tddb); + vfree(tmp_tddb); return ret; } @@ -6525,10 +6518,8 @@ static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha, } exit_check: - if (fw_tddb) - vfree(fw_tddb); - if (tmp_tddb) - vfree(tmp_tddb); + vfree(fw_tddb); + vfree(tmp_tddb); return ret; } @@ -7806,10 +7797,8 @@ static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess, ret = -ESRCH; exit_ddb_logout: - if (flash_tddb) - vfree(flash_tddb); - if (tmp_tddb) - vfree(tmp_tddb); + vfree(flash_tddb); + vfree(tmp_tddb); if (fw_ddb_entry) dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma); @@ -9002,7 +8991,7 @@ static void qla4xxx_remove_adapter(struct pci_dev *pdev) /* destroy iface from sysfs */ qla4xxx_destroy_ifaces(ha); - if ((!ql4xdisablesysfsboot) && ha->boot_kset) + if (!ql4xdisablesysfsboot) iscsi_boot_destroy_kset(ha->boot_kset); qla4xxx_destroy_fw_ddb_session(ha); -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 6 Feb 2015 21:14:40 +0100 The vfree() function was called in two cases by the qla4xxx_is_session_exists() function during error handling even if the passed variables "fw_tddb" and "tmp_tddb" contained still a null pointer. * This implementation detail could be improved by adjustments for jump labels. * Let us return immediately after the first failed function call according to the current Linux coding style convention. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/scsi/qla4xxx/ql4_os.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c index 2a00fd3..a7ca479 100644 --- a/drivers/scsi/qla4xxx/ql4_os.c +++ b/drivers/scsi/qla4xxx/ql4_os.c @@ -6327,17 +6327,15 @@ static int qla4xxx_is_session_exists(struct scsi_qla_host *ha, uint32_t *index) { struct ddb_entry *ddb_entry; - struct ql4_tuple_ddb *fw_tddb = NULL; - struct ql4_tuple_ddb *tmp_tddb = NULL; int idx; int ret = QLA_ERROR; + struct ql4_tuple_ddb *tmp_tddb; + struct ql4_tuple_ddb *fw_tddb = vzalloc(sizeof(*fw_tddb)); - fw_tddb = vzalloc(sizeof(*fw_tddb)); if (!fw_tddb) { DEBUG2(ql4_printk(KERN_WARNING, ha, "Memory Allocation failed.\n")); - ret = QLA_SUCCESS; - goto exit_check; + return QLA_SUCCESS; } tmp_tddb = vzalloc(sizeof(*tmp_tddb)); @@ -6345,7 +6343,7 @@ static int qla4xxx_is_session_exists(struct scsi_qla_host *ha, DEBUG2(ql4_printk(KERN_WARNING, ha, "Memory Allocation failed.\n")); ret = QLA_SUCCESS; - goto exit_check; + goto free_fw; } qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL); @@ -6360,13 +6358,14 @@ static int qla4xxx_is_session_exists(struct scsi_qla_host *ha, ret = QLA_SUCCESS; /* found */ if (index != NULL) *index = idx; - goto exit_check; + goto free_tmp; } } -exit_check: - vfree(fw_tddb); +free_tmp: vfree(tmp_tddb); +free_fw: + vfree(fw_tddb); return ret; } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 6 Feb 2015 21:55:55 +0100 The vfree() function was called in two cases by the qla4xxx_is_flash_ddb_exists() function during error handling even if the passed variables "fw_tddb" and "tmp_tddb" contained still a null pointer. * This implementation detail could be improved by adjustments for jump labels. * Let us return immediately after the first failed function call according to the current Linux coding style convention. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/scsi/qla4xxx/ql4_os.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c index a7ca479..e508bc9 100644 --- a/drivers/scsi/qla4xxx/ql4_os.c +++ b/drivers/scsi/qla4xxx/ql4_os.c @@ -6470,16 +6470,14 @@ static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha, struct dev_db_entry *fw_ddb_entry) { struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp; - struct ql4_tuple_ddb *fw_tddb = NULL; - struct ql4_tuple_ddb *tmp_tddb = NULL; int rval, ret = QLA_ERROR; + struct ql4_tuple_ddb *tmp_tddb; + struct ql4_tuple_ddb *fw_tddb = vzalloc(sizeof(*fw_tddb)); - fw_tddb = vzalloc(sizeof(*fw_tddb)); if (!fw_tddb) { DEBUG2(ql4_printk(KERN_WARNING, ha, "Memory Allocation failed.\n")); - ret = QLA_SUCCESS; - goto exit_check; + return QLA_SUCCESS; } tmp_tddb = vzalloc(sizeof(*tmp_tddb)); @@ -6487,7 +6485,7 @@ static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha, DEBUG2(ql4_printk(KERN_WARNING, ha, "Memory Allocation failed.\n")); ret = QLA_SUCCESS; - goto exit_check; + goto vfree_fw; } qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL); @@ -6498,7 +6496,7 @@ static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha, ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true); /* found duplicate ddb */ if (ret = QLA_SUCCESS) - goto exit_check; + goto vfree_tmp; } list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) { @@ -6512,13 +6510,14 @@ static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha, else ret = QLA_SUCCESS; - goto exit_check; + goto vfree_tmp; } } -exit_check: - vfree(fw_tddb); +vfree_tmp: vfree(tmp_tddb); +vfree_fw: + vfree(fw_tddb); return ret; } -- 2.2.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 6 Feb 2015 22:44:23 +0100 The vfree() function was called in three cases by the qla4xxx_sysfs_ddb_logout() function during error handling even if the passed variables "flash_tddb" and "tmp_tddb" contained still a null pointer. * This implementation detail could be improved by adjustments for jump labels. * Let us return immediately after the first failed function call according to the current Linux coding style convention. * Delete also an unnecessary check for the variable "fw_ddb_entry" there. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/scsi/qla4xxx/ql4_os.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c index e508bc9..802390b 100644 --- a/drivers/scsi/qla4xxx/ql4_os.c +++ b/drivers/scsi/qla4xxx/ql4_os.c @@ -7699,23 +7699,22 @@ static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess, { struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); struct scsi_qla_host *ha = to_qla_host(shost); - struct ql4_tuple_ddb *flash_tddb = NULL; - struct ql4_tuple_ddb *tmp_tddb = NULL; - struct dev_db_entry *fw_ddb_entry = NULL; - struct ddb_entry *ddb_entry = NULL; dma_addr_t fw_ddb_dma; uint32_t next_idx = 0; uint32_t state = 0, conn_err = 0; uint16_t conn_id = 0; int idx, index; int status, ret = 0; + struct ql4_tuple_ddb *flash_tddb; + struct ql4_tuple_ddb *tmp_tddb; + struct ddb_entry *ddb_entry; + struct dev_db_entry *fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, + GFP_KERNEL, + &fw_ddb_dma); - fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL, - &fw_ddb_dma); - if (fw_ddb_entry = NULL) { + if (!fw_ddb_entry) { ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__); - ret = -ENOMEM; - goto exit_ddb_logout; + return -ENOMEM; } flash_tddb = vzalloc(sizeof(*flash_tddb)); @@ -7723,7 +7722,7 @@ static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess, ql4_printk(KERN_WARNING, ha, "%s:Memory Allocation failed.\n", __func__); ret = -ENOMEM; - goto exit_ddb_logout; + goto free_pool; } tmp_tddb = vzalloc(sizeof(*tmp_tddb)); @@ -7731,7 +7730,7 @@ static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess, ql4_printk(KERN_WARNING, ha, "%s:Memory Allocation failed.\n", __func__); ret = -ENOMEM; - goto exit_ddb_logout; + goto free_flash; } if (!fnode_sess->targetname) { @@ -7739,7 +7738,7 @@ static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess, "%s:Cannot logout from SendTarget entry\n", __func__); ret = -EPERM; - goto exit_ddb_logout; + goto free_tmp; } if (fnode_sess->is_boot_target) { @@ -7747,7 +7746,7 @@ static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess, "%s: Logout from boot target entry is not permitted.\n", __func__); ret = -EPERM; - goto exit_ddb_logout; + goto free_tmp; } strlcpy(flash_tddb->iscsi_name, fnode_sess->targetname, @@ -7794,12 +7793,12 @@ static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess, if (idx = MAX_DDB_ENTRIES) ret = -ESRCH; -exit_ddb_logout: - vfree(flash_tddb); +free_tmp: vfree(tmp_tddb); - if (fw_ddb_entry) - dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma); - +free_flash: + vfree(flash_tddb); +free_pool: + dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma); return ret; } -- 2.2.2
On Fri, Feb 06, 2015 at 11:15:13PM +0100, SF Markus Elfring wrote:
> diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
> index 2a00fd3..a7ca479 100644
> --- a/drivers/scsi/qla4xxx/ql4_os.c
> +++ b/drivers/scsi/qla4xxx/ql4_os.c
> @@ -6327,17 +6327,15 @@ static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
> uint32_t *index)
> {
> struct ddb_entry *ddb_entry;
> - struct ql4_tuple_ddb *fw_tddb = NULL;
> - struct ql4_tuple_ddb *tmp_tddb = NULL;
> int idx;
> int ret = QLA_ERROR;
> + struct ql4_tuple_ddb *tmp_tddb;
> + struct ql4_tuple_ddb *fw_tddb = vzalloc(sizeof(*fw_tddb));
>
Don't do allocations in the initializers. Same for patches 3 and 4 as
well.
regards,
dan carpenter
On Sat, 7 Feb 2015, Dan Carpenter wrote:
> On Fri, Feb 06, 2015 at 11:15:13PM +0100, SF Markus Elfring wrote:
> > diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
> > index 2a00fd3..a7ca479 100644
> > --- a/drivers/scsi/qla4xxx/ql4_os.c
> > +++ b/drivers/scsi/qla4xxx/ql4_os.c
> > @@ -6327,17 +6327,15 @@ static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
> > uint32_t *index)
> > {
> > struct ddb_entry *ddb_entry;
> > - struct ql4_tuple_ddb *fw_tddb = NULL;
> > - struct ql4_tuple_ddb *tmp_tddb = NULL;
> > int idx;
> > int ret = QLA_ERROR;
> > + struct ql4_tuple_ddb *tmp_tddb;
> > + struct ql4_tuple_ddb *fw_tddb = vzalloc(sizeof(*fw_tddb));
> >
>
> Don't do allocations in the initializers. Same for patches 3 and 4 as
> well.
Why not? I can think of some reasons, but I am wondering what is the
precise one.
thanks,
julia
On Sat, Feb 07, 2015 at 11:11:03AM +0100, Julia Lawall wrote: > On Sat, 7 Feb 2015, Dan Carpenter wrote: > > > On Fri, Feb 06, 2015 at 11:15:13PM +0100, SF Markus Elfring wrote: > > > diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c > > > index 2a00fd3..a7ca479 100644 > > > --- a/drivers/scsi/qla4xxx/ql4_os.c > > > +++ b/drivers/scsi/qla4xxx/ql4_os.c > > > @@ -6327,17 +6327,15 @@ static int qla4xxx_is_session_exists(struct scsi_qla_host *ha, > > > uint32_t *index) > > > { > > > struct ddb_entry *ddb_entry; > > > - struct ql4_tuple_ddb *fw_tddb = NULL; > > > - struct ql4_tuple_ddb *tmp_tddb = NULL; > > > int idx; > > > int ret = QLA_ERROR; > > > + struct ql4_tuple_ddb *tmp_tddb; > > > + struct ql4_tuple_ddb *fw_tddb = vzalloc(sizeof(*fw_tddb)); > > > > > > > Don't do allocations in the initializers. Same for patches 3 and 4 as > > well. > > Why not? I can think of some reasons, but I am wondering what is the > precise one. 1) People gloss over initializers without reading them. You shouldn't put complicated code in initializers. Sarah Sharp is more strict on this than I am. http://www.spinics.net/lists/linux-usb/msg44389.html 2) It means you have to put a line of separation between the allocation and the NULL check, but they should be next to each other. regards, dan carpenter
> 1) People gloss over initializers without reading them. I would find such a habit strange. > You shouldn't put complicated code in initializers. Does the affected memory allocation fall into such a category? > 2) It means you have to put a line of separation between the allocation > and the NULL check, but they should be next to each other. Would you like to extend the Linux coding style documentation? Regards, Markus
> Your proposed patch (while technically correct) hurts code clarity.
How many source code readability and understanding challenges does each
additional condition check cause?
Can the affected place become also a bit more efficient?
Regards,
Markus
> Do symbols which are not exported (no EXPORT_SYMBOL_(GPL)) cause conflicts? How do you think about to mark more functions from your software module as static? > I was under the impression that those are module private. > If they are indeed private then I would prefer to not rename them. Would you like to help in avoiding difficulties around name space issues? Will specific prefixes make understanding a bit easier? Regards, Markus
On Sun, Feb 8, 2015 at 4:55 AM, SF Markus Elfring <elfring@users.sourceforge.net> wrote: >> Your proposed patch (while technically correct) hurts code clarity. > > How many source code readability and understanding challenges does each > additional condition check cause? Please don't make a mountain out of a mole hill in an attempt to defend your robotic patch (I'm quite tired of some of these static analyzer patch submissions). FYI, I did stage your other patch for 3.20, see: https://git.kernel.org/cgit/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=dm-for-3.20&idÐce7e911c97c7c6df1081dcedfefced82a0c6bf > Can the affected place become also a bit more efficient? Efficiency isn't a concern in this instance (it isn't a hot IO path). And even if it were, a branch (with current code) is more efficient vs a a jump + branch (your proposed patch) -- in the case that no active table exists. Now if it likely that old_map does exist then yes your patch is always a very slight win. But given the duality of the calling function (deals with loading a new map and destroying the old map if it exists) I prefer to keep the code as is. Sorry. -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
> FYI, I did stage your other patch for 3.20, see: > https://git.kernel.org/cgit/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=dm-for-3.20&idÐce7e911c97c7c6df1081dcedfefced82a0c6bf Thanks for your acceptance of the suggested clean-up around vfree() function calls at least. Additional source code places can also be reconsidered at other times, can't they? Regards, Markus -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 9 Feb 2015 11:10:41 +0100 The vunmap() 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> Acked-by: Eli Cohen <eli@mellanox.com> --- drivers/net/ethernet/mellanox/mlx4/alloc.c | 2 +- drivers/net/ethernet/mellanox/mlx5/core/alloc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx4/alloc.c b/drivers/net/ethernet/mellanox/mlx4/alloc.c index a716c26..0c51c69 100644 --- a/drivers/net/ethernet/mellanox/mlx4/alloc.c +++ b/drivers/net/ethernet/mellanox/mlx4/alloc.c @@ -662,7 +662,7 @@ void mlx4_buf_free(struct mlx4_dev *dev, int size, struct mlx4_buf *buf) buf->direct.buf, buf->direct.map); else { - if (BITS_PER_LONG = 64 && buf->direct.buf) + if (BITS_PER_LONG = 64) vunmap(buf->direct.buf); for (i = 0; i < buf->nbufs; ++i) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/alloc.c b/drivers/net/ethernet/mellanox/mlx5/core/alloc.c index 56779c1..201ca6d 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/alloc.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/alloc.c @@ -121,7 +121,7 @@ void mlx5_buf_free(struct mlx5_core_dev *dev, struct mlx5_buf *buf) dma_free_coherent(&dev->pdev->dev, buf->size, buf->direct.buf, buf->direct.map); else { - if (BITS_PER_LONG = 64 && buf->direct.buf) + if (BITS_PER_LONG = 64) vunmap(buf->direct.buf); for (i = 0; i < buf->nbufs; i++) -- 2.2.2
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 09 Feb 2015 11:21:26 +0100
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Mon, 9 Feb 2015 11:10:41 +0100
>
> The vunmap() 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>
> Acked-by: Eli Cohen <eli@mellanox.com>
Applied.
On Thu, Feb 05, 2015 at 05:40:20PM +0100, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Thu, 5 Feb 2015 17:35:35 +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> Applied, thank you. > --- > drivers/input/joystick/adi.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c > index b784257..d09cefa 100644 > --- a/drivers/input/joystick/adi.c > +++ b/drivers/input/joystick/adi.c > @@ -535,8 +535,7 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv) > } > } > fail2: for (i = 0; i < 2; i++) > - if (port->adi[i].dev) > - input_free_device(port->adi[i].dev); > + input_free_device(port->adi[i].dev); > gameport_close(gameport); > fail1: gameport_set_drvdata(gameport, NULL); > kfree(port); > -- > 2.2.2 > -- Dmitry
Markus,
Suggestions noted. If not merged, I'll pull them into the next patch set.
-- james
Acked-By: James Smart <james.smart@emulex.com>
On 2/5/2015 5:25 PM, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 5 Feb 2015 23:17:52 +0100
>
> Another update suggestion was taken into account after a patch was applied
> from static source code analysis.
>
> Markus Elfring (2):
> Delete an unnecessary check before the function call "kfree"
> One function call less in lpfc_bsg_hba_set_event() after error detection
>
> drivers/scsi/lpfc/lpfc_bsg.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 21 Feb 2015 14:14:56 +0100 The functions sisfb_search_crt2type(), sisfb_search_specialtiming() and sisfb_search_tvstd() test whether their argument is NULL and then return immediately. Thus the test around their calls is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/video/fbdev/sis/sis_main.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/video/fbdev/sis/sis_main.c b/drivers/video/fbdev/sis/sis_main.c index fcf610e..20ca80f 100644 --- a/drivers/video/fbdev/sis/sis_main.c +++ b/drivers/video/fbdev/sis/sis_main.c @@ -6605,12 +6605,9 @@ static int __init sisfb_init_module(void) sisfb_scalelcd = scalelcd ^ 1; /* Need to check crt2 type first for fstn/dstn */ + sisfb_search_crt2type(forcecrt2type); - if(forcecrt2type) - sisfb_search_crt2type(forcecrt2type); - - if(tvstandard) - sisfb_search_tvstd(tvstandard); + sisfb_search_tvstd(tvstandard); if(mode) sisfb_search_mode(mode, false); @@ -6656,9 +6653,7 @@ static int __init sisfb_init_module(void) sisfb_pdca = (pdc1 & 0x1f); sisfb_nocrt2rate = nocrt2rate; - - if(specialtiming) - sisfb_search_specialtiming(specialtiming); + sisfb_search_specialtiming(specialtiming); if((lvdshl >= 0) && (lvdshl <= 3)) sisfb_lvdshl = lvdshl; -- 2.3.0
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 21 Feb 2015 20:15:16 +0100 Further update suggestions were taken into account after a patch was applied from static source code analysis. Markus Elfring (7): Deletion of unnecessary checks before three function calls Less function calls in ocfs2_convert_inline_data_to_extents() after error detection Less function calls in ocfs2_figure_merge_contig_type() after error detection One function call less in ocfs2_merge_rec_left() after error detection One function call less in ocfs2_merge_rec_right() after error detection One function call less in ocfs2_init_slot_info() after error detection One function call less in user_cluster_connect() after error detection fs/ocfs2/alloc.c | 48 ++++++++++++++++++++++-------------------------- fs/ocfs2/slot_map.c | 4 ++-- fs/ocfs2/stack_user.c | 8 +++----- 3 files changed, 27 insertions(+), 33 deletions(-) -- 2.3.0
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 21 Feb 2015 17:40:57 +0100 The functions kfree(), ocfs2_free_path() and __ocfs2_free_slot_info() test whether their argument is NULL and then return immediately. Thus the test around their calls 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 | 17 +++++------------ fs/ocfs2/slot_map.c | 2 +- fs/ocfs2/stack_user.c | 2 +- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c index 044158b..fdab27c 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,11 +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; } @@ -6996,9 +6991,7 @@ out_commit: out: if (data_ac) ocfs2_free_alloc_context(data_ac); - if (pages) - kfree(pages); - + kfree(pages); return ret; } diff --git a/fs/ocfs2/slot_map.c b/fs/ocfs2/slot_map.c index d5493e3..c5e530a 100644 --- a/fs/ocfs2/slot_map.c +++ b/fs/ocfs2/slot_map.c @@ -452,7 +452,7 @@ int ocfs2_init_slot_info(struct ocfs2_super *osb) osb->slot_info = (struct ocfs2_slot_info *)si; bail: - if (status < 0 && si) + if (status < 0) __ocfs2_free_slot_info(si); return status; diff --git a/fs/ocfs2/stack_user.c b/fs/ocfs2/stack_user.c index 720aa38..c3b7807 100644 --- a/fs/ocfs2/stack_user.c +++ b/fs/ocfs2/stack_user.c @@ -1063,7 +1063,7 @@ static int user_cluster_connect(struct ocfs2_cluster_connection *conn) } out: - if (rc && lc) + if (rc) kfree(lc); return rc; } -- 2.3.0
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 21 Feb 2015 18:19:04 +0100 The kfree() function was called in a few cases by the ocfs2_convert_inline_data_to_extents() function during error handling even if the passed variable "pages" contained a null pointer. * Return from this implementation directly after failure detection for the function call "kcalloc". * Corresponding details could be improved by the introduction of another jump label. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- fs/ocfs2/alloc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c index fdab27c..bf806e5 100644 --- a/fs/ocfs2/alloc.c +++ b/fs/ocfs2/alloc.c @@ -6853,13 +6853,13 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode, if (pages = NULL) { ret = -ENOMEM; mlog_errno(ret); - goto out; + return ret; } ret = ocfs2_reserve_clusters(osb, 1, &data_ac); if (ret) { mlog_errno(ret); - goto out; + goto free_pages; } } @@ -6991,6 +6991,7 @@ out_commit: out: if (data_ac) ocfs2_free_alloc_context(data_ac); +free_pages: kfree(pages); return ret; } -- 2.3.0
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 21 Feb 2015 18:54:25 +0100 The ocfs2_free_path() function was called in some cases by the ocfs2_figure_merge_contig_type() function during error handling even if the passed variables "left_path" and "right_path" contained still a null pointer. Corresponding implementation details could be improved by adjustments for jump labels according to the current Linux coding style convention. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- fs/ocfs2/alloc.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c index bf806e5..370b4ea 100644 --- a/fs/ocfs2/alloc.c +++ b/fs/ocfs2/alloc.c @@ -4332,17 +4332,17 @@ ocfs2_figure_merge_contig_type(struct ocfs2_extent_tree *et, } else if (path->p_tree_depth > 0) { status = ocfs2_find_cpos_for_left_leaf(sb, path, &left_cpos); if (status) - goto out; + goto exit; if (left_cpos != 0) { left_path = ocfs2_new_path_from_path(path); if (!left_path) - goto out; + goto exit; status = ocfs2_find_path(et->et_ci, left_path, left_cpos); if (status) - goto out; + goto free_left_path; new_el = path_leaf_el(left_path); @@ -4359,7 +4359,7 @@ ocfs2_figure_merge_contig_type(struct ocfs2_extent_tree *et, le16_to_cpu(new_el->l_next_free_rec), le16_to_cpu(new_el->l_count)); status = -EINVAL; - goto out; + goto free_left_path; } rec = &new_el->l_recs[ le16_to_cpu(new_el->l_next_free_rec) - 1]; @@ -4386,18 +4386,18 @@ ocfs2_figure_merge_contig_type(struct ocfs2_extent_tree *et, path->p_tree_depth > 0) { status = ocfs2_find_cpos_for_right_leaf(sb, path, &right_cpos); if (status) - goto out; + goto free_left_path; if (right_cpos = 0) - goto out; + goto free_left_path; right_path = ocfs2_new_path_from_path(path); if (!right_path) - goto out; + goto free_left_path; status = ocfs2_find_path(et->et_ci, right_path, right_cpos); if (status) - goto out; + goto free_right_path; new_el = path_leaf_el(right_path); rec = &new_el->l_recs[0]; @@ -4411,7 +4411,7 @@ ocfs2_figure_merge_contig_type(struct ocfs2_extent_tree *et, (unsigned long long)le64_to_cpu(eb->h_blkno), le16_to_cpu(new_el->l_next_free_rec)); status = -EINVAL; - goto out; + goto free_right_path; } rec = &new_el->l_recs[1]; } @@ -4428,9 +4428,11 @@ ocfs2_figure_merge_contig_type(struct ocfs2_extent_tree *et, ret = contig_type; } -out: - ocfs2_free_path(left_path); +free_right_path: ocfs2_free_path(right_path); +free_left_path: + ocfs2_free_path(left_path); +exit: return ret; } -- 2.3.0
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 21 Feb 2015 19:16:33 +0100 The ocfs2_free_path() function was called by the ocfs2_merge_rec_left() function even if a call of the ocfs2_get_left_path() function failed. Return from this implementation directly after corresponding exception handling. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- fs/ocfs2/alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c index 370b4ea..4bdc19f 100644 --- a/fs/ocfs2/alloc.c +++ b/fs/ocfs2/alloc.c @@ -3535,7 +3535,7 @@ static int ocfs2_merge_rec_left(struct ocfs2_path *right_path, ret = ocfs2_get_left_path(et, right_path, &left_path); if (ret) { mlog_errno(ret); - goto out; + return ret; } left_el = path_leaf_el(left_path); -- 2.3.0
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 21 Feb 2015 19:23:55 +0100 The ocfs2_free_path() function was called by the ocfs2_merge_rec_right() function even if a call of the ocfs2_get_right_path() function failed. Return from this implementation directly after corresponding exception handling. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- fs/ocfs2/alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c index 4bdc19f..2d7f76e 100644 --- a/fs/ocfs2/alloc.c +++ b/fs/ocfs2/alloc.c @@ -3370,7 +3370,7 @@ static int ocfs2_merge_rec_right(struct ocfs2_path *left_path, ret = ocfs2_get_right_path(et, left_path, &right_path); if (ret) { mlog_errno(ret); - goto out; + return ret; } right_el = path_leaf_el(right_path); -- 2.3.0
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 21 Feb 2015 19:49:50 +0100 The __ocfs2_free_slot_info() function was called by the ocfs2_init_slot_info() function even if a call of the kzalloc() function failed. Return from this implementation directly after corresponding exception handling. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- fs/ocfs2/slot_map.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ocfs2/slot_map.c b/fs/ocfs2/slot_map.c index c5e530a..e78a203 100644 --- a/fs/ocfs2/slot_map.c +++ b/fs/ocfs2/slot_map.c @@ -427,7 +427,7 @@ int ocfs2_init_slot_info(struct ocfs2_super *osb) if (!si) { status = -ENOMEM; mlog_errno(status); - goto bail; + return status; } si->si_extended = ocfs2_uses_extended_slot_map(osb); -- 2.3.0
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 21 Feb 2015 20:09:00 +0100 The kfree() function was called by the user_cluster_connect() function even if a previous call of the kzalloc() function failed. Return from this implementation directly after failure detection. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- fs/ocfs2/stack_user.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/ocfs2/stack_user.c b/fs/ocfs2/stack_user.c index c3b7807..2768eb1 100644 --- a/fs/ocfs2/stack_user.c +++ b/fs/ocfs2/stack_user.c @@ -1004,10 +1004,8 @@ static int user_cluster_connect(struct ocfs2_cluster_connection *conn) BUG_ON(conn = NULL); lc = kzalloc(sizeof(struct ocfs2_live_connection), GFP_KERNEL); - if (!lc) { - rc = -ENOMEM; - goto out; - } + if (!lc) + return -ENOMEM; init_waitqueue_head(&lc->oc_wait); init_completion(&lc->oc_sync_wait); -- 2.3.0
On 15-02-06 12:23 PM, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Fri, 6 Feb 2015 16:56:57 +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> Acked-by: Douglas Gilbert <dgilbert@interlog.com> > --- > drivers/scsi/scsi_debug.c | 12 +++--------- > 1 file changed, 3 insertions(+), 9 deletions(-) > > diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c > index 1132321..9e4add7 100644 > --- a/drivers/scsi/scsi_debug.c > +++ b/drivers/scsi/scsi_debug.c > @@ -4969,12 +4969,9 @@ bus_unreg: > dev_unreg: > root_device_unregister(pseudo_primary); > free_vm: > - if (map_storep) > - vfree(map_storep); > - if (dif_storep) > - vfree(dif_storep); > + vfree(map_storep); > + vfree(dif_storep); > vfree(fake_storep); > - > return ret; > } > > @@ -4989,10 +4986,7 @@ static void __exit scsi_debug_exit(void) > driver_unregister(&sdebug_driverfs_driver); > bus_unregister(&pseudo_lld_bus); > root_device_unregister(pseudo_primary); > - > - if (dif_storep) > - vfree(dif_storep); > - > + vfree(dif_storep); > vfree(fake_storep); > } > >
On 15-02-06 12:25 PM, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Fri, 6 Feb 2015 17:48:34 +0100 > > The vfree() function was called in two cases by the scsi_debug_init() function > during error handling even if the passed variables "dif_storep" and > "map_storep" contained null pointers eventually. > > This implementation detail could be improved by the introduction of two > jump labels. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> Acked-by: Douglas Gilbert <dgilbert@interlog.com> > --- > drivers/scsi/scsi_debug.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c > index 9e4add7..756b7be 100644 > --- a/drivers/scsi/scsi_debug.c > +++ b/drivers/scsi/scsi_debug.c > @@ -4887,7 +4887,7 @@ static int __init scsi_debug_init(void) > if (dif_storep = NULL) { > pr_err("%s: out of mem. (DIX)\n", __func__); > ret = -ENOMEM; > - goto free_vm; > + goto free_fake; > } > > memset(dif_storep, 0xff, dif_size); > @@ -4920,7 +4920,7 @@ static int __init scsi_debug_init(void) > if (map_storep = NULL) { > pr_err("%s: out of mem. (MAP)\n", __func__); > ret = -ENOMEM; > - goto free_vm; > + goto free_dif; > } > > bitmap_zero(map_storep, map_size); > @@ -4934,7 +4934,7 @@ static int __init scsi_debug_init(void) > if (IS_ERR(pseudo_primary)) { > pr_warn("%s: root_device_register() error\n", __func__); > ret = PTR_ERR(pseudo_primary); > - goto free_vm; > + goto free_map; > } > ret = bus_register(&pseudo_lld_bus); > if (ret < 0) { > @@ -4968,9 +4968,11 @@ bus_unreg: > bus_unregister(&pseudo_lld_bus); > dev_unreg: > root_device_unregister(pseudo_primary); > -free_vm: > +free_map: > vfree(map_storep); > +free_dif: > vfree(dif_storep); > +free_fake: > vfree(fake_storep); > return ret; > } >
On 15-02-06 12:26 PM, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Fri, 6 Feb 2015 17:57:32 +0100 > > The scsi_debug_init() function returned directly if the data items "alignment" > and "granularity" did not fit together. > > Let us improve the affected exception handling by replacing the return > statement by a goto statement so that previously allocated resources will also > be appropriately released. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> Acked-by: Douglas Gilbert <dgilbert@interlog.com> > --- > drivers/scsi/scsi_debug.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c > index 756b7be..2c78663 100644 > --- a/drivers/scsi/scsi_debug.c > +++ b/drivers/scsi/scsi_debug.c > @@ -4909,7 +4909,8 @@ static int __init scsi_debug_init(void) > scsi_debug_unmap_alignment) { > pr_err("%s: ERR: unmap_granularity <= unmap_alignment\n", > __func__); > - return -EINVAL; > + ret = -EINVAL; > + goto free_dif; > } > > map_size = lba_to_map_index(sdebug_store_sectors - 1) + 1; >
SF Markus Elfring <elfring@users.sourceforge.net> writes:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 4 Feb 2015 19:30:23 +0100
>
> The release_firmware() 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>
Thanks, applied to ath.git.
--
Kalle Valo
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 23 Jun 2015 22:30:21 +0200 The kzfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- crypto/jitterentropy.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crypto/jitterentropy.c b/crypto/jitterentropy.c index d3c3045..22ded3e 100644 --- a/crypto/jitterentropy.c +++ b/crypto/jitterentropy.c @@ -698,11 +698,9 @@ static struct rand_data *jent_entropy_collector_alloc(unsigned int osr, static void jent_entropy_collector_free(struct rand_data *entropy_collector) { - if (entropy_collector->mem) - kzfree(entropy_collector->mem); + kzfree(entropy_collector->mem); entropy_collector->mem = NULL; - if (entropy_collector) - kzfree(entropy_collector); + kzfree(entropy_collector); entropy_collector = NULL; } -- 2.4.4
Am Dienstag, 23. Juni 2015, 23:20:21 schrieb SF Markus Elfring: Hi Markus, > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Tue, 23 Jun 2015 22:30:21 +0200 > > The kzfree() function tests whether its argument is NULL and then > returns immediately. Thus the test around the call is not needed. > > This issue was detected by using the Coccinelle software. Ack: the patch is correct and I was overzealous. Nack: I just proposed a patch earlier today to avoid compiler warnings [1]. That patch clashes with yours. May I ask you to wait briefly to see whether that patch will be accepted? If yes, it would be great if you could repost the patch that applies to the changed code. PS: when you are at it, maybe even the last line in the function can be removed: setting the entropy_collector to NULL at that the end of the function is moot as well. Thanks. [1] http://lkml.iu.edu/hypermail/linux/kernel/1506.2/05196.html > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > crypto/jitterentropy.c | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/crypto/jitterentropy.c b/crypto/jitterentropy.c > index d3c3045..22ded3e 100644 > --- a/crypto/jitterentropy.c > +++ b/crypto/jitterentropy.c > @@ -698,11 +698,9 @@ static struct rand_data > *jent_entropy_collector_alloc(unsigned int osr, > > static void jent_entropy_collector_free(struct rand_data > *entropy_collector) { > - if (entropy_collector->mem) > - kzfree(entropy_collector->mem); > + kzfree(entropy_collector->mem); > entropy_collector->mem = NULL; > - if (entropy_collector) > - kzfree(entropy_collector); > + kzfree(entropy_collector); > entropy_collector = NULL; > } -- Ciao Stephan
The other NULL assignment isn't useful either. Also If "entropy_collector" is NULL then we would oops calling kzfree(entropy_collector->mem); ^^^^^^^^^^^^^^^^^^^^^^ Dereference. I don't understand the patch that you sent. We shouldn't be introducing jent_zalloc() or jent_zfree(). Why are you adding abstractions there? Quite bad ones as well. regards, dan carpenter
Am Mittwoch, 24. Juni 2015, 10:48:19 schrieb Dan Carpenter: Hi Dan, >The other NULL assignment isn't useful either. Also If >"entropy_collector" is NULL then we would oops calling >kzfree(entropy_collector->mem); > ^^^^^^^^^^^^^^^^^^^^^^ >Dereference. > >I don't understand the patch that you sent. We shouldn't be introducing >jent_zalloc() or jent_zfree(). Why are you adding abstractions there? The one C file should have no dependencies on any kernel header files. Thus, all links to kernel functions are wrapped. >Quite bad ones as well. What would you suggest to change? Thanks. Ciao Stephan
Ah. I should have read the whole thread. I sort of assumed we were just adding abstractions for the fun of it (because I have worked in staging for too long). regards, dan carpenter
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 24 Jun 2015 11:41:46 +0200 Return from the __einj_error_trigger() function directly after a failed call for the request_mem_region() function according to the current Linux coding style convention. Drop an unnecessary initialisation for the variable "trigger_tab" then. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/acpi/apei/einj.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/acpi/apei/einj.c b/drivers/acpi/apei/einj.c index a095d4f..c3a2c06 100644 --- a/drivers/acpi/apei/einj.c +++ b/drivers/acpi/apei/einj.c @@ -299,7 +299,7 @@ static struct acpi_generic_address *einj_get_trigger_parameter_region( static int __einj_error_trigger(u64 trigger_paddr, u32 type, u64 param1, u64 param2) { - struct acpi_einj_trigger *trigger_tab = NULL; + struct acpi_einj_trigger *trigger_tab; struct apei_exec_context trigger_ctx; struct apei_resources trigger_resources; struct acpi_whea_header *trigger_entry; @@ -316,7 +316,7 @@ static int __einj_error_trigger(u64 trigger_paddr, u32 type, (unsigned long long)trigger_paddr, (unsigned long long)trigger_paddr + sizeof(*trigger_tab) - 1); - goto out; + return rc; } trigger_tab = ioremap_cache(trigger_paddr, sizeof(*trigger_tab)); if (!trigger_tab) { @@ -407,7 +407,7 @@ out_rel_entry: table_size - sizeof(*trigger_tab)); out_rel_header: release_mem_region(trigger_paddr, sizeof(*trigger_tab)); -out: + if (trigger_tab) iounmap(trigger_tab); -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 24 Jun 2015 13:33:47 +0200 The acpi_ds_delete_walk_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> --- drivers/acpi/acpica/dsmethod.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/acpi/acpica/dsmethod.c b/drivers/acpi/acpica/dsmethod.c index 85bb951..188b254 100644 --- a/drivers/acpi/acpica/dsmethod.c +++ b/drivers/acpi/acpica/dsmethod.c @@ -574,10 +574,7 @@ cleanup: /* On error, we must terminate the method properly */ acpi_ds_terminate_control_method(obj_desc, next_walk_state); - if (next_walk_state) { - acpi_ds_delete_walk_state(next_walk_state); - } - + acpi_ds_delete_walk_state(next_walk_state); return_ACPI_STATUS(status); } -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 24 Jun 2015 14:30:17 +0200 The kdbus_domain_unref() 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> --- ipc/kdbus/fs.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ipc/kdbus/fs.c b/ipc/kdbus/fs.c index d01f33b..205a3ad 100644 --- a/ipc/kdbus/fs.c +++ b/ipc/kdbus/fs.c @@ -325,9 +325,7 @@ static void fs_super_kill(struct super_block *sb) } kill_anon_super(sb); - - if (domain) - kdbus_domain_unref(domain); + kdbus_domain_unref(domain); } static int fs_super_set(struct super_block *sb, void *data) -- 2.4.4
Hi On Wed, Jun 24, 2015 at 2:40 PM, SF Markus Elfring <elfring@users.sourceforge.net> wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Wed, 24 Jun 2015 14:30:17 +0200 > > The kdbus_domain_unref() 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> > --- > ipc/kdbus/fs.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/ipc/kdbus/fs.c b/ipc/kdbus/fs.c > index d01f33b..205a3ad 100644 > --- a/ipc/kdbus/fs.c > +++ b/ipc/kdbus/fs.c > @@ -325,9 +325,7 @@ static void fs_super_kill(struct super_block *sb) > } > > kill_anon_super(sb); > - > - if (domain) > - kdbus_domain_unref(domain); > + kdbus_domain_unref(domain); Yeah, your patch is correct. The condition was kinda nice as it shows the connection to the tear-down before the call to kill_anon_super(). But the function is simple enough for a reader to figure out themselves. Reviewed-by: David Herrmann <dh.herrmann@gmail.com> Thanks David > } > > static int fs_super_set(struct super_block *sb, void *data) > -- > 2.4.4 >
On Wed, Jun 24, 2015 at 02:40:11PM +0200, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Wed, 24 Jun 2015 14:30:17 +0200 > > The kdbus_domain_unref() 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> > --- > ipc/kdbus/fs.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/ipc/kdbus/fs.c b/ipc/kdbus/fs.c > index d01f33b..205a3ad 100644 > --- a/ipc/kdbus/fs.c > +++ b/ipc/kdbus/fs.c > @@ -325,9 +325,7 @@ static void fs_super_kill(struct super_block *sb) > } > > kill_anon_super(sb); > - > - if (domain) > - kdbus_domain_unref(domain); > + kdbus_domain_unref(domain); > } > > static int fs_super_set(struct super_block *sb, void *data) > -- > 2.4.4 > Reviewed-by: Djalal Harouni <tixxdz@opendz.org> -- Djalal Harouni http://opendz.org
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 24 Jun 2015 15:16:35 +0200 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 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/security/keys/process_keys.c b/security/keys/process_keys.c index bd536cb..225dd08 100644 --- a/security/keys/process_keys.c +++ b/security/keys/process_keys.c @@ -242,9 +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.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 24 Jun 2015 16:06:21 +0200 The put_disk() 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/scsi/osd/osd_uld.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/scsi/osd/osd_uld.c b/drivers/scsi/osd/osd_uld.c index 243eab3..e2075522 100644 --- a/drivers/scsi/osd/osd_uld.c +++ b/drivers/scsi/osd/osd_uld.c @@ -407,9 +407,7 @@ static void __remove(struct device *dev) OSD_INFO("osd_remove %s\n", oud->disk ? oud->disk->disk_name : NULL); - - if (oud->disk) - put_disk(oud->disk); + put_disk(oud->disk); ida_remove(&osd_minor_ida, oud->minor); kfree(oud); -- 2.4.4
On Wed, Jun 24, 2015 at 04:16:34PM +0200, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Wed, 24 Jun 2015 16:06:21 +0200 > > The put_disk() 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/scsi/osd/osd_uld.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/drivers/scsi/osd/osd_uld.c b/drivers/scsi/osd/osd_uld.c > index 243eab3..e2075522 100644 > --- a/drivers/scsi/osd/osd_uld.c > +++ b/drivers/scsi/osd/osd_uld.c > @@ -407,9 +407,7 @@ static void __remove(struct device *dev) > > OSD_INFO("osd_remove %s\n", > oud->disk ? oud->disk->disk_name : NULL); > - > - if (oud->disk) > - put_disk(oud->disk); > + put_disk(oud->disk); > ida_remove(&osd_minor_ida, oud->minor); > > kfree(oud); > -- > 2.4.4 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-scsi" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de> -- Johannes Thumshirn Storage jthumshirn@suse.de +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG Nürnberg) -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
R290IGl0LCB0aGFua3MuDQoNCg0KPiAtLS0tLU9yaWdpbmFsIE1lc3NhZ2UtLS0tLQ0KPiBGcm9t OiBTRiBNYXJrdXMgRWxmcmluZyBbbWFpbHRvOmVsZnJpbmdAdXNlcnMuc291cmNlZm9yZ2UubmV0 XQ0KPiBTZW50OiBXZWRuZXNkYXksIEp1bmUgMjQsIDIwMTUgNDo0NiBBTQ0KPiBUbzogTGVuIEJy b3duOyBaaGVuZywgTHY7IFd5c29ja2ksIFJhZmFlbCBKOyBNb29yZSwgUm9iZXJ0OyBsaW51eC0N Cj4gYWNwaUB2Z2VyLmtlcm5lbC5vcmc7IGRldmVsQGFjcGljYS5vcmcNCj4gQ2M6IExLTUw7IGtl cm5lbC1qYW5pdG9yc0B2Z2VyLmtlcm5lbC5vcmc7IEp1bGlhIExhd2FsbA0KPiBTdWJqZWN0OiBb UEFUQ0hdIEFDUElDQTogRGVsZXRlIGFuIHVubmVjZXNzYXJ5IGNoZWNrIGJlZm9yZSB0aGUgZnVu Y3Rpb24NCj4gY2FsbCAiYWNwaV9kc19kZWxldGVfd2Fsa19zdGF0ZSINCj4gDQo+IEZyb206IE1h cmt1cyBFbGZyaW5nIDxlbGZyaW5nQHVzZXJzLnNvdXJjZWZvcmdlLm5ldD4NCj4gRGF0ZTogV2Vk LCAyNCBKdW4gMjAxNSAxMzozMzo0NyArMDIwMA0KPiANCj4gVGhlIGFjcGlfZHNfZGVsZXRlX3dh bGtfc3RhdGUoKSBmdW5jdGlvbiB0ZXN0cyB3aGV0aGVyIGl0cyBhcmd1bWVudCBpcw0KPiBOVUxM IGFuZCB0aGVuIHJldHVybnMgaW1tZWRpYXRlbHkuIFRodXMgdGhlIHRlc3QgYXJvdW5kIHRoZSBj YWxsIGlzIG5vdA0KPiBuZWVkZWQuDQo+IA0KPiBUaGlzIGlzc3VlIHdhcyBkZXRlY3RlZCBieSB1 c2luZyB0aGUgQ29jY2luZWxsZSBzb2Z0d2FyZS4NCj4gDQo+IFNpZ25lZC1vZmYtYnk6IE1hcmt1 cyBFbGZyaW5nIDxlbGZyaW5nQHVzZXJzLnNvdXJjZWZvcmdlLm5ldD4NCj4gLS0tDQo+ICBkcml2 ZXJzL2FjcGkvYWNwaWNhL2RzbWV0aG9kLmMgfCA1ICstLS0tDQo+ICAxIGZpbGUgY2hhbmdlZCwg MSBpbnNlcnRpb24oKyksIDQgZGVsZXRpb25zKC0pDQo+IA0KPiBkaWZmIC0tZ2l0IGEvZHJpdmVy cy9hY3BpL2FjcGljYS9kc21ldGhvZC5jDQo+IGIvZHJpdmVycy9hY3BpL2FjcGljYS9kc21ldGhv ZC5jIGluZGV4IDg1YmI5NTEuLjE4OGIyNTQgMTAwNjQ0DQo+IC0tLSBhL2RyaXZlcnMvYWNwaS9h Y3BpY2EvZHNtZXRob2QuYw0KPiArKysgYi9kcml2ZXJzL2FjcGkvYWNwaWNhL2RzbWV0aG9kLmMN Cj4gQEAgLTU3NCwxMCArNTc0LDcgQEAgY2xlYW51cDoNCj4gIAkvKiBPbiBlcnJvciwgd2UgbXVz dCB0ZXJtaW5hdGUgdGhlIG1ldGhvZCBwcm9wZXJseSAqLw0KPiANCj4gIAlhY3BpX2RzX3Rlcm1p bmF0ZV9jb250cm9sX21ldGhvZChvYmpfZGVzYywgbmV4dF93YWxrX3N0YXRlKTsNCj4gLQlpZiAo bmV4dF93YWxrX3N0YXRlKSB7DQo+IC0JCWFjcGlfZHNfZGVsZXRlX3dhbGtfc3RhdGUobmV4dF93 YWxrX3N0YXRlKTsNCj4gLQl9DQo+IC0NCj4gKwlhY3BpX2RzX2RlbGV0ZV93YWxrX3N0YXRlKG5l eHRfd2Fsa19zdGF0ZSk7DQo+ICAJcmV0dXJuX0FDUElfU1RBVFVTKHN0YXR1cyk7DQo+ICB9DQo+ IA0KPiAtLQ0KPiAyLjQuNA0KDQo
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 24 Jun 2015 17:15:17 +0200 The wd33c93_setup() 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/scsi/wd33c93.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/wd33c93.c b/drivers/scsi/wd33c93.c index 9e09da4..e5ed956 100644 --- a/drivers/scsi/wd33c93.c +++ b/drivers/scsi/wd33c93.c @@ -1939,7 +1939,7 @@ wd33c93_init(struct Scsi_Host *instance, const wd33c93_regs regs, int val; char buf[32]; - if (!done_setup && setup_strings) + if (!done_setup) wd33c93_setup(setup_strings); hostdata = (struct WD33C93_hostdata *) instance->hostdata; -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 24 Jun 2015 17:50:32 +0200 The fc_fcp_ddp_done() 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/scsi/libfc/fc_exch.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c index 1b3a094..aad6f48 100644 --- a/drivers/scsi/libfc/fc_exch.c +++ b/drivers/scsi/libfc/fc_exch.c @@ -2120,8 +2120,7 @@ static struct fc_seq *fc_exch_seq_send(struct fc_lport *lport, spin_unlock_bh(&ep->ex_lock); return sp; err: - if (fsp) - fc_fcp_ddp_done(fsp); + fc_fcp_ddp_done(fsp); rc = fc_exch_done_locked(ep); spin_unlock_bh(&ep->ex_lock); if (!rc) -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 24 Jun 2015 19:24:01 +0200 The put_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/scsi/hosts.c | 4 +--- drivers/scsi/scsi_sysfs.c | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c index 8bb173e..84c8565 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -336,9 +336,7 @@ static void scsi_host_dev_release(struct device *dev) } kfree(shost->shost_data); - - if (parent) - put_device(parent); + put_device(parent); kfree(shost); } diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index 1ac38e7..9ed5391 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -425,9 +425,7 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work) kfree(sdev->vpd_pg80); kfree(sdev->inquiry); kfree(sdev); - - if (parent) - put_device(parent); + put_device(parent); } static void scsi_device_dev_release(struct device *dev) -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 24 Jun 2015 20:40:35 +0200 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/scsi/fnic/fnic_debugfs.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/scsi/fnic/fnic_debugfs.c b/drivers/scsi/fnic/fnic_debugfs.c index d6498fa..855d382 100644 --- a/drivers/scsi/fnic/fnic_debugfs.c +++ b/drivers/scsi/fnic/fnic_debugfs.c @@ -102,9 +102,7 @@ void fnic_debugfs_terminate(void) debugfs_remove(fnic_trace_debugfs_root); fnic_trace_debugfs_root = NULL; - - if (fc_trc_flag) - vfree(fc_trc_flag); + vfree(fc_trc_flag); } /* -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 24 Jun 2015 22:40:30 +0200 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> --- arch/s390/kernel/process.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c index dc5edc2..22e6448 100644 --- a/arch/s390/kernel/process.c +++ b/arch/s390/kernel/process.c @@ -81,8 +81,7 @@ void release_thread(struct task_struct *dead_task) void arch_release_task_struct(struct task_struct *tsk) { - if (tsk->thread.vxrs) - kfree(tsk->thread.vxrs); + kfree(tsk->thread.vxrs); } int copy_thread(unsigned long clone_flags, unsigned long new_stackp, -- 2.4.4
On Wed, Jun 24, 2015 at 05:33:50PM +0200, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Wed, 24 Jun 2015 17:15:17 +0200 > > The wd33c93_setup() function performs also input parameter validation. > Thus the test around the call is not needed. > Guys, you should be aware that Markus auto generates his patches and he doesn't even do a cursory review. "I find it acceptable that some of my update suggestions do not fit to your quality expectations at the moment." -- Markus Elfring (https://lkml.org/lkml/2015/1/22/446) regards, dan carpenter
Am 24.06.2015 22:48, schrieb SF Markus Elfring:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 24 Jun 2015 22:40:30 +0200
>
> 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>
> ---
> arch/s390/kernel/process.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
> index dc5edc2..22e6448 100644
> --- a/arch/s390/kernel/process.c
> +++ b/arch/s390/kernel/process.c
> @@ -81,8 +81,7 @@ void release_thread(struct task_struct *dead_task)
>
> void arch_release_task_struct(struct task_struct *tsk)
> {
> - if (tsk->thread.vxrs)
> - kfree(tsk->thread.vxrs);
> + kfree(tsk->thread.vxrs);
> }
>
> int copy_thread(unsigned long clone_flags, unsigned long new_stackp,
maybe the intention was to check tsk != NULL ?
re,
wh
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 25 Jun 2015 13:24:35 +0200 Some functions which release a system resource tolerate the passing of a null pointer. I do not see a need because of this fact that a function caller repeats a corresponding check. Markus Elfring (2): Delete a check before the function call "omap_device_delete" Delete a check before the function call "of_node_put" arch/arm/mach-omap2/omap_device.c | 3 +-- arch/arm/mach-omap2/timer.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) -- 2.4.4
On Thu, Jun 25, 2015 at 12:02:28PM +0200, walter harms wrote: > > Am 24.06.2015 22:48, schrieb SF Markus Elfring: > > From: Markus Elfring <elfring@users.sourceforge.net> > > Date: Wed, 24 Jun 2015 22:40:30 +0200 > > > > 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> > > --- > > arch/s390/kernel/process.c | 3 +-- > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c > > index dc5edc2..22e6448 100644 > > --- a/arch/s390/kernel/process.c > > +++ b/arch/s390/kernel/process.c > > @@ -81,8 +81,7 @@ void release_thread(struct task_struct *dead_task) > > > > void arch_release_task_struct(struct task_struct *tsk) > > { > > - if (tsk->thread.vxrs) > > - kfree(tsk->thread.vxrs); > > + kfree(tsk->thread.vxrs); > > } This code will be changed soon anyway. So it would be rather pointless to apply your patch now. Thanks anyway! > > int copy_thread(unsigned long clone_flags, unsigned long new_stackp, > maybe the intention was to check tsk != NULL ? No.
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 25 Jun 2015 13:00:11 +0200 The omap_device_delete() 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> --- arch/arm/mach-omap2/omap_device.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c index 4cb8fd9..196366e 100644 --- a/arch/arm/mach-omap2/omap_device.c +++ b/arch/arm/mach-omap2/omap_device.c @@ -193,8 +193,7 @@ static int _omap_device_notifier_call(struct notifier_block *nb, switch (event) { case BUS_NOTIFY_DEL_DEVICE: - if (pdev->archdata.od) - omap_device_delete(pdev->archdata.od); + omap_device_delete(pdev->archdata.od); break; case BUS_NOTIFY_ADD_DEVICE: if (pdev->dev.of_node) -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 25 Jun 2015 13:05:28 +0200 The of_node_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> --- arch/arm/mach-omap2/timer.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/arm/mach-omap2/timer.c b/arch/arm/mach-omap2/timer.c index cac46d8..15448221 100644 --- a/arch/arm/mach-omap2/timer.c +++ b/arch/arm/mach-omap2/timer.c @@ -208,8 +208,7 @@ static void __init omap_dmtimer_init(void) /* If we are a secure device, remove any secure timer nodes */ if ((omap_type() != OMAP2_DEVICE_TYPE_GP)) { np = omap_get_timer_dt(omap_timer_match, "ti,timer-secure"); - if (np) - of_node_put(np); + of_node_put(np); } } -- 2.4.4
On Wed, Jun 24, 2015 at 03:20:47PM +0200, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Wed, 24 Jun 2015 15:16:35 +0200 > > 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> Acked-by: Serge Hallyn <serge.hallyn@canonical.com> > --- > security/keys/process_keys.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/security/keys/process_keys.c b/security/keys/process_keys.c > index bd536cb..225dd08 100644 > --- a/security/keys/process_keys.c > +++ b/security/keys/process_keys.c > @@ -242,9 +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.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Some functions tolerate the passing of a null pointer. I do not see a need because of this fact that a function caller repeats a corresponding check. Markus Elfring (2): Delete a check before the function call "smp_set_ops" Delete a check before the function call "unwind_table_del" arch/arm/kernel/module.c | 3 +-- arch/arm/kernel/setup.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 25 Jun 2015 15:00:17 +0200 The smp_set_ops() 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> --- arch/arm/kernel/setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index e6d8c76..9ac786d 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -977,7 +977,7 @@ void __init setup_arch(char **cmdline_p) if (!mdesc->smp_init || !mdesc->smp_init()) { if (psci_smp_available()) smp_set_ops(&psci_smp_ops); - else if (mdesc->smp) + else smp_set_ops(mdesc->smp); } smp_init_cpus(); -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 25 Jun 2015 15:05:21 +0200 The unwind_table_del() 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> --- arch/arm/kernel/module.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c index efdddcb..0cc1afa 100644 --- a/arch/arm/kernel/module.c +++ b/arch/arm/kernel/module.c @@ -390,7 +390,6 @@ module_arch_cleanup(struct module *mod) int i; for (i = 0; i < ARM_SEC_MAX; i++) - if (mod->arch.unwind[i]) - unwind_table_del(mod->arch.unwind[i]); + unwind_table_del(mod->arch.unwind[i]); #endif } -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 25 Jun 2015 16:13:47 +0200 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 0144b3d..724a3be 100644 --- a/tools/lib/traceevent/parse-filter.c +++ b/tools/lib/traceevent/parse-filter.c @@ -1239,8 +1239,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.4.4
On Tue, Jun 23, 2015 at 11:20:21PM +0200, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Tue, 23 Jun 2015 22:30:21 +0200 > > The kzfree() function tests whether its argument is NULL and then > returns immediately. Thus the test around the call is not needed. > > This issue was detected by using the Coccinelle software. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> Applied. -- Email: Herbert Xu <herbert@gondor.apana.org.au> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
From: Markus Elfring <elfring@users.sourceforge.net> Further update suggestions were taken into account after a patch was applied from static source code analysis. Markus Elfring (2): Delete an unnecessary check before the function call "free_event_desc" Less function calls in read_event_desc() after error detection tools/perf/util/header.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 25 Jun 2015 17:12:32 +0200 The free_event_desc() 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/perf/util/header.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 21a77e7..03ace57 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -1063,8 +1063,7 @@ out: free(buf); return events; error: - if (events) - free_event_desc(events); + free_event_desc(events); events = NULL; goto out; } -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 25 Jun 2015 17:50:37 +0200 The functions "free" and "free_event_desc" were called in a few cases by the function "read_event_desc" during error handling even if the passed variable contained a null pointer. This implementation detail could be improved by the adjustment of jump targets. Drop unnecessary initialisations for the variables "buf" and "events" then. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- tools/perf/util/header.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 03ace57..8071163 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -978,9 +978,9 @@ static void free_event_desc(struct perf_evsel *events) static struct perf_evsel * read_event_desc(struct perf_header *ph, int fd) { - struct perf_evsel *evsel, *events = NULL; + struct perf_evsel *evsel, *events; u64 *id; - void *buf = NULL; + void *buf; u32 nre, sz, nr, i, j; ssize_t ret; size_t msz; @@ -988,14 +988,14 @@ read_event_desc(struct perf_header *ph, int fd) /* number of events */ ret = readn(fd, &nre, sizeof(nre)); if (ret != (ssize_t)sizeof(nre)) - goto error; + return NULL; if (ph->needs_swap) nre = bswap_32(nre); ret = readn(fd, &sz, sizeof(sz)); if (ret != (ssize_t)sizeof(sz)) - goto error; + return NULL; if (ph->needs_swap) sz = bswap_32(sz); @@ -1003,12 +1003,12 @@ read_event_desc(struct perf_header *ph, int fd) /* buffer to hold on file attr struct */ buf = malloc(sz); if (!buf) - goto error; + return NULL; /* the last event terminates with evsel->attr.size = 0: */ events = calloc(nre + 1, sizeof(*events)); if (!events) - goto error; + goto free_buffer; msz = sizeof(evsel->attr); if (sz < msz) @@ -1023,7 +1023,7 @@ read_event_desc(struct perf_header *ph, int fd) */ ret = readn(fd, buf, sz); if (ret != (ssize_t)sz) - goto error; + goto free_events; if (ph->needs_swap) perf_event__attr_swap(buf); @@ -1032,7 +1032,7 @@ read_event_desc(struct perf_header *ph, int fd) ret = readn(fd, &nr, sizeof(nr)); if (ret != (ssize_t)sizeof(nr)) - goto error; + goto free_events; if (ph->needs_swap) { nr = bswap_32(nr); @@ -1046,26 +1046,27 @@ read_event_desc(struct perf_header *ph, int fd) id = calloc(nr, sizeof(*id)); if (!id) - goto error; + goto free_events; evsel->ids = nr; evsel->id = id; for (j = 0 ; j < nr; j++) { ret = readn(fd, id, sizeof(*id)); if (ret != (ssize_t)sizeof(*id)) - goto error; + goto free_events; if (ph->needs_swap) *id = bswap_64(*id); id++; } } -out: + free(buf); return events; -error: +free_events: free_event_desc(events); - events = NULL; - goto out; +free_buffer: + free(buf); + return NULL; } static int __desc_attr__fprintf(FILE *fp, const char *name, const char *val, -- 2.4.4
Em Thu, Jun 25, 2015 at 06:24:09PM +0200, SF Markus Elfring escreveu: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Thu, 25 Jun 2015 17:50:37 +0200 > > The functions "free" and "free_event_desc" were called in a few cases by the > function "read_event_desc" during error handling even if the passed variable > contained a null pointer. And that is not a problem, free(NULL) is perfectly valid, as is valid to call free_event_desc(NULL). But if you want to avoid those extra NULL checks done at those functions, then add a new out: label that just do 'return events;' that is NULL, etc. - Arnaldo > This implementation detail could be improved by the adjustment of jump targets. > Drop unnecessary initialisations for the variables "buf" and "events" then. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > tools/perf/util/header.c | 29 +++++++++++++++-------------- > 1 file changed, 15 insertions(+), 14 deletions(-) > > diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c > index 03ace57..8071163 100644 > --- a/tools/perf/util/header.c > +++ b/tools/perf/util/header.c > @@ -978,9 +978,9 @@ static void free_event_desc(struct perf_evsel *events) > static struct perf_evsel * > read_event_desc(struct perf_header *ph, int fd) > { > - struct perf_evsel *evsel, *events = NULL; > + struct perf_evsel *evsel, *events; > u64 *id; > - void *buf = NULL; > + void *buf; > u32 nre, sz, nr, i, j; > ssize_t ret; > size_t msz; > @@ -988,14 +988,14 @@ read_event_desc(struct perf_header *ph, int fd) > /* number of events */ > ret = readn(fd, &nre, sizeof(nre)); > if (ret != (ssize_t)sizeof(nre)) > - goto error; > + return NULL; Please leave the single point of exit, i.e. this should 'goto out:' and the out: label will return events, that is set to NULL > > if (ph->needs_swap) > nre = bswap_32(nre); > > ret = readn(fd, &sz, sizeof(sz)); > if (ret != (ssize_t)sizeof(sz)) > - goto error; > + return NULL; > > if (ph->needs_swap) > sz = bswap_32(sz); > @@ -1003,12 +1003,12 @@ read_event_desc(struct perf_header *ph, int fd) > /* buffer to hold on file attr struct */ > buf = malloc(sz); > if (!buf) > - goto error; > + return NULL; > > /* the last event terminates with evsel->attr.size = 0: */ > events = calloc(nre + 1, sizeof(*events)); > if (!events) > - goto error; > + goto free_buffer; > > msz = sizeof(evsel->attr); > if (sz < msz) > @@ -1023,7 +1023,7 @@ read_event_desc(struct perf_header *ph, int fd) > */ > ret = readn(fd, buf, sz); > if (ret != (ssize_t)sz) > - goto error; > + goto free_events; > > if (ph->needs_swap) > perf_event__attr_swap(buf); > @@ -1032,7 +1032,7 @@ read_event_desc(struct perf_header *ph, int fd) > > ret = readn(fd, &nr, sizeof(nr)); > if (ret != (ssize_t)sizeof(nr)) > - goto error; > + goto free_events; > > if (ph->needs_swap) { > nr = bswap_32(nr); > @@ -1046,26 +1046,27 @@ read_event_desc(struct perf_header *ph, int fd) > > id = calloc(nr, sizeof(*id)); > if (!id) > - goto error; > + goto free_events; > evsel->ids = nr; > evsel->id = id; > > for (j = 0 ; j < nr; j++) { > ret = readn(fd, id, sizeof(*id)); > if (ret != (ssize_t)sizeof(*id)) > - goto error; > + goto free_events; > if (ph->needs_swap) > *id = bswap_64(*id); > id++; > } > } > -out: > + > free(buf); > return events; > -error: > +free_events: > free_event_desc(events); > - events = NULL; > - goto out; > +free_buffer: > + free(buf); > + return NULL; > } > > static int __desc_attr__fprintf(FILE *fp, const char *name, const char *val, > -- > 2.4.4
Em Thu, Jun 25, 2015 at 06:22:18PM +0200, SF Markus Elfring escreveu: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Thu, 25 Jun 2015 17:12:32 +0200 > > The free_event_desc() function tests whether its argument is NULL and then > returns immediately. Thus the test around the call is not needed. > > This issue was detected by using the Coccinelle software. Thanks, applying. - Arnaldo > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > tools/perf/util/header.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c > index 21a77e7..03ace57 100644 > --- a/tools/perf/util/header.c > +++ b/tools/perf/util/header.c > @@ -1063,8 +1063,7 @@ out: > free(buf); > return events; > error: > - if (events) > - free_event_desc(events); > + free_event_desc(events); > events = NULL; > goto out; > } > -- > 2.4.4
On Wed, 2015-06-24 at 17:54 +0200, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 24 Jun 2015 17:50:32 +0200
>
> The fc_fcp_ddp_done() 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/scsi/libfc/fc_exch.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
> index 1b3a094..aad6f48 100644
> --- a/drivers/scsi/libfc/fc_exch.c
> +++ b/drivers/scsi/libfc/fc_exch.c
> @@ -2120,8 +2120,7 @@ static struct fc_seq *fc_exch_seq_send(struct fc_lport *lport,
> spin_unlock_bh(&ep->ex_lock);
> return sp;
> err:
> - if (fsp)
> - fc_fcp_ddp_done(fsp);
> + fc_fcp_ddp_done(fsp);
> rc = fc_exch_done_locked(ep);
> spin_unlock_bh(&ep->ex_lock);
> if (!rc)
Looks good.
Acked-by: Vasu Dev <vasu.dev@intel.com>
>> The functions "free" and "free_event_desc" were called in a few cases by the >> function "read_event_desc" during error handling even if the passed variable >> contained a null pointer. > > And that is not a problem, free(NULL) is perfectly valid, as is valid to > call free_event_desc(NULL). I hope that inefficient exception handling can be fixed. > But if you want to avoid those extra NULL checks done at those functions, > then add a new out: label that just do 'return events;' that is NULL, etc. I adjusted the jump labels in the affected function already. >> This implementation detail could be improved by the adjustment of jump targets. >> Drop unnecessary initialisations for the variables "buf" and "events" then. >> >> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> >> --- >> tools/perf/util/header.c | 29 +++++++++++++++-------------- >> 1 file changed, 15 insertions(+), 14 deletions(-) >> >> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c >> index 03ace57..8071163 100644 >> --- a/tools/perf/util/header.c >> +++ b/tools/perf/util/header.c >> @@ -978,9 +978,9 @@ static void free_event_desc(struct perf_evsel *events) >> static struct perf_evsel * >> read_event_desc(struct perf_header *ph, int fd) >> { >> - struct perf_evsel *evsel, *events = NULL; >> + struct perf_evsel *evsel, *events; >> u64 *id; >> - void *buf = NULL; >> + void *buf; >> u32 nre, sz, nr, i, j; >> ssize_t ret; >> size_t msz; >> @@ -988,14 +988,14 @@ read_event_desc(struct perf_header *ph, int fd) >> /* number of events */ >> ret = readn(fd, &nre, sizeof(nre)); >> if (ret != (ssize_t)sizeof(nre)) >> - goto error; >> + return NULL; > > Please leave the single point of exit, i.e. this should 'goto out:' and > the out: label will return events, that is set to NULL Does my update suggestion fit to the wording "If there is no cleanup needed then just return directly." from the Linux coding style documentation? >> if (ph->needs_swap) >> nre = bswap_32(nre); >> >> ret = readn(fd, &sz, sizeof(sz)); >> if (ret != (ssize_t)sizeof(sz)) >> - goto error; >> + return NULL; >> >> if (ph->needs_swap) >> sz = bswap_32(sz); >> @@ -1003,12 +1003,12 @@ read_event_desc(struct perf_header *ph, int fd) >> /* buffer to hold on file attr struct */ >> buf = malloc(sz); >> if (!buf) >> - goto error; >> + return NULL; >> >> /* the last event terminates with evsel->attr.size = 0: */ >> events = calloc(nre + 1, sizeof(*events)); >> if (!events) >> - goto error; >> + goto free_buffer; >> >> msz = sizeof(evsel->attr); >> if (sz < msz) >> @@ -1023,7 +1023,7 @@ read_event_desc(struct perf_header *ph, int fd) >> */ >> ret = readn(fd, buf, sz); >> if (ret != (ssize_t)sz) >> - goto error; >> + goto free_events; >> >> if (ph->needs_swap) >> perf_event__attr_swap(buf); >> @@ -1032,7 +1032,7 @@ read_event_desc(struct perf_header *ph, int fd) >> >> ret = readn(fd, &nr, sizeof(nr)); >> if (ret != (ssize_t)sizeof(nr)) >> - goto error; >> + goto free_events; >> >> if (ph->needs_swap) { >> nr = bswap_32(nr); >> @@ -1046,26 +1046,27 @@ read_event_desc(struct perf_header *ph, int fd) >> >> id = calloc(nr, sizeof(*id)); >> if (!id) >> - goto error; >> + goto free_events; >> evsel->ids = nr; >> evsel->id = id; >> >> for (j = 0 ; j < nr; j++) { >> ret = readn(fd, id, sizeof(*id)); >> if (ret != (ssize_t)sizeof(*id)) >> - goto error; >> + goto free_events; >> if (ph->needs_swap) >> *id = bswap_64(*id); >> id++; >> } >> } >> -out: >> + >> free(buf); >> return events; >> -error: >> +free_events: >> free_event_desc(events); >> - events = NULL; >> - goto out; >> +free_buffer: >> + free(buf); >> + return NULL; >> } >> >> static int __desc_attr__fprintf(FILE *fp, const char *name, const char *val, >> -- >> 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 26 Jun 2015 10:11:19 +0200 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.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 26 Jun 2015 11:05:41 +0200 The xfs_qm_dqrele() 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/xfs/xfs_qm_syscalls.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/xfs/xfs_qm_syscalls.c b/fs/xfs/xfs_qm_syscalls.c index 3640c6e..6deee1e 100644 --- a/fs/xfs/xfs_qm_syscalls.c +++ b/fs/xfs/xfs_qm_syscalls.c @@ -735,15 +735,15 @@ xfs_dqrele_inode( } xfs_ilock(ip, XFS_ILOCK_EXCL); - if ((flags & XFS_UQUOTA_ACCT) && ip->i_udquot) { + if (flags & XFS_UQUOTA_ACCT) { xfs_qm_dqrele(ip->i_udquot); ip->i_udquot = NULL; } - if ((flags & XFS_GQUOTA_ACCT) && ip->i_gdquot) { + if (flags & XFS_GQUOTA_ACCT) { xfs_qm_dqrele(ip->i_gdquot); ip->i_gdquot = NULL; } - if ((flags & XFS_PQUOTA_ACCT) && ip->i_pdquot) { + if (flags & XFS_PQUOTA_ACCT) { xfs_qm_dqrele(ip->i_pdquot); ip->i_pdquot = NULL; } -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 26 Jun 2015 14:00:06 +0200 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> --- fs/dlm/lockspace.c | 6 ++---- fs/dlm/memory.c | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c index f3e7278..41c53b3 100644 --- a/fs/dlm/lockspace.c +++ b/fs/dlm/lockspace.c @@ -673,10 +673,8 @@ static int new_lockspace(const char *name, const char *cluster, kfree(ls->ls_recover_buf); out_lkbidr: idr_destroy(&ls->ls_lkbidr); - for (i = 0; i < DLM_REMOVE_NAMES_MAX; i++) { - if (ls->ls_remove_names[i]) - kfree(ls->ls_remove_names[i]); - } + for (i = 0; i < DLM_REMOVE_NAMES_MAX; i++) + kfree(ls->ls_remove_names[i]); out_rsbtbl: vfree(ls->ls_rsbtbl); out_lsfree: diff --git a/fs/dlm/memory.c b/fs/dlm/memory.c index 7cd24bc..2d2eaa0 100644 --- a/fs/dlm/memory.c +++ b/fs/dlm/memory.c @@ -86,8 +86,7 @@ void dlm_free_lkb(struct dlm_lkb *lkb) struct dlm_user_args *ua; ua = lkb->lkb_ua; if (ua) { - if (ua->lksb.sb_lvbptr) - kfree(ua->lksb.sb_lvbptr); + kfree(ua->lksb.sb_lvbptr); kfree(ua); } } -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 26 Jun 2015 15:20:43 +0200 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 | 5 ++--- fs/configfs/item.c | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/fs/configfs/file.c b/fs/configfs/file.c index 403269f..c70997f 100644 --- a/fs/configfs/file.c +++ b/fs/configfs/file.c @@ -274,7 +274,7 @@ static int check_perm(struct inode * inode, struct file * file) Enomem: module_put(attr->ca_owner); Done: - if (error && item) + if (error) config_item_put(item); return error; } @@ -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 4d6a30e..6173fa7 100644 --- a/fs/configfs/item.c +++ b/fs/configfs/item.c @@ -152,8 +152,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.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 26 Jun 2015 16:10:54 +0200 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> --- fs/ext4/crypto_key.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/ext4/crypto_key.c b/fs/ext4/crypto_key.c index 442d24e..f8d15ae 100644 --- a/fs/ext4/crypto_key.c +++ b/fs/ext4/crypto_key.c @@ -89,8 +89,7 @@ void ext4_free_crypt_info(struct ext4_crypt_info *ci) if (!ci) return; - if (ci->ci_keyring_key) - key_put(ci->ci_keyring_key); + key_put(ci->ci_keyring_key); crypto_free_ablkcipher(ci->ci_ctfm); kmem_cache_free(ext4_crypt_info_cachep, ci); } -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 26 Jun 2015 16:10:54 +0200 Subject: [PATCH] fs-ext4 crypto: Delete an unnecessary check before the function call "key_put" 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> --- fs/ext4/crypto_key.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/ext4/crypto_key.c b/fs/ext4/crypto_key.c index 442d24e..f8d15ae 100644 --- a/fs/ext4/crypto_key.c +++ b/fs/ext4/crypto_key.c @@ -89,8 +89,7 @@ void ext4_free_crypt_info(struct ext4_crypt_info *ci) if (!ci) return; - if (ci->ci_keyring_key) - key_put(ci->ci_keyring_key); + key_put(ci->ci_keyring_key); crypto_free_ablkcipher(ci->ci_ctfm); kmem_cache_free(ext4_crypt_info_cachep, ci); } -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 26 Jun 2015 17:28:55 +0200 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> --- fs/f2fs/crypto_key.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/f2fs/crypto_key.c b/fs/f2fs/crypto_key.c index 95b8f93..9f77de2 100644 --- a/fs/f2fs/crypto_key.c +++ b/fs/f2fs/crypto_key.c @@ -92,8 +92,7 @@ static void f2fs_free_crypt_info(struct f2fs_crypt_info *ci) if (!ci) return; - if (ci->ci_keyring_key) - key_put(ci->ci_keyring_key); + key_put(ci->ci_keyring_key); crypto_free_ablkcipher(ci->ci_ctfm); kmem_cache_free(f2fs_crypt_info_cachep, ci); } -- 2.4.4
>> 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);
>> }
>>
>
> Thanks will submit for next Kernel
Is this small update suggestion still in the waiting queue
for further software improvements?
Regards,
Markus
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 26 Jun 2015 18:18:54 +0200 The key_put() function tests whether its argument is NULL and then returns immediately. Thus the test around this call might not be needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- fs/ecryptfs/crypto.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index 97315f2..80d6901 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c @@ -258,8 +258,7 @@ void ecryptfs_destroy_mount_crypt_stat( &mount_crypt_stat->global_auth_tok_list, mount_crypt_stat_list) { list_del(&auth_tok->mount_crypt_stat_list); - if (auth_tok->global_auth_tok_key - && !(auth_tok->flags & ECRYPTFS_AUTH_TOK_INVALID)) + if (!(auth_tok->flags & ECRYPTFS_AUTH_TOK_INVALID)) key_put(auth_tok->global_auth_tok_key); kmem_cache_free(ecryptfs_global_auth_tok_cache, auth_tok); } -- 2.4.4
> 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;
> }
>
Would anybody like to integrate this update suggestion
into a source code repository?
Regards,
Markus
> 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();
> }
>
>
How are the chances to integrate this update suggestion
into another source code repository?
Regards,
Markus
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 26 Jun 2015 20:30:11 +0200 The functions kfree() and release_firmware() test whether their argument is NULL and then return immediately. Thus the test around the calls is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/crypto/qat/qat_common/adf_accel_engine.c | 5 +---- drivers/crypto/qat/qat_common/adf_transport.c | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/crypto/qat/qat_common/adf_accel_engine.c b/drivers/crypto/qat/qat_common/adf_accel_engine.c index 7f8b66c..fdda8e7 100644 --- a/drivers/crypto/qat/qat_common/adf_accel_engine.c +++ b/drivers/crypto/qat/qat_common/adf_accel_engine.c @@ -88,10 +88,7 @@ void adf_ae_fw_release(struct adf_accel_dev *accel_dev) qat_uclo_del_uof_obj(loader_data->fw_loader); qat_hal_deinit(loader_data->fw_loader); - - if (loader_data->uof_fw) - release_firmware(loader_data->uof_fw); - + release_firmware(loader_data->uof_fw); loader_data->uof_fw = NULL; loader_data->fw_loader = NULL; } diff --git a/drivers/crypto/qat/qat_common/adf_transport.c b/drivers/crypto/qat/qat_common/adf_transport.c index ccec3274..db2926b 100644 --- a/drivers/crypto/qat/qat_common/adf_transport.c +++ b/drivers/crypto/qat/qat_common/adf_transport.c @@ -449,7 +449,7 @@ static int adf_init_bank(struct adf_accel_dev *accel_dev, err: for (i = 0; i < ADF_ETR_MAX_RINGS_PER_BANK; i++) { ring = &bank->rings[i]; - if (hw_data->tx_rings_mask & (1 << i) && ring->inflights) + if (hw_data->tx_rings_mask & (1 << i)) kfree(ring->inflights); } return -ENOMEM; -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 26 Jun 2015 21:21:16 +0200 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> --- drivers/platform/x86/tc1100-wmi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/platform/x86/tc1100-wmi.c b/drivers/platform/x86/tc1100-wmi.c index e365425..89aa976 100644 --- a/drivers/platform/x86/tc1100-wmi.c +++ b/drivers/platform/x86/tc1100-wmi.c @@ -82,7 +82,7 @@ static int get_state(u32 *out, u8 instance) tmp = 0; } - if (result.length > 0 && result.pointer) + if (result.length > 0) kfree(result.pointer); switch (instance) { -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 26 Jun 2015 21:50:41 +0200 The XGIfb_search_crt2type() 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/staging/xgifb/XGI_main_26.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/staging/xgifb/XGI_main_26.c b/drivers/staging/xgifb/XGI_main_26.c index 943d463..ee0906e 100644 --- a/drivers/staging/xgifb/XGI_main_26.c +++ b/drivers/staging/xgifb/XGI_main_26.c @@ -2090,8 +2090,7 @@ static int __init xgifb_init(void) { char *option = NULL; - if (forcecrt2type != NULL) - XGIfb_search_crt2type(forcecrt2type); + XGIfb_search_crt2type(forcecrt2type); if (fb_get_options("xgifb", &option)) return -ENODEV; XGIfb_setup(option); -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 26 Jun 2015 23:10:42 +0200 The following functions test whether their argument is NULL and then return immediately. * kfree * ll_file_data_put * ptlrpc_connection_put Thus the test around such calls is not needed. This issue was detected by using the Coccinelle software. See also a previous update suggestion: "remove unneeded null test before free" by Julia Lawall https://lkml.org/lkml/2015/5/1/498 https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg878600.html Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/staging/lustre/lustre/llite/file.c | 3 +-- drivers/staging/lustre/lustre/llite/llite_lib.c | 2 +- drivers/staging/lustre/lustre/ptlrpc/import.c | 6 ++---- drivers/staging/lustre/lustre/ptlrpc/service.c | 4 +--- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/staging/lustre/lustre/llite/file.c b/drivers/staging/lustre/lustre/llite/file.c index 3075db2..1a85c41 100644 --- a/drivers/staging/lustre/lustre/llite/file.c +++ b/drivers/staging/lustre/lustre/llite/file.c @@ -702,8 +702,7 @@ out_och_free: out_openerr: if (opendir_set != 0) ll_stop_statahead(inode, lli->lli_opendir_key); - if (fd != NULL) - ll_file_data_put(fd); + ll_file_data_put(fd); } else { ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_OPEN, 1); } diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c b/drivers/staging/lustre/lustre/llite/llite_lib.c index 2513988..ab4839c 100644 --- a/drivers/staging/lustre/lustre/llite/llite_lib.c +++ b/drivers/staging/lustre/lustre/llite/llite_lib.c @@ -1114,7 +1114,7 @@ void ll_clear_inode(struct inode *inode) if (lli->lli_mds_read_och) ll_md_real_close(inode, FMODE_READ); - if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) { + if (S_ISLNK(inode->i_mode)) { kfree(lli->lli_symlink_name); lli->lli_symlink_name = NULL; } diff --git a/drivers/staging/lustre/lustre/ptlrpc/import.c b/drivers/staging/lustre/lustre/ptlrpc/import.c index c9b8481..1eae389 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/import.c +++ b/drivers/staging/lustre/lustre/ptlrpc/import.c @@ -555,14 +555,12 @@ static int import_select_connection(struct obd_import *imp) imp_conn->oic_last_attempt = cfs_time_current_64(); /* switch connection, don't mind if it's same as the current one */ - if (imp->imp_connection) - ptlrpc_connection_put(imp->imp_connection); + ptlrpc_connection_put(imp->imp_connection); imp->imp_connection = ptlrpc_connection_addref(imp_conn->oic_conn); dlmexp = class_conn2export(&imp->imp_dlm_handle); LASSERT(dlmexp != NULL); - if (dlmexp->exp_connection) - ptlrpc_connection_put(dlmexp->exp_connection); + ptlrpc_connection_put(dlmexp->exp_connection); dlmexp->exp_connection = ptlrpc_connection_addref(imp_conn->oic_conn); class_export_put(dlmexp); diff --git a/drivers/staging/lustre/lustre/ptlrpc/service.c b/drivers/staging/lustre/lustre/ptlrpc/service.c index 9117f1c..b9ae0b7 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/service.c +++ b/drivers/staging/lustre/lustre/ptlrpc/service.c @@ -2826,9 +2826,7 @@ void ptlrpc_hr_fini(void) ptlrpc_stop_hr_threads(); cfs_percpt_for_each(hrp, i, ptlrpc_hr.hr_partitions) { - if (hrp->hrp_thrs != NULL) { - kfree(hrp->hrp_thrs); - } + kfree(hrp->hrp_thrs); } cfs_percpt_free(ptlrpc_hr.hr_partitions); -- 2.4.4
On Fri, Jun 26, 2015 at 09:28:08PM +0200, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 26 Jun 2015 21:21:16 +0200
>
> 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>
Queued, thanks.
--
Darren Hart
Intel Open Source Technology Center
On Thu, Nov 27, 2014 at 07:13:10PM +0100, Julia Lawall wrote:
>
>
> On Mon, 24 Nov 2014, SF Markus Elfring wrote:
>
> > >> This issue was detected by using the Coccinelle software.
> > >
> > > What script was used ?
> >
> > A semantic patch approach which I published on the mailing lists in March
> > is in action on my software development system for a while.
> >
> >
> > > Is it in scripts/coccinelle ?
> >
> > Not yet.
> >
> > I hope that the involved update suggestions got sufficient positive feedback
> > to integrate five scripts there.
>
> The current scripts are very complicated, involving the interaction
> between multiple scripts and a database, and I think they are not very
> suitable for make coccicheck. Also, the idea of removing the null checks
> is not appropriate in all contexts. Perhaps it could be possible to add
> a script to the Linux kernel that handles a number of common cases for
> which removing the null test is widely considered to be desirable.
>
> julia
>
Julia, do you have any particular objection to this specific patch? I didn't see
a reason to prevent it going in.
--
Darren Hart
Intel Open Source Technology Center
On Fri, 26 Jun 2015, Darren Hart wrote:
> On Thu, Nov 27, 2014 at 07:13:10PM +0100, Julia Lawall wrote:
> >
> >
> > On Mon, 24 Nov 2014, SF Markus Elfring wrote:
> >
> > > >> This issue was detected by using the Coccinelle software.
> > > >
> > > > What script was used ?
> > >
> > > A semantic patch approach which I published on the mailing lists in March
> > > is in action on my software development system for a while.
> > >
> > >
> > > > Is it in scripts/coccinelle ?
> > >
> > > Not yet.
> > >
> > > I hope that the involved update suggestions got sufficient positive feedback
> > > to integrate five scripts there.
> >
> > The current scripts are very complicated, involving the interaction
> > between multiple scripts and a database, and I think they are not very
> > suitable for make coccicheck. Also, the idea of removing the null checks
> > is not appropriate in all contexts. Perhaps it could be possible to add
> > a script to the Linux kernel that handles a number of common cases for
> > which removing the null test is widely considered to be desirable.
> >
> > julia
> >
>
> Julia, do you have any particular objection to this specific patch? I didn't see
> a reason to prevent it going in.
Sorry if I was unclear. If there is no problem with the current patch, I
have no objection to it. I don't think that the semantic patch that
caused this patch to be generated is suitable for inclusion in the Linux
kernel.
julia
> Julia, do you have any particular objection to this specific patch?
> I didn't see a reason to prevent it going in.
Thanks for your interest around this concrete update suggestion.
* Would you like to distinguish the consequences a bit more
for results from the application of the semantic patch language?
* Where do you prefer to store special extensions for
Coccinelle's script collection
Regards,
Markus
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 27 Jun 2015 13:50:43 +0200 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> --- drivers/staging/comedi/drivers/adl_pci9118.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/staging/comedi/drivers/adl_pci9118.c b/drivers/staging/comedi/drivers/adl_pci9118.c index fb3043d..19b5806 100644 --- a/drivers/staging/comedi/drivers/adl_pci9118.c +++ b/drivers/staging/comedi/drivers/adl_pci9118.c @@ -1717,8 +1717,7 @@ static void pci9118_detach(struct comedi_device *dev) pci9118_reset(dev); comedi_pci_detach(dev); pci9118_free_dma(dev); - if (pcidev) - pci_dev_put(pcidev); + pci_dev_put(pcidev); } static struct comedi_driver adl_pci9118_driver = { -- 2.4.4
On Fri, Jun 26, 2015 at 04:06:55PM -0700, Darren Hart wrote:
> Julia, do you have any particular objection to this specific patch? I didn't see
> a reason to prevent it going in.
I hate these patches...
We're saying "these functions have sanity checks so let's pass nonsense
values to them, it's fine." It makes the code harder to understand.
There is no way for a human being to remember the complete list of
functions with sanity checks and which don't have sanity checks.
Markus has introduced quite a few bugs as well (people have so far
managed to catch his bugs before they were committed). He so far has
resisted any suggestion that he should manually review his patches
before sending them.
Btw do have a scripts/coccinelle/free/ifnullfree.cocci which removes
checks before kfree, debugfs_remove, debugfs_remove_recursive, and
usb_free_urb.
regards,
dan carpenter
From: Markus Elfring <elfring@users.sourceforge.net> Further update suggestions were taken into account after a patch was applied from static source code analysis. Markus Elfring (2): Delete unnecessary checks before two function calls One function call less in mac_ioctl() after error detection drivers/staging/wilc1000/linux_wlan.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 27 Jun 2015 15:56:57 +0200 The functions kfree() and release_firmware() test whether their argument is NULL and then return immediately. Thus the test around the calls is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/staging/wilc1000/linux_wlan.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c index b352c50..2aa8d9b 100644 --- a/drivers/staging/wilc1000/linux_wlan.c +++ b/drivers/staging/wilc1000/linux_wlan.c @@ -2421,11 +2421,7 @@ int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd) } done: - - if (buff != NULL) { - kfree(buff); - } - + kfree(buff); return s32Error; } @@ -2707,8 +2703,7 @@ static void __exit exit_wilc_driver(void) } } - - if ((g_linux_wlan != NULL) && g_linux_wlan->wilc_firmware != NULL) { + if (g_linux_wlan) { release_firmware(g_linux_wlan->wilc_firmware); g_linux_wlan->wilc_firmware = NULL; } -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 27 Jun 2015 16:00:59 +0200 The kfree() function was called in two cases by the mac_ioctl() function during error handling even if the passed variable did not contain a pointer for a valid data item. * This implementation detail could be improved by the introduction of another jump label. * Drop an unnecessary initialisation for the variable "buff" then. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/staging/wilc1000/linux_wlan.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c index 2aa8d9b..f492310 100644 --- a/drivers/staging/wilc1000/linux_wlan.c +++ b/drivers/staging/wilc1000/linux_wlan.c @@ -2351,16 +2351,13 @@ int mac_close(struct net_device *ndev) int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd) { - - u8 *buff = NULL; + u8 *buff; s8 rssi; u32 size = 0, length = 0; perInterface_wlan_t *nic; struct WILC_WFI_priv *priv; s32 s32Error = WILC_SUCCESS; - - /* struct iwreq *wrq = (struct iwreq *) req; // tony moved to case SIOCSIWPRIV */ #ifdef USE_WIRELESS nic = netdev_priv(ndev); @@ -2405,7 +2402,7 @@ int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd) if (copy_to_user(wrq->u.data.pointer, buff, size)) { PRINT_ER("%s: failed to copy data to user buffer\n", __func__); s32Error = -EFAULT; - goto done; + goto free_buffer; } } } @@ -2420,8 +2417,9 @@ int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd) } } -done: +free_buffer: kfree(buff); +done: return s32Error; } -- 2.4.4
>> From: Markus Elfring <elfring@users.sourceforge.net>
>> Date: Sat, 22 Nov 2014 12:55:28 +0100
>>
>> The free_tce_table() 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>
>
> Looks good to me
>
> Acked-by: Jon Mason <jdmason@kudzu.us>
>
>
>> ---
>> arch/x86/kernel/pci-calgary_64.c | 3 +--
>> 1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
>> index 0497f71..d22a386 100644
>> --- a/arch/x86/kernel/pci-calgary_64.c
>> +++ b/arch/x86/kernel/pci-calgary_64.c
>> @@ -1476,8 +1476,7 @@ cleanup:
>> for (--bus; bus >= 0; --bus) {
>> struct calgary_bus_info *info = &bus_info[bus];
>>
>> - if (info->tce_space)
>> - free_tce_table(info->tce_space);
>> + free_tce_table(info->tce_space);
>> }
>> return -ENOMEM;
>> }
>> --
>> 2.1.3
>>
Do the chances increase to integrate this update suggestion
into another source code repository?
Regards,
Markus
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 27 Jun 2015 18:12:14 +0200 The cleanup_one_si() 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/char/ipmi/ipmi_si_intf.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c index cb90f76..fbfed36 100644 --- a/drivers/char/ipmi/ipmi_si_intf.c +++ b/drivers/char/ipmi/ipmi_si_intf.c @@ -2778,9 +2778,7 @@ static int ipmi_remove(struct platform_device *dev) { struct smi_info *info = dev_get_drvdata(&dev->dev); - if (info) - cleanup_one_si(info); - + cleanup_one_si(info); return 0; } -- 2.4.4
On Sat, 27 Jun 2015, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sat, 27 Jun 2015 16:00:59 +0200 > > The kfree() function was called in two cases by the mac_ioctl() function > during error handling even if the passed variable did not contain a pointer > for a valid data item. > > * This implementation detail could be improved by the introduction > of another jump label. > > * Drop an unnecessary initialisation for the variable "buff" then. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > drivers/staging/wilc1000/linux_wlan.c | 10 ++++------ > 1 file changed, 4 insertions(+), 6 deletions(-) > > diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c > index 2aa8d9b..f492310 100644 > --- a/drivers/staging/wilc1000/linux_wlan.c > +++ b/drivers/staging/wilc1000/linux_wlan.c > @@ -2351,16 +2351,13 @@ int mac_close(struct net_device *ndev) > > int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd) > { > - > - u8 *buff = NULL; > + u8 *buff; > s8 rssi; > u32 size = 0, length = 0; > perInterface_wlan_t *nic; > struct WILC_WFI_priv *priv; > s32 s32Error = WILC_SUCCESS; > > - > - Removing these blank lines seems to have nothing to do with the topic of the patch. julia > /* struct iwreq *wrq = (struct iwreq *) req; // tony moved to case SIOCSIWPRIV */ > #ifdef USE_WIRELESS > nic = netdev_priv(ndev); > @@ -2405,7 +2402,7 @@ int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd) > if (copy_to_user(wrq->u.data.pointer, buff, size)) { > PRINT_ER("%s: failed to copy data to user buffer\n", __func__); > s32Error = -EFAULT; > - goto done; > + goto free_buffer; > } > } > } > @@ -2420,8 +2417,9 @@ int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd) > } > } > > -done: > +free_buffer: > kfree(buff); > +done: > return s32Error; > } > > -- > 2.4.4 > > -- > To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 19 Nov 2014 14:24:20 +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>
> ---
> drivers/char/agp/intel-gtt.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/char/agp/intel-gtt.c b/drivers/char/agp/intel-gtt.c
> index 9a024f8..db5877e 100644
> --- a/drivers/char/agp/intel-gtt.c
> +++ b/drivers/char/agp/intel-gtt.c
> @@ -1434,10 +1434,8 @@ void intel_gmch_remove(void)
> if (--intel_private.refcount)
> return;
>
> - if (intel_private.pcidev)
> - pci_dev_put(intel_private.pcidev);
> - if (intel_private.bridge_dev)
> - pci_dev_put(intel_private.bridge_dev);
> + pci_dev_put(intel_private.pcidev);
> + pci_dev_put(intel_private.bridge_dev);
> intel_private.driver = NULL;
> }
> EXPORT_SYMBOL(intel_gmch_remove);
>
Would you like to integrate this update suggestion
into a source code repository?
Regards,
Markus
>> From: Markus Elfring <elfring@users.sourceforge.net>
>> Date: Wed, 4 Feb 2015 21:54:45 +0100
>>
>> The functions phy_power_on() and vunmap() perform also input
>> parameter validation. Thus the test around their calls is not needed.
>>
>> This issue was detected by using the Coccinelle software.
>>
>> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
>> ---
>> drivers/gpu/drm/exynos/exynos_dp_core.c | 6 ++----
>> drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 2 +-
>> 2 files changed, 3 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/exynos/exynos_dp_core.c b/drivers/gpu/drm/exynos/exynos_dp_core.c
>> index 34d46aa..306cf1d 100644
>> --- a/drivers/gpu/drm/exynos/exynos_dp_core.c
>> +++ b/drivers/gpu/drm/exynos/exynos_dp_core.c
>> @@ -1057,14 +1057,12 @@ static int exynos_dp_create_connector(struct exynos_drm_display *display,
>>
>> static void exynos_dp_phy_init(struct exynos_dp_device *dp)
>> {
>> - if (dp->phy)
>> - phy_power_on(dp->phy);
>> + phy_power_on(dp->phy);
>> }
>>
>> static void exynos_dp_phy_exit(struct exynos_dp_device *dp)
>> {
>> - if (dp->phy)
>> - phy_power_off(dp->phy);
>> + phy_power_off(dp->phy);
>> }
>>
>> static void exynos_dp_poweron(struct exynos_drm_display *display)
>> diff --git a/drivers/gpu/drm/exynos/exynos_drm_fbdev.c b/drivers/gpu/drm/exynos/exynos_drm_fbdev.c
>> index e12ea90..0dd448a 100644
>> --- a/drivers/gpu/drm/exynos/exynos_drm_fbdev.c
>> +++ b/drivers/gpu/drm/exynos/exynos_drm_fbdev.c
>> @@ -313,7 +313,7 @@ static void exynos_drm_fbdev_destroy(struct drm_device *dev,
>> struct exynos_drm_gem_obj *exynos_gem_obj = exynos_fbd->exynos_gem_obj;
>> struct drm_framebuffer *fb;
>>
>> - if (is_drm_iommu_supported(dev) && exynos_gem_obj->buffer->kvaddr)
>> + if (is_drm_iommu_supported(dev))
>> vunmap(exynos_gem_obj->buffer->kvaddr);
>>
>> /* release drm framebuffer and real buffer */
>>
>
> Acked-by: Joonyoung Shim <jy0922.shim@samsung.com>
Do the chances increase to integrate this update suggestion
into another source code repository?
Regards,
Markus
> There is no way for a human being to remember the complete list of > functions with sanity checks and which don't have sanity checks. I understand also this software development challenge. > Markus has introduced quite a few bugs as well I have only found other opinions about specific update suggestions. Which of such "bugs" are real mistakes? Are you looking for a better consensus? > (people have so far managed to catch his bugs before they were committed). Would you like to refer to any concrete software developers? > He so far has resisted any suggestion that he should manually review > his patches before sending them. I am performing source code review to some degree. My approach does partly not fit to your expectations. Regards, Markus
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 27 Jun 2015 20:44:49 +0200 The backlight_device_unregister() 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/gpu/drm/bridge/ps8622.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/gpu/drm/bridge/ps8622.c b/drivers/gpu/drm/bridge/ps8622.c index 1a6607b..70dacb8 100644 --- a/drivers/gpu/drm/bridge/ps8622.c +++ b/drivers/gpu/drm/bridge/ps8622.c @@ -646,9 +646,7 @@ static int ps8622_remove(struct i2c_client *client) { struct ps8622_bridge *ps8622 = i2c_get_clientdata(client); - if (ps8622->bl) - backlight_device_unregister(ps8622->bl); - + backlight_device_unregister(ps8622->bl); drm_bridge_remove(&ps8622->bridge); return 0; -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Further update suggestions were taken into account after a patch was applied from static source code analysis. Markus Elfring (2): Delete an unnecessary check before the function call "dsi_destroy" One function call less in dsi_init() after error detection drivers/gpu/drm/msm/dsi/dsi.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 27 Jun 2015 22:05:31 +0200 The dsi_destroy() 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/gpu/drm/msm/dsi/dsi.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/gpu/drm/msm/dsi/dsi.c b/drivers/gpu/drm/msm/dsi/dsi.c index 1f2561e..dc4f38f 100644 --- a/drivers/gpu/drm/msm/dsi/dsi.c +++ b/drivers/gpu/drm/msm/dsi/dsi.c @@ -110,9 +110,7 @@ static struct msm_dsi *dsi_init(struct platform_device *pdev) return msm_dsi; fail: - if (msm_dsi) - dsi_destroy(msm_dsi); - + dsi_destroy(msm_dsi); return ERR_PTR(ret); } -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 27 Jun 2015 22:23:28 +0200 The dsi_destroy() function was called in two cases by the dsi_init() function during error handling even if the passed variable contained a null pointer. * This implementation detail could be improved by adjustments for jump targets according to the Linux coding style convention. * Drop an unnecessary initialisation for the variable "msm_dsi" then. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/gpu/drm/msm/dsi/dsi.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/msm/dsi/dsi.c b/drivers/gpu/drm/msm/dsi/dsi.c index dc4f38f..971f000 100644 --- a/drivers/gpu/drm/msm/dsi/dsi.c +++ b/drivers/gpu/drm/msm/dsi/dsi.c @@ -74,19 +74,15 @@ static void dsi_destroy(struct msm_dsi *msm_dsi) static struct msm_dsi *dsi_init(struct platform_device *pdev) { - struct msm_dsi *msm_dsi = NULL; + struct msm_dsi *msm_dsi; int ret; - if (!pdev) { - ret = -ENXIO; - goto fail; - } + if (!pdev) + return -ENXIO; msm_dsi = devm_kzalloc(&pdev->dev, sizeof(*msm_dsi), GFP_KERNEL); - if (!msm_dsi) { - ret = -ENOMEM; - goto fail; - } + if (!msm_dsi) + return -ENOMEM; DBG("dsi probed=%p", msm_dsi); msm_dsi->pdev = pdev; @@ -95,21 +91,21 @@ static struct msm_dsi *dsi_init(struct platform_device *pdev) /* Init dsi host */ ret = msm_dsi_host_init(msm_dsi); if (ret) - goto fail; + goto destroy_dsi; /* GET dsi PHY */ ret = dsi_get_phy(msm_dsi); if (ret) - goto fail; + goto destroy_dsi; /* Register to dsi manager */ ret = msm_dsi_manager_register(msm_dsi); if (ret) - goto fail; + goto destroy_dsi; return msm_dsi; -fail: +destroy_dsi: dsi_destroy(msm_dsi); return ERR_PTR(ret); } -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 28 Jun 2015 10:27:35 +0200 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> --- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index fec487d..a85cd08 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -1575,8 +1575,7 @@ void amdgpu_device_fini(struct amdgpu_device *adev) amdgpu_fence_driver_fini(adev); amdgpu_fbdev_fini(adev); r = amdgpu_fini(adev); - if (adev->ip_block_enabled) - kfree(adev->ip_block_enabled); + kfree(adev->ip_block_enabled); adev->ip_block_enabled = NULL; adev->accel_working = false; /* free i2c buses */ -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 28 Jun 2015 11:15:28 +0200 The snd_info_free_entry() 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/hda/patch_hdmi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c index f852734..2f24338 100644 --- a/sound/pci/hda/patch_hdmi.c +++ b/sound/pci/hda/patch_hdmi.c @@ -591,7 +591,7 @@ static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index) static void eld_proc_free(struct hdmi_spec_per_pin *per_pin) { - if (!per_pin->codec->bus->shutdown && per_pin->proc_entry) { + if (!per_pin->codec->bus->shutdown) { snd_info_free_entry(per_pin->proc_entry); per_pin->proc_entry = NULL; } -- 2.4.4
On 06/24/2015 05:16 PM, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Wed, 24 Jun 2015 16:06:21 +0200 > > The put_disk() 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> ACK-by: Boaz Harrosh <ooo@electrozaur.com> > --- > drivers/scsi/osd/osd_uld.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/drivers/scsi/osd/osd_uld.c b/drivers/scsi/osd/osd_uld.c > index 243eab3..e2075522 100644 > --- a/drivers/scsi/osd/osd_uld.c > +++ b/drivers/scsi/osd/osd_uld.c > @@ -407,9 +407,7 @@ static void __remove(struct device *dev) > > OSD_INFO("osd_remove %s\n", > oud->disk ? oud->disk->disk_name : NULL); > - > - if (oud->disk) > - put_disk(oud->disk); > + put_disk(oud->disk); > ida_remove(&osd_minor_ida, oud->minor); > > kfree(oud); >
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 28 Jun 2015 12:14:43 +0200 The functions dev_pm_disarm_wake_irq() and wakeup_source_unregister() test whether their argument is NULL and then return immediately. Thus the test around the calls is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/base/power/wakeup.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c index 40f7160..3741bc2 100644 --- a/drivers/base/power/wakeup.c +++ b/drivers/base/power/wakeup.c @@ -341,8 +341,7 @@ void device_wakeup_arm_wake_irqs(void) rcu_read_lock(); list_for_each_entry_rcu(ws, &wakeup_sources, entry) { - if (ws->wakeirq) - dev_pm_arm_wake_irq(ws->wakeirq); + dev_pm_arm_wake_irq(ws->wakeirq); } rcu_read_unlock(); } @@ -358,8 +357,7 @@ void device_wakeup_disarm_wake_irqs(void) rcu_read_lock(); list_for_each_entry_rcu(ws, &wakeup_sources, entry) { - if (ws->wakeirq) - dev_pm_disarm_wake_irq(ws->wakeirq); + dev_pm_disarm_wake_irq(ws->wakeirq); } rcu_read_unlock(); } @@ -396,9 +394,7 @@ int device_wakeup_disable(struct device *dev) return -EINVAL; ws = device_wakeup_detach(dev); - if (ws) - wakeup_source_unregister(ws); - + wakeup_source_unregister(ws); return 0; } EXPORT_SYMBOL_GPL(device_wakeup_disable); -- 2.4.4
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 19 Nov 2014 13:33:32 +0100
>
> The lc_destroy() 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/block/drbd/drbd_nl.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
> index 1cd47df..0bcb3e0 100644
> --- a/drivers/block/drbd/drbd_nl.c
> +++ b/drivers/block/drbd/drbd_nl.c
> @@ -1115,8 +1115,7 @@ static int drbd_check_al_size(struct drbd_device *device, struct disk_conf *dc)
> lc_destroy(n);
> return -EBUSY;
> } else {
> - if (t)
> - lc_destroy(t);
> + lc_destroy(t);
> }
> drbd_md_mark_dirty(device); /* we changed device->act_log->nr_elemens */
> return 0;
>
Would you like to integrate this update suggestion
into another source code repository?
Regards,
Markus
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Mon, 1 Dec 2014 19:19:25 +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/block/rsxx/dma.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/block/rsxx/dma.c b/drivers/block/rsxx/dma.c
> index cf8cd29..0181387 100644
> --- a/drivers/block/rsxx/dma.c
> +++ b/drivers/block/rsxx/dma.c
> @@ -960,8 +960,7 @@ failed_dma_setup:
> ctrl->done_wq = NULL;
> }
>
> - if (ctrl->trackers)
> - vfree(ctrl->trackers);
> + vfree(ctrl->trackers);
>
> if (ctrl->status.buf)
> pci_free_consistent(card->dev, STATUS_BUFFER_SIZE8,
>
Would you like to integrate this update suggestion
into another source code repository?
Regards,
Markus
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Mon, 1 Dec 2014 18:15:46 +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>
> ---
> drivers/block/skd_main.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/block/skd_main.c b/drivers/block/skd_main.c
> index 1e46eb2..c4b0259 100644
> --- a/drivers/block/skd_main.c
> +++ b/drivers/block/skd_main.c
> @@ -3998,8 +3998,7 @@ static int skd_acquire_msix(struct skd_device *skdev)
> return 0;
>
> msix_out:
> - if (entries)
> - kfree(entries);
> + kfree(entries);
> skd_release_msix(skdev);
> return rc;
> }
>
Would anybody like to integrate this update suggestion
into another source code repository?
Regards,
Markus
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 19 Nov 2014 18:30:22 +0100
>
> The functions backlight_device_unregister(), lcd_device_unregister() and
> rc_unregister_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/hid/hid-picolcd_backlight.c | 3 +--
> drivers/hid/hid-picolcd_cir.c | 3 +--
> drivers/hid/hid-picolcd_lcd.c | 3 +--
> 3 files changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/hid/hid-picolcd_backlight.c b/drivers/hid/hid-picolcd_backlight.c
> index a32c5f8..808807a 100644
> --- a/drivers/hid/hid-picolcd_backlight.c
> +++ b/drivers/hid/hid-picolcd_backlight.c
> @@ -94,8 +94,7 @@ void picolcd_exit_backlight(struct picolcd_data *data)
> struct backlight_device *bdev = data->backlight;
>
> data->backlight = NULL;
> - if (bdev)
> - backlight_device_unregister(bdev);
> + backlight_device_unregister(bdev);
> }
>
> int picolcd_resume_backlight(struct picolcd_data *data)
> diff --git a/drivers/hid/hid-picolcd_cir.c b/drivers/hid/hid-picolcd_cir.c
> index 045f8eb..9628651 100644
> --- a/drivers/hid/hid-picolcd_cir.c
> +++ b/drivers/hid/hid-picolcd_cir.c
> @@ -145,7 +145,6 @@ void picolcd_exit_cir(struct picolcd_data *data)
> struct rc_dev *rdev = data->rc_dev;
>
> data->rc_dev = NULL;
> - if (rdev)
> - rc_unregister_device(rdev);
> + rc_unregister_device(rdev);
> }
>
> diff --git a/drivers/hid/hid-picolcd_lcd.c b/drivers/hid/hid-picolcd_lcd.c
> index 89821c2..22dcbe1 100644
> --- a/drivers/hid/hid-picolcd_lcd.c
> +++ b/drivers/hid/hid-picolcd_lcd.c
> @@ -92,8 +92,7 @@ void picolcd_exit_lcd(struct picolcd_data *data)
> struct lcd_device *ldev = data->lcd;
>
> data->lcd = NULL;
> - if (ldev)
> - lcd_device_unregister(ldev);
> + lcd_device_unregister(ldev);
> }
>
> int picolcd_resume_lcd(struct picolcd_data *data)
>
Would you like to integrate this update suggestion
into another source code repository?
Regards,
Markus
> From: Markus Elfring <elfring@users.sourceforge.net>
>
> The backlight_device_unregister() 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/video/backlight/lp8788_bl.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/video/backlight/lp8788_bl.c b/drivers/video/backlight/lp8788_bl.c
> index d6c4f6a..24a055c 100644
> --- a/drivers/video/backlight/lp8788_bl.c
> +++ b/drivers/video/backlight/lp8788_bl.c
> @@ -221,8 +221,7 @@ static void lp8788_backlight_unregister(struct lp8788_bl *bl)
> {
> struct backlight_device *bl_dev = bl->bl_dev;
>
> - if (bl_dev)
> - backlight_device_unregister(bl_dev);
> + backlight_device_unregister(bl_dev);
> }
>
> static ssize_t lp8788_get_bl_ctl_mode(struct device *dev,
>
Would you like to integrate this update suggestion
into another source code repository?
Regards,
Markus
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 28 Jun 2015 14:30:17 +0200 The backlight_device_unregister() 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/video/fbdev/omap2/displays-new/panel-dsi-cm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/video/fbdev/omap2/displays-new/panel-dsi-cm.c b/drivers/video/fbdev/omap2/displays-new/panel-dsi-cm.c index 3414c26..d2caa41 100644 --- a/drivers/video/fbdev/omap2/displays-new/panel-dsi-cm.c +++ b/drivers/video/fbdev/omap2/displays-new/panel-dsi-cm.c @@ -1323,8 +1323,7 @@ static int dsicm_probe(struct platform_device *pdev) return 0; err_sysfs_create: - if (bldev != NULL) - backlight_device_unregister(bldev); + backlight_device_unregister(bldev); err_bl: destroy_workqueue(ddata->workqueue); err_reg: -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 28 Jun 2015 14:59:04 +0200 The release_firmware() 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/usb/serial/mxuport.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/usb/serial/mxuport.c b/drivers/usb/serial/mxuport.c index 460a406..92f7aee 100644 --- a/drivers/usb/serial/mxuport.c +++ b/drivers/usb/serial/mxuport.c @@ -1101,8 +1101,7 @@ static int mxuport_probe(struct usb_serial *serial, */ usb_set_serial_data(serial, (void *)id->driver_info); out: - if (fw_p) - release_firmware(fw_p); + release_firmware(fw_p); return err; } -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 28 Jun 2015 15:55:11 +0200 The free_io_pgtable_ops() 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/iommu/arm-smmu-v3.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index f141301..8e9ec81 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -1389,8 +1389,7 @@ static void arm_smmu_domain_free(struct iommu_domain *domain) struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); struct arm_smmu_device *smmu = smmu_domain->smmu; - if (smmu_domain->pgtbl_ops) - free_io_pgtable_ops(smmu_domain->pgtbl_ops); + free_io_pgtable_ops(smmu_domain->pgtbl_ops); /* Free the CD and ASID, if we allocated them */ if (smmu_domain->stage = ARM_SMMU_DOMAIN_S1) { -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 28 Jun 2015 16:42:04 +0200 The functions phy_exit() and phy_power_off() test whether their argument is NULL and then return immediately. Thus the test around the calls is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/pci/host/pcie-iproc.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/pci/host/pcie-iproc.c b/drivers/pci/host/pcie-iproc.c index d77481e..f875821 100644 --- a/drivers/pci/host/pcie-iproc.c +++ b/drivers/pci/host/pcie-iproc.c @@ -239,12 +239,9 @@ err_rm_root_bus: pci_remove_root_bus(bus); err_power_off_phy: - if (pcie->phy) - phy_power_off(pcie->phy); + phy_power_off(pcie->phy); err_exit_phy: - if (pcie->phy) - phy_exit(pcie->phy); - + phy_exit(pcie->phy); return ret; } EXPORT_SYMBOL(iproc_pcie_setup); -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Another update suggestion was taken into account after a patch was applied from static source code analysis. Markus Elfring (2): Delete an unnecessary check before the function call "kfree" One function call less in tce_iommu_attach_group() after kzalloc() failure drivers/vfio/vfio_iommu_spapr_tce.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 28 Jun 2015 17:43:48 +0200 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> --- drivers/vfio/vfio_iommu_spapr_tce.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c b/drivers/vfio/vfio_iommu_spapr_tce.c index 0582b72..50ddfac 100644 --- a/drivers/vfio/vfio_iommu_spapr_tce.c +++ b/drivers/vfio/vfio_iommu_spapr_tce.c @@ -1215,7 +1215,7 @@ static int tce_iommu_attach_group(void *iommu_data, } unlock_exit: - if (ret && tcegrp) + if (ret) kfree(tcegrp); mutex_unlock(&container->lock); -- 2.4.4
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 28 Jun 2015 17:58:42 +0200 The kfree() function was called even if a previous memory allocation try failed. This implementation detail could be improved by the introduction of another jump label. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/vfio/vfio_iommu_spapr_tce.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c b/drivers/vfio/vfio_iommu_spapr_tce.c index 50ddfac..2523075 100644 --- a/drivers/vfio/vfio_iommu_spapr_tce.c +++ b/drivers/vfio/vfio_iommu_spapr_tce.c @@ -1200,7 +1200,7 @@ static int tce_iommu_attach_group(void *iommu_data, tcegrp = kzalloc(sizeof(*tcegrp), GFP_KERNEL); if (!tcegrp) { ret = -ENOMEM; - goto unlock_exit; + goto unlock_container; } if (!table_group->ops || !table_group->ops->take_ownership || @@ -1217,7 +1217,7 @@ static int tce_iommu_attach_group(void *iommu_data, unlock_exit: if (ret) kfree(tcegrp); - +unlock_container: mutex_unlock(&container->lock); return ret; -- 2.4.4
On 06/29/2015 02:24 AM, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sun, 28 Jun 2015 17:58:42 +0200 > > The kfree() function was called even if a previous memory allocation > try failed. tcegrp will be NULL and kfree() can handle this just fine (is not it the whole point of this patchset - remove the check and just call kfree() even if the pointer is NULL?). And if you wanted another label, than the existing one should have been renamed to "free_exit" or "free_unlock_exit" and new one would be "unlock_exit". > This implementation detail could be improved by the introduction > of another jump label. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > drivers/vfio/vfio_iommu_spapr_tce.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c b/drivers/vfio/vfio_iommu_spapr_tce.c > index 50ddfac..2523075 100644 > --- a/drivers/vfio/vfio_iommu_spapr_tce.c > +++ b/drivers/vfio/vfio_iommu_spapr_tce.c > @@ -1200,7 +1200,7 @@ static int tce_iommu_attach_group(void *iommu_data, > tcegrp = kzalloc(sizeof(*tcegrp), GFP_KERNEL); > if (!tcegrp) { > ret = -ENOMEM; > - goto unlock_exit; > + goto unlock_container; > } > > if (!table_group->ops || !table_group->ops->take_ownership || > @@ -1217,7 +1217,7 @@ static int tce_iommu_attach_group(void *iommu_data, > unlock_exit: > if (ret) > kfree(tcegrp); > - > +unlock_container: > mutex_unlock(&container->lock); > > return ret; > -- Alexey
> tcegrp will be NULL and kfree() can handle this just fine The affected function did not show this API knowledge, did it? > (is not it the whole point of this patchset > - remove the check and just call kfree() even if the pointer is NULL?). Partly, yes. > And if you wanted another label, I suggest this to improve corresponding exception handling. > than the existing one should have been renamed to "free_exit" or "free_unlock_exit" > and new one would be "unlock_exit". I chose a smaller change at this place. I am not familiar enough with other called functions there at the moment. Are the remaining goto statements also update candidates? Regards, Markus
On Sun, 28 Jun 2015 13:54:56 +0200 SF Markus Elfring wrote: > > From: Markus Elfring <elfring@users.sourceforge.net> > > Date: Wed, 19 Nov 2014 18:30:22 +0100 > > > > The functions backlight_device_unregister(), lcd_device_unregister() and > > rc_unregister_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/hid/hid-picolcd_backlight.c | 3 +-- > > drivers/hid/hid-picolcd_cir.c | 3 +-- > > drivers/hid/hid-picolcd_lcd.c | 3 +-- > > 3 files changed, 3 insertions(+), 6 deletions(-) > > > > diff --git a/drivers/hid/hid-picolcd_backlight.c b/drivers/hid/hid-picolcd_backlight.c > > index a32c5f8..808807a 100644 > > --- a/drivers/hid/hid-picolcd_backlight.c > > +++ b/drivers/hid/hid-picolcd_backlight.c > > @@ -94,8 +94,7 @@ void picolcd_exit_backlight(struct picolcd_data *data) > > struct backlight_device *bdev = data->backlight; > > > > data->backlight = NULL; > > - if (bdev) > > - backlight_device_unregister(bdev); > > + backlight_device_unregister(bdev); > > } > > > > int picolcd_resume_backlight(struct picolcd_data *data) > > diff --git a/drivers/hid/hid-picolcd_cir.c b/drivers/hid/hid-picolcd_cir.c > > index 045f8eb..9628651 100644 > > --- a/drivers/hid/hid-picolcd_cir.c > > +++ b/drivers/hid/hid-picolcd_cir.c > > @@ -145,7 +145,6 @@ void picolcd_exit_cir(struct picolcd_data *data) > > struct rc_dev *rdev = data->rc_dev; > > > > data->rc_dev = NULL; > > - if (rdev) > > - rc_unregister_device(rdev); > > + rc_unregister_device(rdev); > > } > > > > diff --git a/drivers/hid/hid-picolcd_lcd.c b/drivers/hid/hid-picolcd_lcd.c > > index 89821c2..22dcbe1 100644 > > --- a/drivers/hid/hid-picolcd_lcd.c > > +++ b/drivers/hid/hid-picolcd_lcd.c > > @@ -92,8 +92,7 @@ void picolcd_exit_lcd(struct picolcd_data *data) > > struct lcd_device *ldev = data->lcd; > > > > data->lcd = NULL; > > - if (ldev) > > - lcd_device_unregister(ldev); > > + lcd_device_unregister(ldev); > > } > > > > int picolcd_resume_lcd(struct picolcd_data *data) > > > > Would you like to integrate this update suggestion > into another source code repository? Sorry for forgetting about this patch. Looks good to me: Reviewed-by: Bruno Prémont <bonbons@linux-vserver.org> Jiri, can you take it? Best regards, Bruno > Regards, > Markus -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Fri, Jun 26, 2015 at 08:45:28PM +0200, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Fri, 26 Jun 2015 20:30:11 +0200 > > The functions kfree() and release_firmware() test whether their argument > is NULL and then return immediately. > Thus the test around the calls is not needed. > > This issue was detected by using the Coccinelle software. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> Applied. -- Email: Herbert Xu <herbert@gondor.apana.org.au> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
At Sun, 28 Jun 2015 11:21:36 +0200, SF Markus Elfring wrote: > > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sun, 28 Jun 2015 11:15:28 +0200 > > The snd_info_free_entry() 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> Applied, thanks. Takashi > --- > sound/pci/hda/patch_hdmi.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c > index f852734..2f24338 100644 > --- a/sound/pci/hda/patch_hdmi.c > +++ b/sound/pci/hda/patch_hdmi.c > @@ -591,7 +591,7 @@ static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index) > > static void eld_proc_free(struct hdmi_spec_per_pin *per_pin) > { > - if (!per_pin->codec->bus->shutdown && per_pin->proc_entry) { > + if (!per_pin->codec->bus->shutdown) { > snd_info_free_entry(per_pin->proc_entry); > per_pin->proc_entry = NULL; > } > -- > 2.4.4 >
On 27/06/15 13:10, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sat, 27 Jun 2015 13:50:43 +0200 > > 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> > --- > drivers/staging/comedi/drivers/adl_pci9118.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/staging/comedi/drivers/adl_pci9118.c b/drivers/staging/comedi/drivers/adl_pci9118.c > index fb3043d..19b5806 100644 > --- a/drivers/staging/comedi/drivers/adl_pci9118.c > +++ b/drivers/staging/comedi/drivers/adl_pci9118.c > @@ -1717,8 +1717,7 @@ static void pci9118_detach(struct comedi_device *dev) > pci9118_reset(dev); > comedi_pci_detach(dev); > pci9118_free_dma(dev); > - if (pcidev) > - pci_dev_put(pcidev); > + pci_dev_put(pcidev); > } > > static struct comedi_driver adl_pci9118_driver = { > The same patch was posted independently (and earlier) by Maninder Singh, but I think we concluded that the code was more understandable without this change, as the test within pci_dev_put() is more of a safety net. -- -=( Ian Abbott @ MEV Ltd. E-mail: <abbotti@mev.co.uk> )=- -=( Web: http://www.mev.co.uk/ )=-
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 29 Jun 2015 12:22:24 +0200 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/cavium/liquidio/octeon_device.c | 11 +++-------- drivers/net/ethernet/cavium/liquidio/octeon_droq.c | 4 +--- drivers/net/ethernet/cavium/liquidio/request_manager.c | 3 +-- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/cavium/liquidio/octeon_device.c b/drivers/net/ethernet/cavium/liquidio/octeon_device.c index 0d3106b..f67641a 100644 --- a/drivers/net/ethernet/cavium/liquidio/octeon_device.c +++ b/drivers/net/ethernet/cavium/liquidio/octeon_device.c @@ -650,14 +650,12 @@ void octeon_free_device_mem(struct octeon_device *oct) for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES; i++) { /* could check mask as well */ - if (oct->droq[i]) - vfree(oct->droq[i]); + vfree(oct->droq[i]); } for (i = 0; i < MAX_OCTEON_INSTR_QUEUES; i++) { /* could check mask as well */ - if (oct->instr_queue[i]) - vfree(oct->instr_queue[i]); + vfree(oct->instr_queue[i]); } i = oct->octeon_id; @@ -1078,10 +1076,7 @@ octeon_unregister_dispatch_fn(struct octeon_device *oct, u16 opcode, oct->dispatch.count--; spin_unlock_bh(&oct->dispatch.lock); - - if (dfree) - vfree(dfree); - + vfree(dfree); return retval; } diff --git a/drivers/net/ethernet/cavium/liquidio/octeon_droq.c b/drivers/net/ethernet/cavium/liquidio/octeon_droq.c index 94b502a..4dba86e 100644 --- a/drivers/net/ethernet/cavium/liquidio/octeon_droq.c +++ b/drivers/net/ethernet/cavium/liquidio/octeon_droq.c @@ -216,9 +216,7 @@ int octeon_delete_droq(struct octeon_device *oct, u32 q_no) dev_dbg(&oct->pci_dev->dev, "%s[%d]\n", __func__, q_no); octeon_droq_destroy_ring_buffers(oct, droq); - - if (droq->recv_buf_list) - vfree(droq->recv_buf_list); + vfree(droq->recv_buf_list); if (droq->info_base_addr) cnnic_free_aligned_dma(oct->pci_dev, droq->info_list, diff --git a/drivers/net/ethernet/cavium/liquidio/request_manager.c b/drivers/net/ethernet/cavium/liquidio/request_manager.c index 356796b..a2a2465 100644 --- a/drivers/net/ethernet/cavium/liquidio/request_manager.c +++ b/drivers/net/ethernet/cavium/liquidio/request_manager.c @@ -175,8 +175,7 @@ int octeon_delete_instr_queue(struct octeon_device *oct, u32 iq_no) desc_size CFG_GET_IQ_INSTR_TYPE(CHIP_FIELD(oct, cn6xxx, conf)); - if (iq->request_list) - vfree(iq->request_list); + vfree(iq->request_list); if (iq->base_addr) { q_size = iq->max_count * desc_size; -- 2.4.5
On Mon, 29 Jun 2015, Bruno Prémont wrote:
> Sorry for forgetting about this patch.
>
> Looks good to me:
> Reviewed-by: Bruno Prémont <bonbons@linux-vserver.org>
>
> Jiri, can you take it?
Could either of you please bounce me the original patch? I don't think
I've seen in in my mailbox (or it's too long time ago).
Thanks,
--
Jiri Kosina
SUSE Labs
>> 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.
>>
>
> Thank you. It's the reasonable correction. Looks good for me.
>
> Reviewed-by: Vyacheslav Dubeyko <slava@dubeyko.com>
>
> Thanks,
> Vyacheslav Dubeyko.
>
>> 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);
>> }
>>
>
>
Can this update suggestion be still integrated
into another source code repository?
Regards,
Markus
On Sun, Jun 28, 2015 at 4:45 AM, SF Markus Elfring <elfring@users.sourceforge.net> wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sun, 28 Jun 2015 10:27:35 +0200 > > 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> I already have the same patch from Maninder Singh. Thanks! Alex > --- > drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c > index fec487d..a85cd08 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c > @@ -1575,8 +1575,7 @@ void amdgpu_device_fini(struct amdgpu_device *adev) > amdgpu_fence_driver_fini(adev); > amdgpu_fbdev_fini(adev); > r = amdgpu_fini(adev); > - if (adev->ip_block_enabled) > - kfree(adev->ip_block_enabled); > + kfree(adev->ip_block_enabled); > adev->ip_block_enabled = NULL; > adev->accel_working = false; > /* free i2c buses */ > -- > 2.4.4 > > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > http://lists.freedesktop.org/mailman/listinfo/dri-devel
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 29 Jun 2015 12:48:16 +0200
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Mon, 29 Jun 2015 12:22:24 +0200
>
> 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>
Applied.
Hi Markus,
On 6/28/2015 7:52 AM, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sun, 28 Jun 2015 16:42:04 +0200
>
> The functions phy_exit() and phy_power_off() test whether their argument
> is NULL and then return immediately.
> Thus the test around the calls is not needed.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> drivers/pci/host/pcie-iproc.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/pci/host/pcie-iproc.c b/drivers/pci/host/pcie-iproc.c
> index d77481e..f875821 100644
> --- a/drivers/pci/host/pcie-iproc.c
> +++ b/drivers/pci/host/pcie-iproc.c
> @@ -239,12 +239,9 @@ err_rm_root_bus:
> pci_remove_root_bus(bus);
>
> err_power_off_phy:
> - if (pcie->phy)
> - phy_power_off(pcie->phy);
> + phy_power_off(pcie->phy);
> err_exit_phy:
> - if (pcie->phy)
> - phy_exit(pcie->phy);
> -
> + phy_exit(pcie->phy);
> return ret;
> }
> EXPORT_SYMBOL(iproc_pcie_setup);
>
Thanks for catching this. Could you please help to make similar changes
to both phy_init and phy_power_on calls in the driver, to make it
consistent?
Thanks,
Ray
On Fri, Jun 26, 2015 at 11:15:31AM +0200, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Fri, 26 Jun 2015 11:05:41 +0200 > > The xfs_qm_dqrele() function tests whether its argument is NULL and > then returns immediately. True. > Thus the test around the call is not needed. But wrong. xfs_dqrele_inode() gets called on every inode in the inode cache, and this change results in a cacheline in every inode being dirtied even if they don't have dquots attached. Given the inode cache can hold tens to hundreds of millions of inodes on large machines, we don't want to dirty any cachelines we don't need to while walking the inode cache and releasing dquots... Cheers, Dave. -- Dave Chinner david@fromorbit.com
On 06/29/2015 04:02 PM, SF Markus Elfring wrote: >> tcegrp will be NULL and kfree() can handle this just fine > > The affected function did not show this API knowledge, did it? but you fixed this in 1/2 :) > > >> (is not it the whole point of this patchset >> - remove the check and just call kfree() even if the pointer is NULL?). > > Partly, yes. > > >> And if you wanted another label, > > I suggest this to improve corresponding exception handling. > > >> than the existing one should have been renamed to "free_exit" or "free_unlock_exit" >> and new one would be "unlock_exit". > > I chose a smaller change at this place. I'd just drop this patch. > I am not familiar enough with other called functions there at the moment. > Are the remaining goto statements also update candidates? -- Alexey
>>> than the existing one should have been renamed to "free_exit" or "free_unlock_exit"
>>> and new one would be "unlock_exit".
>>
>> I chose a smaller change at this place.
>
> I'd just drop this patch.
How do you think about to improve the affected jump labels
a bit more there?
Regards,
Markus
Am 04.02.2015 um 21:36 schrieb SF Markus Elfring:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 4 Feb 2015 21:32:27 +0100
>
> The of_node_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>
> ---
> drivers/macintosh/smu.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/macintosh/smu.c b/drivers/macintosh/smu.c
> index 10ae69b..d531f80 100644
> --- a/drivers/macintosh/smu.c
> +++ b/drivers/macintosh/smu.c
> @@ -557,8 +557,7 @@ int __init smu_init (void)
> return 0;
>
> fail_msg_node:
> - if (smu->msg_node)
> - of_node_put(smu->msg_node);
> + of_node_put(smu->msg_node);
> fail_db_node:
> of_node_put(smu->db_node);
> fail_bootmem:
>
Would you like to integrate this update suggestion
into another source code repository?
Regards,
Markus
On 06/30/2015 04:08 PM, SF Markus Elfring wrote:
>>>> than the existing one should have been renamed to "free_exit" or "free_unlock_exit"
>>>> and new one would be "unlock_exit".
>>>
>>> I chose a smaller change at this place.
>>
>> I'd just drop this patch.
>
> How do you think about to improve the affected jump labels
> a bit more there?
This branch is very unlikely to work ever so I cannot think of any
improvement here.
--
Alexey
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 30 Jun 2015 14:00:16 +0200 The functions clk_disable(), of_node_put() and omap_device_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> --- arch/arm/mach-omap2/omap_device.c | 3 +-- arch/arm/mach-omap2/omap_hwmod.c | 5 +---- arch/arm/mach-omap2/timer.c | 3 +-- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c index 4cb8fd9..196366e 100644 --- a/arch/arm/mach-omap2/omap_device.c +++ b/arch/arm/mach-omap2/omap_device.c @@ -193,8 +193,7 @@ static int _omap_device_notifier_call(struct notifier_block *nb, switch (event) { case BUS_NOTIFY_DEL_DEVICE: - if (pdev->archdata.od) - omap_device_delete(pdev->archdata.od); + omap_device_delete(pdev->archdata.od); break; case BUS_NOTIFY_ADD_DEVICE: if (pdev->dev.of_node) diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c index d78c12e..1091ee7 100644 --- a/arch/arm/mach-omap2/omap_hwmod.c +++ b/arch/arm/mach-omap2/omap_hwmod.c @@ -921,10 +921,7 @@ static int _disable_clocks(struct omap_hwmod *oh) int i = 0; pr_debug("omap_hwmod: %s: disabling clocks\n", oh->name); - - if (oh->_clk) - clk_disable(oh->_clk); - + clk_disable(oh->_clk); p = oh->slave_ports.next; while (i < oh->slaves_cnt) { diff --git a/arch/arm/mach-omap2/timer.c b/arch/arm/mach-omap2/timer.c index cac46d8..15448221 100644 --- a/arch/arm/mach-omap2/timer.c +++ b/arch/arm/mach-omap2/timer.c @@ -208,8 +208,7 @@ static void __init omap_dmtimer_init(void) /* If we are a secure device, remove any secure timer nodes */ if ((omap_type() != OMAP2_DEVICE_TYPE_GP)) { np = omap_get_timer_dt(omap_timer_match, "ti,timer-secure"); - if (np) - of_node_put(np); + of_node_put(np); } } -- 2.4.5
> Patch looks good.
> Thanks!
> Acked-by: Anil Gurumurthy <anil.gurumurthy@qlogic.com>
>
> -----Original Message-----
> From: SF Markus Elfring [mailto:elfring@users.sourceforge.net]
> Sent: 21 November 2014 04:17
> To: Anil Gurumurthy; James E. J. Bottomley; Sudarsana Kalluru; linux-scsi
> Cc: linux-kernel; kernel-janitors@vger.kernel.org; Julia Lawall
> Subject: [PATCH 1/1] SCSI-bfa: Deletion of an unnecessary check before the function call "vfree"
>
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 20 Nov 2014 23:43:17 +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/scsi/bfa/bfad_debugfs.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/bfa/bfad_debugfs.c b/drivers/scsi/bfa/bfad_debugfs.c index 8e83d04..a72170f 100644
> --- a/drivers/scsi/bfa/bfad_debugfs.c
> +++ b/drivers/scsi/bfa/bfad_debugfs.c
> @@ -399,8 +399,7 @@ bfad_debugfs_release_fwtrc(struct inode *inode, struct file *file)
> if (!fw_debug)
> return 0;
>
> - if (fw_debug->debug_buffer)
> - vfree(fw_debug->debug_buffer);
> + vfree(fw_debug->debug_buffer);
>
> file->private_data = NULL;
> kfree(fw_debug);
> --
> 2.1.3
>
Would you like to integrate this update suggestion
into another source code repository?
Regards,
Markus
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 20 Nov 2014 23:18:56 +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>
> ---
> drivers/scsi/aic94xx/aic94xx_init.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
> index c56741f..0bfdcba 100644
> --- a/drivers/scsi/aic94xx/aic94xx_init.c
> +++ b/drivers/scsi/aic94xx/aic94xx_init.c
> @@ -597,8 +597,7 @@ static void asd_destroy_ha_caches(struct asd_ha_struct *asd_ha)
> if (asd_ha->hw_prof.scb_ext)
> asd_free_coherent(asd_ha, asd_ha->hw_prof.scb_ext);
>
> - if (asd_ha->hw_prof.ddb_bitmap)
> - kfree(asd_ha->hw_prof.ddb_bitmap);
> + kfree(asd_ha->hw_prof.ddb_bitmap);
> asd_ha->hw_prof.ddb_bitmap = NULL;
>
> for (i = 0; i < ASD_MAX_PHYS; i++) {
>
How are the chances to integrate this update suggestion
into another source code repository?
Regards,
Markus
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 20 Nov 2014 20:37:30 +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>
> ---
> drivers/scsi/eata_pio.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/eata_pio.c b/drivers/scsi/eata_pio.c
> index 8319d2b..707f64d 100644
> --- a/drivers/scsi/eata_pio.c
> +++ b/drivers/scsi/eata_pio.c
> @@ -122,8 +122,7 @@ static int eata_pio_release(struct Scsi_Host *sh)
> release_region(sh->io_port, sh->n_io_port);
> }
> /* At this point the PCI reference can go */
> - if (hd->pdev)
> - pci_dev_put(hd->pdev);
> + pci_dev_put(hd->pdev);
> return 1;
> }
>
>
Would you like to integrate this update suggestion
into another source code repository?
Regards,
Markus
> xfs_dqrele_inode() gets called on every inode in the inode cache,
> and this change results in a cacheline in every inode being dirtied
> even if they don't have dquots attached. Given the inode cache can
> hold tens to hundreds of millions of inodes on large machines, we
> don't want to dirty any cachelines we don't need to while walking
> the inode cache and releasing dquots...
Would it make sense to annotate checks before such function calls
as "LIKELY"?
Regards,
Markus
On Sun, 28 Jun 2015, SF Markus Elfring wrote: > > From: Markus Elfring <elfring@users.sourceforge.net> > > > > The backlight_device_unregister() 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/video/backlight/lp8788_bl.c | 3 +-- > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > diff --git a/drivers/video/backlight/lp8788_bl.c b/drivers/video/backlight/lp8788_bl.c > > index d6c4f6a..24a055c 100644 > > --- a/drivers/video/backlight/lp8788_bl.c > > +++ b/drivers/video/backlight/lp8788_bl.c > > @@ -221,8 +221,7 @@ static void lp8788_backlight_unregister(struct lp8788_bl *bl) > > { > > struct backlight_device *bl_dev = bl->bl_dev; > > > > - if (bl_dev) > > - backlight_device_unregister(bl_dev); > > + backlight_device_unregister(bl_dev); > > } > > > > static ssize_t lp8788_get_bl_ctl_mode(struct device *dev, > > > > Would you like to integrate this update suggestion > into another source code repository? If this patch has not received any attention in some time, it's possible that it may have slipped through the gaps. Please re-submit the set. -- Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
> From: Markus Elfring <elfring@users.sourceforge.net> > Date: Wed, 19 Nov 2014 19:19:21 +0100 > > The functions kfree() and pci_dev_put() test whether their argument is NULL > and then return immediately. Thus the test around the call is not needed. > > This issue was detected by using the Coccinelle software. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > drivers/infiniband/hw/mlx4/main.c | 3 +-- > drivers/infiniband/hw/mthca/mthca_reset.c | 3 +-- > 2 files changed, 2 insertions(+), 4 deletions(-) > > diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c > index 8b72cf3..50dee1a 100644 > --- a/drivers/infiniband/hw/mlx4/main.c > +++ b/drivers/infiniband/hw/mlx4/main.c > @@ -2512,8 +2512,7 @@ static void do_slave_init(struct mlx4_ib_dev *ibdev, int slave, int do_init) > if (!dm[i]) { > pr_err("failed to allocate memory for tunneling qp update work struct\n"); > for (i = 0; i < dev->caps.num_ports; i++) { > - if (dm[i]) > - kfree(dm[i]); > + kfree(dm[i]); > } > goto out; > } > diff --git a/drivers/infiniband/hw/mthca/mthca_reset.c b/drivers/infiniband/hw/mthca/mthca_reset.c > index 74c6a94..c521654 100644 > --- a/drivers/infiniband/hw/mthca/mthca_reset.c > +++ b/drivers/infiniband/hw/mthca/mthca_reset.c > @@ -279,8 +279,7 @@ good: > } > > out: > - if (bridge) > - pci_dev_put(bridge); > + pci_dev_put(bridge); > kfree(bridge_header); > kfree(hca_header); > > More software developers became interested in similar source code improvements. infiniband: Remove redundant NULL check before kfree https://lkml.org/lkml/2015/6/26/45 https://www.mail-archive.com/linux-kernel%40vger.kernel.org/msg919966.html Regards, Markus
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 1 Jul 2015 12:08:31 +0200 The backlight_device_unregister() 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/video/backlight/lp8788_bl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/video/backlight/lp8788_bl.c b/drivers/video/backlight/lp8788_bl.c index e418d5b..5d583d7 100644 --- a/drivers/video/backlight/lp8788_bl.c +++ b/drivers/video/backlight/lp8788_bl.c @@ -221,8 +221,7 @@ static void lp8788_backlight_unregister(struct lp8788_bl *bl) { struct backlight_device *bl_dev = bl->bl_dev; - if (bl_dev) - backlight_device_unregister(bl_dev); + backlight_device_unregister(bl_dev); } static ssize_t lp8788_get_bl_ctl_mode(struct device *dev, -- 2.4.5
On Wed, Jul 01, 2015 at 09:50:00AM +0200, SF Markus Elfring wrote:
> > xfs_dqrele_inode() gets called on every inode in the inode cache,
> > and this change results in a cacheline in every inode being dirtied
> > even if they don't have dquots attached. Given the inode cache can
> > hold tens to hundreds of millions of inodes on large machines, we
> > don't want to dirty any cachelines we don't need to while walking
> > the inode cache and releasing dquots...
>
> Would it make sense to annotate checks before such function calls
> as "LIKELY"?
No - it will be random as to whether the inodes have dquots attached
or not and so a static hint is always going to be wrong for
someone....
Cheers,
Dave.
--
Dave Chinner
david@fromorbit.com
> On 2015. 7. 1., at PM 7:30, SF Markus Elfring <elfring@users.sourceforge.net> wrote: > > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Wed, 1 Jul 2015 12:08:31 +0200 > > The backlight_device_unregister() 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> It looks good. Acked-by: Jingoo Han <jingoohan1@gmail.com> > --- > drivers/video/backlight/lp8788_bl.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/video/backlight/lp8788_bl.c b/drivers/video/backlight/lp8788_bl.c > index e418d5b..5d583d7 100644 > --- a/drivers/video/backlight/lp8788_bl.c > +++ b/drivers/video/backlight/lp8788_bl.c > @@ -221,8 +221,7 @@ static void lp8788_backlight_unregister(struct lp8788_bl *bl) > { > struct backlight_device *bl_dev = bl->bl_dev; > > - if (bl_dev) > - backlight_device_unregister(bl_dev); > + backlight_device_unregister(bl_dev); > } > > static ssize_t lp8788_get_bl_ctl_mode(struct device *dev, > -- > 2.4.5 >
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 2 Jul 2015 16:30:24 +0200 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> --- net/ipv6/route.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 1a1122a..6090969 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -369,10 +369,7 @@ static void ip6_dst_destroy(struct dst_entry *dst) struct inet6_dev *idev; dst_destroy_metrics_generic(dst); - - if (rt->rt6i_pcpu) - free_percpu(rt->rt6i_pcpu); - + free_percpu(rt->rt6i_pcpu); rt6_uncached_list_del(rt); idev = rt->rt6i_idev; -- 2.4.5
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 2 Jul 2015 17:00:14 +0200 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> --- net/netfilter/ipvs/ip_vs_sched.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/netfilter/ipvs/ip_vs_sched.c b/net/netfilter/ipvs/ip_vs_sched.c index 199760c..e50221b 100644 --- a/net/netfilter/ipvs/ip_vs_sched.c +++ b/net/netfilter/ipvs/ip_vs_sched.c @@ -137,7 +137,7 @@ struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name) void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler) { - if (scheduler && scheduler->module) + if (scheduler) module_put(scheduler->module); } -- 2.4.5
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 2 Jul 2015 17:58:21 +0200 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> --- net/rds/transport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/rds/transport.c b/net/rds/transport.c index 8b4a6cd..83498e1 100644 --- a/net/rds/transport.c +++ b/net/rds/transport.c @@ -73,7 +73,7 @@ EXPORT_SYMBOL_GPL(rds_trans_unregister); void rds_trans_put(struct rds_transport *trans) { - if (trans && trans->t_owner) + if (trans) module_put(trans->t_owner); } -- 2.4.5
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 2 Jul 2015 18:38:12 +0200 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> --- net/netlink/af_netlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index dea9253..9a0ae71 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c @@ -158,7 +158,7 @@ static int __netlink_remove_tap(struct netlink_tap *nt) out: spin_unlock(&netlink_tap_lock); - if (found && nt->module) + if (found) module_put(nt->module); return found ? 0 : -ENODEV; -- 2.4.5
From: Markus Elfring <elfring@users.sourceforge.net> Another update suggestion was taken into account after a patch was applied from static source code analysis. Markus Elfring (2): Delete an unnecessary check before the function call "vfree" Improve error detection in __test_alloc() tools/testing/nvdimm/test/nfit.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) -- 2.4.5
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 2 Jul 2015 19:24:27 +0200 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> --- tools/testing/nvdimm/test/nfit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/nvdimm/test/nfit.c b/tools/testing/nvdimm/test/nfit.c index 4b69b83..9c910f1 100644 --- a/tools/testing/nvdimm/test/nfit.c +++ b/tools/testing/nvdimm/test/nfit.c @@ -270,7 +270,7 @@ static void *__test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma, err: if (buf && !is_vmalloc_addr(buf)) dma_free_coherent(dev, size, buf, *dma); - else if (buf) + else vfree(buf); kfree(res); kfree(nfit_res); -- 2.4.5
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 2 Jul 2015 20:45:53 +0200 Three checks were combined at the beginning of the __test_alloc() function. This implementation detail can become safer according to the Linux coding style convention. * Return directly if a null pointer was passed for the variable "buf". Delete an unnecessary check then. * Allocate memory for the data structure "nfit_test_resource" only if a previous allocation succeeded. * Rename a jump label. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- tools/testing/nvdimm/test/nfit.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tools/testing/nvdimm/test/nfit.c b/tools/testing/nvdimm/test/nfit.c index 9c910f1..d5f22ea 100644 --- a/tools/testing/nvdimm/test/nfit.c +++ b/tools/testing/nvdimm/test/nfit.c @@ -244,16 +244,21 @@ static void *__test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma, void *buf) { struct device *dev = &t->pdev.dev; - struct resource *res = kzalloc(sizeof(*res) * 2, GFP_KERNEL); - struct nfit_test_resource *nfit_res = kzalloc(sizeof(*nfit_res), - GFP_KERNEL); + struct resource *res; + struct nfit_test_resource *nfit_res = NULL; int rc; - if (!res || !buf || !nfit_res) - goto err; + if (!buf) + return NULL; + res = kzalloc(sizeof(*res) * 2, GFP_KERNEL); + if (!res) + goto free_memory; + nfit_res = kzalloc(sizeof(*nfit_res), GFP_KERNEL); + if (!nfit_res) + goto free_memory; rc = devm_add_action(dev, release_nfit_res, nfit_res); if (rc) - goto err; + goto free_memory; INIT_LIST_HEAD(&nfit_res->list); memset(buf, 0, size); nfit_res->dev = dev; @@ -267,8 +272,8 @@ static void *__test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma, spin_unlock(&nfit_test_lock); return nfit_res->buf; - err: - if (buf && !is_vmalloc_addr(buf)) +free_memory: + if (!is_vmalloc_addr(buf)) dma_free_coherent(dev, size, buf, *dma); else vfree(buf); -- 2.4.5
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 02 Jul 2015 16:43:43 +0200
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 2 Jul 2015 16:30:24 +0200
>
> 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>
Applied.
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 02 Jul 2015 18:08:19 +0200
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 2 Jul 2015 17:58:21 +0200
>
> 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>
Applied.
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 02 Jul 2015 18:45:53 +0200
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 2 Jul 2015 18:38:12 +0200
>
> 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>
Applied.
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 4 Jul 2015 07:44:22 +0200 The strfilter__delete() 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/perf/builtin-probe.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c index 1272559..b81cec3 100644 --- a/tools/perf/builtin-probe.c +++ b/tools/perf/builtin-probe.c @@ -297,8 +297,7 @@ static void cleanup_params(void) clear_perf_probe_event(params.events + i); 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)); } -- 2.4.5
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 4 Jul 2015 09:06:32 +0200 The unregister_sysctl_table() 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/sched/core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index b803e1b..4756d1c 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -5298,8 +5298,7 @@ static void register_sched_domain_sysctl(void) /* may be called multiple times per register */ static void unregister_sched_domain_sysctl(void) { - if (sd_sysctl_header) - unregister_sysctl_table(sd_sysctl_header); + unregister_sysctl_table(sd_sysctl_header); sd_sysctl_header = NULL; if (sd_ctl_dir[0].child) sd_free_ctl_entry(&sd_ctl_dir[0].child); -- 2.4.5
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 4 Jul 2015 10:00:26 +0200 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 | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/kernel/kprobes.c b/kernel/kprobes.c index c90e417..52e3529 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -1531,10 +1531,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; } EXPORT_SYMBOL_GPL(register_kprobe); -- 2.4.5
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 4 Jul 2015 11:21:17 +0200 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 | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/fs/namespace.c b/fs/namespace.c index e0b2f36..bc689bd 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -2809,12 +2809,8 @@ struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns, p = next_mnt(p, old); } namespace_unlock(); - - if (rootmnt) - mntput(rootmnt); - if (pwdmnt) - mntput(pwdmnt); - + mntput(rootmnt); + mntput(pwdmnt); return new_ns; } -- 2.4.5
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 29 Nov 2014 16:42:50 +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/notify/inode_mark.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/fs/notify/inode_mark.c b/fs/notify/inode_mark.c
> index 3daf513..d8157a6 100644
> --- a/fs/notify/inode_mark.c
> +++ b/fs/notify/inode_mark.c
> @@ -231,8 +231,7 @@ void fsnotify_unmount_inodes(struct list_head *list)
> */
> spin_unlock(&inode_sb_list_lock);
>
> - if (need_iput_tmp)
> - iput(need_iput_tmp);
> + iput(need_iput_tmp);
>
> /* for each watch, send FS_UNMOUNT and then remove it */
> fsnotify(inode, FS_UNMOUNT, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
>
Would anybody like to integrate this update suggestion
into another source code repository?
Regards,
Markus
> 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;
> }
>
Would you like to integrate this update suggestion
into another source code repository?
Regards,
Markus
Hi Andrew, Can you please take up this trivial patch and merge it upstream? Reviewed-by: Anton Altaparmakov <anton@tuxera.com> Thanks a lot in advance! Best regards, Anton > On 4 Jul 2015, at 11:32, SF Markus Elfring <elfring@users.sourceforge.net> 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: >> - 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; >> } >> > > Would you like to integrate this update suggestion > into another source code repository? > > Regards, > Markus -- Anton Altaparmakov <anton at tuxera.com> (replace at with @) Lead in File System Development, Tuxera Inc., http://www.tuxera.com/ Linux NTFS maintainer
From: Markus Elfring <elfring@users.sourceforge.net> Further update suggestions were taken into account after two patches were applied from static source code analysis. Markus Elfring (11): Delete an unnecessary check before unregister_sysctl_table() Delete unnecessary checks before the function call "iput" Less checks in ocfs2_rename() after error detection One check less in ocfs2_statfs() Less error log repetition in ocfs2_begin_truncate_log_recovery() Two checks less in ocfs2_local_alloc_slide_window() Less function calls in ocfs2_shutdown_local_alloc() after error detection Less checks in ocfs2_load_local_alloc() One function call less in ocfs2_trylock_journal() after error detection Less function calls in ocfs2_replay_journal() after error detection One function call less in ocfs2_journal_shutdown() from input checks fs/ocfs2/alloc.c | 24 +++++++-------- fs/ocfs2/ioctl.c | 4 +-- fs/ocfs2/journal.c | 62 +++++++++++++++---------------------- fs/ocfs2/localalloc.c | 84 +++++++++++++++++++++------------------------------ fs/ocfs2/namei.c | 17 +++++------ fs/ocfs2/slot_map.c | 3 +- fs/ocfs2/stackglue.c | 3 +- fs/ocfs2/super.c | 22 ++++++-------- 8 files changed, 90 insertions(+), 129 deletions(-) -- 2.4.5
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 4 Jul 2015 13:20:13 +0200 The unregister_sysctl_table() 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/ocfs2/stackglue.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/ocfs2/stackglue.c b/fs/ocfs2/stackglue.c index 5d965e8..4222f93 100644 --- a/fs/ocfs2/stackglue.c +++ b/fs/ocfs2/stackglue.c @@ -737,8 +737,7 @@ static void __exit ocfs2_stack_glue_exit(void) locking_max_version.pv_major = 0; locking_max_version.pv_minor = 0; ocfs2_sysfs_exit(); - if (ocfs2_table_header) - unregister_sysctl_table(ocfs2_table_header); + unregister_sysctl_table(ocfs2_table_header); } MODULE_AUTHOR("Oracle"); -- 2.4.5
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 4 Jul 2015 13:40:07 +0200 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/ocfs2/alloc.c | 3 +-- fs/ocfs2/ioctl.c | 4 +--- fs/ocfs2/journal.c | 11 +++-------- fs/ocfs2/localalloc.c | 13 +++---------- fs/ocfs2/namei.c | 4 +--- fs/ocfs2/slot_map.c | 3 +-- fs/ocfs2/super.c | 3 +-- 7 files changed, 11 insertions(+), 30 deletions(-) diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c index 0afb4cb..f36dcaa 100644 --- a/fs/ocfs2/alloc.c +++ b/fs/ocfs2/alloc.c @@ -6197,8 +6197,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..a7dae26 100644 --- a/fs/ocfs2/ioctl.c +++ b/fs/ocfs2/ioctl.c @@ -606,9 +606,7 @@ bail: if (gb_inode) mutex_unlock(&gb_inode->i_mutex); - if (gb_inode) - iput(gb_inode); - + iput(gb_inode); brelse(bh); return status; diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c index 8f853ea..c644997 100644 --- a/fs/ocfs2/journal.c +++ b/fs/ocfs2/journal.c @@ -1026,8 +1026,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, @@ -1671,9 +1670,7 @@ done: if (got_lock) ocfs2_inode_unlock(inode, 1); - if (inode) - iput(inode); - + iput(inode); brelse(bh); return status; @@ -1780,9 +1777,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 0a4457f..a614037 100644 --- a/fs/ocfs2/localalloc.c +++ b/fs/ocfs2/localalloc.c @@ -358,9 +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); if (status) @@ -473,9 +471,7 @@ out_mutex: iput(main_bm_inode); out: - if (local_alloc_inode) - iput(local_alloc_inode); - + iput(local_alloc_inode); kfree(alloc_copy); } @@ -1326,10 +1322,7 @@ bail: ocfs2_commit_trans(osb, handle); brelse(main_bm_bh); - - if (main_bm_inode) - iput(main_bm_inode); - + iput(main_bm_inode); kfree(alloc_copy); if (ac) diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c index af9c4c8..a04d70b 100644 --- a/fs/ocfs2/namei.c +++ b/fs/ocfs2/namei.c @@ -1655,9 +1655,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); ocfs2_free_dir_lookup_result(&old_inode_dot_dot_res); diff --git a/fs/ocfs2/slot_map.c b/fs/ocfs2/slot_map.c index e78a203..47bba1b 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 2fc02f7..37e418f 100644 --- a/fs/ocfs2/super.c +++ b/fs/ocfs2/super.c @@ -1726,8 +1726,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.4.5
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 4 Jul 2015 15:30:18 +0200 Skip checks for a few variables in three error handling cases within the ocfs2_rename() function by adjustment of a few jump targets according to the Linux coding style convention. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- fs/ocfs2/namei.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c index a04d70b..04a61cb 100644 --- a/fs/ocfs2/namei.c +++ b/fs/ocfs2/namei.c @@ -1255,7 +1255,7 @@ static int ocfs2_rename(struct inode *old_dir, status = ocfs2_rename_lock(osb); if (status < 0) { mlog_errno(status); - goto bail; + goto basic_clean_up; } rename_lock = 1; @@ -1265,13 +1265,13 @@ static int ocfs2_rename(struct inode *old_dir, old_inode->i_ino); if (status < 0) { mlog_errno(status); - goto bail; + goto rename_unlock; } else if (status = 1) { status = -EPERM; trace_ocfs2_rename_not_permitted( (unsigned long long)old_inode->i_ino, (unsigned long long)new_dir->i_ino); - goto bail; + goto rename_unlock; } } @@ -1630,9 +1630,10 @@ static int ocfs2_rename(struct inode *old_dir, ocfs2_dentry_move(old_dentry, new_dentry, old_dir, new_dir); status = 0; bail: - if (rename_lock) + if (rename_lock) { +rename_unlock: ocfs2_rename_unlock(osb); - + } if (handle) ocfs2_commit_trans(osb, handle); @@ -1651,7 +1652,7 @@ bail: mutex_unlock(&orphan_dir->i_mutex); iput(orphan_dir); } - +basic_clean_up: if (new_inode) sync_mapping_buffers(old_inode->i_mapping); -- 2.4.5
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 4 Jul 2015 16:28:50 +0200 Delete a check for the variable "status" by adjustment of two jump targets according to the Linux coding style convention. Separate the exception handling statements from the ordinary execution path. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- fs/ocfs2/super.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c index 37e418f..ed16f08 100644 --- a/fs/ocfs2/super.c +++ b/fs/ocfs2/super.c @@ -1692,14 +1692,12 @@ static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf) if (!inode) { mlog(ML_ERROR, "failed to get bitmap inode\n"); status = -EIO; - goto bail; + goto log_error; } status = ocfs2_inode_lock(inode, &bh, 0); - if (status < 0) { - mlog_errno(status); - goto bail; - } + if (status < 0) + goto put_inode; bm_lock = (struct ocfs2_dinode *) bh->b_data; @@ -1724,13 +1722,12 @@ static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf) brelse(bh); ocfs2_inode_unlock(inode, 0); - status = 0; -bail: iput(inode); - - if (status) - mlog_errno(status); - + return 0; +put_inode: + iput(inode); +log_error: + mlog_errno(status); return status; } -- 2.4.5
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 4 Jul 2015 17:23:08 +0200 Delete three direct calls of the mlog_errno() function within ocfs2_begin_truncate_log_recovery(). A single logging call can be sufficient. Drop initialisation for the variables "tl_inode" and "tl_bh" then. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- fs/ocfs2/alloc.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c index f36dcaa..59e639e 100644 --- a/fs/ocfs2/alloc.c +++ b/fs/ocfs2/alloc.c @@ -6147,8 +6147,8 @@ int ocfs2_begin_truncate_log_recovery(struct ocfs2_super *osb, struct ocfs2_dinode **tl_copy) { int status; - struct inode *tl_inode = NULL; - struct buffer_head *tl_bh = NULL; + struct inode *tl_inode; + struct buffer_head *tl_bh; struct ocfs2_dinode *di; struct ocfs2_truncate_log *tl; @@ -6157,10 +6157,8 @@ int ocfs2_begin_truncate_log_recovery(struct ocfs2_super *osb, trace_ocfs2_begin_truncate_log_recovery(slot_num); status = ocfs2_get_truncate_log_info(osb, slot_num, &tl_inode, &tl_bh); - if (status < 0) { - mlog_errno(status); - goto bail; - } + if (status < 0) + goto log_error; di = (struct ocfs2_dinode *) tl_bh->b_data; @@ -6176,7 +6174,6 @@ int ocfs2_begin_truncate_log_recovery(struct ocfs2_super *osb, *tl_copy = kmalloc(tl_bh->b_size, GFP_KERNEL); if (!(*tl_copy)) { status = -ENOMEM; - mlog_errno(status); goto bail; } @@ -6191,7 +6188,6 @@ int ocfs2_begin_truncate_log_recovery(struct ocfs2_super *osb, ocfs2_compute_meta_ecc(osb->sb, tl_bh->b_data, &di->i_check); status = ocfs2_write_block(osb, tl_bh, INODE_CACHE(tl_inode)); if (status < 0) { - mlog_errno(status); goto bail; } } @@ -6200,9 +6196,12 @@ bail: iput(tl_inode); brelse(tl_bh); - if (status < 0 && (*tl_copy)) { - kfree(*tl_copy); - *tl_copy = NULL; + if (status < 0) { + if (*tl_copy) { + kfree(*tl_copy); + *tl_copy = NULL; + } +log_error: mlog_errno(status); } -- 2.4.5
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 4 Jul 2015 18:18:23 +0200 * Return directly from the ocfs2_local_alloc_slide_window() function if a call of the ocfs2_local_alloc_reserve_for_window() function failed at the beginning. * Rename jump labels according to the Linux coding style convention. * Drop an unnecessary initialisation for the variable "handle" then. * Delete a call of the mlog_errno() function at the end. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- fs/ocfs2/localalloc.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c index a614037..16579ed 100644 --- a/fs/ocfs2/localalloc.c +++ b/fs/ocfs2/localalloc.c @@ -1248,7 +1248,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb, int status = 0; struct buffer_head *main_bm_bh = NULL; struct inode *main_bm_inode = NULL; - handle_t *handle = NULL; + handle_t *handle; struct ocfs2_dinode *alloc; struct ocfs2_dinode *alloc_copy = NULL; struct ocfs2_alloc_context *ac = NULL; @@ -1263,15 +1263,14 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb, if (status < 0) { if (status != -ENOSPC) mlog_errno(status); - goto bail; + return status; } handle = ocfs2_start_trans(osb, OCFS2_WINDOW_MOVE_CREDITS); if (IS_ERR(handle)) { status = PTR_ERR(handle); - handle = NULL; mlog_errno(status); - goto bail; + goto clean_up_main; } alloc = (struct ocfs2_dinode *) osb->local_alloc_bh->b_data; @@ -1285,7 +1284,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb, if (!alloc_copy) { status = -ENOMEM; mlog_errno(status); - goto bail; + goto commit; } memcpy(alloc_copy, alloc, osb->local_alloc_bh->b_size); @@ -1295,7 +1294,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb, OCFS2_JOURNAL_ACCESS_WRITE); if (status < 0) { mlog_errno(status); - goto bail; + goto commit; } ocfs2_clear_local_alloc(alloc); @@ -1305,31 +1304,27 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb, main_bm_inode, main_bm_bh); if (status < 0) { mlog_errno(status); - goto bail; + goto commit; } status = ocfs2_local_alloc_new_window(osb, handle, ac); if (status < 0) { if (status != -ENOSPC) mlog_errno(status); - goto bail; + goto commit; } atomic_inc(&osb->alloc_stats.moves); -bail: - if (handle) - ocfs2_commit_trans(osb, handle); - +commit: + ocfs2_commit_trans(osb, handle); +clean_up_main: brelse(main_bm_bh); iput(main_bm_inode); kfree(alloc_copy); if (ac) ocfs2_free_alloc_context(ac); - - if (status) - mlog_errno(status); return status; } -- 2.4.5
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 4 Jul 2015 21:02:05 +0200 The functions kfree() and iput() were called in a few cases by the ocfs2_shutdown_local_alloc() function during error handling even if the passed variables contained still a null pointer. * Return directly if the local allocation feature is unused or if a call for the ocfs2_get_system_file_inode() function failed. * Adjust jump targets. * Drop unnecessary initialisations for the variables "alloc", "alloc_copy", "bh", "local_alloc_inode" and "main_bm_inode" then. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- fs/ocfs2/localalloc.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c index 16579ed..e6d5074 100644 --- a/fs/ocfs2/localalloc.c +++ b/fs/ocfs2/localalloc.c @@ -377,18 +377,18 @@ void ocfs2_shutdown_local_alloc(struct ocfs2_super *osb) { int status; handle_t *handle; - struct inode *local_alloc_inode = NULL; - struct buffer_head *bh = NULL; + struct inode *local_alloc_inode; + struct buffer_head *bh; struct buffer_head *main_bm_bh = NULL; - struct inode *main_bm_inode = NULL; - struct ocfs2_dinode *alloc_copy = NULL; - struct ocfs2_dinode *alloc = NULL; + struct inode *main_bm_inode; + struct ocfs2_dinode *alloc_copy; + struct ocfs2_dinode *alloc; cancel_delayed_work(&osb->la_enable_wq); flush_workqueue(ocfs2_wq); if (osb->local_alloc_state = OCFS2_LA_UNUSED) - goto out; + return; local_alloc_inode ocfs2_get_system_file_inode(osb, @@ -397,7 +397,7 @@ void ocfs2_shutdown_local_alloc(struct ocfs2_super *osb) if (!local_alloc_inode) { status = -ENOENT; mlog_errno(status); - goto out; + return; } osb->local_alloc_state = OCFS2_LA_DISABLED; @@ -410,7 +410,7 @@ void ocfs2_shutdown_local_alloc(struct ocfs2_super *osb) if (!main_bm_inode) { status = -EINVAL; mlog_errno(status); - goto out; + goto put_local_alloc_inode; } mutex_lock(&main_bm_inode->i_mutex); @@ -443,7 +443,7 @@ void ocfs2_shutdown_local_alloc(struct ocfs2_super *osb) bh, OCFS2_JOURNAL_ACCESS_WRITE); if (status < 0) { mlog_errno(status); - goto out_commit; + goto free_copy; } ocfs2_clear_local_alloc(alloc); @@ -458,21 +458,18 @@ void ocfs2_shutdown_local_alloc(struct ocfs2_super *osb) if (status < 0) mlog_errno(status); +free_copy: + kfree(alloc_copy); out_commit: ocfs2_commit_trans(osb, handle); - out_unlock: brelse(main_bm_bh); - ocfs2_inode_unlock(main_bm_inode, 1); - out_mutex: mutex_unlock(&main_bm_inode->i_mutex); iput(main_bm_inode); - -out: +put_local_alloc_inode: iput(local_alloc_inode); - kfree(alloc_copy); } /* -- 2.4.5
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 4 Jul 2015 22:06:32 +0200 * Skip checks for the variable "status" in a few cases within the ocfs2_load_local_alloc() function by adjustment of two jump targets according to the Linux coding style convention. * Drop unnecessary initialisations for the variables "alloc" and "inode" then. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- fs/ocfs2/localalloc.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c index e6d5074..08f812b 100644 --- a/fs/ocfs2/localalloc.c +++ b/fs/ocfs2/localalloc.c @@ -284,14 +284,14 @@ bail: int ocfs2_load_local_alloc(struct ocfs2_super *osb) { int status = 0; - struct ocfs2_dinode *alloc = NULL; + struct ocfs2_dinode *alloc; struct buffer_head *alloc_bh = NULL; u32 num_used; - struct inode *inode = NULL; + struct inode *inode; struct ocfs2_local_alloc *la; - if (osb->local_alloc_bits = 0) - goto bail; + if (osb->local_alloc_bits) + goto trace_bits; if (osb->local_alloc_bits >= osb->bitmap_cpg) { mlog(ML_NOTICE, "Requested local alloc window %d is larger " @@ -308,14 +308,14 @@ int ocfs2_load_local_alloc(struct ocfs2_super *osb) if (!inode) { status = -EINVAL; mlog_errno(status); - goto bail; + goto trace_bits; } status = ocfs2_read_inode_block_full(inode, &alloc_bh, OCFS2_BH_IGNORE_CACHE); if (status < 0) { mlog_errno(status); - goto bail; + goto put_inode; } alloc = (struct ocfs2_dinode *) alloc_bh->b_data; @@ -326,6 +326,7 @@ int ocfs2_load_local_alloc(struct ocfs2_super *osb) mlog(ML_ERROR, "Invalid local alloc inode, %llu\n", (unsigned long long)OCFS2_I(inode)->ip_blkno); status = -EINVAL; + mlog_errno(status); goto bail; } @@ -334,6 +335,7 @@ int ocfs2_load_local_alloc(struct ocfs2_super *osb) mlog(ML_ERROR, "Local alloc size is invalid (la_size = %u)\n", le16_to_cpu(la->la_size)); status = -EINVAL; + mlog_errno(status); goto bail; } @@ -358,11 +360,10 @@ int ocfs2_load_local_alloc(struct ocfs2_super *osb) bail: if (status < 0) brelse(alloc_bh); +put_inode: iput(inode); +trace_bits: trace_ocfs2_load_local_alloc(osb->local_alloc_bits); - - if (status) - mlog_errno(status); return status; } -- 2.4.5
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 4 Jul 2015 22:34:43 +0200 The iput() function was called in one case by the ocfs2_trylock_journal() function during error handling even if the passed variable "inode" contained still a null pointer. * Return directly if a call of the ocfs2_get_system_file_inode() function failed at the beginning. * Rename a jump label according to the Linux coding style convention. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- fs/ocfs2/journal.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c index c644997..c343e36 100644 --- a/fs/ocfs2/journal.c +++ b/fs/ocfs2/journal.c @@ -1749,21 +1749,18 @@ static int ocfs2_trylock_journal(struct ocfs2_super *osb, int slot_num) { int status, flags; - struct inode *inode = NULL; + struct inode *inode; inode = ocfs2_get_system_file_inode(osb, JOURNAL_SYSTEM_INODE, slot_num); if (inode = NULL) { mlog(ML_ERROR, "access error\n"); - status = -EACCES; - goto bail; + return -EACCES; } if (is_bad_inode(inode)) { mlog(ML_ERROR, "access error (bad inode)\n"); - iput(inode); - inode = NULL; status = -EACCES; - goto bail; + goto put_inode; } SET_INODE_JOURNAL(inode); @@ -1772,11 +1769,11 @@ static int ocfs2_trylock_journal(struct ocfs2_super *osb, if (status < 0) { if (status != -EAGAIN) mlog_errno(status); - goto bail; + goto put_inode; } ocfs2_inode_unlock(inode, 1); -bail: +put_inode: iput(inode); return status; } -- 2.4.5
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 5 Jul 2015 12:23:37 +0200 The functions brelse() and iput() were called in one case by the ocfs2_replay_journal() function during error handling even if the passed variables contained still a pointer which did not refer to valid data. * Return directly if a call of the ocfs2_read_journal_inode() function failed at the beginning. * Rename jump labels according to the Linux coding style convention. * Delete the variable "got_lock" then. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- fs/ocfs2/journal.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c index c343e36..7bb50f4 100644 --- a/fs/ocfs2/journal.c +++ b/fs/ocfs2/journal.c @@ -1544,7 +1544,6 @@ static int ocfs2_replay_journal(struct ocfs2_super *osb, int slot_num) { int status; - int got_lock = 0; unsigned int flags; struct inode *inode = NULL; struct ocfs2_dinode *fe; @@ -1555,7 +1554,7 @@ static int ocfs2_replay_journal(struct ocfs2_super *osb, status = ocfs2_read_journal_inode(osb, slot_num, &bh, &inode); if (status) { mlog_errno(status); - goto done; + return status; } fe = (struct ocfs2_dinode *)bh->b_data; @@ -1576,7 +1575,7 @@ static int ocfs2_replay_journal(struct ocfs2_super *osb, osb->slot_recovery_generations[slot_num], slot_reco_gen); osb->slot_recovery_generations[slot_num] = slot_reco_gen; status = -EBUSY; - goto done; + goto put_inode; } /* Continue with recovery as the journal has not yet been recovered */ @@ -1586,9 +1585,8 @@ static int ocfs2_replay_journal(struct ocfs2_super *osb, trace_ocfs2_replay_journal_lock_err(status); if (status != -ERESTARTSYS) mlog(ML_ERROR, "Could not lock journal!\n"); - goto done; + goto put_inode; } - got_lock = 1; fe = (struct ocfs2_dinode *) bh->b_data; @@ -1599,7 +1597,7 @@ static int ocfs2_replay_journal(struct ocfs2_super *osb, trace_ocfs2_replay_journal_skip(node_num); /* Refresh recovery generation for the slot */ osb->slot_recovery_generations[slot_num] = slot_reco_gen; - goto done; + goto unlock_inode; } /* we need to run complete recovery for offline orphan slots */ @@ -1614,14 +1612,14 @@ static int ocfs2_replay_journal(struct ocfs2_super *osb, status = ocfs2_force_read_journal(inode); if (status < 0) { mlog_errno(status); - goto done; + goto unlock_inode; } journal = jbd2_journal_init_inode(inode); if (journal = NULL) { mlog(ML_ERROR, "Linux journal layer error\n"); status = -EIO; - goto done; + goto unlock_inode; } status = jbd2_journal_load(journal); @@ -1630,7 +1628,7 @@ static int ocfs2_replay_journal(struct ocfs2_super *osb, if (!igrab(inode)) BUG(); jbd2_journal_destroy(journal); - goto done; + goto unlock_inode; } ocfs2_clear_journal_error(osb->sb, journal, slot_num); @@ -1665,11 +1663,10 @@ static int ocfs2_replay_journal(struct ocfs2_super *osb, printk(KERN_NOTICE "ocfs2: End replay journal (node %d, slot %d) on "\ "device (%u,%u)\n", node_num, slot_num, MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev)); -done: +unlock_inode: /* drop the lock on this nodes journal */ - if (got_lock) - ocfs2_inode_unlock(inode, 1); - + ocfs2_inode_unlock(inode, 1); +put_inode: iput(inode); brelse(bh); -- 2.4.5
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 5 Jul 2015 14:54:33 +0200 The iput() function was called in one case by the ocfs2_journal_shutdown() function during input parameter validation even if the passed variable contained still a null pointer. * Return directly if received values indicate that at the beginning. * Delete the unnecessary jump label "done". * Drop unnecessary initialisations for the variables "inode", "journal" and "num_running_trans" then. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- fs/ocfs2/journal.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c index 7bb50f4..f13e6fdb 100644 --- a/fs/ocfs2/journal.c +++ b/fs/ocfs2/journal.c @@ -951,22 +951,20 @@ static int ocfs2_journal_toggle_dirty(struct ocfs2_super *osb, */ void ocfs2_journal_shutdown(struct ocfs2_super *osb) { - struct ocfs2_journal *journal = NULL; + struct ocfs2_journal *journal; int status = 0; - struct inode *inode = NULL; - int num_running_trans = 0; + struct inode *inode; + int num_running_trans; BUG_ON(!osb); journal = osb->journal; if (!journal) - goto done; - - inode = journal->j_inode; - + return; if (journal->j_state != OCFS2_JOURNAL_LOADED) - goto done; + return; + inode = journal->j_inode; /* need to inc inode use count - jbd2_journal_destroy will iput. */ if (!igrab(inode)) BUG(); @@ -1025,7 +1023,6 @@ void ocfs2_journal_shutdown(struct ocfs2_super *osb) journal->j_state = OCFS2_JOURNAL_FREE; // up_write(&journal->j_trans_barrier); -done: iput(inode); } -- 2.4.5
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 5 Jul 2015 20:15:12 +0200 The functions nvkm_namedb_put() and pci_dev_put() test whether their argument is NULL and then return immediately. Thus the test around the calls is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/gpu/drm/nouveau/nouveau_drm.c | 3 +-- drivers/gpu/drm/nouveau/nvkm/core/handle.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c b/drivers/gpu/drm/nouveau/nouveau_drm.c index 36b40c9..8ca3d0c 100644 --- a/drivers/gpu/drm/nouveau/nouveau_drm.c +++ b/drivers/gpu/drm/nouveau/nouveau_drm.c @@ -515,8 +515,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; } diff --git a/drivers/gpu/drm/nouveau/nvkm/core/handle.c b/drivers/gpu/drm/nouveau/nvkm/core/handle.c index dc7ff10..165f3ff 100644 --- a/drivers/gpu/drm/nouveau/nvkm/core/handle.c +++ b/drivers/gpu/drm/nouveau/nvkm/core/handle.c @@ -216,6 +216,5 @@ nvkm_handle_get_cinst(struct nvkm_object *engctx, u32 cinst) void nvkm_handle_put(struct nvkm_handle *handle) { - if (handle) - nvkm_namedb_put(handle); + nvkm_namedb_put(handle); } -- 2.4.5
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 5 Jul 2015 21:55:10 +0200 The drm_property_unreference_blob() 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/gpu/drm/drm_crtc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index 2d57fc5..6e4c8b0 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -4469,9 +4469,7 @@ static int drm_property_replace_global_blob(struct drm_device *dev, goto err_created; } - if (old_blob) - drm_property_unreference_blob(old_blob); - + drm_property_unreference_blob(old_blob); *replace = new_blob; return 0; -- 2.4.5
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 5 Jul 2015 22:45:23 +0200 The drm_fbdev_cma_restore_mode() 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/gpu/drm/imx/imx-drm-core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/gpu/drm/imx/imx-drm-core.c b/drivers/gpu/drm/imx/imx-drm-core.c index 74f505b..9172c0e 100644 --- a/drivers/gpu/drm/imx/imx-drm-core.c +++ b/drivers/gpu/drm/imx/imx-drm-core.c @@ -63,8 +63,7 @@ static void imx_drm_driver_lastclose(struct drm_device *drm) #if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER) struct imx_drm_device *imxdrm = drm->dev_private; - if (imxdrm->fbhelper) - drm_fbdev_cma_restore_mode(imxdrm->fbhelper); + drm_fbdev_cma_restore_mode(imxdrm->fbhelper); #endif } -- 2.4.5
On Mon, Jul 06, 2015 at 10:01:52AM +0800, John Hunter wrote: > On Mon, Jul 6, 2015 at 4:00 AM, SF Markus Elfring < > elfring@users.sourceforge.net> wrote: > > > From: Markus Elfring <elfring@users.sourceforge.net> > > Date: Sun, 5 Jul 2015 21:55:10 +0200 > > > > The drm_property_unreference_blob() 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> > > > > Reviewed-by: Zhao Junwang <zhjwpku@gmail.com> Applied to topic/drm-misc, thanks. -Daniel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
From: Markus Elfring <elfring@users.sourceforge.net> Date: Mon, 6 Jul 2015 09:49:11 +0200 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/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c index 654c8da..f718a6d 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c @@ -2292,9 +2292,7 @@ static int vmw_resize_cmd_bounce(struct vmw_sw_context *sw_context, (sw_context->cmd_bounce_size >> 1)); } - if (sw_context->cmd_bounce != NULL) - vfree(sw_context->cmd_bounce); - + vfree(sw_context->cmd_bounce); sw_context->cmd_bounce = vmalloc(sw_context->cmd_bounce_size); if (sw_context->cmd_bounce = NULL) { -- 2.4.5
On Sun, Jul 05, 2015 at 03:30:24PM +0200, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 4 Jul 2015 15:30:18 +0200
>
> Skip checks for a few variables in three error handling cases within
> the ocfs2_rename() function by adjustment of a few jump targets
> according to the Linux coding style convention.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
I don't think this is an improvement.
regards,
dan carpenter
On Sun, Jun 28, 2015 at 03:09:00PM +0200, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sun, 28 Jun 2015 14:59:04 +0200 > > The release_firmware() 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/usb/serial/mxuport.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/usb/serial/mxuport.c b/drivers/usb/serial/mxuport.c > index 460a406..92f7aee 100644 > --- a/drivers/usb/serial/mxuport.c > +++ b/drivers/usb/serial/mxuport.c > @@ -1101,8 +1101,7 @@ static int mxuport_probe(struct usb_serial *serial, > */ > usb_set_serial_data(serial, (void *)id->driver_info); > out: > - if (fw_p) > - release_firmware(fw_p); > + release_firmware(fw_p); > return err; > } You sent the exact same patch last year and it was rejected then as it does not improve readability: https://www.marc.info/?l=linux-usb&m\x141682024201419&w=3 So I'll drop this one again. Johan
On 2015/07/04 17:10, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sat, 4 Jul 2015 10:00:26 +0200 > > 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. > OK, looks good to me. Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > kernel/kprobes.c | 5 +---- > 1 file changed, 1 insertion(+), 4 deletions(-) > > diff --git a/kernel/kprobes.c b/kernel/kprobes.c > index c90e417..52e3529 100644 > --- a/kernel/kprobes.c > +++ b/kernel/kprobes.c > @@ -1531,10 +1531,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; > } > EXPORT_SYMBOL_GPL(register_kprobe); > -- Masami HIRAMATSU Linux Technology Research Center, System Productivity Research Dept. Center for Technology Innovation - Systems Engineering Hitachi, Ltd., Research & Development Group E-mail: masami.hiramatsu.pt@hitachi.com
On 2015/07/04 14:54, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sat, 4 Jul 2015 07:44:22 +0200 > > The strfilter__delete() 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. > This looks OK for me. Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > tools/perf/builtin-probe.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c > index 1272559..b81cec3 100644 > --- a/tools/perf/builtin-probe.c > +++ b/tools/perf/builtin-probe.c > @@ -297,8 +297,7 @@ static void cleanup_params(void) > clear_perf_probe_event(params.events + i); > 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)); > } > > -- Masami HIRAMATSU Linux Technology Research Center, System Productivity Research Dept. Center for Technology Innovation - Systems Engineering Hitachi, Ltd., Research & Development Group E-mail: masami.hiramatsu.pt@hitachi.com
Hi On Wed, Jun 24, 2015 at 2:40 PM, SF Markus Elfring <elfring@users.sourceforge.net> wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Wed, 24 Jun 2015 14:30:17 +0200 > > The kdbus_domain_unref() 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> > --- > ipc/kdbus/fs.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) Applied! Thanks David > diff --git a/ipc/kdbus/fs.c b/ipc/kdbus/fs.c > index d01f33b..205a3ad 100644 > --- a/ipc/kdbus/fs.c > +++ b/ipc/kdbus/fs.c > @@ -325,9 +325,7 @@ static void fs_super_kill(struct super_block *sb) > } > > kill_anon_super(sb); > - > - if (domain) > - kdbus_domain_unref(domain); > + kdbus_domain_unref(domain); > } > > static int fs_super_set(struct super_block *sb, void *data) > -- > 2.4.4 >
On Sat, 4 Jul 2015 10:36:57 +0000 Anton Altaparmakov <anton@tuxera.com> wrote:
> Hi Andrew,
>
> Can you please take up this trivial patch and merge it upstream?
>
> Reviewed-by: Anton Altaparmakov <anton@tuxera.com>
>
Nobody responded to Julia's review comment: "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?"
She has a good point. We can either change those gotos to go to the
correct place (current code is rather bizarre) or we can simply do
--- a/fs/ntfs/super.c~a
+++ a/fs/ntfs/super.c
@@ -2202,36 +2202,26 @@ get_ctx_vol_failed:
}
#endif /* NTFS_RW */
return true;
+out:
#ifdef NTFS_RW
-iput_usnjrnl_err_out:
iput(vol->usnjrnl_j_ino);
iput(vol->usnjrnl_max_ino);
iput(vol->usnjrnl_ino);
-iput_quota_err_out:
iput(vol->quota_q_ino);
iput(vol->quota_ino);
iput(vol->extend_ino);
#endif /* NTFS_RW */
-iput_sec_err_out:
iput(vol->secure_ino);
-iput_root_err_out:
iput(vol->root_ino);
-iput_logfile_err_out:
#ifdef NTFS_RW
iput(vol->logfile_ino);
-iput_vol_err_out:
#endif /* NTFS_RW */
iput(vol->vol_ino);
-iput_lcnbmp_err_out:
iput(vol->lcnbmp_ino);
-iput_attrdef_err_out:
vol->attrdef_size = 0;
- if (vol->attrdef) {
- ntfs_free(vol->attrdef);
- vol->attrdef = NULL;
- }
+ ntfs_free(vol->attrdef);
+ vol->attrdef = NULL;
#ifdef NTFS_RW
-iput_upcase_err_out:
#endif /* NTFS_RW */
vol->upcase_len = 0;
mutex_lock(&ntfs_lock);
@@ -2246,7 +2236,6 @@ iput_upcase_err_out:
}
iput_mftbmp_err_out:
iput(vol->mftbmp_ino);
-iput_mirr_err_out:
#ifdef NTFS_RW
iput(vol->mftmirr_ino);
#endif /* NTFS_RW */
(note that ntfs_free(NULL) is OK)
then change all the appropriate gotos to good old "goto out;".
Or we can not bother ;)
On Sat, Jun 27, 2015 at 04:36:14PM +0200, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 27 Jun 2015 15:56:57 +0200
Why is this in the body of the email? Please fix your email client or
just use git send-email properly.
On Sat, Jun 27, 2015 at 04:37:24PM +0200, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sat, 27 Jun 2015 16:00:59 +0200 Again, please fix. > > The kfree() function was called in two cases by the mac_ioctl() function > during error handling even if the passed variable did not contain a pointer > for a valid data item. > > * This implementation detail could be improved by the introduction > of another jump label. > > * Drop an unnecessary initialisation for the variable "buff" then. That's a different issue, please fix it in a separate patch. thanks, greg k-h
>> From: Markus Elfring <elfring@users.sourceforge.net>
>> Date: Sat, 27 Jun 2015 15:56:57 +0200
>
> Why is this in the body of the email?
Does the canonical patch format support to preserve
specific details about a shown commit by specification
of fields like "Date" and "From" in the message body?
Regards,
Markus
On Tue, Jul 7, 2015 at 8:21 AM, SF Markus Elfring
<elfring@users.sourceforge.net> wrote:
>>> From: Markus Elfring <elfring@users.sourceforge.net>
>>> Date: Sat, 27 Jun 2015 15:56:57 +0200
>>
>> Why is this in the body of the email?
>
> Does the canonical patch format support to preserve
> specific details about a shown commit by specification
> of fields like "Date" and "From" in the message body?
Using "From:" in the body can be used to provide your properly spelled
name, or the name/e-mail of the actual author, if that happens not to
be the sender. git-send-email will do that automagically for you. If
"From:" is not specified in the message body, the e-mails sender will
be used as author.
The date, as far as I know, is ignored. It is the commit date, not the
authoring date, and once your patch is applied by a maintainer (i.e.
committed), the date gets reset anyway. No need to try and preserve
it.
Frans
On Wed, 01 Jul 2015, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Wed, 1 Jul 2015 12:08:31 +0200 > > The backlight_device_unregister() 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/video/backlight/lp8788_bl.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) Applied, thanks. > diff --git a/drivers/video/backlight/lp8788_bl.c b/drivers/video/backlight/lp8788_bl.c > index e418d5b..5d583d7 100644 > --- a/drivers/video/backlight/lp8788_bl.c > +++ b/drivers/video/backlight/lp8788_bl.c > @@ -221,8 +221,7 @@ static void lp8788_backlight_unregister(struct lp8788_bl *bl) > { > struct backlight_device *bl_dev = bl->bl_dev; > > - if (bl_dev) > - backlight_device_unregister(bl_dev); > + backlight_device_unregister(bl_dev); > } > > static ssize_t lp8788_get_bl_ctl_mode(struct device *dev, -- Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
> The date, as far as I know, is ignored. It is the commit date, > not the authoring date, and once your patch is applied by a maintainer > (i.e. committed), the date gets reset anyway. Thanks for your feedback. > No need to try and preserve it. I find that it might occasionally help to share and keep the record on timestamps about the evolution for an original update suggestion. Regards, Markus
On Tue, Jul 7, 2015 at 9:54 AM, SF Markus Elfring
<elfring@users.sourceforge.net> wrote:
>> No need to try and preserve it.
>
> I find that it might occasionally help to share and keep the record
> on timestamps about the evolution for an original update suggestion.
I think that as far as these kernel mailing lists are concerned, the
date of the update suggestion is the date on which you submitted the
patch, rather than the date you originally committed it to your local
tree. If you wish to keep track of this evolution for yourself, or
wish to share it, you're better off stashing it somewhere in a
(public) git repo that you control. If you wish, you can always make
mention of that repo below the ---, just above the diffstat. If you
insist on placing the date somewhere, you can also put the date there
if you wish. It'll be ignored by git when applied.
Cheers,
Frans
> I think that as far as these kernel mailing lists are concerned, > the date of the update suggestion is the date on which you submitted the patch, > rather than the date you originally committed it to your local tree. I imagine that there are committers who would like to keep corresponding software development history a bit more accurate. > If you wish to keep track of this evolution for yourself, or > wish to share it, you're better off stashing it somewhere in a > (public) git repo that you control. Would it be nicer to preserve such data directly also by the usual mail interface? > If you insist on placing the date somewhere, you can also put the date > there if you wish. It'll be ignored by git when applied. This content management tool provides the capability to store the discussed information by the parameters "--author=" and "--date=", doesn't it? Is the environment variable "GIT_AUTHOR_DATE" also interesting occasionally? How often do you take extra care for passing appropriate data there? Regards, Markus
On Tue, Jul 7, 2015 at 1:53 PM, SF Markus Elfring <elfring@users.sourceforge.net> wrote: >> I think that as far as these kernel mailing lists are concerned, >> the date of the update suggestion is the date on which you submitted the patch, >> rather than the date you originally committed it to your local tree. > > I imagine that there are committers who would like to keep > corresponding software development history a bit more accurate. I guess it depends on what your view on accurate is. >> If you wish to keep track of this evolution for yourself, or >> wish to share it, you're better off stashing it somewhere in a >> (public) git repo that you control. > > Would it be nicer to preserve such data directly also > by the usual mail interface? > > >> If you insist on placing the date somewhere, you can also put the date >> there if you wish. It'll be ignored by git when applied. > > This content management tool provides the capability to store > the discussed information by the parameters "--author=" and "--date=", > doesn't it? > Is the environment variable "GIT_AUTHOR_DATE" also interesting occasionally? > > How often do you take extra care for passing appropriate data there? I can't remember ever changing or explicitly preserving the commit date. I don't think I care enough. I did change the author on botched patches, but that's an exception. Remembering the author separately from the committer is something git does by design anyway. Frans
> I can't remember ever changing or explicitly preserving the commit date. > I don't think I care enough. Would any more software developers and maintainers like to share their experiences around such details? When do commit timestamps become relevant as a documentation item for contribution authorship? > Remembering the author separately from the committer is something > git does by design anyway. Do you usually just reuse a procedure from a well-known command for which a description is provided like the following? http://git-scm.com/docs/git-am '… "From: " and "Subject: " lines starting the body override the respective commit author name and title values taken from the headers. …' Will further fields be eventually mentioned there? Regards, Markus
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 7 Jul 2015 21:48:23 +0200 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 | 7 ++----- scripts/kconfig/symbol.c | 3 +-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index c814f57..0b7dc2f 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -268,8 +268,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; } @@ -404,9 +403,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 70c5ee1..50878dc 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -467,8 +467,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); } bool sym_tristate_within_range(struct symbol *sym, tristate val) -- 2.4.5
Hi Markus, On Wed, Jul 8, 2015 at 2:15 AM, SF Markus Elfring <elfring@users.sourceforge.net> wrote: >> I can't remember ever changing or explicitly preserving the commit date. >> I don't think I care enough. > > Would any more software developers and maintainers like to share > their experiences around such details? > > When do commit timestamps become relevant as a documentation item > for contribution authorship? They are never relevant. "When" a commit happened is never relevant except in relation to other things, at which point the actual date and time is almost completely irrelevant. Just submit your patches using git-format-patch or git-send-email and friends. There's a file in the documentation directory of the kernel tree describing submitting patches and email client setup. Read them both, do what they say without anything extra. >> Remembering the author separately from the committer is something >> git does by design anyway. > > Do you usually just reuse a procedure from a well-known command > for which a description is provided like the following? > http://git-scm.com/docs/git-am > '… > "From: " and "Subject: " lines starting the body override > the respective commit author name and title values > taken from the headers. > …' > > Will further fields be eventually mentioned there? Why? Just do what is described in SubmittingPatches. Your attempts to "improve" on the system are unnecessary and annoying people. The instructions there are the recommended way to do things for a reason. Thanks, -- Julian Calaby Email: julian.calaby@gmail.com Profile: http://www.google.com/profiles/julian.calaby/
> There's a file in the documentation directory of the kernel > tree describing submitting patches and email client setup. > Read them both, I read this information several times. > do what they say without anything extra. Do you see any special consequences if a bit of "extra" functionality is already provided by the Git software for a while? > Your attempts to "improve" on the system are unnecessary It seems that my approach does not need improvements for the current command "git am". Would a few extensions for the available documentation help to clarify the situation? Do items like "commit mail address" and "commit timestamp" belong together for the data structure "author" by design in this content management system? > and annoying people. I understand that various update suggestions can be surprising. It is also usual that corresponding acceptance might take a bit longer than what some contributors would prefer. Regards, Markus
Hi Markus, On Wed, Jul 8, 2015 at 5:09 PM, SF Markus Elfring <elfring@users.sourceforge.net> wrote: >> There's a file in the documentation directory of the kernel >> tree describing submitting patches and email client setup. >> Read them both, > > I read this information several times. > > >> do what they say without anything extra. > > Do you see any special consequences if a bit of "extra" functionality > is already provided by the Git software for a while? If it's harmless, then no, but in this case, people are questioning why you're adding it as it adds no value to anyone and makes it look like you don't know what you're doing. >> Your attempts to "improve" on the system are unnecessary > > It seems that my approach does not need improvements for the current > command "git am". > Would a few extensions for the available documentation help to clarify > the situation? The issue is that the headers you're adding, From: and Date: are unnecessary. The From: header you add is unnecessary as your email's From: header has the exact same information. The reason it's there is because sometimes people forward patches on from other people, e.g. if I were to resend one of your patches, I'd add a From: header to the body of the email so it'd be credited to you. The Date: header you add is unnecessary as git-format-patch sets the date header in the email it produces to the author date stored in the commit. (see below) So if you're sending your patches in emails produced by git-format-patch, there's absolutely no reason to include it. > Do items like "commit mail address" and "commit timestamp" > belong together for the data structure "author" by design > in this content management system? The information stored for a commit is: = = = = = tree 09496defc9eb793c665a7b80aa22f24c7bd5f204 parent 63c07589832bfe5ec49f2523ddb0e94a20af0f31 author Julian Calaby <julian.calaby@gmail.com> 1435196810 +1000 committer Julian Calaby <julian.calaby@gmail.com> 1436322540 +1000 = = = = = Then the subject and commit message. The numbers after the email addresses are the timestamps. They are both almost completely irrelevant for most workflows as people are less interested in when a commit was made and more interested in what release it's in, how it was merged, etc. All of which should be determined without using the timestamp. To be honest, I've only ever used that timestamp for reporting purposes at work, and I'd be surprised if anyone was doing anything other than that with them. In short, nobody cares, and nobody's going to be upset if the actual time you authored a patch is different to the time recorded upstream. >> and annoying people. > > I understand that various update suggestions can be surprising. > It is also usual that corresponding acceptance might take > a bit longer than what some contributors would prefer. How would you feel if someone came in to your place of work and told you to change how you do the job you've been doing for years without a good reason? Thanks, -- Julian Calaby Email: julian.calaby@gmail.com Profile: http://www.google.com/profiles/julian.calaby/
>> The kfree() function was called in two cases by the mac_ioctl() function
>> during error handling even if the passed variable did not contain a pointer
>> for a valid data item.
>>
>> * This implementation detail could be improved by the introduction
>> of another jump label.
>>
>> * Drop an unnecessary initialisation for the variable "buff" then.
>
> That's a different issue, please fix it in a separate patch.
I have got an other opinion here.
This update suggestion depends on a small source code clean-up
from the previous patch, doesn't it?
Do you want that I split the second suggestion from this series
into more steps?
Regards,
Markus
> If it's harmless, then no, but in this case, people are questioning > why you're adding it as it adds no value Some Git software developers care to keep the information complete for the author commit. > to anyone and makes it look like you don't know what you're doing. I specify message field overrides in my update suggestions intentionally. > The issue is that the headers you're adding, From: and Date: are unnecessary. We have got different opinions about the purpose. > The From: header you add is unnecessary as your email's From: header > has the exact same information. I would like to point out that there is a slight difference in my use case. > The reason it's there is because sometimes people forward patches on > from other people, e.g. if I were to resend one of your patches, > I'd add a From: header to the body of the email so it'd be credited to you. I am also interested in such an use case. > The Date: header you add is unnecessary as git-format-patch sets the > date header in the email it produces to the author date stored in the commit. How do you think about my extra patch preparation for the mentioned mail forwarding? > So if you're sending your patches in emails produced by git-format-patch, > there's absolutely no reason to include it. I disagree here to some degree. The difference in suggested commit timestamps of a few minutes might look negligible for some patches. There are few occasions where the delay between a concrete commit and its publishing by an interface like email can become days. > They are both almost completely irrelevant for most workflows as people > are less interested in when a commit was made and more interested in what > release it's in, how it was merged, etc. All of which should be > determined without using the timestamp. How often will it matter who made and published a change first? > To be honest, I've only ever used that timestamp for reporting > purposes at work, and I'd be surprised if anyone was doing anything > other than that with them. Thanks for your detailed feedback. > How would you feel if someone came in to your place of work > and told you to change how you do the job you've been doing for years > without a good reason? You might feel uncomfortable for a moment if you would interpret such a suggestion as a personal attack. I guess that I point only a few technical details out which can change the popularity of existing functionality from the Git software. Regards, Markus
Hi Markus, On Wed, Jul 8, 2015 at 7:28 PM, SF Markus Elfring <elfring@users.sourceforge.net> wrote: >> If it's harmless, then no, but in this case, people are questioning >> why you're adding it as it adds no value > > Some Git software developers care to keep the information complete > for the author commit. > > >> to anyone and makes it look like you don't know what you're doing. > > I specify message field overrides in my update suggestions intentionally. > > >> The issue is that the headers you're adding, From: and Date: are unnecessary. > > We have got different opinions about the purpose. Let me rephrase that: they _should_ be unnecessary. >> The From: header you add is unnecessary as your email's From: header >> has the exact same information. > > I would like to point out that there is a slight difference in my use case. Then fix your email client or patch submission process. >> The reason it's there is because sometimes people forward patches on >> from other people, e.g. if I were to resend one of your patches, >> I'd add a From: header to the body of the email so it'd be credited to you. > > I am also interested in such an use case. This happens automatically if you use git-format-patch on a commit you didn't author. Nobody is adding this manually. >> The Date: header you add is unnecessary as git-format-patch sets the >> date header in the email it produces to the author date stored in the commit. > > How do you think about my extra patch preparation for the mentioned > mail forwarding? It sounds like you're using what could only be described as a Rube-Goldberg process to send email. Is there truly no way to simplify that process? (Also, are the servers you send it through re-writing the original headers?) You should be sending the patches directly with SMTP using git-send-email, if you're not, then you're making things overly complicated for yourself. >> So if you're sending your patches in emails produced by git-format-patch, >> there's absolutely no reason to include it. > > I disagree here to some degree. > > The difference in suggested commit timestamps of a few minutes might look > negligible for some patches. There are few occasions where the delay between > a concrete commit and its publishing by an interface like email > can become days. I made a commit a month ago, it got rebased today, in fact, I sent it's metadata in my previous email. When I ran git-format-patch on it, the timestamp in the headers of the email produced was the date from a month ago. If I then sent that email, I believe it'd make it to the list here with that date intact. If it hadn't, I'd be trying to figure out why and either fix it or find a different path to get my patch here. >> They are both almost completely irrelevant for most workflows as people >> are less interested in when a commit was made and more interested in what >> release it's in, how it was merged, etc. All of which should be >> determined without using the timestamp. > > How often will it matter who made and published a change first? If multiple people are submitting identical changes, then the one that is applied is the one the maintainer sees first, which will most likely be determined by which one hit their inbox / list first. Nobody is going to look at timestamps in emails to determine which one will be applied. If you're worried about which one of several versions of a patch will be applied, change the subject to [PATCH v2] ..... instead of [PATCH] .... for the second version. >> To be honest, I've only ever used that timestamp for reporting >> purposes at work, and I'd be surprised if anyone was doing anything >> other than that with them. > > Thanks for your detailed feedback. > > >> How would you feel if someone came in to your place of work >> and told you to change how you do the job you've been doing for years >> without a good reason? > > You might feel uncomfortable for a moment if you would interpret > such a suggestion as a personal attack. I'm not interpreting this as a personal attack. > I guess that I point only a few technical details out which can change > the popularity of existing functionality from the Git software. Git was originally written to manage the Linux kernel. This feature was probably added by either Linus himself or one of the original developers who I believe were kernel developers. The patch submission process has been around for a long time, if this feature isn't used, it's for a good reason. Having a feature doesn't mean that it should be used. Thanks, -- Julian Calaby Email: julian.calaby@gmail.com Profile: http://www.google.com/profiles/julian.calaby/
> Is there truly no way to simplify that process? I see some software development possibilities which could improve the communication with high volume mailing lists. > You should be sending the patches directly with SMTP using git-send-email, This tool is also fine for the publishing of a lot of patches. > if you're not, then you're making things overly complicated for yourself. But I prefer a graphical user interface for my mail handling so far. > Having a feature doesn't mean that it should be used. Does any of the "questionable functionality" get occasionally overlooked a bit too often? Regards, Markus
On Wed, Jul 08, 2015 at 09:05:53PM +1000, Julian Calaby wrote: > If multiple people are submitting identical changes, then the one that > is applied is the one the maintainer sees first, which will most > likely be determined by which one hit their inbox / list first. Nobody > is going to look at timestamps in emails to determine which one will > be applied. And some maintainers may choose *not* to act on a patch first, even if they see it first. They might be focused on bug fix patches, and not act on cleanup or feature patches until -rc3 or rc4. Or maybe they will use separate branches for "urgent_for_linus" patches, so two different patchs may end up in completely different git flows. > If you're worried about which one of several versions of a patch will > be applied, change the subject to [PATCH v2] ..... instead of [PATCH] > .... for the second version. *Please* do this. In fact, this is the one thing I wish git send-email would do automatically, along with having a place to edit and track the 0/N summary patch. > >> To be honest, I've only ever used that timestamp for reporting > >> purposes at work, and I'd be surprised if anyone was doing anything > >> other than that with them. > > > > Thanks for your detailed feedback. Note also that some maintainers have work flow that deliberately smash the date (i.e., because they are using a system such as guilt), so if you are depending on the submitted timestamp, it's going to break on you. - Ted
> Note also that some maintainers have work flow that deliberately smash
> the date (i.e., because they are using a system such as guilt),
> so if you are depending on the submitted timestamp, it's going to
> break on you.
Thanks for your hint.
I am just trying to offer the possibility for the reuse of a more
precise commit timestamp together with an appropriate author mail
address for my update suggestions.
Do you reject any more such message field overrides?
Regards,
Markus
> Reviewed-by: Zhao Junwang <zhjwpku@gmail.com>
>
> kfree will check that.
How does this feedback fit to a check before a call
of the vfree() function?
Regards,
Markus
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 19 Nov 2014 21:25:39 +0100
>
> The kobject_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>
> ---
> drivers/md/bcache/super.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
> index d4713d0..1443c55 100644
> --- a/drivers/md/bcache/super.c
> +++ b/drivers/md/bcache/super.c
> @@ -2076,8 +2076,7 @@ static void bcache_exit(void)
> {
> bch_debug_exit();
> bch_request_exit();
> - if (bcache_kobj)
> - kobject_put(bcache_kobj);
> + kobject_put(bcache_kobj);
> if (bcache_wq)
> destroy_workqueue(bcache_wq);
> if (bcache_major)
>
Would you like to integrate this update suggestion
into another source code repository?
Regards,
Markus
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 5 Feb 2015 10:12:51 +0100
>
> The vunmap() 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/gpu/drm/tegra/fb.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/tegra/fb.c b/drivers/gpu/drm/tegra/fb.c
> index e9c715d..803598e 100644
> --- a/drivers/gpu/drm/tegra/fb.c
> +++ b/drivers/gpu/drm/tegra/fb.c
> @@ -66,7 +66,7 @@ static void tegra_fb_destroy(struct drm_framebuffer *framebuffer)
> struct tegra_bo *bo = fb->planes[i];
>
> if (bo) {
> - if (bo->pages && bo->vaddr)
> + if (bo->pages)
> vunmap(bo->vaddr);
>
> drm_gem_object_unreference_unlocked(&bo->gem);
>
Would you like to integrate this update suggestion
into another source code repository?
Regards,
Markus
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 8 Jul 2015 21:26:02 +0200 The kobject_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/hda/hdac_sysfs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sound/hda/hdac_sysfs.c b/sound/hda/hdac_sysfs.c index 0a6ce3b..089b35f 100644 --- a/sound/hda/hdac_sysfs.c +++ b/sound/hda/hdac_sysfs.c @@ -321,8 +321,7 @@ static void widget_tree_free(struct hdac_device *codec) free_widget_node(*p, &widget_node_group); kfree(tree->nodes); } - if (tree->root) - kobject_put(tree->root); + kobject_put(tree->root); kfree(tree); codec->widgets = NULL; } -- 2.4.5
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 8 Jul 2015 22:12:25 +0200 The gpiod_put() function performs also input parameter validation by forwarding its single input pointer to the gpiod_free() function. Thus the test around the calls is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/hid/i2c-hid/i2c-hid.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c index f77469d..09ff4e7 100644 --- a/drivers/hid/i2c-hid/i2c-hid.c +++ b/drivers/hid/i2c-hid/i2c-hid.c @@ -1048,9 +1048,7 @@ err_pm: pm_runtime_disable(&client->dev); err: - if (ihid->desc) - gpiod_put(ihid->desc); - + gpiod_put(ihid->desc); i2c_hid_free_buffers(ihid); kfree(ihid); return ret; @@ -1074,9 +1072,7 @@ static int i2c_hid_remove(struct i2c_client *client) if (ihid->bufsize) i2c_hid_free_buffers(ihid); - if (ihid->desc) - gpiod_put(ihid->desc); - + gpiod_put(ihid->desc); kfree(ihid); acpi_dev_remove_driver_gpios(ACPI_COMPANION(&client->dev)); -- 2.4.5
Hi Markus, On Wed, Jul 8, 2015 at 11:46 PM, SF Markus Elfring <elfring@users.sourceforge.net> wrote: >> Is there truly no way to simplify that process? > > I see some software development possibilities which could improve > the communication with high volume mailing lists. You shouldn't need any software development, most people's processes are: 1. Make changes 2. git add <files> 3. git commit 4. Repeat 1-3 for all changes they want to make 5. git-format-patch 6. git-send-email through some SMTP server to the list and appropriate other people From what I've read, you appear to have some semi-automatic tool for steps 1 through 4. I'd strongly recommend changing your patch submission process to use git-format-patch and git-send-email. If Sourceforge's email system doesn't let you send emails with SMTP directly, then you might want to try sending emails through your ISP's mail server. Maintainers use a very similar process, however they collect and review patches in some personal repository in addition to making changes and committing them. Tools like patchwork are simply fancy methods of accumulating patches into git trees. Most people are using git-format-patch and git-send-email, possibly with some scripting around them, to format and send patches. >> You should be sending the patches directly with SMTP using git-send-email, > > This tool is also fine for the publishing of a lot of patches. git-send-email or some other tool? >> if you're not, then you're making things overly complicated for yourself. > > But I prefer a graphical user interface for my mail handling so far. I send my patches using git-send-email through gmail's servers then deal with literally everything else through gmail's web interface or Android app. Using git-send-email doesn't mean you can't use a graphical mail interface. I used to send patches through a carefully configured instance of Thunderbird, however this required too many steps and it loved to mangle patches in ways that annoyed people. >> Having a feature doesn't mean that it should be used. > > Does any of the "questionable functionality" get occasionally overlooked > a bit too often? It's not "questionable functionality", it's functionality we don't see a need for. If I wanted to, I could insert a patch at any point in the history of Linux in my own repository, however any attempt to push that upstream would cause enormous amounts of pain and annoyance, to everyone who attempted to deal with it, so I don't. Thanks, -- Julian Calaby Email: julian.calaby@gmail.com Profile: http://www.google.com/profiles/julian.calaby/
On Thu, Jul 02, 2015 at 05:10:41PM +0200, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 2 Jul 2015 17:00:14 +0200
>
> 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.
Thanks, applied to ipvs-next for v4.3.
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 9 Jul 2015 08:00:10 +0200 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 | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 4c0ffca..936ad77 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -1149,12 +1149,9 @@ static void wacom_free_inputs(struct wacom *wacom) { struct wacom_wac *wacom_wac = &(wacom->wacom_wac); - if (wacom_wac->pen_input) - input_free_device(wacom_wac->pen_input); - if (wacom_wac->touch_input) - input_free_device(wacom_wac->touch_input); - if (wacom_wac->pad_input) - input_free_device(wacom_wac->pad_input); + input_free_device(wacom_wac->pen_input); + input_free_device(wacom_wac->touch_input); + input_free_device(wacom_wac->pad_input); wacom_wac->pen_input = NULL; wacom_wac->touch_input = NULL; wacom_wac->pad_input = NULL; -- 2.4.5
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 9 Jul 2015 09:52:24 +0200 The unregister_sysctl_table() 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/cdrom/cdrom.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c index 5d28a45..e43e84d 100644 --- a/drivers/cdrom/cdrom.c +++ b/drivers/cdrom/cdrom.c @@ -3698,8 +3698,7 @@ static void cdrom_sysctl_register(void) static void cdrom_sysctl_unregister(void) { - if (cdrom_sysctl_header) - unregister_sysctl_table(cdrom_sysctl_header); + unregister_sysctl_table(cdrom_sysctl_header); } #else /* CONFIG_SYSCTL */ -- 2.4.5
This one deserves some extra review because it introduces a call to: WARN_ON(extra_checks); in gpiod_free(). That may or may not matter... regards, dan carpenter
Am 05.02.2015 um 22:27 schrieb SF Markus Elfring:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 5 Feb 2015 22:23:48 +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>
> ---
> drivers/scsi/aic7xxx/aic7xxx_core.c | 15 +++++----------
> 1 file changed, 5 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/scsi/aic7xxx/aic7xxx_core.c b/drivers/scsi/aic7xxx/aic7xxx_core.c
> index 10172a3..98a5ed1 100644
> --- a/drivers/scsi/aic7xxx/aic7xxx_core.c
> +++ b/drivers/scsi/aic7xxx/aic7xxx_core.c
> @@ -2200,8 +2200,7 @@ ahc_free_tstate(struct ahc_softc *ahc, u_int scsi_id, char channel, int force)
> if (channel = 'B')
> scsi_id += 8;
> tstate = ahc->enabled_targets[scsi_id];
> - if (tstate != NULL)
> - kfree(tstate);
> + kfree(tstate);
> ahc->enabled_targets[scsi_id] = NULL;
> }
> #endif
> @@ -4482,8 +4481,7 @@ ahc_set_unit(struct ahc_softc *ahc, int unit)
> void
> ahc_set_name(struct ahc_softc *ahc, char *name)
> {
> - if (ahc->name != NULL)
> - kfree(ahc->name);
> + kfree(ahc->name);
> ahc->name = name;
> }
>
> @@ -4550,10 +4548,8 @@ ahc_free(struct ahc_softc *ahc)
> kfree(ahc->black_hole);
> }
> #endif
> - if (ahc->name != NULL)
> - kfree(ahc->name);
> - if (ahc->seep_config != NULL)
> - kfree(ahc->seep_config);
> + kfree(ahc->name);
> + kfree(ahc->seep_config);
> #ifndef __FreeBSD__
> kfree(ahc);
> #endif
> @@ -4958,8 +4954,7 @@ ahc_fini_scbdata(struct ahc_softc *ahc)
> case 0:
> break;
> }
> - if (scb_data->scbarray != NULL)
> - kfree(scb_data->scbarray);
> + kfree(scb_data->scbarray);
> }
>
> static void
>
Would you like to integrate this update suggestion
into another source code repository?
Regards,
Markus
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 21 Nov 2014 09:15:10 +0100
>
> The dst_release() 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/scsi/cxgbi/libcxgbi.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/cxgbi/libcxgbi.c b/drivers/scsi/cxgbi/libcxgbi.c
> index addd1dd..95d2654 100644
> --- a/drivers/scsi/cxgbi/libcxgbi.c
> +++ b/drivers/scsi/cxgbi/libcxgbi.c
> @@ -798,8 +798,7 @@ void cxgbi_sock_closed(struct cxgbi_sock *csk)
> return;
> if (csk->saddr.sin_port)
> sock_put_port(csk);
> - if (csk->dst)
> - dst_release(csk->dst);
> + dst_release(csk->dst);
> csk->cdev->csk_release_offload_resources(csk);
> cxgbi_sock_set_state(csk, CTP_CLOSED);
> cxgbi_inform_iscsi_conn_closing(csk);
>
Would you like to integrate this update suggestion
into another source code repository?
Regards,
Markus
On Wed, 08 Jul 2015 21:31:57 +0200, SF Markus Elfring wrote: > > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Wed, 8 Jul 2015 21:26:02 +0200 > > The kobject_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> Applied, thanks. Takashi > --- > sound/hda/hdac_sysfs.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/sound/hda/hdac_sysfs.c b/sound/hda/hdac_sysfs.c > index 0a6ce3b..089b35f 100644 > --- a/sound/hda/hdac_sysfs.c > +++ b/sound/hda/hdac_sysfs.c > @@ -321,8 +321,7 @@ static void widget_tree_free(struct hdac_device *codec) > free_widget_node(*p, &widget_node_group); > kfree(tree->nodes); > } > - if (tree->root) > - kobject_put(tree->root); > + kobject_put(tree->root); > kfree(tree); > codec->widgets = NULL; > } > -- > 2.4.5 >
On Thu, 9 Jul 2015, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 9 Jul 2015 08:00:10 +0200
>
> 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>
This is really on a "is it worth it?" borderline, but anyway ... applied
to for-4.3/upstream.
Thanks,
--
Jiri Kosina
SUSE Labs
On Wed, 8 Jul 2015, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 8 Jul 2015 22:12:25 +0200
>
> The gpiod_put() function performs also input parameter validation
> by forwarding its single input pointer to the gpiod_free() function.
> Thus the test around the calls is not needed.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
As Dan correctly pointed out, this is not as straightforward as it might
seem on a firsr sight, because there is a WARN_ON() that might start
triggering in case of !ihid->desc.
Adding Benjamin. I am not applying this without his Ack.
--
Jiri Kosina
SUSE Labs
On Wed, Jul 08, 2015 at 05:27:38PM +0200, SF Markus Elfring wrote:
> > Note also that some maintainers have work flow that deliberately smash
> > the date (i.e., because they are using a system such as guilt),
> > so if you are depending on the submitted timestamp, it's going to
> > break on you.
>
> Thanks for your hint.
>
> I am just trying to offer the possibility for the reuse of a more
> precise commit timestamp together with an appropriate author mail
> address for my update suggestions.
> Do you reject any more such message field overrides?
Well, I won't hold it against you, since I also often need to fix
patches or git commit descriptions anyway. But at the same time, my
workflow (which you have no right to dictate) **will** destroy your
timestamp. Given that you haven't explained why you want to do this,
I'm not going have much sympathy if you complain.
Personally, given that you're going through some extremely baroque
e-mail/patchsubmission scheme, I don't understand why you can't also
arrange to override the Date field in the e-mail header. But I don't
really care all that much, because I can ignore your timestamp no
matter where you put it.
Regards,
- Ted
On Thu, Jul 9, 2015 at 8:34 AM, Jiri Kosina <jkosina@suse.com> wrote:
> On Wed, 8 Jul 2015, SF Markus Elfring wrote:
>
>> From: Markus Elfring <elfring@users.sourceforge.net>
>> Date: Wed, 8 Jul 2015 22:12:25 +0200
>>
>> The gpiod_put() function performs also input parameter validation
>> by forwarding its single input pointer to the gpiod_free() function.
>> Thus the test around the calls is not needed.
>>
>> This issue was detected by using the Coccinelle software.
>>
>> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
>
> As Dan correctly pointed out, this is not as straightforward as it might
> seem on a firsr sight, because there is a WARN_ON() that might start
> triggering in case of !ihid->desc.
>
> Adding Benjamin. I am not applying this without his Ack.
>
I think the gpiod case is the exception rather than the common rule
(most i2c-hid device we saw until recently were using irqs, not
gpios). So if I understand correctly, removing the check on ihid->desc
would raise a warning for most devices. This is IMO not a good thing,
so I would say NACK.
Mika might have a different opinion though.
Cheers,
Benjamin
>>> The gpiod_put() function performs also input parameter validation
>>> by forwarding its single input pointer to the gpiod_free() function.
>>> Thus the test around the calls is not needed.
>>>
>>> This issue was detected by using the Coccinelle software.
>>>
>>> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
>>
>> As Dan correctly pointed out, this is not as straightforward as it might
>> seem on a firsr sight, because there is a WARN_ON() that might start
>> triggering in case of !ihid->desc.
>>
>> Adding Benjamin. I am not applying this without his Ack.
>>
>
> I think the gpiod case is the exception rather than the common rule
> (most i2c-hid device we saw until recently were using irqs, not
> gpios). So if I understand correctly, removing the check on ihid->desc
> would raise a warning for most devices. This is IMO not a good thing,
> so I would say NACK.
>
> Mika might have a different opinion though.
The proposed update candidates are contained in the source
file "drivers/hid/i2c-hid/i2c-hid.c" from Linux next-20150708.
* i2c_hid_remove() function:
Can it be tolerated here that the pointer "ihid->desc" might be eventually null?
* i2c_hid_probe() function:
Is this implementation structured in such a way that a pointer for valid data
will be usually passed for "ihid->desc" if the statements after the jump
label "err" will be reached?
Regards,
Markus
On Thu, Jul 9, 2015 at 4:49 PM, SF Markus Elfring
<elfring@users.sourceforge.net> wrote:
>>>> The gpiod_put() function performs also input parameter validation
>>>> by forwarding its single input pointer to the gpiod_free() function.
>>>> Thus the test around the calls is not needed.
>>>>
>>>> This issue was detected by using the Coccinelle software.
>>>>
>>>> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
>>>
>>> As Dan correctly pointed out, this is not as straightforward as it might
>>> seem on a firsr sight, because there is a WARN_ON() that might start
>>> triggering in case of !ihid->desc.
>>>
>>> Adding Benjamin. I am not applying this without his Ack.
>>>
>>
>> I think the gpiod case is the exception rather than the common rule
>> (most i2c-hid device we saw until recently were using irqs, not
>> gpios). So if I understand correctly, removing the check on ihid->desc
>> would raise a warning for most devices. This is IMO not a good thing,
>> so I would say NACK.
>>
>> Mika might have a different opinion though.
>
> The proposed update candidates are contained in the source
> file "drivers/hid/i2c-hid/i2c-hid.c" from Linux next-20150708.
>
> * i2c_hid_remove() function:
> Can it be tolerated here that the pointer "ihid->desc" might be eventually null?
>
> * i2c_hid_probe() function:
> Is this implementation structured in such a way that a pointer for valid data
> will be usually passed for "ihid->desc" if the statements after the jump
> label "err" will be reached?
>
Again, in both case it is completely normal to have "ihid->desc =
NULL" given that this field is only retrieved in case of an ACPI
device which does not declares an IRQ but a GPIO. Most ACPI devices I
saw are using a simple IRQ, and the OF instantiations of the driver
will definitively have ihid->desc null. So I do not want to have a
warning for most of i2c-hid devices out there (because I will have to
explain that this is completely normal again and again).
Cheers,
Benjamin
>> The proposed update candidates are contained in the source
>> file "drivers/hid/i2c-hid/i2c-hid.c" from Linux next-20150708.
>>
>> * i2c_hid_remove() function:
>> Can it be tolerated here that the pointer "ihid->desc" might be eventually null?
>>
>> * i2c_hid_probe() function:
>> Is this implementation structured in such a way that a pointer for valid data
>> will be usually passed for "ihid->desc" if the statements after the jump
>> label "err" will be reached?
>>
>
> Again, in both case it is completely normal to have "ihid->desc =
> NULL" given that this field is only retrieved in case of an ACPI
> device which does not declares an IRQ but a GPIO. Most ACPI devices I
> saw are using a simple IRQ, and the OF instantiations of the driver
> will definitively have ihid->desc null. So I do not want to have a
> warning for most of i2c-hid devices out there (because I will have to
> explain that this is completely normal again and again).
Would it make sense to annotate checks before such function calls
as "unlikely" then?
Regards,
Markus
On Thu, Jul 9, 2015 at 5:10 PM, SF Markus Elfring
<elfring@users.sourceforge.net> wrote:
>>> The proposed update candidates are contained in the source
>>> file "drivers/hid/i2c-hid/i2c-hid.c" from Linux next-20150708.
>>>
>>> * i2c_hid_remove() function:
>>> Can it be tolerated here that the pointer "ihid->desc" might be eventually null?
>>>
>>> * i2c_hid_probe() function:
>>> Is this implementation structured in such a way that a pointer for valid data
>>> will be usually passed for "ihid->desc" if the statements after the jump
>>> label "err" will be reached?
>>>
>>
>> Again, in both case it is completely normal to have "ihid->desc =
>> NULL" given that this field is only retrieved in case of an ACPI
>> device which does not declares an IRQ but a GPIO. Most ACPI devices I
>> saw are using a simple IRQ, and the OF instantiations of the driver
>> will definitively have ihid->desc null. So I do not want to have a
>> warning for most of i2c-hid devices out there (because I will have to
>> explain that this is completely normal again and again).
>
> Would it make sense to annotate checks before such function calls
> as "unlikely" then?
>
I don't see the benefits of this right now. These calls are not time
critical and it's not because today they are few devices with GPIOs
rather than IRQs that it will be the case all the time.
You can always submit a patch preventing coccinelle to raise this
warning, but maybe a simple comment in the code would be enough.
Cheers,
Benjamin
On Thu, Jul 9, 2015 at 3:40 AM, SF Markus Elfring
<elfring@users.sourceforge.net> wrote:
>> From: Markus Elfring <elfring@users.sourceforge.net>
>> Date: Thu, 5 Feb 2015 10:12:51 +0100
>>
>> The vunmap() function performs also input parameter validation.
>> Thus the test around the call is not needed.
>>
>> This issue was detected by using the Coccinelle software.
The fix is correct, but the subject looks weird.
"GPU-DRM-Tegra:"should be "drm/tegra:".
Otherwise,
Acked-by: Alexandre Courbot <acourbot@nvidia.com>
Maybe Thierry can take it through his tree once this issue is addressed?
On Fri, Jun 26, 2015 at 11:23:29PM +0200, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 26 Jun 2015 23:10:42 +0200
Sorry, I'm not taking any of your patches until you fix this all up.
greg k-h
From: Markus Elfring <elfring@users.sourceforge.net> The following functions test whether their argument is NULL and then return immediately. * kfree * ll_file_data_put * ptlrpc_connection_put Thus the test around such calls is not needed. This issue was detected by using the Coccinelle software. See also a previous update suggestion: "remove unneeded null test before free" by Julia Lawall https://lkml.org/lkml/2015/5/1/498 https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg878600.html Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/staging/lustre/lustre/llite/file.c | 3 +-- drivers/staging/lustre/lustre/llite/llite_lib.c | 2 +- drivers/staging/lustre/lustre/ptlrpc/import.c | 6 ++---- drivers/staging/lustre/lustre/ptlrpc/service.c | 4 +--- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/staging/lustre/lustre/llite/file.c b/drivers/staging/lustre/lustre/llite/file.c index 3075db2..1a85c41 100644 --- a/drivers/staging/lustre/lustre/llite/file.c +++ b/drivers/staging/lustre/lustre/llite/file.c @@ -702,8 +702,7 @@ out_och_free: out_openerr: if (opendir_set != 0) ll_stop_statahead(inode, lli->lli_opendir_key); - if (fd != NULL) - ll_file_data_put(fd); + ll_file_data_put(fd); } else { ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_OPEN, 1); } diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c b/drivers/staging/lustre/lustre/llite/llite_lib.c index 2513988..ab4839c 100644 --- a/drivers/staging/lustre/lustre/llite/llite_lib.c +++ b/drivers/staging/lustre/lustre/llite/llite_lib.c @@ -1114,7 +1114,7 @@ void ll_clear_inode(struct inode *inode) if (lli->lli_mds_read_och) ll_md_real_close(inode, FMODE_READ); - if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) { + if (S_ISLNK(inode->i_mode)) { kfree(lli->lli_symlink_name); lli->lli_symlink_name = NULL; } diff --git a/drivers/staging/lustre/lustre/ptlrpc/import.c b/drivers/staging/lustre/lustre/ptlrpc/import.c index c9b8481..1eae389 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/import.c +++ b/drivers/staging/lustre/lustre/ptlrpc/import.c @@ -555,14 +555,12 @@ static int import_select_connection(struct obd_import *imp) imp_conn->oic_last_attempt = cfs_time_current_64(); /* switch connection, don't mind if it's same as the current one */ - if (imp->imp_connection) - ptlrpc_connection_put(imp->imp_connection); + ptlrpc_connection_put(imp->imp_connection); imp->imp_connection = ptlrpc_connection_addref(imp_conn->oic_conn); dlmexp = class_conn2export(&imp->imp_dlm_handle); LASSERT(dlmexp != NULL); - if (dlmexp->exp_connection) - ptlrpc_connection_put(dlmexp->exp_connection); + ptlrpc_connection_put(dlmexp->exp_connection); dlmexp->exp_connection = ptlrpc_connection_addref(imp_conn->oic_conn); class_export_put(dlmexp); diff --git a/drivers/staging/lustre/lustre/ptlrpc/service.c b/drivers/staging/lustre/lustre/ptlrpc/service.c index 9117f1c..b9ae0b7 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/service.c +++ b/drivers/staging/lustre/lustre/ptlrpc/service.c @@ -2826,9 +2826,7 @@ void ptlrpc_hr_fini(void) ptlrpc_stop_hr_threads(); cfs_percpt_for_each(hrp, i, ptlrpc_hr.hr_partitions) { - if (hrp->hrp_thrs != NULL) { - kfree(hrp->hrp_thrs); - } + kfree(hrp->hrp_thrs); } cfs_percpt_free(ptlrpc_hr.hr_partitions); -- 2.4.4
On Sun, Jun 28, 2015 at 04:52:16PM +0200, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sun, 28 Jun 2015 16:42:04 +0200 > > The functions phy_exit() and phy_power_off() test whether their argument > is NULL and then return immediately. > Thus the test around the calls is not needed. > > This issue was detected by using the Coccinelle software. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> I haven't seen a followup to Ray's review, but in the interest of making progress, I updated and applied the patch as appended. I also reviewed other phy_*() calls under drivers/pci, and they all look OK (with no unnecessary tests for NULL). This is on the pci/host-iproc branch for v4.3. > --- > drivers/pci/host/pcie-iproc.c | 7 ++----- > 1 file changed, 2 insertions(+), 5 deletions(-) > > diff --git a/drivers/pci/host/pcie-iproc.c b/drivers/pci/host/pcie-iproc.c > index d77481e..f875821 100644 > --- a/drivers/pci/host/pcie-iproc.c > +++ b/drivers/pci/host/pcie-iproc.c > @@ -239,12 +239,9 @@ err_rm_root_bus: > pci_remove_root_bus(bus); > > err_power_off_phy: > - if (pcie->phy) > - phy_power_off(pcie->phy); > + phy_power_off(pcie->phy); > err_exit_phy: > - if (pcie->phy) > - phy_exit(pcie->phy); > - > + phy_exit(pcie->phy); > return ret; > } > EXPORT_SYMBOL(iproc_pcie_setup); > -- > 2.4.4 commit 55b5e16332eb9ffc1cbaf975585f4521417ab427 Author: Markus Elfring <elfring@users.sourceforge.net> Date: Sun Jun 28 16:42:04 2015 +0200 PCI: iproc: Delete unnecessary checks before phy calls The functions phy_exit() and phy_power_off() test whether their argument is NULL and then return immediately. Thus the test around the calls is not needed. This issue was detected by using the Coccinelle software. [bhelgaas: also phy_init() and phy_power_on(), as Ray Jui suggested] [bhelgaas: also remove tests in iproc_pcie_remove()] Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> diff --git a/drivers/pci/host/pcie-iproc.c b/drivers/pci/host/pcie-iproc.c index d77481e..9a00dca 100644 --- a/drivers/pci/host/pcie-iproc.c +++ b/drivers/pci/host/pcie-iproc.c @@ -191,19 +191,16 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res) if (!pcie || !pcie->dev || !pcie->base) return -EINVAL; - if (pcie->phy) { - ret = phy_init(pcie->phy); - if (ret) { - dev_err(pcie->dev, "unable to initialize PCIe PHY\n"); - return ret; - } - - ret = phy_power_on(pcie->phy); - if (ret) { - dev_err(pcie->dev, "unable to power on PCIe PHY\n"); - goto err_exit_phy; - } + ret = phy_init(pcie->phy); + if (ret) { + dev_err(pcie->dev, "unable to initialize PCIe PHY\n"); + return ret; + } + ret = phy_power_on(pcie->phy); + if (ret) { + dev_err(pcie->dev, "unable to power on PCIe PHY\n"); + goto err_exit_phy; } iproc_pcie_reset(pcie); @@ -239,12 +236,9 @@ err_rm_root_bus: pci_remove_root_bus(bus); err_power_off_phy: - if (pcie->phy) - phy_power_off(pcie->phy); + phy_power_off(pcie->phy); err_exit_phy: - if (pcie->phy) - phy_exit(pcie->phy); - + phy_exit(pcie->phy); return ret; } EXPORT_SYMBOL(iproc_pcie_setup); @@ -254,10 +248,8 @@ int iproc_pcie_remove(struct iproc_pcie *pcie) pci_stop_root_bus(pcie->root_bus); pci_remove_root_bus(pcie->root_bus); - if (pcie->phy) { - phy_power_off(pcie->phy); - phy_exit(pcie->phy); - } + phy_power_off(pcie->phy); + phy_exit(pcie->phy); return 0; }
Hi Bjorn, On 7/14/2015 1:10 PM, Bjorn Helgaas wrote: > On Sun, Jun 28, 2015 at 04:52:16PM +0200, SF Markus Elfring wrote: >> From: Markus Elfring <elfring@users.sourceforge.net> >> Date: Sun, 28 Jun 2015 16:42:04 +0200 >> >> The functions phy_exit() and phy_power_off() test whether their argument >> is NULL and then return immediately. >> Thus the test around the calls is not needed. >> >> This issue was detected by using the Coccinelle software. >> >> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > > I haven't seen a followup to Ray's review, but in the interest of making > progress, I updated and applied the patch as appended. I also reviewed > other phy_*() calls under drivers/pci, and they all look OK (with no > unnecessary tests for NULL). > > This is on the pci/host-iproc branch for v4.3. > Hmmm....I searched my mailbox but cannot find an email with this patch (while I remember I reviewed and commented on the initial version of this patch). It must have gone into some sub-folder or deleted by me by accident. My bad. Nevertheless,the current patch looks good to me! Thanks, Ray >> --- >> drivers/pci/host/pcie-iproc.c | 7 ++----- >> 1 file changed, 2 insertions(+), 5 deletions(-) >> >> diff --git a/drivers/pci/host/pcie-iproc.c b/drivers/pci/host/pcie-iproc.c >> index d77481e..f875821 100644 >> --- a/drivers/pci/host/pcie-iproc.c >> +++ b/drivers/pci/host/pcie-iproc.c >> @@ -239,12 +239,9 @@ err_rm_root_bus: >> pci_remove_root_bus(bus); >> >> err_power_off_phy: >> - if (pcie->phy) >> - phy_power_off(pcie->phy); >> + phy_power_off(pcie->phy); >> err_exit_phy: >> - if (pcie->phy) >> - phy_exit(pcie->phy); >> - >> + phy_exit(pcie->phy); >> return ret; >> } >> EXPORT_SYMBOL(iproc_pcie_setup); >> -- >> 2.4.4 > > commit 55b5e16332eb9ffc1cbaf975585f4521417ab427 > Author: Markus Elfring <elfring@users.sourceforge.net> > Date: Sun Jun 28 16:42:04 2015 +0200 > > PCI: iproc: Delete unnecessary checks before phy calls > > The functions phy_exit() and phy_power_off() test whether their argument is > NULL and then return immediately. Thus the test around the calls is not > needed. > > This issue was detected by using the Coccinelle software. > > [bhelgaas: also phy_init() and phy_power_on(), as Ray Jui suggested] > [bhelgaas: also remove tests in iproc_pcie_remove()] > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> > > diff --git a/drivers/pci/host/pcie-iproc.c b/drivers/pci/host/pcie-iproc.c > index d77481e..9a00dca 100644 > --- a/drivers/pci/host/pcie-iproc.c > +++ b/drivers/pci/host/pcie-iproc.c > @@ -191,19 +191,16 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res) > if (!pcie || !pcie->dev || !pcie->base) > return -EINVAL; > > - if (pcie->phy) { > - ret = phy_init(pcie->phy); > - if (ret) { > - dev_err(pcie->dev, "unable to initialize PCIe PHY\n"); > - return ret; > - } > - > - ret = phy_power_on(pcie->phy); > - if (ret) { > - dev_err(pcie->dev, "unable to power on PCIe PHY\n"); > - goto err_exit_phy; > - } > + ret = phy_init(pcie->phy); > + if (ret) { > + dev_err(pcie->dev, "unable to initialize PCIe PHY\n"); > + return ret; > + } > > + ret = phy_power_on(pcie->phy); > + if (ret) { > + dev_err(pcie->dev, "unable to power on PCIe PHY\n"); > + goto err_exit_phy; > } > > iproc_pcie_reset(pcie); > @@ -239,12 +236,9 @@ err_rm_root_bus: > pci_remove_root_bus(bus); > > err_power_off_phy: > - if (pcie->phy) > - phy_power_off(pcie->phy); > + phy_power_off(pcie->phy); > err_exit_phy: > - if (pcie->phy) > - phy_exit(pcie->phy); > - > + phy_exit(pcie->phy); > return ret; > } > EXPORT_SYMBOL(iproc_pcie_setup); > @@ -254,10 +248,8 @@ int iproc_pcie_remove(struct iproc_pcie *pcie) > pci_stop_root_bus(pcie->root_bus); > pci_remove_root_bus(pcie->root_bus); > > - if (pcie->phy) { > - phy_power_off(pcie->phy); > - phy_exit(pcie->phy); > - } > + phy_power_off(pcie->phy); > + phy_exit(pcie->phy); > > return 0; > } >
On Tue, Jul 14, 2015 at 01:23:23PM -0700, Ray Jui wrote: > Hi Bjorn, > > On 7/14/2015 1:10 PM, Bjorn Helgaas wrote: > > On Sun, Jun 28, 2015 at 04:52:16PM +0200, SF Markus Elfring wrote: > >> From: Markus Elfring <elfring@users.sourceforge.net> > >> Date: Sun, 28 Jun 2015 16:42:04 +0200 > >> > >> The functions phy_exit() and phy_power_off() test whether their argument > >> is NULL and then return immediately. > >> Thus the test around the calls is not needed. > >> > >> This issue was detected by using the Coccinelle software. > >> > >> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > > > > I haven't seen a followup to Ray's review, but in the interest of making > > progress, I updated and applied the patch as appended. I also reviewed > > other phy_*() calls under drivers/pci, and they all look OK (with no > > unnecessary tests for NULL). > > > > This is on the pci/host-iproc branch for v4.3. > > > > Hmmm....I searched my mailbox but cannot find an email with this patch > (while I remember I reviewed and commented on the initial version of > this patch). It must have gone into some sub-folder or deleted by me by > accident. My bad. > > Nevertheless,the current patch looks good to me! Thanks for checking it out! Can I add your Reviewed-by to the patch below? > > commit 55b5e16332eb9ffc1cbaf975585f4521417ab427 > > Author: Markus Elfring <elfring@users.sourceforge.net> > > Date: Sun Jun 28 16:42:04 2015 +0200 > > > > PCI: iproc: Delete unnecessary checks before phy calls > > > > The functions phy_exit() and phy_power_off() test whether their argument is > > NULL and then return immediately. Thus the test around the calls is not > > needed. > > > > This issue was detected by using the Coccinelle software. > > > > [bhelgaas: also phy_init() and phy_power_on(), as Ray Jui suggested] > > [bhelgaas: also remove tests in iproc_pcie_remove()] > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > > Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> > > > > diff --git a/drivers/pci/host/pcie-iproc.c b/drivers/pci/host/pcie-iproc.c > > index d77481e..9a00dca 100644 > > --- a/drivers/pci/host/pcie-iproc.c > > +++ b/drivers/pci/host/pcie-iproc.c > > @@ -191,19 +191,16 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res) > > if (!pcie || !pcie->dev || !pcie->base) > > return -EINVAL; > > > > - if (pcie->phy) { > > - ret = phy_init(pcie->phy); > > - if (ret) { > > - dev_err(pcie->dev, "unable to initialize PCIe PHY\n"); > > - return ret; > > - } > > - > > - ret = phy_power_on(pcie->phy); > > - if (ret) { > > - dev_err(pcie->dev, "unable to power on PCIe PHY\n"); > > - goto err_exit_phy; > > - } > > + ret = phy_init(pcie->phy); > > + if (ret) { > > + dev_err(pcie->dev, "unable to initialize PCIe PHY\n"); > > + return ret; > > + } > > > > + ret = phy_power_on(pcie->phy); > > + if (ret) { > > + dev_err(pcie->dev, "unable to power on PCIe PHY\n"); > > + goto err_exit_phy; > > } > > > > iproc_pcie_reset(pcie); > > @@ -239,12 +236,9 @@ err_rm_root_bus: > > pci_remove_root_bus(bus); > > > > err_power_off_phy: > > - if (pcie->phy) > > - phy_power_off(pcie->phy); > > + phy_power_off(pcie->phy); > > err_exit_phy: > > - if (pcie->phy) > > - phy_exit(pcie->phy); > > - > > + phy_exit(pcie->phy); > > return ret; > > } > > EXPORT_SYMBOL(iproc_pcie_setup); > > @@ -254,10 +248,8 @@ int iproc_pcie_remove(struct iproc_pcie *pcie) > > pci_stop_root_bus(pcie->root_bus); > > pci_remove_root_bus(pcie->root_bus); > > > > - if (pcie->phy) { > > - phy_power_off(pcie->phy); > > - phy_exit(pcie->phy); > > - } > > + phy_power_off(pcie->phy); > > + phy_exit(pcie->phy); > > > > return 0; > > } > >
On 7/14/2015 1:51 PM, Bjorn Helgaas wrote:
> On Tue, Jul 14, 2015 at 01:23:23PM -0700, Ray Jui wrote:
>> Hi Bjorn,
>>
>> On 7/14/2015 1:10 PM, Bjorn Helgaas wrote:
>>> On Sun, Jun 28, 2015 at 04:52:16PM +0200, SF Markus Elfring wrote:
>>>> From: Markus Elfring <elfring@users.sourceforge.net>
>>>> Date: Sun, 28 Jun 2015 16:42:04 +0200
>>>>
>>>> The functions phy_exit() and phy_power_off() test whether their argument
>>>> is NULL and then return immediately.
>>>> Thus the test around the calls is not needed.
>>>>
>>>> This issue was detected by using the Coccinelle software.
>>>>
>>>> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
>>>
>>> I haven't seen a followup to Ray's review, but in the interest of making
>>> progress, I updated and applied the patch as appended. I also reviewed
>>> other phy_*() calls under drivers/pci, and they all look OK (with no
>>> unnecessary tests for NULL).
>>>
>>> This is on the pci/host-iproc branch for v4.3.
>>>
>>
>> Hmmm....I searched my mailbox but cannot find an email with this patch
>> (while I remember I reviewed and commented on the initial version of
>> this patch). It must have gone into some sub-folder or deleted by me by
>> accident. My bad.
>>
>> Nevertheless,the current patch looks good to me!
>
> Thanks for checking it out! Can I add your Reviewed-by to the patch below?
>
Sure thanks!
Reviewed-by: Ray Jui <rjui@broadcom.com>
Ray
* SF Markus Elfring <elfring@users.sourceforge.net> [150625 04:35]:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 25 Jun 2015 13:24:35 +0200
>
> Some functions which release a system resource tolerate the passing
> of a null pointer. I do not see a need because of this fact
> that a function caller repeats a corresponding check.
>
> Markus Elfring (2):
> Delete a check before the function call "omap_device_delete"
> Delete a check before the function call "of_node_put"
>
> arch/arm/mach-omap2/omap_device.c | 3 +--
> arch/arm/mach-omap2/timer.c | 3 +--
> 2 files changed, 2 insertions(+), 4 deletions(-)
Applying both into omap-for-v4.3/soc thanks.
Tony
Hello Markus On Tue, 30 Jun 2015, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Tue, 30 Jun 2015 14:00:16 +0200 > > The functions clk_disable(), of_node_put() and omap_device_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> Thanks for the patch. I have to say, I am a bit leery about applying the omap_device.c and omap_hwmod.c changes, since the called functions -- omap_device_delete() and clk_disable() -- don't explicitly document that NULLs are allowed to be passed in. So there's no explicit contract that callers can rely upon, to (at least in theory) prevent those internal NULL pointer checks from being removed. So I would suggest that those two functions' kerneldoc be patched first to explicitly state that passing in a NULL pointer is allowed. Then I would feel a bit more comfortable applying the omap_device.c and omap_hwmod.c changes. The kerneldoc for of_node_put() does explicitly allow NULLs to be passed in. So I'll apply that change now for v4.3, touching up the commit message accordingly. regards, - Paul > --- > arch/arm/mach-omap2/omap_device.c | 3 +-- > arch/arm/mach-omap2/omap_hwmod.c | 5 +---- > arch/arm/mach-omap2/timer.c | 3 +-- > 3 files changed, 3 insertions(+), 8 deletions(-) > > diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c > index 4cb8fd9..196366e 100644 > --- a/arch/arm/mach-omap2/omap_device.c > +++ b/arch/arm/mach-omap2/omap_device.c > @@ -193,8 +193,7 @@ static int _omap_device_notifier_call(struct notifier_block *nb, > > switch (event) { > case BUS_NOTIFY_DEL_DEVICE: > - if (pdev->archdata.od) > - omap_device_delete(pdev->archdata.od); > + omap_device_delete(pdev->archdata.od); > break; > case BUS_NOTIFY_ADD_DEVICE: > if (pdev->dev.of_node) > diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c > index d78c12e..1091ee7 100644 > --- a/arch/arm/mach-omap2/omap_hwmod.c > +++ b/arch/arm/mach-omap2/omap_hwmod.c > @@ -921,10 +921,7 @@ static int _disable_clocks(struct omap_hwmod *oh) > int i = 0; > > pr_debug("omap_hwmod: %s: disabling clocks\n", oh->name); > - > - if (oh->_clk) > - clk_disable(oh->_clk); > - > + clk_disable(oh->_clk); > p = oh->slave_ports.next; > > while (i < oh->slaves_cnt) { > diff --git a/arch/arm/mach-omap2/timer.c b/arch/arm/mach-omap2/timer.c > index cac46d8..15448221 100644 > --- a/arch/arm/mach-omap2/timer.c > +++ b/arch/arm/mach-omap2/timer.c > @@ -208,8 +208,7 @@ static void __init omap_dmtimer_init(void) > /* If we are a secure device, remove any secure timer nodes */ > if ((omap_type() != OMAP2_DEVICE_TYPE_GP)) { > np = omap_get_timer_dt(omap_timer_match, "ti,timer-secure"); > - if (np) > - of_node_put(np); > + of_node_put(np); > } > } > > -- > 2.4.5 > - Paul
* Paul Walmsley <paul@pwsan.com> [150715 22:58]:
> Hello Markus
>
> On Tue, 30 Jun 2015, SF Markus Elfring wrote:
>
> > From: Markus Elfring <elfring@users.sourceforge.net>
> > Date: Tue, 30 Jun 2015 14:00:16 +0200
> >
> > The functions clk_disable(), of_node_put() and omap_device_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>
>
> Thanks for the patch. I have to say, I am a bit leery about applying the
> omap_device.c and omap_hwmod.c changes, since the called functions --
> omap_device_delete() and clk_disable() -- don't explicitly document that
> NULLs are allowed to be passed in. So there's no explicit contract that
> callers can rely upon, to (at least in theory) prevent those internal NULL
> pointer checks from being removed.
>
> So I would suggest that those two functions' kerneldoc be patched first to
> explicitly state that passing in a NULL pointer is allowed. Then I would
> feel a bit more comfortable applying the omap_device.c and omap_hwmod.c
> changes.
>
> The kerneldoc for of_node_put() does explicitly allow NULLs to be passed
> in. So I'll apply that change now for v4.3, touching up the commit
> message accordingly.
I have them applied from a later thread already, but will drop both in
my branch as I have not pushed them out yet.
Regards,
Tony
> I have to say, I am a bit leery about applying the omap_device.c and > omap_hwmod.c changes, since the called functions -- omap_device_delete() > and clk_disable() -- don't explicitly document that NULLs are allowed > to be passed in. How are the chances to improve documentation around such implementation details? > So there's no explicit contract that callers can rely upon, to (at least > in theory) prevent those internal NULL pointer checks from being removed. Are there any additional variations to consider for source files from different processor architectures? > So I would suggest that those two functions' kerneldoc be patched first to > explicitly state that passing in a NULL pointer is allowed. Should my static source code analysis approach help you any more to clarify further open issues? > So I'll apply that change now for v4.3, touching up the commit message accordingly. Thanks for your constructive feedback. >> arch/arm/mach-omap2/omap_device.c | 3 +-- >> arch/arm/mach-omap2/omap_hwmod.c | 5 +---- >> arch/arm/mach-omap2/timer.c | 3 +-- Did Tony Lindgren pick a similar update suggestion up, too? https://lkml.org/lkml/2015/7/15/112 Regards, Markus
On Wed, 15 Jul 2015, Tony Lindgren wrote:
> * Paul Walmsley <paul@pwsan.com> [150715 22:58]:
> > Hello Markus
> >
> > On Tue, 30 Jun 2015, SF Markus Elfring wrote:
> >
> > > From: Markus Elfring <elfring@users.sourceforge.net>
> > > Date: Tue, 30 Jun 2015 14:00:16 +0200
> > >
> > > The functions clk_disable(), of_node_put() and omap_device_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>
> >
> > Thanks for the patch. I have to say, I am a bit leery about applying the
> > omap_device.c and omap_hwmod.c changes, since the called functions --
> > omap_device_delete() and clk_disable() -- don't explicitly document that
> > NULLs are allowed to be passed in. So there's no explicit contract that
> > callers can rely upon, to (at least in theory) prevent those internal NULL
> > pointer checks from being removed.
> >
> > So I would suggest that those two functions' kerneldoc be patched first to
> > explicitly state that passing in a NULL pointer is allowed. Then I would
> > feel a bit more comfortable applying the omap_device.c and omap_hwmod.c
> > changes.
> >
> > The kerneldoc for of_node_put() does explicitly allow NULLs to be passed
> > in. So I'll apply that change now for v4.3, touching up the commit
> > message accordingly.
>
> I have them applied from a later thread already, but will drop both in
> my branch as I have not pushed them out yet.
Oops sorry about stepping on your toes - I obviously missed that followup.
- Paul
* Paul Walmsley <paul@pwsan.com> [150716 07:09]:
> On Wed, 15 Jul 2015, Tony Lindgren wrote:
>
> > * Paul Walmsley <paul@pwsan.com> [150715 22:58]:
> > > Hello Markus
> > >
> > > On Tue, 30 Jun 2015, SF Markus Elfring wrote:
> > >
> > > > From: Markus Elfring <elfring@users.sourceforge.net>
> > > > Date: Tue, 30 Jun 2015 14:00:16 +0200
> > > >
> > > > The functions clk_disable(), of_node_put() and omap_device_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>
> > >
> > > Thanks for the patch. I have to say, I am a bit leery about applying the
> > > omap_device.c and omap_hwmod.c changes, since the called functions --
> > > omap_device_delete() and clk_disable() -- don't explicitly document that
> > > NULLs are allowed to be passed in. So there's no explicit contract that
> > > callers can rely upon, to (at least in theory) prevent those internal NULL
> > > pointer checks from being removed.
> > >
> > > So I would suggest that those two functions' kerneldoc be patched first to
> > > explicitly state that passing in a NULL pointer is allowed. Then I would
> > > feel a bit more comfortable applying the omap_device.c and omap_hwmod.c
> > > changes.
> > >
> > > The kerneldoc for of_node_put() does explicitly allow NULLs to be passed
> > > in. So I'll apply that change now for v4.3, touching up the commit
> > > message accordingly.
> >
> > I have them applied from a later thread already, but will drop both in
> > my branch as I have not pushed them out yet.
>
> Oops sorry about stepping on your toes - I obviously missed that followup.
No problem :)
Tony
>> From: Markus Elfring <elfring@users.sourceforge.net>
>> Date: Sat, 4 Jul 2015 15:30:18 +0200
>>
>> Skip checks for a few variables in three error handling cases within
>> the ocfs2_rename() function by adjustment of a few jump targets
>> according to the Linux coding style convention.
>>
>> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
>
> I don't think this is an improvement.
How do you think about the other update suggestions from this patch series?
Can the corresponding source code review be continued?
Regards,
Markus
[-- Attachment #1: Type: text/plain, Size: 1267 bytes --] On 2015-06-26 18:25:09, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Fri, 26 Jun 2015 18:18:54 +0200 > > The key_put() function tests whether its argument is NULL and then > returns immediately. Thus the test around this call might not be needed. > > This issue was detected by using the Coccinelle software. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> Thanks for the cleanup. I'll include it in an upcoming eCryptfs pull request. Tyler > --- > fs/ecryptfs/crypto.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c > index 97315f2..80d6901 100644 > --- a/fs/ecryptfs/crypto.c > +++ b/fs/ecryptfs/crypto.c > @@ -258,8 +258,7 @@ void ecryptfs_destroy_mount_crypt_stat( > &mount_crypt_stat->global_auth_tok_list, > mount_crypt_stat_list) { > list_del(&auth_tok->mount_crypt_stat_list); > - if (auth_tok->global_auth_tok_key > - && !(auth_tok->flags & ECRYPTFS_AUTH_TOK_INVALID)) > + if (!(auth_tok->flags & ECRYPTFS_AUTH_TOK_INVALID)) > key_put(auth_tok->global_auth_tok_key); > kmem_cache_free(ecryptfs_global_auth_tok_cache, auth_tok); > } > -- > 2.4.4 > [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 819 bytes --]
On Sun 2015-06-28 12:21:53, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sun, 28 Jun 2015 12:14:43 +0200 > > The functions dev_pm_disarm_wake_irq() and wakeup_source_unregister() test > whether their argument is NULL and then return immediately. > Thus the test around the calls is not needed. > > This issue was detected by using the Coccinelle software. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> ACK. > --- > drivers/base/power/wakeup.c | 10 +++------- > 1 file changed, 3 insertions(+), 7 deletions(-) > > diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c > index 40f7160..3741bc2 100644 > --- a/drivers/base/power/wakeup.c > +++ b/drivers/base/power/wakeup.c > @@ -341,8 +341,7 @@ void device_wakeup_arm_wake_irqs(void) > > rcu_read_lock(); > list_for_each_entry_rcu(ws, &wakeup_sources, entry) { > - if (ws->wakeirq) > - dev_pm_arm_wake_irq(ws->wakeirq); > + dev_pm_arm_wake_irq(ws->wakeirq); > } > rcu_read_unlock(); > } > @@ -358,8 +357,7 @@ void device_wakeup_disarm_wake_irqs(void) > > rcu_read_lock(); > list_for_each_entry_rcu(ws, &wakeup_sources, entry) { > - if (ws->wakeirq) > - dev_pm_disarm_wake_irq(ws->wakeirq); > + dev_pm_disarm_wake_irq(ws->wakeirq); > } > rcu_read_unlock(); > } > @@ -396,9 +394,7 @@ int device_wakeup_disable(struct device *dev) > return -EINVAL; > > ws = device_wakeup_detach(dev); > - if (ws) > - wakeup_source_unregister(ws); > - > + wakeup_source_unregister(ws); > return 0; > } > EXPORT_SYMBOL_GPL(device_wakeup_disable); > -- > 2.4.4 -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
On 2015-07-07 21:54, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Tue, 7 Jul 2015 21:48:23 +0200
>
> 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.
Applied to kbuild.git#kconfig.
Michal
>> From: Markus Elfring <elfring@users.sourceforge.net>
>> Date: Sat, 4 Jul 2015 15:30:18 +0200
>>
>> Skip checks for a few variables in three error handling cases within
>> the ocfs2_rename() function by adjustment of a few jump targets
>> according to the Linux coding style convention.
>>
>> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
>
> I don't think this is an improvement.
How do you think about the other update suggestions from this patch series?
Would anybody like to contribute constructive comments so that further progress
can eventually be achieved for a corresponding source code review?
Regards,
Markus
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 3 Nov 2015 18:18:37 +0100 The irlmp_unregister_service() 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/irda/af_irda.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/irda/af_irda.c b/net/irda/af_irda.c index fae6822..e6aa48b 100644 --- a/net/irda/af_irda.c +++ b/net/irda/af_irda.c @@ -2123,8 +2123,7 @@ static int irda_setsockopt(struct socket *sock, int level, int optname, } /* Unregister any old registration */ - if (self->skey) - irlmp_unregister_service(self->skey); + irlmp_unregister_service(self->skey); self->skey = irlmp_register_service((__u16) opt); break; -- 2.6.2
From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 3 Nov 2015 18:30:58 +0100
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Tue, 3 Nov 2015 18:18:37 +0100
>
> The irlmp_unregister_service() 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>
Applied.
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 3 Nov 2015 21:34:29 +0100 Further update suggestions were taken into account after a patch was applied from static source code analysis. Markus Elfring (3): Delete an unnecessary check before the function call "batadv_softif_vlan_free_ref" Split a condition check Less function calls in batadv_is_ap_isolated() after error detection net/batman-adv/translation-table.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) -- 2.6.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 3 Nov 2015 19:20:34 +0100 The batadv_softif_vlan_free_ref() 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/batman-adv/translation-table.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 4228b10..48315de 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -3336,8 +3336,7 @@ bool batadv_is_ap_isolated(struct batadv_priv *bat_priv, u8 *src, u8 *dst, ret = true; out: - if (vlan) - batadv_softif_vlan_free_ref(vlan); + batadv_softif_vlan_free_ref(vlan); if (tt_global_entry) batadv_tt_global_entry_free_ref(tt_global_entry); if (tt_local_entry) -- 2.6.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 3 Nov 2015 20:41:02 +0100 Let us split a check for a condition at the beginning of the batadv_is_ap_isolated() function so that a direct return can be performed in this function if the variable "vlan" contained a null pointer. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- net/batman-adv/translation-table.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 48315de..965a004 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -3319,7 +3319,10 @@ bool batadv_is_ap_isolated(struct batadv_priv *bat_priv, u8 *src, u8 *dst, bool ret = false; vlan = batadv_softif_vlan_get(bat_priv, vid); - if (!vlan || !atomic_read(&vlan->ap_isolation)) + if (!vlan) + return false; + + if (!atomic_read(&vlan->ap_isolation)) goto out; tt_local_entry = batadv_tt_local_hash_find(bat_priv, dst, vid); -- 2.6.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Tue, 3 Nov 2015 21:10:51 +0100 The variables "tt_local_entry" and "tt_global_entry" were eventually checked again despite of a corresponding null pointer test before. Let us avoid this double check by reordering a function call sequence and the better selection of jump targets. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- net/batman-adv/translation-table.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 965a004..3ac32d9 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -3323,27 +3323,24 @@ bool batadv_is_ap_isolated(struct batadv_priv *bat_priv, u8 *src, u8 *dst, return false; if (!atomic_read(&vlan->ap_isolation)) - goto out; + goto vlan_free; tt_local_entry = batadv_tt_local_hash_find(bat_priv, dst, vid); if (!tt_local_entry) - goto out; + goto vlan_free; tt_global_entry = batadv_tt_global_hash_find(bat_priv, src, vid); if (!tt_global_entry) - goto out; + goto local_entry_free; - if (!_batadv_is_ap_isolated(tt_local_entry, tt_global_entry)) - goto out; - - ret = true; + if (_batadv_is_ap_isolated(tt_local_entry, tt_global_entry)) + ret = true; -out: + batadv_tt_global_entry_free_ref(tt_global_entry); +local_entry_free: + batadv_tt_local_entry_free_ref(tt_local_entry); +vlan_free: batadv_softif_vlan_free_ref(vlan); - if (tt_global_entry) - batadv_tt_global_entry_free_ref(tt_global_entry); - if (tt_local_entry) - batadv_tt_local_entry_free_ref(tt_local_entry); return ret; } -- 2.6.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 4 Nov 2015 18:48:38 +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/resize.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c index ad62d7a..7918012 100644 --- a/fs/ext4/resize.c +++ b/fs/ext4/resize.c @@ -1942,10 +1942,10 @@ retry: err = ext4_convert_meta_bg(sb, resize_inode); if (err) goto out; - if (resize_inode) { - iput(resize_inode); - resize_inode = NULL; - } + + iput(resize_inode); + resize_inode = NULL; + if (n_blocks_count_retry) { n_blocks_count = n_blocks_count_retry; n_blocks_count_retry = 0; @@ -2011,8 +2011,7 @@ retry: out: if (flex_gd) free_flex_gd(flex_gd); - if (resize_inode != NULL) - iput(resize_inode); + iput(resize_inode); ext4_msg(sb, KERN_INFO, "resized filesystem to %llu", n_blocks_count); return err; } -- 2.6.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 4 Nov 2015 20:00:42 +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/ubifs/recovery.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/ubifs/recovery.c b/fs/ubifs/recovery.c index 2a1f0bc..586d593 100644 --- a/fs/ubifs/recovery.c +++ b/fs/ubifs/recovery.c @@ -1331,8 +1331,7 @@ void ubifs_destroy_size_tree(struct ubifs_info *c) struct size_entry *e, *n; rbtree_postorder_for_each_entry_safe(e, n, &c->size_tree, rb) { - if (e->inode) - iput(e->inode); + iput(e->inode); kfree(e); } @@ -1533,8 +1532,7 @@ int ubifs_recover_size(struct ubifs_info *c) err = fix_size_in_place(c, e); if (err) return err; - if (e->inode) - iput(e->inode); + iput(e->inode); } } -- 2.6.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 4 Nov 2015 20:44:50 +0100 The kernfs_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> --- fs/sysfs/group.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index dc1358b..9b34c07 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c @@ -388,8 +388,7 @@ int __compat_only_sysfs_link_entry_to_kobj(struct kobject *kobj, */ spin_lock(&sysfs_symlink_target_lock); target = target_kobj->sd; - if (target) - kernfs_get(target); + kernfs_get(target); spin_unlock(&sysfs_symlink_target_lock); if (!target) return -ENOENT; -- 2.6.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 4 Nov 2015 21:23:43 +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/gfs2/ops_fstype.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index baab99b..1f9de17 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -910,8 +910,7 @@ fail_qc_i: fail_ut_i: iput(sdp->sd_sc_inode); fail: - if (pn) - iput(pn); + iput(pn); return error; } -- 2.6.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Nov 2015 08:41:00 +0100 The functions "sc_return_credits" and "vfree" perform also input parameter validation. Thus the tests around their calls are not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/staging/rdma/hfi1/file_ops.c | 2 +- drivers/staging/rdma/hfi1/user_sdma.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/staging/rdma/hfi1/file_ops.c b/drivers/staging/rdma/hfi1/file_ops.c index aae9826..204d1d0 100644 --- a/drivers/staging/rdma/hfi1/file_ops.c +++ b/drivers/staging/rdma/hfi1/file_ops.c @@ -313,7 +313,7 @@ static ssize_t hfi1_file_write(struct file *fp, const char __user *data, case HFI1_CMD_SDMA_STATUS_UPD: break; case HFI1_CMD_CREDIT_UPD: - if (uctxt && uctxt->sc) + if (uctxt) sc_return_credits(uctxt->sc); break; case HFI1_CMD_TID_UPDATE: diff --git a/drivers/staging/rdma/hfi1/user_sdma.c b/drivers/staging/rdma/hfi1/user_sdma.c index 36c838d..45f3797 100644 --- a/drivers/staging/rdma/hfi1/user_sdma.c +++ b/drivers/staging/rdma/hfi1/user_sdma.c @@ -473,8 +473,7 @@ int hfi1_user_sdma_free_queues(struct hfi1_filedata *fd) fd->pq = NULL; } if (fd->cq) { - if (fd->cq->comps) - vfree(fd->cq->comps); + vfree(fd->cq->comps); kfree(fd->cq); fd->cq = NULL; } -- 2.6.2
On Thu, Nov 05, 2015 at 09:10:47AM +0100, SF Markus Elfring wrote:
> diff --git a/drivers/staging/rdma/hfi1/file_ops.c b/drivers/staging/rdma/hfi1/file_ops.c
> index aae9826..204d1d0 100644
> --- a/drivers/staging/rdma/hfi1/file_ops.c
> +++ b/drivers/staging/rdma/hfi1/file_ops.c
> @@ -313,7 +313,7 @@ static ssize_t hfi1_file_write(struct file *fp, const char __user *data,
> case HFI1_CMD_SDMA_STATUS_UPD:
> break;
> case HFI1_CMD_CREDIT_UPD:
> - if (uctxt && uctxt->sc)
> + if (uctxt)
> sc_return_credits(uctxt->sc);
Relying on hidden sanity checks makes the code harder to read.
regards,
dan carpenter
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Nov 2015 13:03:33 +0100 Further update suggestions were taken into account after a patch was applied from static source code analysis. Markus Elfring (3): Delete unnecessary checks before two function calls Delete an unnecessary variable initialisation in class_register_type() Less function calls in class_register_type() after error detection drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c | 10 +++----- drivers/staging/lustre/lustre/lmv/lmv_obd.c | 5 ++-- drivers/staging/lustre/lustre/lov/lov_obd.c | 4 +-- drivers/staging/lustre/lustre/obdclass/genops.c | 34 ++++++++++++++----------- 4 files changed, 25 insertions(+), 28 deletions(-) -- 2.6.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Nov 2015 10:18:45 +0100 The functions kobject_put() and kset_unregister() test whether their argument is NULL and then return immediately. Thus the tests around their calls are not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c | 10 +++------- drivers/staging/lustre/lustre/lmv/lmv_obd.c | 5 ++--- drivers/staging/lustre/lustre/lov/lov_obd.c | 4 +--- drivers/staging/lustre/lustre/obdclass/genops.c | 6 ++---- 4 files changed, 8 insertions(+), 17 deletions(-) diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c index ca11511..e67e84b 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c @@ -1062,13 +1062,9 @@ static int ldlm_cleanup(void) if (ldlm_state->ldlm_cb_service != NULL) ptlrpc_unregister_service(ldlm_state->ldlm_cb_service); - if (ldlm_ns_kset) - kset_unregister(ldlm_ns_kset); - if (ldlm_svc_kset) - kset_unregister(ldlm_svc_kset); - if (ldlm_kobj) - kobject_put(ldlm_kobj); - + kset_unregister(ldlm_ns_kset); + kset_unregister(ldlm_svc_kset); + kobject_put(ldlm_kobj); ldlm_debugfs_cleanup(); kfree(ldlm_state); diff --git a/drivers/staging/lustre/lustre/lmv/lmv_obd.c b/drivers/staging/lustre/lustre/lmv/lmv_obd.c index 635a93c..c3c8e8c 100644 --- a/drivers/staging/lustre/lustre/lmv/lmv_obd.c +++ b/drivers/staging/lustre/lustre/lmv/lmv_obd.c @@ -240,7 +240,7 @@ static int lmv_connect(const struct lu_env *env, if (data->ocd_connect_flags & OBD_CONNECT_REAL) rc = lmv_check_connect(obd); - if (rc && lmv->lmv_tgts_kobj) + if (rc) kobject_put(lmv->lmv_tgts_kobj); return rc; @@ -646,8 +646,7 @@ static int lmv_disconnect(struct obd_export *exp) lmv_disconnect_mdc(obd, lmv->tgts[i]); } - if (lmv->lmv_tgts_kobj) - kobject_put(lmv->lmv_tgts_kobj); + kobject_put(lmv->lmv_tgts_kobj); out_local: /* diff --git a/drivers/staging/lustre/lustre/lov/lov_obd.c b/drivers/staging/lustre/lustre/lov/lov_obd.c index 7abe484..910c62c 100644 --- a/drivers/staging/lustre/lustre/lov/lov_obd.c +++ b/drivers/staging/lustre/lustre/lov/lov_obd.c @@ -109,9 +109,7 @@ static void lov_putref(struct obd_device *obd) __lov_del_obd(obd, tgt); } - if (lov->lov_tgts_kobj) - kobject_put(lov->lov_tgts_kobj); - + kobject_put(lov->lov_tgts_kobj); } else { mutex_unlock(&lov->lov_lock); } diff --git a/drivers/staging/lustre/lustre/obdclass/genops.c b/drivers/staging/lustre/lustre/obdclass/genops.c index 6477aeb..a1cf8e1 100644 --- a/drivers/staging/lustre/lustre/obdclass/genops.c +++ b/drivers/staging/lustre/lustre/obdclass/genops.c @@ -216,8 +216,7 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops, return 0; failed: - if (type->typ_kobj) - kobject_put(type->typ_kobj); + kobject_put(type->typ_kobj); kfree(type->typ_name); kfree(type->typ_md_ops); kfree(type->typ_dt_ops); @@ -244,8 +243,7 @@ int class_unregister_type(const char *name) return -EBUSY; } - if (type->typ_kobj) - kobject_put(type->typ_kobj); + kobject_put(type->typ_kobj); if (!IS_ERR_OR_NULL(type->typ_debugfs_entry)) ldebugfs_remove(&type->typ_debugfs_entry); -- 2.6.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Nov 2015 10:55:16 +0100 The variable "rc" will be eventually set to an error return code in the class_register_type() function. Thus let us omit the explicit initialisation at the beginning. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/staging/lustre/lustre/obdclass/genops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/staging/lustre/lustre/obdclass/genops.c b/drivers/staging/lustre/lustre/obdclass/genops.c index a1cf8e1..acb86f0 100644 --- a/drivers/staging/lustre/lustre/obdclass/genops.c +++ b/drivers/staging/lustre/lustre/obdclass/genops.c @@ -155,7 +155,7 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops, struct lu_device_type *ldt) { struct obd_type *type; - int rc = 0; + int rc; /* sanity check */ LASSERT(strnlen(name, CLASS_MAX_NAME) < CLASS_MAX_NAME); -- 2.6.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Nov 2015 12:48:58 +0100 The functions "kfree" and "kobject_put" were called in a few cases by the function "class_register_type" during error handling even if the passed variable contained a null pointer. This implementation detail could be improved by the adjustment of jump targets. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/staging/lustre/lustre/obdclass/genops.c | 26 +++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/drivers/staging/lustre/lustre/obdclass/genops.c b/drivers/staging/lustre/lustre/obdclass/genops.c index acb86f0..4d99a39 100644 --- a/drivers/staging/lustre/lustre/obdclass/genops.c +++ b/drivers/staging/lustre/lustre/obdclass/genops.c @@ -171,13 +171,16 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops, return rc; type->typ_dt_ops = kzalloc(sizeof(*type->typ_dt_ops), GFP_NOFS); + if (!type->typ_dt_ops) + goto free_type; + type->typ_md_ops = kzalloc(sizeof(*type->typ_md_ops), GFP_NOFS); - type->typ_name = kzalloc(strlen(name) + 1, GFP_NOFS); + if (!type->typ_md_ops) + goto free_dt_ops; - if (!type->typ_dt_ops || - !type->typ_md_ops || - !type->typ_name) - goto failed; + type->typ_name = kzalloc(strlen(name) + 1, GFP_NOFS); + if (!type->typ_name) + goto free_md_ops; *(type->typ_dt_ops) = *dt_ops; /* md_ops is optional */ @@ -193,20 +196,20 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops, rc = type->typ_debugfs_entry ? PTR_ERR(type->typ_debugfs_entry) : -ENOMEM; type->typ_debugfs_entry = NULL; - goto failed; + goto free_name; } type->typ_kobj = kobject_create_and_add(type->typ_name, lustre_kobj); if (!type->typ_kobj) { rc = -ENOMEM; - goto failed; + goto free_name; } if (ldt != NULL) { type->typ_lu = ldt; rc = lu_device_type_init(ldt); if (rc != 0) - goto failed; + goto put_object; } spin_lock(&obd_types_lock); @@ -214,12 +217,15 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops, spin_unlock(&obd_types_lock); return 0; - - failed: +put_object: kobject_put(type->typ_kobj); +free_name: kfree(type->typ_name); +free_md_ops: kfree(type->typ_md_ops); +free_dt_ops: kfree(type->typ_dt_ops); +free_type: kfree(type); return rc; } -- 2.6.2
I don't like these patches because relying on hidden sanity checks makes the code harder to read. I am CC'd on all these patches because of kernel-janitors and normally I ignore them but this is drivers/staging so I am invested in this code. Feel free to send them to other subsystems though. regards, dan carpenter
Looks good. regards, dan carpenter
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Nov 2015 14:34:43 +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> --- drivers/staging/most/mostcore/core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/staging/most/mostcore/core.c b/drivers/staging/most/mostcore/core.c index 19852ca..ed1ed25 100644 --- a/drivers/staging/most/mostcore/core.c +++ b/drivers/staging/most/mostcore/core.c @@ -1587,8 +1587,7 @@ out: return 0; error: - if (iface->mod) - module_put(iface->mod); + module_put(iface->mod); modref--; mutex_unlock(&c->start_mutex); return ret; -- 2.6.2
Relying on hidden sanity checks makes the code harder to read. A human being cannot remember which functions have sanity checks and which do not. These sorts of patches are easy to generate automatically but they make the code worse. There are so many *better* things to do instead of focusing on making the code bad. Please stop sending these patches for drivers/staging. You are welcome to send them for other subsystems which I don't care about. regards, dan carpenter
> Please stop sending these patches for drivers/staging. Will further contributors take another look at similar update suggestions? > You are welcome to send them for other subsystems Thanks for this suggestion. > which I don't care about. I am curious if other software developers will give more positive feedback on the proposed source code fine-tuning because of collateral evolution. Regards, Markus
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Nov 2015 16:12:32 +0100 The acpi_ut_strupr() 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/acpi/acpica/dbcmds.c | 9 ++------- drivers/acpi/acpica/dbinput.c | 5 +---- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/drivers/acpi/acpica/dbcmds.c b/drivers/acpi/acpica/dbcmds.c index 30414b3..7dcc95a 100644 --- a/drivers/acpi/acpica/dbcmds.c +++ b/drivers/acpi/acpica/dbcmds.c @@ -1131,13 +1131,8 @@ void acpi_db_trace(char *enable_arg, char *method_arg, char *once_arg) u32 debug_layer = 0; u32 flags = 0; - if (enable_arg) { - acpi_ut_strupr(enable_arg); - } - - if (once_arg) { - acpi_ut_strupr(once_arg); - } + acpi_ut_strupr(enable_arg); + acpi_ut_strupr(once_arg); if (method_arg) { if (acpi_db_trace_method_name) { diff --git a/drivers/acpi/acpica/dbinput.c b/drivers/acpi/acpica/dbinput.c index 0480254..aa1dcee 100644 --- a/drivers/acpi/acpica/dbinput.c +++ b/drivers/acpi/acpica/dbinput.c @@ -622,10 +622,7 @@ static u32 acpi_db_get_line(char *input_buffer) } /* Uppercase the actual command */ - - if (acpi_gbl_db_args[0]) { - acpi_ut_strupr(acpi_gbl_db_args[0]); - } + acpi_ut_strupr(acpi_gbl_db_args[0]); count = i; if (count) { -- 2.6.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Nov 2015 17:10:22 +0100 The pinctrl_unregister() 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/pinctrl/bcm/pinctrl-cygnus-gpio.c | 3 +-- drivers/pinctrl/pinctrl-single.c | 5 +---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/pinctrl/bcm/pinctrl-cygnus-gpio.c b/drivers/pinctrl/bcm/pinctrl-cygnus-gpio.c index 12a48f4..663ad0a 100644 --- a/drivers/pinctrl/bcm/pinctrl-cygnus-gpio.c +++ b/drivers/pinctrl/bcm/pinctrl-cygnus-gpio.c @@ -638,8 +638,7 @@ static int cygnus_gpio_register_pinconf(struct cygnus_gpio *chip) static void cygnus_gpio_unregister_pinconf(struct cygnus_gpio *chip) { - if (chip->pctl) - pinctrl_unregister(chip->pctl); + pinctrl_unregister(chip->pctl); } struct cygnus_gpio_data { diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c index ef04b96..d24e5f1 100644 --- a/drivers/pinctrl/pinctrl-single.c +++ b/drivers/pinctrl/pinctrl-single.c @@ -1484,10 +1484,7 @@ static void pcs_irq_free(struct pcs_device *pcs) static void pcs_free_resources(struct pcs_device *pcs) { pcs_irq_free(pcs); - - if (pcs->pctl) - pinctrl_unregister(pcs->pctl); - + pinctrl_unregister(pcs->pctl); pcs_free_funcs(pcs); pcs_free_pingroups(pcs); } -- 2.6.2
QWdyZWVkLCB3ZSB3aWxsIGltcGxlbWVudCB5b3VyIHN1Z2dlc3Rpb25zIGluIHRoZSBBQ1BJQ0Eg Y29kZSAod2hpY2ggaXMgaW4gYSBkaWZmZXJlbnQgZm9ybWF0IHRoYW4gdGhlIExpbnV4IHZlcnNp b24pLg0KDQoNCj4gLS0tLS1PcmlnaW5hbCBNZXNzYWdlLS0tLS0NCj4gRnJvbTogU0YgTWFya3Vz IEVsZnJpbmcgW21haWx0bzplbGZyaW5nQHVzZXJzLnNvdXJjZWZvcmdlLm5ldF0NCj4gU2VudDog VGh1cnNkYXksIE5vdmVtYmVyIDA1LCAyMDE1IDc6MjMgQU0NCj4gVG86IExlbiBCcm93bjsgWmhl bmcsIEx2OyBXeXNvY2tpLCBSYWZhZWwgSjsgTW9vcmUsIFJvYmVydDsgbGludXgtDQo+IGFjcGlA dmdlci5rZXJuZWwub3JnOyBkZXZlbEBhY3BpY2Eub3JnDQo+IENjOiBMS01MOyBrZXJuZWwtamFu aXRvcnNAdmdlci5rZXJuZWwub3JnOyBKdWxpYSBMYXdhbGwNCj4gU3ViamVjdDogW1BBVENIXSBB Q1BJQ0E6IERlbGV0ZSB1bm5lY2Vzc2FyeSBjaGVja3MgYmVmb3JlIHRoZSBmdW5jdGlvbg0KPiBj YWxsICJhY3BpX3V0X3N0cnVwciINCj4gDQo+IEZyb206IE1hcmt1cyBFbGZyaW5nIDxlbGZyaW5n QHVzZXJzLnNvdXJjZWZvcmdlLm5ldD4NCj4gRGF0ZTogVGh1LCA1IE5vdiAyMDE1IDE2OjEyOjMy ICswMTAwDQo+IA0KPiBUaGUgYWNwaV91dF9zdHJ1cHIoKSBmdW5jdGlvbiB0ZXN0cyB3aGV0aGVy IGl0cyBhcmd1bWVudCBpcyBOVUxMIGFuZCB0aGVuDQo+IHJldHVybnMgaW1tZWRpYXRlbHkuIFRo dXMgdGhlIHRlc3QgYXJvdW5kIHRoZSBjYWxsIGlzIG5vdCBuZWVkZWQuDQo+IA0KPiBUaGlzIGlz c3VlIHdhcyBkZXRlY3RlZCBieSB1c2luZyB0aGUgQ29jY2luZWxsZSBzb2Z0d2FyZS4NCj4gDQo+ IFNpZ25lZC1vZmYtYnk6IE1hcmt1cyBFbGZyaW5nIDxlbGZyaW5nQHVzZXJzLnNvdXJjZWZvcmdl Lm5ldD4NCj4gLS0tDQo+ICBkcml2ZXJzL2FjcGkvYWNwaWNhL2RiY21kcy5jICB8IDkgKystLS0t LS0tDQo+IGRyaXZlcnMvYWNwaS9hY3BpY2EvZGJpbnB1dC5jIHwgNSArLS0tLQ0KPiAgMiBmaWxl cyBjaGFuZ2VkLCAzIGluc2VydGlvbnMoKyksIDExIGRlbGV0aW9ucygtKQ0KPiANCj4gZGlmZiAt LWdpdCBhL2RyaXZlcnMvYWNwaS9hY3BpY2EvZGJjbWRzLmMgYi9kcml2ZXJzL2FjcGkvYWNwaWNh L2RiY21kcy5jDQo+IGluZGV4IDMwNDE0YjMuLjdkY2M5NWEgMTAwNjQ0DQo+IC0tLSBhL2RyaXZl cnMvYWNwaS9hY3BpY2EvZGJjbWRzLmMNCj4gKysrIGIvZHJpdmVycy9hY3BpL2FjcGljYS9kYmNt ZHMuYw0KPiBAQCAtMTEzMSwxMyArMTEzMSw4IEBAIHZvaWQgYWNwaV9kYl90cmFjZShjaGFyICpl bmFibGVfYXJnLCBjaGFyDQo+ICptZXRob2RfYXJnLCBjaGFyICpvbmNlX2FyZykNCj4gIAl1MzIg ZGVidWdfbGF5ZXIgPSAwOw0KPiAgCXUzMiBmbGFncyA9IDA7DQo+IA0KPiAtCWlmIChlbmFibGVf YXJnKSB7DQo+IC0JCWFjcGlfdXRfc3RydXByKGVuYWJsZV9hcmcpOw0KPiAtCX0NCj4gLQ0KPiAt CWlmIChvbmNlX2FyZykgew0KPiAtCQlhY3BpX3V0X3N0cnVwcihvbmNlX2FyZyk7DQo+IC0JfQ0K PiArCWFjcGlfdXRfc3RydXByKGVuYWJsZV9hcmcpOw0KPiArCWFjcGlfdXRfc3RydXByKG9uY2Vf YXJnKTsNCj4gDQo+ICAJaWYgKG1ldGhvZF9hcmcpIHsNCj4gIAkJaWYgKGFjcGlfZGJfdHJhY2Vf bWV0aG9kX25hbWUpIHsNCj4gZGlmZiAtLWdpdCBhL2RyaXZlcnMvYWNwaS9hY3BpY2EvZGJpbnB1 dC5jIGIvZHJpdmVycy9hY3BpL2FjcGljYS9kYmlucHV0LmMNCj4gaW5kZXggMDQ4MDI1NC4uYWEx ZGNlZSAxMDA2NDQNCj4gLS0tIGEvZHJpdmVycy9hY3BpL2FjcGljYS9kYmlucHV0LmMNCj4gKysr IGIvZHJpdmVycy9hY3BpL2FjcGljYS9kYmlucHV0LmMNCj4gQEAgLTYyMiwxMCArNjIyLDcgQEAg c3RhdGljIHUzMiBhY3BpX2RiX2dldF9saW5lKGNoYXIgKmlucHV0X2J1ZmZlcikNCj4gIAl9DQo+ IA0KPiAgCS8qIFVwcGVyY2FzZSB0aGUgYWN0dWFsIGNvbW1hbmQgKi8NCj4gLQ0KPiAtCWlmIChh Y3BpX2dibF9kYl9hcmdzWzBdKSB7DQo+IC0JCWFjcGlfdXRfc3RydXByKGFjcGlfZ2JsX2RiX2Fy Z3NbMF0pOw0KPiAtCX0NCj4gKwlhY3BpX3V0X3N0cnVwcihhY3BpX2dibF9kYl9hcmdzWzBdKTsN Cj4gDQo+ICAJY291bnQgPSBpOw0KPiAgCWlmIChjb3VudCkgew0KPiAtLQ0KPiAyLjYuMg0KDQo
On 11/5/2015 8:17 AM, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 5 Nov 2015 17:10:22 +0100
>
> The pinctrl_unregister() 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/pinctrl/bcm/pinctrl-cygnus-gpio.c | 3 +--
> drivers/pinctrl/pinctrl-single.c | 5 +----
> 2 files changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/pinctrl/bcm/pinctrl-cygnus-gpio.c b/drivers/pinctrl/bcm/pinctrl-cygnus-gpio.c
> index 12a48f4..663ad0a 100644
> --- a/drivers/pinctrl/bcm/pinctrl-cygnus-gpio.c
> +++ b/drivers/pinctrl/bcm/pinctrl-cygnus-gpio.c
> @@ -638,8 +638,7 @@ static int cygnus_gpio_register_pinconf(struct cygnus_gpio *chip)
>
> static void cygnus_gpio_unregister_pinconf(struct cygnus_gpio *chip)
> {
> - if (chip->pctl)
> - pinctrl_unregister(chip->pctl);
> + pinctrl_unregister(chip->pctl);
> }
>
> struct cygnus_gpio_data {
> diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
> index ef04b96..d24e5f1 100644
> --- a/drivers/pinctrl/pinctrl-single.c
> +++ b/drivers/pinctrl/pinctrl-single.c
> @@ -1484,10 +1484,7 @@ static void pcs_irq_free(struct pcs_device *pcs)
> static void pcs_free_resources(struct pcs_device *pcs)
> {
> pcs_irq_free(pcs);
> -
> - if (pcs->pctl)
> - pinctrl_unregister(pcs->pctl);
> -
> + pinctrl_unregister(pcs->pctl);
> pcs_free_funcs(pcs);
> pcs_free_pingroups(pcs);
> }
>
The change looks good to me, thanks!
Reviewed-by: Ray Jui <rjui@broadcom.com>
+ Pramod since he's working on changes on the pinctrl-cygnus-gpio driver.
Ray
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Nov 2015 17:55:25 +0100 The functions iput() and unregister_sysctl_table() test whether their argument is NULL and then return immediately. Thus the tests around their calls are not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- ipc/mqueue.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ipc/mqueue.c b/ipc/mqueue.c index 161a180..ade9dd8 100644 --- a/ipc/mqueue.c +++ b/ipc/mqueue.c @@ -885,8 +885,7 @@ SYSCALL_DEFINE1(mq_unlink, const char __user *, u_name) out_unlock: mutex_unlock(&d_inode(mnt->mnt_root)->i_mutex); - if (inode) - iput(inode); + iput(inode); mnt_drop_write(mnt); out_name: putname(name); @@ -1460,8 +1459,7 @@ static int __init init_mqueue_fs(void) out_filesystem: unregister_filesystem(&mqueue_fs_type); out_sysctl: - if (mq_sysctl_table) - unregister_sysctl_table(mq_sysctl_table); + unregister_sysctl_table(mq_sysctl_table); kmem_cache_destroy(mqueue_inode_cachep); return error; } -- 2.6.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Nov 2015 19:39:32 +0100 Another update suggestion was taken into account after a patch was applied from static source code analysis. Markus Elfring (2): Delete unnecessary checks before two function calls Combine three checks into a single if block drivers/media/platform/sti/c8sectpfe/c8sectpfe-common.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) -- 2.6.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Nov 2015 18:55:19 +0100 The functions i2c_put_adapter() and module_put() test whether their argument is NULL and then return immediately. Thus the tests around their calls are not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/media/platform/sti/c8sectpfe/c8sectpfe-common.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/sti/c8sectpfe/c8sectpfe-common.c b/drivers/media/platform/sti/c8sectpfe/c8sectpfe-common.c index 95223ab..07fd6d9 100644 --- a/drivers/media/platform/sti/c8sectpfe/c8sectpfe-common.c +++ b/drivers/media/platform/sti/c8sectpfe/c8sectpfe-common.c @@ -214,12 +214,11 @@ void c8sectpfe_tuner_unregister_frontend(struct c8sectpfe *c8sectpfe, dvb_frontend_detach(tsin->frontend); } - if (tsin && tsin->i2c_adapter) + if (tsin) i2c_put_adapter(tsin->i2c_adapter); if (tsin && tsin->i2c_client) { - if (tsin->i2c_client->dev.driver->owner) - module_put(tsin->i2c_client->dev.driver->owner); + module_put(tsin->i2c_client->dev.driver->owner); i2c_unregister_device(tsin->i2c_client); } } -- 2.6.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Nov 2015 19:23:50 +0100 The variable "tsin" was checked three times in a loop iteration of the c8sectpfe_tuner_unregister_frontend() function. This implementation detail could be improved by the combination of the involved statements into a single if block so that this variable will be checked only once there. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/media/platform/sti/c8sectpfe/c8sectpfe-common.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/media/platform/sti/c8sectpfe/c8sectpfe-common.c b/drivers/media/platform/sti/c8sectpfe/c8sectpfe-common.c index 07fd6d9..2dfbe8a 100644 --- a/drivers/media/platform/sti/c8sectpfe/c8sectpfe-common.c +++ b/drivers/media/platform/sti/c8sectpfe/c8sectpfe-common.c @@ -209,17 +209,18 @@ void c8sectpfe_tuner_unregister_frontend(struct c8sectpfe *c8sectpfe, tsin = fei->channel_data[n]; - if (tsin && tsin->frontend) { - dvb_unregister_frontend(tsin->frontend); - dvb_frontend_detach(tsin->frontend); - } + if (tsin) { + if (tsin->frontend) { + dvb_unregister_frontend(tsin->frontend); + dvb_frontend_detach(tsin->frontend); + } - if (tsin) i2c_put_adapter(tsin->i2c_adapter); - if (tsin && tsin->i2c_client) { - module_put(tsin->i2c_client->dev.driver->owner); - i2c_unregister_device(tsin->i2c_client); + if (tsin->i2c_client) { + module_put(tsin->i2c_client->dev.driver->owner); + i2c_unregister_device(tsin->i2c_client); + } } } -- 2.6.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Nov 2015 21:10:29 +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> --- drivers/cpufreq/cppc_cpufreq.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c index 93c219f..e8cb334 100644 --- a/drivers/cpufreq/cppc_cpufreq.c +++ b/drivers/cpufreq/cppc_cpufreq.c @@ -166,8 +166,7 @@ static int __init cppc_cpufreq_init(void) out: for_each_possible_cpu(i) - if (all_cpu_data[i]) - kfree(all_cpu_data[i]); + kfree(all_cpu_data[i]); kfree(all_cpu_data); return -ENODEV; -- 2.6.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 5 Nov 2015 21:32:42 +0100 The unregister_sysctl_table() 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/char/hpet.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c index 240b6cf..fe511e9 100644 --- a/drivers/char/hpet.c +++ b/drivers/char/hpet.c @@ -1069,8 +1069,7 @@ static int __init hpet_init(void) result = acpi_bus_register_driver(&hpet_acpi_driver); if (result < 0) { - if (sysctl_header) - unregister_sysctl_table(sysctl_header); + unregister_sysctl_table(sysctl_header); misc_deregister(&hpet_misc); return result; } -- 2.6.2
On 05-11-15, 21:15, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 5 Nov 2015 21:10:29 +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>
> ---
> drivers/cpufreq/cppc_cpufreq.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
--
viresh
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 6 Nov 2015 08:00:22 +0100 The of_node_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> --- drivers/net/ethernet/synopsys/dwc_eth_qos.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/ethernet/synopsys/dwc_eth_qos.c b/drivers/net/ethernet/synopsys/dwc_eth_qos.c index 85b3326..9066d7a 100644 --- a/drivers/net/ethernet/synopsys/dwc_eth_qos.c +++ b/drivers/net/ethernet/synopsys/dwc_eth_qos.c @@ -2970,8 +2970,7 @@ err_out_unregister_netdev: err_out_clk_dis_aper: clk_disable_unprepare(lp->apb_pclk); err_out_free_netdev: - if (lp->phy_node) - of_node_put(lp->phy_node); + of_node_put(lp->phy_node); free_netdev(ndev); platform_set_drvdata(pdev, NULL); return ret; -- 2.6.2
Hi Markus,
On 11/05/2015 07:45 PM, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 5 Nov 2015 19:39:32 +0100
>
> Another update suggestion was taken into account after a patch was applied
> from static source code analysis.
>
> Markus Elfring (2):
> Delete unnecessary checks before two function calls
> Combine three checks into a single if block
>
> drivers/media/platform/sti/c8sectpfe/c8sectpfe-common.c | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
>
For the series:
Acked-by: Maxime Coquelin <maxime.coquelin@st.com>
Thanks!
Maxime
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 6 Nov 2015 08:48:23 +0100 The release_firmware() 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/net/wireless/brcm80211/brcmfmac/firmware.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/wireless/brcm80211/brcmfmac/firmware.c b/drivers/net/wireless/brcm80211/brcmfmac/firmware.c index 4248f3c..33afb9a 100644 --- a/drivers/net/wireless/brcm80211/brcmfmac/firmware.c +++ b/drivers/net/wireless/brcm80211/brcmfmac/firmware.c @@ -449,8 +449,7 @@ static void brcmf_fw_request_nvram_done(const struct firmware *fw, void *ctx) if (raw_nvram) bcm47xx_nvram_release_contents(data); - if (fw) - release_firmware(fw); + release_firmware(fw); if (!nvram && !(fwctx->flags & BRCMF_FW_REQ_NV_OPTIONAL)) goto fail; -- 2.6.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 6 Nov 2015 09:30:29 +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/fjes/fjes_hw.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/net/fjes/fjes_hw.c b/drivers/net/fjes/fjes_hw.c index 2d3848c..bb8b530 100644 --- a/drivers/net/fjes/fjes_hw.c +++ b/drivers/net/fjes/fjes_hw.c @@ -143,9 +143,7 @@ static int fjes_hw_alloc_epbuf(struct epbuf_handler *epbh) static void fjes_hw_free_epbuf(struct epbuf_handler *epbh) { - if (epbh->buffer) - vfree(epbh->buffer); - + vfree(epbh->buffer); epbh->buffer = NULL; epbh->size = 0; -- 2.6.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 6 Nov 2015 10:08:46 +0100 The unregister_sysctl_table() 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/misc/sgi-xp/xpc_main.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c index 7f32712..8d4fcac 100644 --- a/drivers/misc/sgi-xp/xpc_main.c +++ b/drivers/misc/sgi-xp/xpc_main.c @@ -1046,9 +1046,7 @@ xpc_do_exit(enum xp_retval reason) /* clear the interface to XPC's functions */ xpc_clear_interface(); - if (xpc_sysctl) - unregister_sysctl_table(xpc_sysctl); - + unregister_sysctl_table(xpc_sysctl); xpc_teardown_partitions(); if (is_shub()) @@ -1331,9 +1329,7 @@ out_3: (void)unregister_die_notifier(&xpc_die_notifier); (void)unregister_reboot_notifier(&xpc_reboot_notifier); out_2: - if (xpc_sysctl) - unregister_sysctl_table(xpc_sysctl); - + unregister_sysctl_table(xpc_sysctl); xpc_teardown_partitions(); out_1: if (is_shub()) -- 2.6.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 6 Nov 2015 10:36:49 +0100 The of_node_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> --- drivers/misc/sram.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c index 736dae7..34287f7 100644 --- a/drivers/misc/sram.c +++ b/drivers/misc/sram.c @@ -326,9 +326,7 @@ static int sram_reserve_regions(struct sram_dev *sram, struct resource *res) } err_chunks: - if (child) - of_node_put(child); - + of_node_put(child); kfree(rblocks); return ret; -- 2.6.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 6 Nov 2015 11:00:23 +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> --- drivers/misc/cxl/context.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/misc/cxl/context.c b/drivers/misc/cxl/context.c index 2faa127..52e39b6 100644 --- a/drivers/misc/cxl/context.c +++ b/drivers/misc/cxl/context.c @@ -275,9 +275,7 @@ static void reclaim_ctx(struct rcu_head *rcu) if (ctx->kernelapi) kfree(ctx->mapping); - if (ctx->irq_bitmap) - kfree(ctx->irq_bitmap); - + kfree(ctx->irq_bitmap); kfree(ctx); } -- 2.6.2
Am 05.11.2015 19:50, schrieb SF Markus Elfring: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Thu, 5 Nov 2015 19:23:50 +0100 > > The variable "tsin" was checked three times in a loop iteration of the > c8sectpfe_tuner_unregister_frontend() function. > This implementation detail could be improved by the combination of the > involved statements into a single if block so that this variable will be > checked only once there. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > drivers/media/platform/sti/c8sectpfe/c8sectpfe-common.c | 17 +++++++++-------- > 1 file changed, 9 insertions(+), 8 deletions(-) > > diff --git a/drivers/media/platform/sti/c8sectpfe/c8sectpfe-common.c b/drivers/media/platform/sti/c8sectpfe/c8sectpfe-common.c > index 07fd6d9..2dfbe8a 100644 > --- a/drivers/media/platform/sti/c8sectpfe/c8sectpfe-common.c > +++ b/drivers/media/platform/sti/c8sectpfe/c8sectpfe-common.c > @@ -209,17 +209,18 @@ void c8sectpfe_tuner_unregister_frontend(struct c8sectpfe *c8sectpfe, > > tsin = fei->channel_data[n]; if you do "if (!tsin) continue ;" you can save one indent level re, wh > > - if (tsin && tsin->frontend) { > - dvb_unregister_frontend(tsin->frontend); > - dvb_frontend_detach(tsin->frontend); > - } > + if (tsin) { > + if (tsin->frontend) { > + dvb_unregister_frontend(tsin->frontend); > + dvb_frontend_detach(tsin->frontend); > + } > > - if (tsin) > i2c_put_adapter(tsin->i2c_adapter); > > - if (tsin && tsin->i2c_client) { > - module_put(tsin->i2c_client->dev.driver->owner); > - i2c_unregister_device(tsin->i2c_client); > + if (tsin->i2c_client) { > + module_put(tsin->i2c_client->dev.driver->owner); > + i2c_unregister_device(tsin->i2c_client); > + } > } > } >
On Fri, Nov 6, 2015 at 3:15 AM, SF Markus Elfring
<elfring@users.sourceforge.net> wrote:
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Acked-by: Robin Holt <robinmholt@gmail.com>
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 6 Nov 2015 12:03:46 +0100 The drm_property_unreference_blob() function tests whether its argument is NULL and then returns immediately. Thus the tests around the calls are not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/gpu/drm/drm_atomic.c | 9 +++------ drivers/gpu/drm/drm_atomic_helper.c | 5 ++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c index 7bb3845..d65dc31 100644 --- a/drivers/gpu/drm/drm_atomic.c +++ b/drivers/gpu/drm/drm_atomic.c @@ -316,8 +316,7 @@ int drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state, if (mode && memcmp(&state->mode, mode, sizeof(*mode)) = 0) return 0; - if (state->mode_blob) - drm_property_unreference_blob(state->mode_blob); + drm_property_unreference_blob(state->mode_blob); state->mode_blob = NULL; if (mode) { @@ -363,8 +362,7 @@ int drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state, if (blob = state->mode_blob) return 0; - if (state->mode_blob) - drm_property_unreference_blob(state->mode_blob); + drm_property_unreference_blob(state->mode_blob); state->mode_blob = NULL; if (blob) { @@ -419,8 +417,7 @@ int drm_atomic_crtc_set_property(struct drm_crtc *crtc, struct drm_property_blob *mode drm_property_lookup_blob(dev, val); ret = drm_atomic_set_mode_prop_for_crtc(state, mode); - if (mode) - drm_property_unreference_blob(mode); + drm_property_unreference_blob(mode); return ret; } else if (crtc->funcs->atomic_set_property) diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c index 0c6f621..9870c70 100644 --- a/drivers/gpu/drm/drm_atomic_helper.c +++ b/drivers/gpu/drm/drm_atomic_helper.c @@ -2173,7 +2173,7 @@ EXPORT_SYMBOL(drm_atomic_helper_connector_dpms); */ void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc) { - if (crtc->state && crtc->state->mode_blob) + if (crtc->state) drm_property_unreference_blob(crtc->state->mode_blob); kfree(crtc->state); crtc->state = kzalloc(sizeof(*crtc->state), GFP_KERNEL); @@ -2241,8 +2241,7 @@ EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state); void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc, struct drm_crtc_state *state) { - if (state->mode_blob) - drm_property_unreference_blob(state->mode_blob); + drm_property_unreference_blob(state->mode_blob); } EXPORT_SYMBOL(__drm_atomic_helper_crtc_destroy_state); -- 2.6.2
SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Thu, 5 Nov 2015 21:32:42 +0100 > > The unregister_sysctl_table() 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: Clemens Ladisch <clemens@ladisch.de> > --- > drivers/char/hpet.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c > index 240b6cf..fe511e9 100644 > --- a/drivers/char/hpet.c > +++ b/drivers/char/hpet.c > @@ -1069,8 +1069,7 @@ static int __init hpet_init(void) > > result = acpi_bus_register_driver(&hpet_acpi_driver); > if (result < 0) { > - if (sysctl_header) > - unregister_sysctl_table(sysctl_header); > + unregister_sysctl_table(sysctl_header); > misc_deregister(&hpet_misc); > return result; > }
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 6 Nov 2015 13:38:22 +0100 The pwm_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> --- drivers/gpu/drm/i915/intel_panel.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c index a24df35..3d8d913 100644 --- a/drivers/gpu/drm/i915/intel_panel.c +++ b/drivers/gpu/drm/i915/intel_panel.c @@ -1729,8 +1729,7 @@ void intel_panel_destroy_backlight(struct drm_connector *connector) struct intel_panel *panel = &intel_connector->panel; /* dispose of the pwm */ - if (panel->backlight.pwm) - pwm_put(panel->backlight.pwm); + pwm_put(panel->backlight.pwm); panel->backlight.present = false; } -- 2.6.2
On Fri, 06 Nov 2015, SF Markus Elfring <elfring@users.sourceforge.net> wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Fri, 6 Nov 2015 13:38:22 +0100 > > The pwm_put() function tests whether its argument is NULL and then > returns immediately. Thus the test around the call is not needed. The compiler doesn't need it, but IMO it's useful documentation for humans. BR, Jani. > > This issue was detected by using the Coccinelle software. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > drivers/gpu/drm/i915/intel_panel.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c > index a24df35..3d8d913 100644 > --- a/drivers/gpu/drm/i915/intel_panel.c > +++ b/drivers/gpu/drm/i915/intel_panel.c > @@ -1729,8 +1729,7 @@ void intel_panel_destroy_backlight(struct drm_connector *connector) > struct intel_panel *panel = &intel_connector->panel; > > /* dispose of the pwm */ > - if (panel->backlight.pwm) > - pwm_put(panel->backlight.pwm); > + pwm_put(panel->backlight.pwm); > > panel->backlight.present = false; > } -- Jani Nikula, Intel Open Source Technology Center
>> The pwm_put() function tests whether its argument is NULL and then
>> returns immediately. Thus the test around the call is not needed.
>
> The compiler doesn't need it, but IMO it's useful documentation for humans.
How do you think about to extend the explicit documentation for
the affected parameters in the Linux programming interfaces?
Regards,
Markus
On Fri, 06 Nov 2015, SF Markus Elfring <elfring@users.sourceforge.net> wrote:
>>> The pwm_put() function tests whether its argument is NULL and then
>>> returns immediately. Thus the test around the call is not needed.
>>
>> The compiler doesn't need it, but IMO it's useful documentation for humans.
>
> How do you think about to extend the explicit documentation for
> the affected parameters in the Linux programming interfaces?
The question is, while reading intel_panel.c, which one conveys the
reader better the idea that panel->backlight.pwm may be NULL for some
connectors:
a) if (panel->backlight.pwm)
pwm_put(panel->backlight.pwm);
b) pwm_put(panel->backlight.pwm);
No amount of documentation in pwm_put() kernel-doc is going to help with
that. In most cases, panel->backlight.pwm is in fact NULL. IMO
unconditionally calling pwm_put() on it gives the reader the wrong idea.
Others may disagree.
BR,
Jani.
--
Jani Nikula, Intel Open Source Technology Center
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 6 Nov 2015 14:38:34 +0100 The backlight_device_unregister() 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/gpu/drm/bridge/parade-ps8622.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/gpu/drm/bridge/parade-ps8622.c b/drivers/gpu/drm/bridge/parade-ps8622.c index be881e9..046fba0 100644 --- a/drivers/gpu/drm/bridge/parade-ps8622.c +++ b/drivers/gpu/drm/bridge/parade-ps8622.c @@ -646,9 +646,7 @@ static int ps8622_remove(struct i2c_client *client) { struct ps8622_bridge *ps8622 = i2c_get_clientdata(client); - if (ps8622->bl) - backlight_device_unregister(ps8622->bl); - + backlight_device_unregister(ps8622->bl); drm_bridge_remove(&ps8622->bridge); return 0; -- 2.6.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 6 Nov 2015 15:00:22 +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> --- drivers/gpu/drm/msm/hdmi/hdmi_hdcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/msm/hdmi/hdmi_hdcp.c b/drivers/gpu/drm/msm/hdmi/hdmi_hdcp.c index 1dc9c34..205e931 100644 --- a/drivers/gpu/drm/msm/hdmi/hdmi_hdcp.c +++ b/drivers/gpu/drm/msm/hdmi/hdmi_hdcp.c @@ -1430,7 +1430,7 @@ struct hdmi_hdcp_ctrl *hdmi_hdcp_init(struct hdmi *hdmi) void hdmi_hdcp_destroy(struct hdmi *hdmi) { - if (hdmi && hdmi->hdcp_ctrl) { + if (hdmi) { kfree(hdmi->hdcp_ctrl); hdmi->hdcp_ctrl = NULL; } -- 2.6.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 6 Nov 2015 16:04:22 +0100 The following functions test whether their argument is NULL and then return immediately. * drm_fbdev_cma_hotplug_event * drm_fbdev_cma_restore_mode Thus the tests around their calls are not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/gpu/drm/vc4/vc4_drv.c | 3 +-- drivers/gpu/drm/vc4/vc4_kms.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_drv.c b/drivers/gpu/drm/vc4/vc4_drv.c index 6e73060..df348c0 100644 --- a/drivers/gpu/drm/vc4/vc4_drv.c +++ b/drivers/gpu/drm/vc4/vc4_drv.c @@ -54,8 +54,7 @@ static void vc4_lastclose(struct drm_device *dev) { struct vc4_dev *vc4 = to_vc4_dev(dev); - if (vc4->fbdev) - drm_fbdev_cma_restore_mode(vc4->fbdev); + drm_fbdev_cma_restore_mode(vc4->fbdev); } static const struct file_operations vc4_drm_fops = { diff --git a/drivers/gpu/drm/vc4/vc4_kms.c b/drivers/gpu/drm/vc4/vc4_kms.c index 2e5597d..1778203 100644 --- a/drivers/gpu/drm/vc4/vc4_kms.c +++ b/drivers/gpu/drm/vc4/vc4_kms.c @@ -25,8 +25,7 @@ static void vc4_output_poll_changed(struct drm_device *dev) { struct vc4_dev *vc4 = to_vc4_dev(dev); - if (vc4->fbdev) - drm_fbdev_cma_hotplug_event(vc4->fbdev); + drm_fbdev_cma_hotplug_event(vc4->fbdev); } static const struct drm_mode_config_funcs vc4_mode_funcs = { -- 2.6.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 6 Nov 2015 16:48:46 +0100 The of_node_put() function tests whether its argument is NULL and then returns immediately. Thus the test around the calls is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/power/bq2415x_charger.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/power/bq2415x_charger.c b/drivers/power/bq2415x_charger.c index 4afd768..27e8953 100644 --- a/drivers/power/bq2415x_charger.c +++ b/drivers/power/bq2415x_charger.c @@ -1704,7 +1704,7 @@ error_4: error_3: bq2415x_power_supply_exit(bq); error_2: - if (bq && bq->notify_node) + if (bq) of_node_put(bq->notify_node); kfree(name); error_1: @@ -1724,9 +1724,7 @@ static int bq2415x_remove(struct i2c_client *client) if (bq->nb.notifier_call) power_supply_unreg_notifier(&bq->nb); - if (bq->notify_node) - of_node_put(bq->notify_node); - + of_node_put(bq->notify_node); bq2415x_sysfs_exit(bq); bq2415x_power_supply_exit(bq); -- 2.6.2
On Friday 06 November 2015 16:56:33 SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 6 Nov 2015 16:48:46 +0100
>
> The of_node_put() function tests whether its argument is NULL and then
> returns immediately. Thus the test around the calls is not needed.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Acked-by: Pali Rohár <pali.rohar@gmail.com>
--
Pali Rohár
pali.rohar@gmail.com
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 6 Nov 2015 17:55:23 +0100 The kobject_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> --- drivers/hid/wacom_sys.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 125e9d5..fb9b1d1 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -1353,8 +1353,7 @@ static void wacom_clean_inputs(struct wacom *wacom) else input_free_device(wacom->wacom_wac.pad_input); } - if (wacom->remote_dir) - kobject_put(wacom->remote_dir); + kobject_put(wacom->remote_dir); wacom->wacom_wac.pen_input = NULL; wacom->wacom_wac.touch_input = NULL; wacom->wacom_wac.pad_input = NULL; -- 2.6.2
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 6 Nov 2015 18:32:41 +0100 The free_io_pgtable_ops() 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/iommu/arm-smmu.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index 47dc7a7..1ce4b85 100644 --- a/drivers/iommu/arm-smmu.c +++ b/drivers/iommu/arm-smmu.c @@ -945,9 +945,7 @@ static void arm_smmu_destroy_domain_context(struct iommu_domain *domain) free_irq(irq, domain); } - if (smmu_domain->pgtbl_ops) - free_io_pgtable_ops(smmu_domain->pgtbl_ops); - + free_io_pgtable_ops(smmu_domain->pgtbl_ops); __arm_smmu_free_bitmap(smmu->context_map, cfg->cbndx); } -- 2.6.2