Staging: acpi: Merge lines for immediate return
Subsystems (3)
PATCH 2756/2756 Staging: acpi: Merge lines for immediate return
This patch merges two lines in a single line if immediate return is found. This is done using Coccinelle.Semantic patch used for this is as follows:
@@
expression ret;
identifier f;
@@
-ret =
+return
f(...);
-return ret;
--- drivers/acpi/apei/erst.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/acpi/apei/erst.c +3 -7
@@ -162,8 +162,7 @@ static int erst_exec_add_value(struct apei_exec_context *ctx,if (rc)return rc; val += ctx->value; - rc =__apei_exec_write_register (entry, val); -return rc; +return __apei_exec_write_register (entry, val); } static int erst_exec_subtract_value(struct apei_exec_context *ctx,
@@ -176,8 +175,7 @@ static int erst_exec_subtract_value(struct apei_exec_context *ctx,if (rc)return rc; val -= ctx->value; - rc =__apei_exec_write_register (entry, val); -return rc; +return __apei_exec_write_register (entry, val); } static int erst_exec_stall(struct apei_exec_context *ctx,
@@ -979,9 +977,7 @@ static int erst_open_pstore(struct pstore_info *psi)if (erst_disable)return -ENODEV ; - rc =erst_get_record_id_begin (&reader_pos); - -return rc; +return erst_get_record_id_begin (&reader_pos); }static int erst_close_pstore (struct pstore_info *psi)
Signature · 1 line
2.1.0
Quoted 54 lines · Shraddha Barke
This patch merges two lines in a single line if immediate return is found. This is done using Coccinelle.Semantic patch used for this is as follows:
@@
expression ret;
identifier f;
@@(quoted diff) +1
-2-ret = +return f(...); -return ret;Signed-off-by Shraddha Barke <[email protected]>--- drivers/acpi/apei/erst.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)drivers/acpi/apei/erst.c +3
-8@@ -162,8 +162,7 @@ static int erst_exec_add_value(struct apei_exec_context *ctx,if (rc)return rc; val += ctx->value; - rc =__apei_exec_write_register (entry, val); -return rc; +return __apei_exec_write_register (entry, val); } static int erst_exec_subtract_value(struct apei_exec_context *ctx,@@ -176,8 +175,7 @@ static int erst_exec_subtract_value(struct apei_exec_context *ctx,if (rc)return rc; val -= ctx->value; - rc =__apei_exec_write_register (entry, val); -return rc; +return __apei_exec_write_register (entry, val); } static int erst_exec_stall(struct apei_exec_context *ctx,@@ -979,9 +977,7 @@ static int erst_open_pstore(struct pstore_info *psi)if (erst_disable)return -ENODEV ; - rc =erst_get_record_id_begin (&reader_pos); - -return rc; +return erst_get_record_id_begin (&reader_pos); }static int erst_close_pstore (struct pstore_info *psi) --
Quoted 2 lines
2.1.0
Personally I prefer the readability of continuing to use the rest of a function's rc = ..., if (rc) ... semantics. If "rc" could be entirely removed from the function, then switching to immediate returns seems like a reasonable cleanup. Otherwise, I think it reduces readability for no effect (the compiler, for example, is already optimizing these kinds of things at build-time).
-Kees
Signature · 2 lines
Kees Cook Chrome OS Security