From patchwork Thu Sep 4 12:01:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 36701 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f199.google.com (mail-pd0-f199.google.com [209.85.192.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0DA38202E4 for ; Thu, 4 Sep 2014 12:04:28 +0000 (UTC) Received: by mail-pd0-f199.google.com with SMTP id v10sf783662pde.6 for ; Thu, 04 Sep 2014 05:04:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=cjt2bCnzzESa9QDxdJ+ORWknn3oNnWpqaA1JtyC53xQ=; b=YwbV0lkpP9ZwJ9xuF4VLcrZlPK5ck5mEzjw0C0KZ/db50+Tpqo/w2QRPtV4vManwYB aHhFkiyzbe8RCxPTGKdnrMSRbwXBebdxXz7uPlICZPgBumjmJ2wH5PvsBEhdCzz4GyT/ BJo496glZnLRF/gt8KOJhR6pC1CxRSkeV7UDDr4xfcAPfCsPqUYUI5EZVVFRYr7BpfsY a7iLWuldZa5vrEjSk2ryj+ajHEJ+l68U7zoUlUS7HuwheevigwT92Hj7m8B21FymFAed AJ2Wh+3zW+ga9RtlUxoRopA94Ep8hb5MapnjMh1h7orouHi4hX22JhVGjcz4Rxq9VgkV +ACw== X-Gm-Message-State: ALoCoQnBFr8rjsVtx8E1uZsQw/rSJTqU2gy7qXtcEAkEhttilskfhBCtdaSRnTdiBLwb7N/XPV6f X-Received: by 10.66.168.197 with SMTP id zy5mr2114892pab.7.1409832267987; Thu, 04 Sep 2014 05:04:27 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.30.245 with SMTP id d108ls203321qgd.68.gmail; Thu, 04 Sep 2014 05:04:27 -0700 (PDT) X-Received: by 10.52.106.168 with SMTP id gv8mr387153vdb.80.1409832267788; Thu, 04 Sep 2014 05:04:27 -0700 (PDT) Received: from mail-vc0-f176.google.com (mail-vc0-f176.google.com [209.85.220.176]) by mx.google.com with ESMTPS id gx1si5460003vcb.61.2014.09.04.05.04.27 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 04 Sep 2014 05:04:27 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.176 as permitted sender) client-ip=209.85.220.176; Received: by mail-vc0-f176.google.com with SMTP id ik5so10469086vcb.35 for ; Thu, 04 Sep 2014 05:04:27 -0700 (PDT) X-Received: by 10.52.3.40 with SMTP id 8mr2632775vdz.24.1409832267575; Thu, 04 Sep 2014 05:04:27 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp824569vcb; Thu, 4 Sep 2014 05:04:27 -0700 (PDT) X-Received: by 10.66.66.163 with SMTP id g3mr7755491pat.150.1409832266715; Thu, 04 Sep 2014 05:04:26 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id lp3si3076549pab.230.2014.09.04.05.04.20 for ; Thu, 04 Sep 2014 05:04:20 -0700 (PDT) Received-SPF: none (google.com: linux-pm-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754003AbaIDMDR (ORCPT + 15 others); Thu, 4 Sep 2014 08:03:17 -0400 Received: from mail-pd0-f175.google.com ([209.85.192.175]:54535 "EHLO mail-pd0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753774AbaIDMDP (ORCPT ); Thu, 4 Sep 2014 08:03:15 -0400 Received: by mail-pd0-f175.google.com with SMTP id z10so204808pdj.34 for ; Thu, 04 Sep 2014 05:03:14 -0700 (PDT) X-Received: by 10.70.126.73 with SMTP id mw9mr8262687pdb.30.1409832194543; Thu, 04 Sep 2014 05:03:14 -0700 (PDT) Received: from localhost ([122.167.123.172]) by mx.google.com with ESMTPSA id q13sm1542026pdj.44.2014.09.04.05.03.12 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 04 Sep 2014 05:03:13 -0700 (PDT) From: Viresh Kumar To: sre@kernel.org, dbaryshkov@gmail.com, dwmw2@infradead.org, anton@enomsg.org Cc: linux-pm@vger.kernel.org, linaro-kernel@lists.linaro.org, Viresh Kumar Subject: [PATCH 14/15] power-supply: Avoid unnecessary 'goto' statements Date: Thu, 4 Sep 2014 17:31:35 +0530 Message-Id: <1a001657c973ac4f639844d8501e0573f1b7bc80.1409831636.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.0.3.693.g996b0fd In-Reply-To: <2eacd908a8094887cc1796f75ae0513be8a3e36d.1409831636.git.viresh.kumar@linaro.org> References: <2eacd908a8094887cc1796f75ae0513be8a3e36d.1409831636.git.viresh.kumar@linaro.org> In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.176 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Using 'goto' statements for freeing resources on failures is a good choice as it makes code very clean, and reduces the chances of human errors. Though in most cases compiler may take care of this. But adding unnecessary 'goto' statements wouldn't make anything better. Code becomes less readable actually. Signed-off-by: Viresh Kumar --- I am not sure if Maintainers would like this patch specially, but I just wanted to give a try at making code better. Sorry if you didn't like it :) --- drivers/power/power_supply_core.c | 3 +-- drivers/power/power_supply_leds.c | 19 ++++--------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c index 376464e..81177e2 100644 --- a/drivers/power/power_supply_core.c +++ b/drivers/power/power_supply_core.c @@ -599,7 +599,7 @@ static int __power_supply_register(struct device *parent, power_supply_changed(psy); - goto success; + return 0; create_triggers_failed: psy_unregister_cooler(psy); @@ -612,7 +612,6 @@ static int __power_supply_register(struct device *parent, check_supplies_failed: dev_set_name_failed: put_device(dev); -success: return rc; } diff --git a/drivers/power/power_supply_leds.c b/drivers/power/power_supply_leds.c index 995f966..effa093 100644 --- a/drivers/power/power_supply_leds.c +++ b/drivers/power/power_supply_leds.c @@ -57,8 +57,6 @@ static void power_supply_update_bat_leds(struct power_supply *psy) static int power_supply_create_bat_triggers(struct power_supply *psy) { - int rc = 0; - psy->charging_full_trig_name = kasprintf(GFP_KERNEL, "%s-charging-or-full", psy->name); if (!psy->charging_full_trig_name) @@ -87,7 +85,7 @@ static int power_supply_create_bat_triggers(struct power_supply *psy) led_trigger_register_simple(psy->charging_blink_full_solid_trig_name, &psy->charging_blink_full_solid_trig); - goto success; + return 0; charging_blink_full_solid_failed: kfree(psy->full_trig_name); @@ -96,9 +94,7 @@ static int power_supply_create_bat_triggers(struct power_supply *psy) charging_failed: kfree(psy->charging_full_trig_name); charging_full_failed: - rc = -ENOMEM; -success: - return rc; + return -ENOMEM; } static void power_supply_remove_bat_triggers(struct power_supply *psy) @@ -132,20 +128,13 @@ static void power_supply_update_gen_leds(struct power_supply *psy) static int power_supply_create_gen_triggers(struct power_supply *psy) { - int rc = 0; - psy->online_trig_name = kasprintf(GFP_KERNEL, "%s-online", psy->name); if (!psy->online_trig_name) - goto online_failed; + return -ENOMEM; led_trigger_register_simple(psy->online_trig_name, &psy->online_trig); - goto success; - -online_failed: - rc = -ENOMEM; -success: - return rc; + return 0; } static void power_supply_remove_gen_triggers(struct power_supply *psy)