From: Guenter Roeck <linux@roeck-us.net>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Alexandre Courbot <gnurou@gmail.com>,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] gpio: Do not accept gpio chip additions before gpiolib initialization
Date: Thu, 31 Mar 2016 08:59:00 -0700 [thread overview]
Message-ID: <20160331155900.GA5605@roeck-us.net> (raw)
In-Reply-To: <1459275638-11717-1-git-send-email-linux@roeck-us.net>
On Tue, Mar 29, 2016 at 11:20:38AM -0700, Guenter Roeck wrote:
> Since commit ff2b13592299 ("gpio: make the gpiochip a real device"),
> attempts to add a gpio chip prior to gpiolib initialization cause the
> system to crash. Dump a warning to the console and return an error
> if the situation is encountered.
>
> Fixes: ff2b13592299 ("gpio: make the gpiochip a real device")
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Please drop this one; I think the other series I sent out earlier today
is much better.
Guenter
> ---
> drivers/gpio/gpiolib.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 72065532c1c7..ac66219f0611 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -68,6 +68,7 @@ LIST_HEAD(gpio_devices);
> static void gpiochip_free_hogs(struct gpio_chip *chip);
> static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip);
>
> +static bool gpiolib_initialized;
>
> static inline void desc_set_label(struct gpio_desc *d, const char *label)
> {
> @@ -457,6 +458,9 @@ static void gpiodevice_release(struct device *dev)
> * the gpio framework's arch_initcall(). Otherwise sysfs initialization
> * for GPIOs will fail rudely.
> *
> + * gpiochip_add_data() must only be called after gpiolib initialization,
> + * ie after core_initcall().
> + *
> * If chip->base is negative, this requests dynamic assignment of
> * a range of valid GPIOs.
> */
> @@ -468,6 +472,11 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data)
> int base = chip->base;
> struct gpio_device *gdev;
>
> + if (!gpiolib_initialized) {
> + WARN(1, "gpiolib not initialized\n");
> + return -EPROBE_DEFER;
> + }
> +
> /*
> * First: allocate and populate the internal stat container, and
> * set up the struct device.
> @@ -2829,6 +2838,8 @@ static int __init gpiolib_dev_init(void)
> if (ret < 0) {
> pr_err("gpiolib: failed to allocate char dev region\n");
> bus_unregister(&gpio_bus_type);
> + } else {
> + gpiolib_initialized = true;
> }
> return ret;
> }
> --
> 2.5.0
>
prev parent reply other threads:[~2016-03-31 15:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-29 18:20 [PATCH] gpio: Do not accept gpio chip additions before gpiolib initialization Guenter Roeck
2016-03-30 8:37 ` Alexandre Courbot
2016-03-30 9:16 ` Guenter Roeck
2016-03-31 5:57 ` Alexandre Courbot
2016-03-31 12:48 ` Guenter Roeck
2016-03-31 15:59 ` Guenter Roeck [this message]
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=20160331155900.GA5605@roeck-us.net \
--to=linux@roeck-us.net \
--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).