public inbox for linuxppc-dev@ozlabs.org 
 help / color / mirror / Atom feed
From: Anton Vorontsov <avorontsov@ru•mvista.com>
To: Andrew Morton <akpm@linux-foundation•org>
Cc: David Brownell <dbrownell@users•sourceforge.net>,
	Dmitry Eremin-Solenikov <dbaryshkov@gmail•com>,
	linux-kernel@vger•kernel.org, linuxppc-dev@ozlabs•org,
	Bill Gatliff <bgat@billgatliff•com>
Subject: [PATCH] gpiolib: Cosmetic improvements for error handling in gpiochip_add()
Date: Fri, 19 Feb 2010 01:48:12 +0300	[thread overview]
Message-ID: <20100218224812.GA11975@oksana.dev.rtsoft.ru> (raw)

Hopefully it makes the code look nicer and makes it easier to extend
this function.

Suggested-by: Grant Likely <grant.likely@secretlab•ca>
Signed-off-by: Anton Vorontsov <avorontsov@ru•mvista.com>
---

On Tue, Feb 09, 2010 at 10:16:44AM -0700, Grant Likely wrote:
[...]
> Rather than doing an else block which will need to be reworked if/when
> any additional code is added to the bottom of this routine, please
> rework the if() block to bail on failure instead of implicitly falling
> through to the return statement.

Here it is.

Andrew,

Please either fold this patch into
  gpiolib-introduce-chip-addition-removal-notifier.patch
or, actually these changes can stay in its own patch for better
sparation of cosmitc/real changes.

Thanks!

 drivers/gpio/gpiolib.c |   24 +++++++++++++++---------
 1 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 375c03a..f227c1f 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1099,17 +1099,23 @@ int gpiochip_add(struct gpio_chip *chip)
 
 unlock:
 	spin_unlock_irqrestore(&gpio_lock, flags);
-	if (status == 0)
-		status = gpiochip_export(chip);
+
+	if (status)
+		goto fail;
+
+	status = gpiochip_export(chip);
+	if (status)
+		goto fail;
+
+	blocking_notifier_call_chain(&gpio_notifier, GPIO_NOTIFY_CHIP_ADDED,
+				     chip);
+
+	return 0;
 fail:
 	/* failures here can mean systems won't boot... */
-	if (status)
-		pr_err("gpiochip_add: gpios %d..%d (%s) not registered\n",
-			chip->base, chip->base + chip->ngpio - 1,
-			chip->label ? : "generic");
-	else
-		blocking_notifier_call_chain(&gpio_notifier,
-					     GPIO_NOTIFY_CHIP_ADDED, chip);
+	pr_err("gpiochip_add: gpios %d..%d (%s) not registered\n",
+		chip->base, chip->base + chip->ngpio - 1,
+		chip->label ? : "generic");
 	return status;
 }
 EXPORT_SYMBOL_GPL(gpiochip_add);
-- 
1.6.5.7

                 reply	other threads:[~2010-02-18 22:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100218224812.GA11975@oksana.dev.rtsoft.ru \
    --to=avorontsov@ru$(echo .)mvista.com \
    --cc=akpm@linux-foundation$(echo .)org \
    --cc=bgat@billgatliff$(echo .)com \
    --cc=dbaryshkov@gmail$(echo .)com \
    --cc=dbrownell@users$(echo .)sourceforge.net \
    --cc=linux-kernel@vger$(echo .)kernel.org \
    --cc=linuxppc-dev@ozlabs$(echo .)org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox