From: Adrian Hunter <adrian.hunter@nokia.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Jarkko Lavinen <jarkko.lavinen@nokia.com>,
Adrian Hunter <adrian.hunter@nokia.com>,
linux-omap Mailing List <linux-omap@vger.kernel.org>,
Pierre Ossman <pierre@ossman.eu>,
Denis Karpov <ext-denis.2.karpov@nokia.com>,
Matt Fleming <matt@console-pimps.org>,
lkml <linux-kernel@vger.kernel.org>
Subject: [PATCH V2 26/32] omap_hsmmc: prevent races with irq handler
Date: Tue, 28 Jul 2009 13:41:47 +0300 [thread overview]
Message-ID: <20090728104147.2371.8059.sendpatchset@ahunter-laptop> (raw)
In-Reply-To: <20090728103834.2371.65809.sendpatchset@ahunter-laptop>
>From 4252559187e96877a2a7ab5a5b0d0631aa51c7d2 Mon Sep 17 00:00:00 2001
From: Adrian Hunter <adrian.hunter@nokia.com>
Date: Sat, 16 May 2009 10:32:34 +0300
Subject: [PATCH] omap_hsmmc: prevent races with irq handler
If an unexpected interrupt occurs while preparing the
next request, an oops can occur.
For example, a new request is setting up DMA for data
transfer so host->data is not NULL. An unexpected
transfer complete (TC) interrupt comes along and
the interrupt handler sets host->data to NULL. Oops!
Prevent that by adding a spinlock.
Signed-off-by: Adrian Hunter <adrian.hunter@nokia.com>
---
drivers/mmc/host/omap_hsmmc.c | 25 +++++++++++++++++++++++++
1 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
index 5121277..5213d87 100644
--- a/drivers/mmc/host/omap_hsmmc.c
+++ b/drivers/mmc/host/omap_hsmmc.c
@@ -146,6 +146,8 @@ struct mmc_omap_host {
struct work_struct mmc_carddetect_work;
void __iomem *base;
resource_size_t mapbase;
+ spinlock_t irq_lock; /* Prevent races with irq handler */
+ unsigned long flags;
unsigned int id;
unsigned int dma_len;
unsigned int dma_sg_idx;
@@ -452,6 +454,14 @@ mmc_omap_start_command(struct mmc_omap_host *host, struct mmc_command *cmd,
if (host->use_dma)
cmdreg |= DMA_EN;
+ /*
+ * In an interrupt context (i.e. STOP command), the spinlock is unlocked
+ * by the interrupt handler, otherwise (i.e. for a new request) it is
+ * unlocked here.
+ */
+ if (!in_interrupt())
+ spin_unlock_irqrestore(&host->irq_lock, host->flags);
+
OMAP_HSMMC_WRITE(host->base, ARG, cmd->arg);
OMAP_HSMMC_WRITE(host->base, CMD, cmdreg);
}
@@ -614,11 +624,14 @@ static irqreturn_t mmc_omap_irq(int irq, void *dev_id)
struct mmc_data *data;
int end_cmd = 0, end_trans = 0, status;
+ spin_lock(&host->irq_lock);
+
if (host->mrq == NULL) {
OMAP_HSMMC_WRITE(host->base, STAT,
OMAP_HSMMC_READ(host->base, STAT));
/* Flush posted write */
OMAP_HSMMC_READ(host->base, STAT);
+ spin_unlock(&host->irq_lock);
return IRQ_HANDLED;
}
@@ -683,6 +696,8 @@ static irqreturn_t mmc_omap_irq(int irq, void *dev_id)
if ((end_trans || (status & TC)) && host->mrq)
mmc_omap_xfer_done(host, data);
+ spin_unlock(&host->irq_lock);
+
return IRQ_HANDLED;
}
@@ -1011,6 +1026,13 @@ static void omap_mmc_request(struct mmc_host *mmc, struct mmc_request *req)
struct mmc_omap_host *host = mmc_priv(mmc);
int err;
+ /*
+ * Prevent races with the interrupt handler because of unexpected
+ * interrupts, but not if we are already in interrupt context i.e.
+ * retries.
+ */
+ if (!in_interrupt())
+ spin_lock_irqsave(&host->irq_lock, host->flags);
WARN_ON(host->mrq != NULL);
host->mrq = req;
err = mmc_omap_prepare_data(host, req);
@@ -1019,6 +1041,8 @@ static void omap_mmc_request(struct mmc_host *mmc, struct mmc_request *req)
if (req->data)
req->data->error = err;
host->mrq = NULL;
+ if (!in_interrupt())
+ spin_unlock_irqrestore(&host->irq_lock, host->flags);
mmc_request_done(mmc, req);
return;
}
@@ -1573,6 +1597,7 @@ static int __init omap_mmc_probe(struct platform_device *pdev)
mmc->f_max = 52000000;
sema_init(&host->sem, 1);
+ spin_lock_init(&host->irq_lock);
host->iclk = clk_get(&pdev->dev, "ick");
if (IS_ERR(host->iclk)) {
--
1.5.6.3
next prev parent reply other threads:[~2009-07-28 10:42 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-28 10:38 [PATCH V2 0/32] mmc and omap_hsmmc patches Adrian Hunter
2009-07-28 10:38 ` [PATCH V2 1/32] mmc: add 'enable' and 'disable' methods to mmc host Adrian Hunter
2009-07-28 10:38 ` [PATCH V2 2/32] mmc: allow host claim / release nesting Adrian Hunter
2009-07-28 10:38 ` [PATCH V2 3/32] mmc: add MMC_CAP_NONREMOVABLE host capability Adrian Hunter
2009-07-28 10:39 ` [PATCH V2 4/32] mmc: add ability to save power by powering off cards Adrian Hunter
2009-07-30 1:05 ` Madhusudhan
2009-07-30 7:16 ` Adrian Hunter
2009-07-28 10:39 ` [PATCH V2 5/32] mmc: add mmc card sleep and awake support Adrian Hunter
2009-07-28 10:39 ` [PATCH V2 6/32] mmc: power off once at removal Adrian Hunter
2009-07-28 10:39 ` [PATCH V2 7/32] mmc: add host capabilities for SD only and MMC only Adrian Hunter
2009-07-28 10:39 ` [PATCH V2 8/32] mmc: check status after MMC SWITCH command Adrian Hunter
2009-07-28 10:39 ` [PATCH V2 9/32] omap_hsmmc: add debugfs entry (host registers) Adrian Hunter
2009-07-28 10:39 ` [PATCH V2 10/32] omap_hsmmc: make use of new enable/disable interface Adrian Hunter
2009-07-28 10:39 ` [PATCH V2 11/32] ARM: OMAP: mmc-twl4030: add context loss counter support Adrian Hunter
2009-07-28 10:40 ` [PATCH V2 12/32] omap_hsmmc: keep track of power mode Adrian Hunter
2009-07-28 10:40 ` [PATCH V2 13/32] omap_hsmmc: context save/restore support Adrian Hunter
2009-07-30 2:00 ` Madhusudhan
2009-07-30 7:40 ` Adrian Hunter
2009-07-30 19:12 ` Madhusudhan
2009-07-30 19:33 ` Adrian Hunter
2009-07-28 10:40 ` [PATCH V2 14/32] omap_hsmmc: set open drain bit correctly Adrian Hunter
2009-07-28 10:40 ` [PATCH V2 15/32] omap_hsmmc: ensure workqueues are empty before suspend Adrian Hunter
2009-07-28 10:40 ` [PATCH V2 16/32] omap_hsmmc: fix scatter-gather list sanity checking Adrian Hunter
2009-07-28 10:40 ` [PATCH V2 17/32] omap_hsmmc: make use of new MMC_CAP_NONREMOVABLE host capability Adrian Hunter
2009-07-28 10:40 ` [PATCH V2 18/32] omap_hsmmc: support for deeper power saving states Adrian Hunter
2009-07-28 10:40 ` [PATCH V2 19/32] ARM: OMAP: mmc-twl4030: add regulator sleep / wake function Adrian Hunter
2009-07-28 10:41 ` [PATCH V2 20/32] omap_hsmmc: put MMC regulator to sleep Adrian Hunter
2009-07-28 10:41 ` [PATCH V2 21/32] omap_hsmmc: add mmc card sleep and awake support Adrian Hunter
2009-07-28 10:41 ` [PATCH V2 22/32] omap_hsmmc: fix NULL pointer dereference Adrian Hunter
2009-07-28 10:41 ` [PATCH V2 23/32] omap_hsmmc: cleanup macro usage Adrian Hunter
2009-07-28 10:41 ` [PATCH V2 24/32] omap_hsmmc: clear interrupt status after init sequence Adrian Hunter
2009-07-28 10:41 ` [PATCH V2 25/32] omap_hsmmc: cater for weird CMD6 behaviour Adrian Hunter
2009-07-28 10:41 ` Adrian Hunter [this message]
2009-07-28 10:41 ` [PATCH V2 27/32] omap_hsmmc: pass host capabilities for SD only and MMC only Adrian Hunter
2009-07-28 10:42 ` [PATCH V2 28/32] omap_hsmmc: code refactoring Adrian Hunter
2009-07-28 10:42 ` [PATCH V2 29/32] omap_hsmmc: protect the card when the cover is open Adrian Hunter
2009-07-28 10:42 ` [PATCH V2 30/32] omap_hsmmc: ensure all clock enables and disables are paired Adrian Hunter
2009-07-28 10:42 ` [PATCH V2 31/32] omap_hsmmc: set a large data timeout for commands with busy signal Adrian Hunter
2009-07-28 10:42 ` [PATCH V2 32/32] ARM: OMAP: RX51: set MMC capabilities and power-saving flag Adrian Hunter
2009-07-29 11:13 ` [PATCH V2 0/32] mmc and omap_hsmmc patches Matt Fleming
2009-07-31 0:52 ` Madhusudhan
2009-08-13 15:27 ` Madhusudhan
2009-08-13 16:29 ` Andrew Morton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090728104147.2371.8059.sendpatchset@ahunter-laptop \
--to=adrian.hunter@nokia.com \
--cc=akpm@linux-foundation.org \
--cc=ext-denis.2.karpov@nokia.com \
--cc=jarkko.lavinen@nokia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=matt@console-pimps.org \
--cc=pierre@ossman.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox