[lkml]   [2014]   [Mar]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
SubjectRe: [PATCH] mmc: sdhci-bcm-kona: Fix locking in sdhci_bcm_kona_sd_card_emulate()
On Wed, Mar 5, 2014 at 8:25 PM, Markus Mayer <> wrote:
> Since sdhci_bcm_kona_sd_card_emulate() can be called from interrupt
> context, we must use a spinlock instead of a mutex. This change
> essentially restores the way things worked before the change to
> mutexes in
> Without this change, we see "scheduling while atomic" errors.
> Signed-off-by: Markus Mayer <>
> ---

So digging back in memory (since I no longer have the
broadcom-internal email threads on this topic), I think I recall what
the problem is. card_event is being called directly from
mmc_gpio_cd_irqt, which is atomic context. My plan for this was to
delay the card_event callback into the mmc_rescan worker, as that
would have 2 nice results: remove the callback from atomic context
which it doesn't need to be in, and put it in line with the debounced
rescan (which I think it should be). I made mention of that option in
this thread ( but seems I never
followed up with code...
Something along the lines of the (untested) code below might do the trick:

diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 098374b..d4ffba8 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -2421,6 +2421,11 @@ void mmc_rescan(struct work_struct *work)
container_of(work, struct mmc_host,;
int i;

+ if (host->trigger_card_event && host->ops->card_event) {
+ host->ops->card_event(host);
+ host->trigger_card_event = 0;
+ }
if (host->rescan_disable)

diff --git a/drivers/mmc/core/slot-gpio.c b/drivers/mmc/core/slot-gpio.c
index 46596b71..fc648ae 100644
--- a/drivers/mmc/core/slot-gpio.c
+++ b/drivers/mmc/core/slot-gpio.c
@@ -29,9 +29,7 @@ static irqreturn_t mmc_gpio_cd_irqt(int irq, void *dev_id)
/* Schedule a card detection after a debounce timeout */
struct mmc_host *host = dev_id;

- if (host->ops->card_event)
- host->ops->card_event(host);
+ host->trigger_card_event = 1;
mmc_detect_change(host, msecs_to_jiffies(200));

diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index 99f5709..0b6bddf 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -322,6 +322,8 @@ struct mmc_host {
int rescan_disable; /* disable card detection */
int rescan_entered; /* used with nonremovable devices */

+ int trigger_card_event; /* card_event necessary */
struct mmc_card *card; /* device attached to this host */

wait_queue_head_t wq;

Of course there are (a few) more users of card_event callback than
bcm_kona that need to be confirmed ok such a change

 \ /
  Last update: 2014-03-19 09:41    [W:0.030 / U:6.824 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site