linux/drivers/gpio
Johan Hovold be323587d2 gpio: sysfs: fix memory leaks and device hotplug
commit 483d821108 upstream.

Unregister GPIOs requested through sysfs at chip remove to avoid leaking
the associated memory and sysfs entries.

The stale sysfs entries prevented the gpio numbers from being exported
when the gpio range was later reused (e.g. at device reconnect).

This also fixes the related module-reference leak.

Note that kernfs makes sure that any on-going sysfs operations finish
before the class devices are unregistered and that further accesses
fail.

The chip exported flag is used to prevent gpiod exports during removal.
This also makes it harder to trigger, but does not fix, the related race
between gpiochip_remove and export_store, which is really a race with
gpiod_request that needs to be addressed separately.

Also note that this would prevent the crashes (e.g. NULL-dereferences)
at reconnect that affects pre-3.18 kernels, as well as use-after-free on
operations on open attribute files on pre-3.14 kernels (prior to
kernfs).

Fixes: d8f388d8dc ("gpio: sysfs interface")
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-05-17 09:53:49 -07:00
..
Kconfig gpio: tb10x: GPIO_TB10X needs to select GENERIC_IRQ_CHIP 2014-02-05 11:13:59 +01:00
Makefile ARM: driver updates for 3.14 2014-01-23 18:49:36 -08:00
devres.c gpiolib: devres: add missing headers 2013-10-29 18:26:14 -07:00
gpio-74x164.c gpio: 74x164: Driver cleanup 2013-12-12 14:28:12 +01:00
gpio-adnp.c Merge branch 'mark-irqs' into devel 2013-12-04 14:48:17 +01:00
gpio-adp5520.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-adp5588.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-amd8111.c gpio: remove DEFINE_PCI_DEVICE_TABLE macro 2013-12-03 13:16:09 +01:00
gpio-arizona.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-bcm-kona.c gpio: bcm281xx: Update MODULE_AUTHOR 2014-02-05 10:59:18 +01:00
gpio-bt8xx.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-clps711x.c gpio: clps711x: Add module alias to support module auto loading 2014-02-05 11:04:20 +01:00
gpio-cs5535.c gpio: remove use of __devexit 2012-11-28 11:39:59 -08:00
gpio-da9052.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-da9055.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-davinci.c gpio: davinci: don't create irq_domain in case of unbanked irqs 2013-12-26 00:02:12 +05:30
gpio-em.c Merge branch 'mark-irqs' into devel 2013-12-04 14:48:17 +01:00
gpio-ep93xx.c gpio: ep93xx: get rid of bogus __raw* accessors 2013-10-16 09:59:54 +02:00
gpio-f7188x.c gpio: f7188x: set can_sleep attribute 2014-01-07 19:02:01 +01:00
gpio-ge.c
gpio-generic.c GPIO: gpio-generic: remove kfree() from bgpio_remove call 2013-04-11 19:33:54 +02:00
gpio-grgpio.c gpio: grgpio: Staticize local symbols 2013-06-19 21:40:38 +02:00
gpio-ich.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-intel-mid.c gpio: intel-mid: fix the incorrect return of idle callback 2014-02-05 10:37:06 +01:00
gpio-iop.c ARM: plat-iop: pass physical base for GPIO 2013-09-20 23:05:19 +02:00
gpio-it8761e.c
gpio-janz-ttl.c gpio: use dev_get_platdata() 2013-08-16 15:24:35 +02:00
gpio-kempld.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-ks8695.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-lp3943.c gpio: lp3943: Remove redundant of_match_ptr helper 2014-01-21 08:29:00 +00:00
gpio-lpc32xx.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-lynxpoint.c Merge branch 'mark-irqs' into devel 2013-12-04 14:48:17 +01:00
gpio-max730x.c gpio: max730x: Remove redundant dev_set_drvdata 2014-01-02 13:54:34 +01:00
gpio-max732x.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-max7300.c gpio: max7300: use devm_kzalloc() 2013-03-27 16:05:11 +01:00
gpio-max7301.c gpio: max7301: Reverting "Do not force SPI speed when using OF Platform" 2013-08-23 19:44:28 +02:00
gpio-mc9s08dz60.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-mc33880.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-mcp23s08.c gpio: mcp23s08: Bug fix of SPI device tree registration. 2014-06-11 11:54:14 -07:00
gpio-ml-ioh.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-mm-lantiq.c GPIO: MIPS: lantiq: convert gpio-mm-lantiq to OF and of_mm_gpio 2012-05-21 14:31:53 +01:00
gpio-moxart.c gpio: moxart: remove redundant dev_err call in moxart_gpio_probe() 2013-12-20 10:22:19 +01:00
gpio-mpc8xxx.c powerpc/gpio: Fix the wrong GPIO input data on MPC8572/MPC8536 2013-12-03 13:10:48 +01:00
gpio-mpc5200.c gpio: remove use of __devinit 2012-11-28 11:39:33 -08:00
gpio-msic.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-msm-v1.c gpio_msm: Fix build error due to missing err.h 2013-07-31 00:34:31 +02:00
gpio-msm-v2.c GPIO tree bulk changes for v3.14 2014-01-21 10:09:12 -08:00
gpio-mvebu.c gpio: mvebu: Fix mask/unmask managment per irq chip type 2015-05-06 21:59:18 +02:00
gpio-mxc.c gpio: mxc: Do not hard code return value 2014-01-02 13:55:53 +01:00
gpio-mxs.c gpio: mxs: Allow for recursive enable_irq_wake() call 2014-05-13 13:32:54 +02:00
gpio-octeon.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-omap.c gpio/omap: raw read and write endian fix 2013-11-25 09:03:39 +01:00
gpio-palmas.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-pca953x.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-pcf857x.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-pch.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-pl061.c gpio: pl061: move irqdomain initialization 2013-11-27 14:13:50 +01:00
gpio-pxa.c gpio: pxa: clamp gpio get value to [0,1] 2014-01-15 08:56:20 +01:00
gpio-rc5t583.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-rcar.c GPIO tree bulk changes for v3.14 2014-01-21 10:09:12 -08:00
gpio-rdc321x.c gpio: use dev_get_platdata() 2013-08-16 15:24:35 +02:00
gpio-sa1100.c ARM: 7841/1: sa1100: remove complex GPIO interface 2013-10-29 11:01:02 +00:00
gpio-samsung.c ARM: S5P[v210|c100|64x0]: Fix build error 2014-01-15 13:48:06 +01:00
gpio-sch.c gpio: Don't override the error code in probe error handling 2013-05-20 20:27:30 +02:00
gpio-sch311x.c gpio: sch311x: fix compilation error 2013-12-23 18:12:48 +01:00
gpio-sodaville.c gpio: sodaville: fix some error return code on error path 2013-12-20 10:23:18 +01:00
gpio-spear-spics.c drivers/gpio: simplify use of devm_ioremap_resource 2013-08-16 17:16:31 +02:00
gpio-sta2x11.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-stmpe.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-stp-xway.c gpio: gpio-stp-xway.c: fix checkpatch error 2013-03-27 16:05:16 +01:00
gpio-sx150x.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-tb10x.c gpio: tb10x: Remove redundant of_match_ptr helper 2014-01-02 14:03:22 +01:00
gpio-tc3589x.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-tegra.c gpio: tegra: add missing error handling to probe 2013-12-11 13:37:48 +01:00
gpio-timberdale.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-tnetv107x.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-tps6586x.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-tps65910.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-tps65912.c gpio: tps65912: fix wrong container_of arguments 2015-03-06 14:43:31 -08:00
gpio-ts5500.c gpio: use dev_get_platdata() 2013-08-16 15:24:35 +02:00
gpio-twl4030.c GPIO tree bulk changes for v3.14 2014-01-21 10:09:12 -08:00
gpio-twl6040.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-tz1090-pdc.c gpio-tz1090-pdc: add TZ1090 PDC gpio driver 2013-07-20 19:03:48 +02:00
gpio-tz1090.c gpio-tz1090: convert to use generic irqchip 2013-07-20 19:05:15 +02:00
gpio-ucb1400.c Linux 3.13-rc3 2013-12-09 14:04:37 +01:00
gpio-viperboard.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-vr41xx.c gpio: remove use of __devexit 2012-11-28 11:39:59 -08:00
gpio-vx855.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-wm831x.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-wm8350.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-wm8994.c gpio/pinctrl: make gpio_chip members typed boolean 2013-12-04 14:42:46 +01:00
gpio-xilinx.c GPIO: xilinx: Use BIT macro 2013-06-17 07:47:33 +02:00
gpio-xtensa.c gpio: xtensa: fix build when XCHAL_HAVE_CP is 0 2014-02-03 09:11:45 +01:00
gpiolib-acpi.c gpio / ACPI: get rid of acpi_gpio.h 2014-01-08 15:07:28 +01:00
gpiolib-of.c gpiolib: of: allow of_gpiochip_find_and_xlate to find more than one chip per node 2015-03-06 14:43:31 -08:00
gpiolib.c gpio: sysfs: fix memory leaks and device hotplug 2015-05-17 09:53:49 -07:00
gpiolib.h gpio / ACPI: get rid of acpi_gpio.h 2014-01-08 15:07:28 +01:00