1 From: Guennadi Liakhovetski <g.liakhovetski@pengutronix.de>
2 Date: Mon, 28 Apr 2008 09:14:44 +0000 (-0700)
3 Subject: gpiolib: better rmmod infrastructure
4 X-Git-Tag: v2.6.26-rc1~851
5 X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux-2.6.git;a=commitdiff_plain;h=438d8908b379b6322fc3b28d45c9ebdddf58bc20
7 gpiolib: better rmmod infrastructure
9 As long as one or more GPIOs on a gpio chip are used its driver should not be
10 unloaded. The existing mechanism (gpiochip_remove failure) doesn't address
11 that, since rmmod can no longer be made to fail by having the cleanup code
12 report errors. Module usecounts are the solution.
14 Assuming standard "initialize struct to zero" policies, this change won't
15 affect SOC platform drivers. However, drivers for external chips (on I2C and
16 SPI busses) should be updated if they can be built as modules.
18 Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@pengutronix.de>
19 [ gpio_ensure_requested() needs to update module usecounts too ]
20 Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
21 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
22 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
25 diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
26 index d8db2f8..eb75d12 100644
27 --- a/drivers/gpio/gpiolib.c
28 +++ b/drivers/gpio/gpiolib.c
29 @@ -68,6 +68,9 @@ static void gpio_ensure_requested(struct gpio_desc *desc)
30 if (test_and_set_bit(FLAG_REQUESTED, &desc->flags) == 0) {
31 pr_warning("GPIO-%d autorequested\n", (int)(desc - gpio_desc));
32 desc_set_label(desc, "[auto]");
33 + if (!try_module_get(desc->chip->owner))
34 + pr_err("GPIO-%d: module can't be gotten \n",
35 + (int)(desc - gpio_desc));
39 @@ -177,6 +180,9 @@ int gpio_request(unsigned gpio, const char *label)
40 if (desc->chip == NULL)
43 + if (!try_module_get(desc->chip->owner))
46 /* NOTE: gpio_request() can be called in early boot,
47 * before IRQs are enabled.
49 @@ -184,8 +190,10 @@ int gpio_request(unsigned gpio, const char *label)
50 if (test_and_set_bit(FLAG_REQUESTED, &desc->flags) == 0) {
51 desc_set_label(desc, label ? : "?");
56 + module_put(desc->chip->owner);
61 @@ -209,9 +217,10 @@ void gpio_free(unsigned gpio)
62 spin_lock_irqsave(&gpio_lock, flags);
64 desc = &gpio_desc[gpio];
65 - if (desc->chip && test_and_clear_bit(FLAG_REQUESTED, &desc->flags))
66 + if (desc->chip && test_and_clear_bit(FLAG_REQUESTED, &desc->flags)) {
67 desc_set_label(desc, NULL);
69 + module_put(desc->chip->owner);
71 WARN_ON(extra_checks);
73 spin_unlock_irqrestore(&gpio_lock, flags);
74 diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
75 index f29a502..7e77b6f 100644
76 --- a/include/asm-generic/gpio.h
77 +++ b/include/asm-generic/gpio.h
85 * struct gpio_chip - abstract a GPIO controller
86 @@ -48,6 +49,7 @@ struct seq_file;
90 + struct module *owner;
92 int (*direction_input)(struct gpio_chip *chip,