* [PATCH 2756/2756] Staging: acpi: Merge lines for immediate return
@ 2015-07-24 17:00 Shraddha Barke
2015-07-24 22:07 ` Kees Cook
0 siblings, 1 reply; 3+ messages in thread
From: Shraddha Barke @ 2015-07-24 17:00 UTC (permalink / raw)
To: Anton Vorontsov, Colin Cross, Kees Cook, Tony Luck
Cc: linux-acpi, linux-kernel, 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;
@@
-ret =
+return
f(...);
-return ret;
Signed-off-by: Shraddha Barke <shraddha.6596@gmail.com>
---
drivers/acpi/apei/erst.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/drivers/acpi/apei/erst.c b/drivers/acpi/apei/erst.c
index 3670bba..58e1bdd 100644
--- a/drivers/acpi/apei/erst.c
+++ b/drivers/acpi/apei/erst.c
@@ -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)
--
2.1.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 2756/2756] Staging: acpi: Merge lines for immediate return
2015-07-24 17:00 [PATCH 2756/2756] Staging: acpi: Merge lines for immediate return Shraddha Barke
@ 2015-07-24 22:07 ` Kees Cook
0 siblings, 0 replies; 3+ messages in thread
From: Kees Cook @ 2015-07-24 22:07 UTC (permalink / raw)
To: Shraddha Barke; +Cc: Anton Vorontsov, Colin Cross, Tony Luck, linux-acpi, LKML
On Fri, Jul 24, 2015 at 10:00 AM, Shraddha Barke
<shraddha.6596@gmail.com> wrote:
> 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;
>
> Signed-off-by: Shraddha Barke <shraddha.6596@gmail.com>
> ---
> drivers/acpi/apei/erst.c | 10 +++-------
> 1 file changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/acpi/apei/erst.c b/drivers/acpi/apei/erst.c
> index 3670bba..58e1bdd 100644
> --- a/drivers/acpi/apei/erst.c
> +++ b/drivers/acpi/apei/erst.c
> @@ -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)
> --
> 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
--
Kees Cook
Chrome OS Security
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2756/2756] Staging: acpi: Merge lines for immediate return
@ 2015-07-24 16:55 Shraddha Barke
0 siblings, 0 replies; 3+ messages in thread
From: Shraddha Barke @ 2015-07-24 16:55 UTC (permalink / raw)
To: shraddha; +Cc: linux-kernel, 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;
@@
-ret =
+return
f(...);
-return ret;
Signed-off-by: Shraddha Barke <shraddha.6596@gmail.com>
---
drivers/acpi/apei/erst.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/drivers/acpi/apei/erst.c b/drivers/acpi/apei/erst.c
index 3670bba..58e1bdd 100644
--- a/drivers/acpi/apei/erst.c
+++ b/drivers/acpi/apei/erst.c
@@ -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)
--
2.1.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-07-24 22:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-24 17:00 [PATCH 2756/2756] Staging: acpi: Merge lines for immediate return Shraddha Barke
2015-07-24 22:07 ` Kees Cook
-- strict thread matches above, loose matches on Subject: below --
2015-07-24 16:55 Shraddha Barke
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).