alistair23-linux/drivers/gpio
Geert Uytterhoeven 3577989091 gpio: Fix gpiochip_add_data_with_key() error path
The err_remove_chip block is too coarse, and may perform cleanup that
must not be done.  E.g. if of_gpiochip_add() fails, of_gpiochip_remove()
is still called, causing:

    OF: ERROR: Bad of_node_put() on /soc/gpio@e6050000
    CPU: 1 PID: 20 Comm: kworker/1:1 Not tainted 5.1.0-rc2-koelsch+ #407
    Hardware name: Generic R-Car Gen2 (Flattened Device Tree)
    Workqueue: events deferred_probe_work_func
    [<c020ec74>] (unwind_backtrace) from [<c020ae58>] (show_stack+0x10/0x14)
    [<c020ae58>] (show_stack) from [<c07c1224>] (dump_stack+0x7c/0x9c)
    [<c07c1224>] (dump_stack) from [<c07c5a80>] (kobject_put+0x94/0xbc)
    [<c07c5a80>] (kobject_put) from [<c0470420>] (gpiochip_add_data_with_key+0x8d8/0xa3c)
    [<c0470420>] (gpiochip_add_data_with_key) from [<c0473738>] (gpio_rcar_probe+0x1d4/0x314)
    [<c0473738>] (gpio_rcar_probe) from [<c052fca8>] (platform_drv_probe+0x48/0x94)

and later, if a GPIO consumer tries to use a GPIO from a failed
controller:

    WARNING: CPU: 0 PID: 1 at lib/refcount.c:156 kobject_get+0x38/0x4c
    refcount_t: increment on 0; use-after-free.
    Modules linked in:
    CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.1.0-rc2-koelsch+ #407
    Hardware name: Generic R-Car Gen2 (Flattened Device Tree)
    [<c020ec74>] (unwind_backtrace) from [<c020ae58>] (show_stack+0x10/0x14)
    [<c020ae58>] (show_stack) from [<c07c1224>] (dump_stack+0x7c/0x9c)
    [<c07c1224>] (dump_stack) from [<c0221580>] (__warn+0xd0/0xec)
    [<c0221580>] (__warn) from [<c02215e0>] (warn_slowpath_fmt+0x44/0x6c)
    [<c02215e0>] (warn_slowpath_fmt) from [<c07c58fc>] (kobject_get+0x38/0x4c)
    [<c07c58fc>] (kobject_get) from [<c068b3ec>] (of_node_get+0x14/0x1c)
    [<c068b3ec>] (of_node_get) from [<c0686f24>] (of_find_node_by_phandle+0xc0/0xf0)
    [<c0686f24>] (of_find_node_by_phandle) from [<c0686fbc>] (of_phandle_iterator_next+0x68/0x154)
    [<c0686fbc>] (of_phandle_iterator_next) from [<c0687fe4>] (__of_parse_phandle_with_args+0x40/0xd0)
    [<c0687fe4>] (__of_parse_phandle_with_args) from [<c0688204>] (of_parse_phandle_with_args_map+0x100/0x3ac)
    [<c0688204>] (of_parse_phandle_with_args_map) from [<c0471240>] (of_get_named_gpiod_flags+0x38/0x380)
    [<c0471240>] (of_get_named_gpiod_flags) from [<c046f864>] (gpiod_get_from_of_node+0x24/0xd8)
    [<c046f864>] (gpiod_get_from_of_node) from [<c0470aa4>] (devm_fwnode_get_index_gpiod_from_child+0xa0/0x144)
    [<c0470aa4>] (devm_fwnode_get_index_gpiod_from_child) from [<c05f425c>] (gpio_keys_probe+0x418/0x7bc)
    [<c05f425c>] (gpio_keys_probe) from [<c052fca8>] (platform_drv_probe+0x48/0x94)

Fix this by splitting the cleanup block, and adding a missing call to
gpiochip_irqchip_remove().

Fixes: 28355f8196 ("gpio: defer probe if pinctrl cannot be found")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2019-04-25 09:12:00 +02:00
..
gpio-74x164.c
gpio-74xx-mmio.c
gpio-104-dio-48e.c gpio: 104-dio-48e: Mask read inputs for get_multiple 2018-11-05 08:54:41 +01:00
gpio-104-idi-48.c gpio: 104-idi-48e: Mask the read inputs for get_multiple 2018-11-05 08:54:41 +01:00
gpio-104-idio-16.c
gpio-adnp.c gpio: adnp: Fix testing wrong value in adnp_gpio_direction_input 2019-03-22 16:48:47 +01:00
gpio-adp5520.c drivers: gpio: Update MODULE AUTHOR email address 2018-08-29 13:30:25 +02:00
gpio-adp5588.c gpio: adp5588.c: Switch to events system 2019-02-09 11:33:37 +01:00
gpio-altera-a10sr.c gpio: altera-a10sr: Trivial coding style fix 2019-02-14 15:14:38 +01:00
gpio-altera.c gpio: altera: Fixup block comment style 2019-01-28 14:59:58 +01:00
gpio-amd-fch.c gpio: amd-fch: Set proper output level for direction_output 2019-03-08 14:11:30 +01:00
gpio-amd8111.c
gpio-amdpt.c
gpio-arizona.c
gpio-aspeed.c gpio: aspeed: fix a potential NULL pointer dereference 2019-03-25 09:26:48 +01:00
gpio-ath79.c
gpio-bcm-kona.c gpio-bcm-kona: use new req/relres and dis/enable_irq funcs 2018-09-10 08:57:36 +02:00
gpio-bd9571mwv.c
gpio-brcmstb.c gpio: brcmstb: allow 0 width GPIO banks 2018-08-30 11:04:50 +02:00
gpio-bt8xx.c
gpio-cadence.c gpio: Add Cadence GPIO driver 2018-12-21 11:41:00 +01:00
gpio-clps711x.c
gpio-creg-snps.c GPIO: add single-register GPIO via CREG driver 2018-10-10 09:21:06 +02:00
gpio-crystalcove.c gpio: crystalcove: Convert to use SPDX identifier 2019-02-08 15:55:40 +02:00
gpio-cs5535.c
gpio-da9052.c
gpio-da9055.c
gpio-davinci.c gpio: davinci: use devm_platform_ioremap_resource() 2019-02-21 13:05:52 +01:00
gpio-dln2.c
gpio-dwapb.c gpio: gpio-dwapb: simplify getting .driver_data 2018-11-05 08:54:41 +01:00
gpio-eic-sprd.c gpio: eic: sprd: Fix incorrect irq type setting for the sync EIC 2019-04-11 15:39:48 +02:00
gpio-em.c
gpio-ep93xx.c gpio: ep93xx: fix test for end of loop 2018-09-10 08:48:24 +02:00
gpio-exar.c gpio: exar: add a check for the return value of ida_simple_get fails 2019-03-22 16:48:39 +01:00
gpio-f7188x.c gpio-f7188x: add support Fintek F81804 & F81966 2019-01-22 15:48:44 +01:00
gpio-ftgpio010.c gpio: ftgpio: Register per-instance irqchip 2019-02-25 10:24:07 +01:00
gpio-ge.c
gpio-gpio-mm.c gpio: gpio-mm: Mask read inputs for get_multiple 2018-11-05 08:54:41 +01:00
gpio-grgpio.c drivers/gpio/gpio-grgpio.c: Remove duplicate header 2018-11-19 15:09:22 +01:00
gpio-gw-pld.c gpio: Add a Gateworks PLD GPIO driver 2019-02-09 11:33:37 +01:00
gpio-hlwd.c gpio: hlwd: Implement edge trigger emulation 2019-01-21 14:34:45 +01:00
gpio-htc-egpio.c gpio: htc-egpio: Remove set but not used variable 'bit' 2018-10-01 12:27:19 +02:00
gpio-ich.c gpio: ich: Convert to use SPDX identifier 2018-12-07 17:34:07 +02:00
gpio-intel-mid.c gpio: intel-mid: Convert to use SPDX identifier 2018-12-07 17:34:07 +02:00
gpio-iop.c
gpio-it87.c
gpio-janz-ttl.c
gpio-kempld.c
gpio-ks8695.c gpio: ks8695: Change to use DEFINE_SHOW_ATTRIBUTE macro 2018-12-07 11:10:14 +01:00
gpio-loongson.c
gpio-loongson1.c
gpio-lp873x.c
gpio-lp3943.c
gpio-lp87565.c
gpio-lpc18xx.c gpio: lpc18xx: fix GPIO controller driver build as a module 2018-12-10 09:10:46 +01:00
gpio-lpc32xx.c
gpio-lynxpoint.c intel-gpio for v4.21-1 2018-12-14 14:27:41 +01:00
gpio-madera.c gpio: madera: Add missing const 2019-02-14 15:14:37 +01:00
gpio-max730x.c
gpio-max732x.c
gpio-max3191x.c gpiolib: Pass array info to get/set array functions 2018-09-13 11:16:54 +02:00
gpio-max7300.c
gpio-max7301.c gpio: max7301: fix driver for use with CONFIG_VMAP_STACK 2018-12-21 09:23:45 +01:00
gpio-max77620.c regmap: regmap-irq/gpio-max77620: add level-irq support 2018-12-19 18:35:45 +00:00
gpio-mb86s7x.c
gpio-mc9s08dz60.c
gpio-mc33880.c
gpio-menz127.c
gpio-merrifield.c gpio: merrifield: Convert to use SPDX identifier 2018-12-07 17:34:08 +02:00
gpio-ml-ioh.c PCI: Move Rohm Vendor ID to generic list 2019-02-01 17:24:52 -06:00
gpio-mm-lantiq.c
gpio-mmio.c gpio: Use SPDX header for core library 2018-09-25 09:08:48 +02:00
gpio-mockup.c gpio: mockup: use simple_read_from_buffer() in debugfs read callback 2019-03-28 18:04:53 +01:00
gpio-mpc8xxx.c
gpio-mpc5200.c
gpio-msic.c gpio: msic: Convert to use SPDX identifier 2019-02-08 15:55:41 +02:00
gpio-mt7621.c gpio: MT7621: use a per instance irq_chip structure 2019-02-08 12:30:15 +01:00
gpio-mvebu.c gpio: mvebu: implement get_direction 2019-01-10 16:19:11 +01:00
gpio-mxc.c gpio: mxc: add check to return defer probe if clock tree NOT ready 2019-02-25 13:42:46 +01:00
gpio-mxs.c gpio: mxs: read pin level directly instead of using .get 2018-12-21 11:29:57 +01:00
gpio-octeon.c
gpio-omap.c gpio: gpio-omap: fix level interrupt idling 2019-03-08 14:11:30 +01:00
gpio-palmas.c
gpio-pca953x.c gpio: pca953x: Use PCA_LATCH_INT 2019-03-08 14:11:30 +01:00
gpio-pcf857x.c gpio updates for v5.1 2019-02-17 21:59:33 +01:00
gpio-pch.c PCI: Move Rohm Vendor ID to generic list 2019-02-01 17:24:52 -06:00
gpio-pci-idio-16.c gpio: pci-idio-16: Mask read inputs for get_multiple 2018-11-05 08:54:42 +01:00
gpio-pcie-idio-24.c gpio: pcie-idio-24: Mask read inputs for get_multiple 2018-11-05 08:54:42 +01:00
gpio-pisosr.c
gpio-pl061.c gpio: pl061: Move irq_chip definition inside struct pl061 2018-11-05 08:54:42 +01:00
gpio-pmic-eic-sprd.c gpio: sprd: Change to use SoC compatible string 2019-02-21 13:18:49 +01:00
gpio-pxa.c gpio: pxa: avoid attempting to set pin direction via pinctrl on MMP2 2019-02-14 10:06:03 +01:00
gpio-raspberrypi-exp.c gpio: raspberrypi-exp: decrease refcount on firmware dt node 2018-12-17 15:28:30 +01:00
gpio-rc5t583.c
gpio-rcar.c gpio: rcar: select General Output Register to set output states 2019-01-21 14:59:50 +01:00
gpio-rdc321x.c
gpio-reg.c
gpio-sa1100.c
gpio-sama5d2-piobu.c gpio: sama5d2-piobu: Set proper output level for direction_output 2019-01-11 10:34:37 +01:00
gpio-sch.c gpio: sch: Convert to use SPDX identifier 2018-12-07 17:34:08 +02:00
gpio-sch311x.c gpio: sch311x: clean an indentation issue, remove extraneous space 2018-11-05 08:54:42 +01:00
gpio-siox.c gpio: new driver to work with a 8x12 siox 2018-09-28 09:30:42 +02:00
gpio-sodaville.c gpio: sodaville: Convert to use SPDX identifier 2018-12-07 17:34:08 +02:00
gpio-spear-spics.c
gpio-sprd.c
gpio-sta2x11.c
gpio-stmpe.c
gpio-stp-xway.c
gpio-syscon.c gpio: syscon: Fix possible NULL ptr usage 2018-10-10 10:33:11 +02:00
gpio-tb10x.c gpio: tb10x: Use GENERIC_GPIO 2018-08-29 08:53:37 +02:00
gpio-tc3589x.c
gpio-tegra.c gpio: tegra: Fix offset of pinctrl calls 2019-02-19 21:48:20 +01:00
gpio-tegra186.c gpio: tegra186: Use TEGRA186_ prefix for GPIO names 2019-02-14 15:14:38 +01:00
gpio-thunderx.c
gpio-timberdale.c
gpio-tpic2810.c
gpio-tps6586x.c gpio: tps65xxx: Use SPDX license tag 2018-09-04 08:22:47 +02:00
gpio-tps65086.c gpio: tps65xxx: Use SPDX license tag 2018-09-04 08:22:47 +02:00
gpio-tps65218.c
gpio-tps65910.c gpio: tps65xxx: Use SPDX license tag 2018-09-04 08:22:47 +02:00
gpio-tps65912.c gpio: tps65xxx: Use SPDX license tag 2018-09-04 08:22:47 +02:00
gpio-tps68470.c
gpio-tqmx86.c gpio: tqmx86: Set proper output level for direction_output 2019-02-21 13:19:52 +01:00
gpio-ts4800.c
gpio-ts4900.c
gpio-ts5500.c gpio: ts5500: Delete platform data handling 2018-09-04 08:22:47 +02:00
gpio-twl4030.c gpio: twl4030: Implement .get_direction() 2018-09-10 08:48:51 +02:00
gpio-twl6040.c gpio: twl6040: Implement .get_direction() 2018-09-10 08:49:22 +02:00
gpio-ucb1400.c
gpio-uniphier.c gpio: uniphier: convert to SPDX License Identifier 2018-12-07 13:40:28 +01:00
gpio-vf610.c gpio: vf610: Mask all GPIO interrupts 2019-01-28 15:28:43 +01:00
gpio-viperboard.c gpio: viperboard: Cut down on boilerplate 2018-09-17 10:55:24 -07:00
gpio-vr41xx.c gpio: vr41xx: Delete vr41xx_gpio_pullupdown() callback 2018-09-17 10:55:24 -07:00
gpio-vx855.c gpio: vx855: Cut down on boilerplate 2018-09-17 10:55:24 -07:00
gpio-wcove.c gpio: wcove: Convert to use SPDX identifier 2019-02-08 15:55:41 +02:00
gpio-winbond.c
gpio-wm831x.c gpio: wm8xxx: Cut down on boilerplate 2018-09-17 10:55:24 -07:00
gpio-wm8350.c gpio: wm8xxx: Cut down on boilerplate 2018-09-17 10:55:24 -07:00
gpio-wm8994.c gpio: wm8xxx: Cut down on boilerplate 2018-09-17 10:55:24 -07:00
gpio-ws16c48.c gpio: ws16c48: Mask read inputs for get_multiple 2018-11-05 08:54:42 +01:00
gpio-xgene-sb.c
gpio-xgene.c
gpio-xilinx.c
gpio-xlp.c gpio: xlp: Cut down on boilerplate 2018-09-17 10:55:24 -07:00
gpio-xra1403.c
gpio-xtensa.c gpio: xtensa: Cut down on boilerplate 2018-09-17 10:55:24 -07:00
gpio-zevio.c gpio: zevio: Include the right header 2018-09-04 08:22:47 +02:00
gpio-zx.c
gpio-zynq.c gpio: zynq: properly support runtime PM for GPIO used as interrupts 2019-02-13 10:36:54 +01:00
gpiolib-acpi.c This is the bulk of GPIO changes for the v5.1 cycle: 2019-03-08 10:09:53 -08:00
gpiolib-devprop.c Accept partial 'gpio-line-names' property. 2018-10-01 13:15:06 +02:00
gpiolib-devres.c gpio: Add devm_gpiod_unhinge() 2018-12-11 01:04:23 +00:00
gpiolib-legacy.c gpio: Use SPDX header for core library 2018-09-25 09:08:48 +02:00
gpiolib-of.c gpio: of: Fix of_gpiochip_add() error path 2019-03-28 17:58:34 +01:00
gpiolib-sysfs.c gpio: Use SPDX header for core library 2018-09-25 09:08:48 +02:00
gpiolib.c gpio: Fix gpiochip_add_data_with_key() error path 2019-04-25 09:12:00 +02:00
gpiolib.h gpio: add core support for pull-up/pull-down configuration 2019-02-13 09:10:14 +01:00
Kconfig gpio: AMD G-Series PCH gpio driver 2019-02-22 17:26:52 +01:00
Makefile gpio: AMD G-Series PCH gpio driver 2019-02-22 17:26:52 +01:00
TODO gpio: Add global TODO file for GPIO 2018-11-05 08:54:40 +01:00