surprise :p
[openwrt.git] / target / linux / generic-2.6 / patches-2.6.25 / 960-backport_gpiolib_better_rmmod_infrastructure.patch
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
6
7 gpiolib: better rmmod infrastructure
8
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.
13
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.
17
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>
23 ---
24
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));
36 }
37 }
38
39 @@ -177,6 +180,9 @@ int gpio_request(unsigned gpio, const char *label)
40 if (desc->chip == NULL)
41 goto done;
42
43 + if (!try_module_get(desc->chip->owner))
44 + goto done;
45 +
46 /* NOTE: gpio_request() can be called in early boot,
47 * before IRQs are enabled.
48 */
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 ? : "?");
52 status = 0;
53 - } else
54 + } else {
55 status = -EBUSY;
56 + module_put(desc->chip->owner);
57 + }
58
59 done:
60 if (status)
61 @@ -209,9 +217,10 @@ void gpio_free(unsigned gpio)
62 spin_lock_irqsave(&gpio_lock, flags);
63
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);
68 - else
69 + module_put(desc->chip->owner);
70 + } else
71 WARN_ON(extra_checks);
72
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
78 @@ -17,6 +17,7 @@
79 #endif
80
81 struct seq_file;
82 +struct module;
83
84 /**
85 * struct gpio_chip - abstract a GPIO controller
86 @@ -48,6 +49,7 @@ struct seq_file;
87 */
88 struct gpio_chip {
89 char *label;
90 + struct module *owner;
91
92 int (*direction_input)(struct gpio_chip *chip,
93 unsigned offset);
This page took 0.045796 seconds and 5 git commands to generate.