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 --- a/drivers/gpio/gpiolib.c
26 +++ b/drivers/gpio/gpiolib.c
28 if (test_and_set_bit(FLAG_REQUESTED, &desc->flags) == 0) {
29 pr_warning("GPIO-%d autorequested\n", (int)(desc - gpio_desc));
30 desc_set_label(desc, "[auto]");
31 + if (!try_module_get(desc->chip->owner))
32 + pr_err("GPIO-%d: module can't be gotten \n",
33 + (int)(desc - gpio_desc));
38 if (desc->chip == NULL)
41 + if (!try_module_get(desc->chip->owner))
44 /* NOTE: gpio_request() can be called in early boot,
45 * before IRQs are enabled.
48 if (test_and_set_bit(FLAG_REQUESTED, &desc->flags) == 0) {
49 desc_set_label(desc, label ? : "?");
54 + module_put(desc->chip->owner);
60 spin_lock_irqsave(&gpio_lock, flags);
62 desc = &gpio_desc[gpio];
63 - if (desc->chip && test_and_clear_bit(FLAG_REQUESTED, &desc->flags))
64 + if (desc->chip && test_and_clear_bit(FLAG_REQUESTED, &desc->flags)) {
65 desc_set_label(desc, NULL);
67 + module_put(desc->chip->owner);
69 WARN_ON(extra_checks);
71 spin_unlock_irqrestore(&gpio_lock, flags);
72 --- a/include/asm-generic/gpio.h
73 +++ b/include/asm-generic/gpio.h
81 * struct gpio_chip - abstract a GPIO controller
86 + struct module *owner;
88 int (*direction_input)(struct gpio_chip *chip,