linux/drivers/mmc/host
Krzysztof Kozlowski b36cd20d35 mmc: sdhci: Fix sleep in atomic after inserting SD card
commit 2836766a9d upstream.

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")
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-01-16 06:59:34 -08:00
..
Kconfig MMC highlights for 3.14: 2014-01-26 11:00:41 -08:00
Makefile mmc: arasan: Add driver for Arasan SDHCI 2014-01-13 12:48:34 -05: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: add vmmc-supply support 2014-01-13 13:03:40 -05:00
au1xmmc.c mmc: au1xmmc: Move away from using deprecated APIs 2013-10-30 20:26:35 -04: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: davinci_mmc: Move away from using deprecated APIs 2013-10-30 20:26:38 -04:00
dw_mmc-exynos.c mmc: dw_mmc: exynos: Revert the sdr_timing assignment 2013-11-08 14:27:39 -05:00
dw_mmc-k3.c mmc: dw_mmc: k3: remove clk_table 2014-01-17 17:59:17 -05:00
dw_mmc-pci.c mmc: dw_mmc-pci: enable bus-mastering mode 2013-08-25 00:10:12 -04:00
dw_mmc-pltfm.c mmc: dw_mmc: move the platform specific init call 2013-09-25 21:32:40 -04:00
dw_mmc-pltfm.h mmc: remove use of __devexit 2012-11-28 12:28:18 -08:00
dw_mmc-socfpga.c mmc: dw_mmc-socfpga: Staticize dw_mci_socfpga_probe 2013-09-25 21:57:35 -04:00
dw_mmc.c mmc: dw_mmc: avoid write to CDTHRCTL on older versions 2015-01-08 10:00:48 -08:00
dw_mmc.h mmc: dw_mmc: control card read threshold 2013-09-25 21:34:39 -04:00
jz4740_mmc.c mmc: jz4740: Move away from using deprecated APIs 2013-10-30 20:26:40 -04:00
mmc_spi.c mmc: mmc_spi: Remove platform data .get_cd() and .get_ro() callbacks 2013-08-24 23:58:06 -04:00
mmci.c ARM: 7906/1: mmc: mmci: Remove unnecessary amba_set_drvdata() 2013-12-29 12:32:36 +00:00
mmci.h ARM: 7831/1: mmc: mmci: Adapt to new pinctrl handling 2013-09-19 20:12:23 +01:00
msm_sdcc.c mmc: msm_sdcc: Move away from using deprecated APIs 2013-10-30 20:26:41 -04:00
msm_sdcc.h
mvsdio.c MMC highlights for 3.13: 2013-11-18 14:47:30 -08:00
mvsdio.h
mxcmmc.c mmc: mxcmmc: Move away from using deprecated APIs 2013-10-30 20:28:26 -04:00
mxs-mmc.c mmc: mxs: use mmc_of_parse to parse devicetree properties 2014-01-13 12:48:21 -05:00
of_mmc_spi.c mmc: mmc_spi: Support CD/RO GPIOs 2013-08-24 23:45:22 -04:00
omap.c mmc: omap: Fix I2C dependency and make driver usable with device tree 2013-11-26 15:51:16 -08:00
omap_hsmmc.c mmc: omap: Remove redundant suspend and resume callbacks 2013-10-30 20:28:24 -04:00
pxamci.c mmc: pxamci: Remove redundant suspend and resume callbacks 2013-10-30 20:28:29 -04:00
pxamci.h
rtsx_pci_sdmmc.c mmc: rtsx_pci_sdmmc: fix incorrect last byte in R2 response 2014-11-14 08:59:46 -08:00
s3cmci.c ARM: s3c24xx: explicit dependency on <plat/gpio-cfg.h> 2014-01-14 15:24:54 +01:00
s3cmci.h
sdhci-acpi.c MMC highlights for 3.14: 2014-01-26 11:00:41 -08:00
sdhci-bcm-kona.c mmc: sdhci-bcm-kona: fix build errors when built-in 2014-05-13 13:32:56 +02:00
sdhci-bcm2835.c mmc: sdhci-bcm2835: Use sdhci_pltfm_unregister instead of open coded 2013-09-25 22:05:57 -04:00
sdhci-cns3xxx.c mmc: sdhci: Add size for caller in init+register 2013-05-31 11:59:29 -04:00
sdhci-dove.c mmc: sdhci: Add size for caller in init+register 2013-05-31 11:59:29 -04:00
sdhci-esdhc-imx.c mmc: sdhci-esdhc-imx: fix warning during module remove function 2014-01-13 14:02:39 -05:00
sdhci-esdhc.h mmc: sdhci-esdhc: move common esdhc_set_clock to platform driver 2013-09-26 07:57:12 -04:00
sdhci-of-arasan.c mmc: arasan: Add driver for Arasan SDHCI 2014-01-13 12:48:34 -05:00
sdhci-of-esdhc.c mmc: sdhci-esdhc-imx: set actual_clock in clock setting 2013-09-27 10:31:48 -04:00
sdhci-of-hlwd.c mmc: sdhci: Add size for caller in init+register 2013-05-31 11:59:29 -04:00
sdhci-pci-data.c
sdhci-pci-o2micro.c mmc: sdhci-pci-o2micro: Fix Dell E5440 issue 2015-01-08 10:00:48 -08:00
sdhci-pci-o2micro.h mmc: sdhci-pci: add support of O2Micro/BayHubTech SD hosts 2014-01-13 12:48:32 -05:00
sdhci-pci.c mmc: sdhci-pci: SDIO host controller support for Intel Quark X1000 2014-11-14 09:00:00 -08:00
sdhci-pci.h mmc: sdhci-pci: SDIO host controller support for Intel Quark X1000 2014-11-14 09:00:00 -08:00
sdhci-pltfm.c mmc: sdhci-pltfm: export pltfm suspend/resume api 2014-01-13 12:48:06 -05: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: Add size for caller in init+register 2013-05-31 11:59:29 -04:00
sdhci-pxav3.c mmc: slot-gpio: Add debouncing capability to mmc_gpio_request_cd() 2013-08-24 23:45:09 -04:00
sdhci-s3c-regs.h mmc: sdhci-s3c: remove platform dependencies 2013-04-19 13:51:23 +02:00
sdhci-s3c.c mmc: sdhci-s3c: initialize host->quirks2 for using quirks2 2013-08-29 21:19:13 -04:00
sdhci-sirf.c mmc: slot-gpio: Add debouncing capability to mmc_gpio_request_cd() 2013-08-24 23:45:09 -04:00
sdhci-spear.c mmc: remove unnecessary platform_set_drvdata() 2013-05-26 14:23:23 -04:00
sdhci-tegra.c mmc: tegra: add support for Tegra124 2014-01-13 12:48:27 -05:00
sdhci.c mmc: sdhci: Fix sleep in atomic after inserting SD card 2015-01-16 06:59:34 -08:00
sdhci.h mmc: sdhci: allow platform access of sdhci_send_command 2013-09-26 07:53:39 -04: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: sh_mmcif: Fix compilation warning on 64-bit platforms 2014-01-13 12:48:26 -05:00
sh_mobile_sdhi.c mmc: SDHI: add SoC specific workaround via HW version 2014-01-13 12:48:24 -05:00
tifm_sd.c mmc: tifm_sd: Move away from using deprecated APIs 2013-10-30 20:28:23 -04:00
tmio_mmc.c mmc: tmio: fixup compile error 2014-01-13 12:48:30 -05:00
tmio_mmc.h mmc: tmio: bus_shift become tmio_mmc_data member 2014-01-13 12:48:23 -05:00
tmio_mmc_dma.c mmc: tmio: bus_shift become tmio_mmc_data member 2014-01-13 12:48:23 -05:00
tmio_mmc_pio.c mmc: tmio: add new TMIO_MMC_HAVE_HIGH_REG flags 2014-01-13 12:48:24 -05:00
ushc.c
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: wbsd: Silence compiler warning 2013-11-08 14:32:03 -05:00
wbsd.h
wmt-sdmmc.c mmc: wmt-sdmmc: Move away from using deprecated APIs 2013-10-30 20:28:27 -04:00