Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754675AbbGXWHE (ORCPT ); Fri, 24 Jul 2015 18:07:04 -0400 Received: from mail-ie0-f171.google.com ([209.85.223.171]:34356 "EHLO mail-ie0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753897AbbGXWHB (ORCPT ); Fri, 24 Jul 2015 18:07:01 -0400 MIME-Version: 1.0 In-Reply-To: <1437757256-10228-1-git-send-email-shraddha.6596@gmail.com> References: <1437757256-10228-1-git-send-email-shraddha.6596@gmail.com> Date: Fri, 24 Jul 2015 15:07:00 -0700 X-Google-Sender-Auth: Bqm8e9I2uG8ssaCX0j_b45YaSJM Message-ID: Subject: Re: [PATCH 2756/2756] Staging: acpi: Merge lines for immediate return From: Kees Cook To: Shraddha Barke Cc: Anton Vorontsov , Colin Cross , Tony Luck , linux-acpi@vger.kernel.org, LKML Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2417 Lines: 76 On Fri, Jul 24, 2015 at 10:00 AM, Shraddha Barke 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 > --- > 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 -- 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/