lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:	Fri, 19 Feb 2010 01:48:12 +0300
From:	Anton Vorontsov <avorontsov@...mvista.com>
To:	Andrew Morton <akpm@...ux-foundation.org>
Cc:	David Brownell <dbrownell@...rs.sourceforge.net>,
	Grant Likely <grant.likely@...retlab.ca>,
	Bill Gatliff <bgat@...lgatliff.com>,
	Dmitry Eremin-Solenikov <dbaryshkov@...il.com>,
	Benjamin Herrenschmidt <benh@...nel.crashing.org>,
	linuxppc-dev@...abs.org, linux-kernel@...r.kernel.org
Subject: [PATCH] gpiolib: Cosmetic improvements for error handling in
 gpiochip_add()

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

Suggested-by: Grant Likely <grant.likely@...retlab.ca>
Signed-off-by: Anton Vorontsov <avorontsov@...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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ