From: Johan Hovold <johan@kernel.org>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Alexandre Courbot <gnurou@gmail.com>,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
Johan Hovold <johan@kernel.org>
Subject: [PATCH 3/6] gpio: clean up gpiochip_add error handling
Date: Mon, 12 Jan 2015 17:12:26 +0100 [thread overview]
Message-ID: <1421079149-2236-4-git-send-email-johan@kernel.org> (raw)
In-Reply-To: <1421079149-2236-1-git-send-email-johan@kernel.org>
Clean up gpiochip_add error handling.
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/gpio/gpiolib.c | 38 +++++++++++++++++---------------------
1 file changed, 17 insertions(+), 21 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index ac5944b4e4d8..4efb92ca3463 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -255,32 +255,29 @@ int gpiochip_add(struct gpio_chip *chip)
}
status = gpiochip_add_to_list(chip);
+ if (status) {
+ spin_unlock_irqrestore(&gpio_lock, flags);
+ goto err_free_descs;
+ }
- if (status == 0) {
- for (id = 0; id < chip->ngpio; id++) {
- struct gpio_desc *desc = &descs[id];
- desc->chip = chip;
-
- /* REVISIT: most hardware initializes GPIOs as
- * inputs (often with pullups enabled) so power
- * usage is minimized. Linux code should set the
- * gpio direction first thing; but until it does,
- * and in case chip->get_direction is not set,
- * we may expose the wrong direction in sysfs.
- */
- desc->flags = !chip->direction_input
- ? (1 << FLAG_IS_OUT)
- : 0;
- }
+ for (id = 0; id < chip->ngpio; id++) {
+ struct gpio_desc *desc = &descs[id];
+
+ desc->chip = chip;
+
+ /* REVISIT: most hardware initializes GPIOs as inputs (often
+ * with pullups enabled) so power usage is minimized. Linux
+ * code should set the gpio direction first thing; but until
+ * it does, and in case chip->get_direction is not set, we may
+ * expose the wrong direction in sysfs.
+ */
+ desc->flags = !chip->direction_input ? (1 << FLAG_IS_OUT) : 0;
}
chip->desc = descs;
spin_unlock_irqrestore(&gpio_lock, flags);
- if (status)
- goto fail;
-
#ifdef CONFIG_PINCTRL
INIT_LIST_HEAD(&chip->pin_ranges);
#endif
@@ -304,10 +301,9 @@ err_remove_chip:
spin_lock_irqsave(&gpio_lock, flags);
list_del(&chip->list);
spin_unlock_irqrestore(&gpio_lock, flags);
-fail:
+ chip->desc = NULL;
err_free_descs:
kfree(descs);
- chip->desc = NULL;
/* failures here can mean systems won't boot... */
pr_err("%s: GPIOs %d..%d (%s) failed to register\n", __func__,
--
2.0.5
next prev parent reply other threads:[~2015-01-12 16:12 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-12 16:12 [PATCH 0/6] gpio: fix gpio_chip add and remove Johan Hovold
2015-01-12 16:12 ` [PATCH 1/6] gpio: fix memory and reference leaks in gpiochip_add error path Johan Hovold
2015-01-12 16:12 ` [PATCH 2/6] gpio: fix gpio-chip list corruption Johan Hovold
2015-01-12 16:12 ` Johan Hovold [this message]
2015-01-12 16:12 ` [PATCH 4/6] gpio: fix memory leak and sleep-while-atomic Johan Hovold
2015-01-12 16:12 ` [PATCH 5/6] gpio: fix sleep-while-atomic in gpiochip_remove Johan Hovold
2015-01-12 16:12 ` [PATCH 6/6] gpio: unregister gpiochip device before removing it Johan Hovold
2015-01-14 13:27 ` [PATCH 0/6] gpio: fix gpio_chip add and remove Linus Walleij
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=1421079149-2236-4-git-send-email-johan@kernel.org \
--to=johan@kernel.org \
--cc=gnurou@gmail.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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;
as well as URLs for NNTP newsgroup(s).