linux/drivers/mmc/host
Krzysztof Kozlowski 2836766a9d mmc: sdhci: Fix sleep in atomic after inserting SD card
Sleep in atomic context happened on Trats2 board after inserting or
removing SD card because mmc_gpio_get_cd() was called under spin lock.

Fix this by moving card detection earlier, before acquiring spin lock.
The mmc_gpio_get_cd() call does not have to be protected by spin lock
because it does not access any sdhci internal data.
The sdhci_do_get_cd() call access host flags (SDHCI_DEVICE_DEAD). After
moving it out side of spin lock it could theoretically race with driver
removal but still there is no actual protection against manual card
eject.

Dmesg after inserting SD card:
[   41.663414] BUG: sleeping function called from invalid context at drivers/gpio/gpiolib.c:1511
[   41.670469] in_atomic(): 1, irqs_disabled(): 128, pid: 30, name: kworker/u8:1
[   41.677580] INFO: lockdep is turned off.
[   41.681486] irq event stamp: 61972
[   41.684872] hardirqs last  enabled at (61971): [<c0490ee0>] _raw_spin_unlock_irq+0x24/0x5c
[   41.693118] hardirqs last disabled at (61972): [<c04907ac>] _raw_spin_lock_irq+0x18/0x54
[   41.701190] softirqs last  enabled at (61648): [<c0026fd4>] __do_softirq+0x234/0x2c8
[   41.708914] softirqs last disabled at (61631): [<c00273a0>] irq_exit+0xd0/0x114
[   41.716206] Preemption disabled at:[<  (null)>]   (null)
[   41.721500]
[   41.722985] CPU: 3 PID: 30 Comm: kworker/u8:1 Tainted: G        W      3.18.0-rc5-next-20141121 #883
[   41.732111] Workqueue: kmmcd mmc_rescan
[   41.735945] [<c0014d2c>] (unwind_backtrace) from [<c0011c80>] (show_stack+0x10/0x14)
[   41.743661] [<c0011c80>] (show_stack) from [<c0489d14>] (dump_stack+0x70/0xbc)
[   41.750867] [<c0489d14>] (dump_stack) from [<c0228b74>] (gpiod_get_raw_value_cansleep+0x18/0x30)
[   41.759628] [<c0228b74>] (gpiod_get_raw_value_cansleep) from [<c03646e8>] (mmc_gpio_get_cd+0x38/0x58)
[   41.768821] [<c03646e8>] (mmc_gpio_get_cd) from [<c036d378>] (sdhci_request+0x50/0x1a4)
[   41.776808] [<c036d378>] (sdhci_request) from [<c0357934>] (mmc_start_request+0x138/0x268)
[   41.785051] [<c0357934>] (mmc_start_request) from [<c0357cc8>] (mmc_wait_for_req+0x58/0x1a0)
[   41.793469] [<c0357cc8>] (mmc_wait_for_req) from [<c0357e68>] (mmc_wait_for_cmd+0x58/0x78)
[   41.801714] [<c0357e68>] (mmc_wait_for_cmd) from [<c0361c00>] (mmc_io_rw_direct_host+0x98/0x124)
[   41.810480] [<c0361c00>] (mmc_io_rw_direct_host) from [<c03620f8>] (sdio_reset+0x2c/0x64)
[   41.818641] [<c03620f8>] (sdio_reset) from [<c035a3d8>] (mmc_rescan+0x254/0x2e4)
[   41.826028] [<c035a3d8>] (mmc_rescan) from [<c003a0e0>] (process_one_work+0x180/0x3f4)
[   41.833920] [<c003a0e0>] (process_one_work) from [<c003a3bc>] (worker_thread+0x34/0x4b0)
[   41.841991] [<c003a3bc>] (worker_thread) from [<c003fed8>] (kthread+0xe4/0x104)
[   41.849285] [<c003fed8>] (kthread) from [<c000f268>] (ret_from_fork+0x14/0x2c)
[   42.038276] mmc0: new high speed SDHC card at address 1234

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Fixes: 94144a465d ("mmc: sdhci: add get_cd() implementation")
Cc: <stable@vger.kernel.org>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2015-01-12 10:14:57 +01:00
..
android-goldfish.c mmc: remove unnecessary platform_set_drvdata() 2013-05-26 14:23:23 -04:00
atmel-mci-regs.h mmc: atmel-mci: AP700x PDC is not connected to MCI 2012-10-03 10:05:23 -04:00
atmel-mci.c mmc: atmel-mci: use SET_RUNTIME_PM_OPS() macro 2014-12-13 00:44:11 +01:00
au1xmmc.c mmc: host: drop owner assignment from platform_drivers 2014-10-20 16:20:56 +02:00
bfin_sdh.c mmc: bfin_sdh: Move away from using deprecated APIs 2013-10-30 20:26:36 -04:00
cb710-mmc.c mmc: cb710: Move away from using deprecated APIs 2013-10-30 20:26:37 -04:00
cb710-mmc.h mmc: host: use platform_{get,set}_drvdata() 2013-06-27 11:13:02 -04:00
davinci_mmc.c mmc: host: drop owner assignment from platform_drivers 2014-10-20 16:20:56 +02:00
dw_mmc-exynos.c mmc: dw_mmc: exynos: Add support for exynos7 2014-11-26 14:30:57 +01:00
dw_mmc-k3.c mmc: dw_mmc: fix possible build error 2014-03-03 14:00:56 -05:00
dw_mmc-pci.c mmc: dw_mmc-pci: Remove superflous #else condition on CONFIG_PM_SLEEP 2014-09-09 13:59:05 +02:00
dw_mmc-pltfm.c mmc: dw_mmc: Add support for IMG Pistachio 2014-11-26 14:31:03 +01:00
dw_mmc-pltfm.h mmc: remove use of __devexit 2012-11-28 12:28:18 -08:00
dw_mmc-rockchip.c mmc: dw_mmc: add support for the other bit of sdio interrupt 2014-11-26 14:31:00 +01:00
dw_mmc.c mmc: dw_mmc: avoid write to CDTHRCTL on older versions 2014-11-26 14:31:02 +01:00
dw_mmc.h mmc: dw_mmc: add support for the other bit of sdio interrupt 2014-11-26 14:31:00 +01:00
jz4740_mmc.c mmc: remove .owner field for drivers using module_platform_driver 2014-09-09 13:59:04 +02:00
Kconfig mmc: dw_mmc: add support for ARM64 2014-11-26 14:30:59 +01:00
Makefile mmc: add Toshiba PCI SD controller driver 2014-11-26 14:30:58 +01:00
mmc_spi.c mmc: don't request CD IRQ until mmc_start_host() 2014-09-23 09:01:36 +02:00
mmci_qcom_dml.c mmc: mmci: Add qcom dml support to the driver. 2014-09-09 13:58:46 +02:00
mmci_qcom_dml.h mmc: mmci: Add qcom dml support to the driver. 2014-09-09 13:58:46 +02:00
mmci.c ACPI and power management updates for 3.19-rc1 2014-12-10 21:17:00 -08:00
mmci.h mmc: mmci: Add Qcom specific rx_fifocnt logic. 2014-07-09 11:25:57 +02:00
moxart-mmc.c mmc: remove .owner field for drivers using module_platform_driver 2014-09-09 13:59:04 +02:00
msm_sdcc.c mmc: msm_sdcc: Use platform_set|get_drvdata 2014-11-10 12:40:34 +01:00
msm_sdcc.h
mvsdio.c mmc: mvsdio: Work around broken TX DMA 2014-11-26 14:31:00 +01:00
mvsdio.h
mxcmmc.c mmc: mxcmmc: fix the default value for available voltages into mxcmci_probe 2014-11-10 12:40:25 +01:00
mxs-mmc.c mmc: mxs-mmc: Check for clk_prepare_enable() error 2014-11-26 14:31:04 +01:00
of_mmc_spi.c mmc: mmc_spi: Support CD/RO GPIOs 2013-08-24 23:45:22 -04:00
omap_hsmmc.c mmc: omap_hsmmc: Fix UHS card with DDR50 support 2014-11-26 14:40:39 +01:00
omap.c mmc: remove .owner field for drivers using module_platform_driver 2014-09-09 13:59:04 +02:00
pxamci.c mmc: pxamci: prepare and unprepare the clocks 2014-09-09 13:59:24 +02:00
pxamci.h
rtsx_pci_sdmmc.c mmc: rtsx_pci: Set power related cap2 macros 2014-09-24 11:20:16 +02:00
rtsx_usb_sdmmc.c mmc: rtsx_pci: Set power related cap2 macros 2014-09-24 11:20:16 +02:00
s3cmci.c mmc: Convert pr_warning to pr_warn 2014-09-24 10:13:09 +02:00
s3cmci.h mmc: s3cmci: port DMA code to dmaengine API 2014-07-09 11:26:13 +02:00
sdhci-acpi.c Driver core patches for 3.19-rc1 2014-12-14 16:10:09 -08:00
sdhci-bcm2835.c mmc: remove .owner field for drivers using module_platform_driver 2014-09-09 13:59:04 +02:00
sdhci-bcm-kona.c mmc, sdhci, bcm-kona, LLVMLinux: Remove use of __initconst 2014-10-03 14:33:46 +02:00
sdhci-cns3xxx.c mmc: remove .owner field for drivers using module_platform_driver 2014-09-09 13:59:04 +02:00
sdhci-dove.c mmc: remove .owner field for drivers using module_platform_driver 2014-09-09 13:59:04 +02:00
sdhci-esdhc-imx.c ACPI and power management updates for 3.19-rc1 2014-12-10 21:17:00 -08:00
sdhci-esdhc.h mmc: sdhci: convert sdhci_set_clock() into a library function 2014-05-22 07:26:32 -04:00
sdhci-msm.c mmc: sdhci-msm: Convert to mmc_send_tuning() 2014-12-08 09:21:06 +01:00
sdhci-of-arasan.c mmc: sdhci-of-arasan: Omit superfluous error messages 2014-11-10 12:40:46 +01:00
sdhci-of-esdhc.c mmc: remove .owner field for drivers using module_platform_driver 2014-09-09 13:59:04 +02:00
sdhci-of-hlwd.c mmc: remove .owner field for drivers using module_platform_driver 2014-09-09 13:59:04 +02:00
sdhci-pci-data.c
sdhci-pci-o2micro.c mmc: sdhci-pci-o2micro: Fix Dell E5440 issue 2014-11-10 12:40:25 +01:00
sdhci-pci-o2micro.h mmc: sdhci-pci-o2micro: Add SeaBird SeaEagle SD3 support 2014-05-22 08:40:44 -04:00
sdhci-pci.c ACPI and power management updates for 3.19-rc1 2014-12-10 21:17:00 -08:00
sdhci-pci.h mmc: sdhci-pci: Add Bay Trail and Braswell SD card detect 2014-10-03 14:24:52 +02:00
sdhci-pltfm.c mmc: sdhci-pltfm: Do not use parent as the host's device 2014-09-09 13:58:58 +02:00
sdhci-pltfm.h mmc: sdhci-pltfm: export pltfm suspend/resume api 2014-01-13 12:48:06 -05:00
sdhci-pxav2.c mmc: sdhci-pxav2: Drop unused struct sdhci_pxa 2014-11-10 12:40:30 +01:00
sdhci-pxav3.c mmc: sdhci-pxav3: do the mbus window configuration after enabling clocks 2015-01-12 10:14:56 +01:00
sdhci-s3c-regs.h mmc: sdhci-s3c: remove platform dependencies 2013-04-19 13:51:23 +02:00
sdhci-s3c.c ACPI and power management updates for 3.19-rc1 2014-12-10 21:17:00 -08:00
sdhci-sirf.c mmc: don't request CD IRQ until mmc_start_host() 2014-09-23 09:01:36 +02:00
sdhci-spear.c mmc: remove .owner field for drivers using module_platform_driver 2014-09-09 13:59:04 +02:00
sdhci-st.c mmc: sdhci-st: Intial support for ST SDHCI controller 2014-07-10 09:11:18 +02:00
sdhci-tegra.c mmc: remove .owner field for drivers using module_platform_driver 2014-09-09 13:59:04 +02:00
sdhci.c mmc: sdhci: Fix sleep in atomic after inserting SD card 2015-01-12 10:14:57 +01:00
sdhci.h ACPI and power management updates for 3.19-rc1 2014-12-10 21:17:00 -08:00
sdricoh_cs.c mmc: sdricoh_cs: Move away from using deprecated APIs 2013-10-30 20:28:32 -04:00
sh_mmcif.c mmc: remove .owner field for drivers using module_platform_driver 2014-09-09 13:59:04 +02:00
sh_mobile_sdhi.c PM: Merge the SET*_RUNTIME_PM_OPS() macros 2014-12-04 00:51:30 +01:00
sunxi-mmc.c mmc: sunxi: Remove unused includes of linux/clk-private.h 2014-11-10 12:40:29 +01:00
tifm_sd.c mmc: Convert pr_warning to pr_warn 2014-09-24 10:13:09 +02:00
tmio_mmc_dma.c mmc: tmio: remove Renesas specific #ifdef 2014-09-09 13:59:15 +02:00
tmio_mmc_pio.c mmc: don't request CD IRQ until mmc_start_host() 2014-09-23 09:01:36 +02:00
tmio_mmc.c Driver core patches for 3.19-rc1 2014-12-14 16:10:09 -08:00
tmio_mmc.h mmc: tmio: Remove library functions for system PM 2014-09-09 13:59:12 +02:00
toshsd.c mmc: toshsd: move dereference below check for NULL 2014-11-26 14:31:01 +01:00
toshsd.h mmc: add Toshiba PCI SD controller driver 2014-11-26 14:30:58 +01:00
usdhi6rol0.c mmc: host: drop owner assignment from platform_drivers 2014-10-20 16:20:56 +02:00
ushc.c mmc: ushc: Fix incorrect parameter in sizeof 2014-02-25 15:42:20 -05:00
via-sdmmc.c mmc: via-sdmmc: Move away from using deprecated APIs 2013-10-30 20:28:36 -04:00
vub300.c mmc: vub300: Move away from using deprecated APIs 2013-10-30 20:26:43 -04:00
wbsd.c mmc: host: drop owner assignment from platform_drivers 2014-10-20 16:20:56 +02:00
wbsd.h
wmt-sdmmc.c mmc: host: drop owner assignment from platform_drivers 2014-10-20 16:20:56 +02:00