From patchwork Tue Sep 2 23:37:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 4829361 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5B0F69F2ED for ; Tue, 2 Sep 2014 23:41:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 55784201ED for ; Tue, 2 Sep 2014 23:41:43 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 660FE201E4 for ; Tue, 2 Sep 2014 23:41:42 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XOxe5-0007vo-Nh; Tue, 02 Sep 2014 23:37:53 +0000 Received: from mail-pa0-x231.google.com ([2607:f8b0:400e:c03::231]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XOxe2-0007sk-MS for linux-arm-kernel@lists.infradead.org; Tue, 02 Sep 2014 23:37:51 +0000 Received: by mail-pa0-f49.google.com with SMTP id kq14so15616378pab.8 for ; Tue, 02 Sep 2014 16:37:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=p91ykb4hPBw1ZKMJyGn72HpUzsPuIs40S837ClAJdzw=; b=K13Lry3N+2tFJjqZ151QWuuWok9zLRNwFavD29WjdtDUU8WXylLacsxFOhL02/Yuwm u5lcpYUj7nHcWG7xiDi7EEN84duc4GWLMX7FFEn9/Cu6yV1tXZhYoVPS7gCvyYh7Peeq vVXTxWLg5OMaBNpB1b6mtzin2MkGNQZVPRhGI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=p91ykb4hPBw1ZKMJyGn72HpUzsPuIs40S837ClAJdzw=; b=QE8EIfMWsADHBam9pC2A3ND74i3TgilzZvFp6Y+dxO53UUXEGoVU1qlrxD220ZahWD MdpXLOOBxLBqr5N+Xuwd3QW6Ctg/Pqtg4Yij7S4ekhR17ep8hm7jIBO9XNWkVicosxbl RbW9rxXJXtY9GOtEVs2dvfzC5AutVEsT11OSZV1NLlEFXaT0y1GULdb87f6q9C+T5B9o rUV/fGxVCYOcW2gr5DKT6u4+uolIM9NO3P9Je7305HwLo8hHrJ38dtOM1JwfST8rNL7i xfwlfoHaGR56V2vdbHinQvufk4SxAXhAD8+riUFN/zGYj3+Q4fYiPpgRf+d+M4KvHJxO 1bPg== X-Gm-Message-State: ALoCoQnglt2V5mSOGrt3yj79HDWg91WTogw/fnFZ5uRRGPT2p5J98t3eiBRFyvXKRausa9aHd6eL X-Received: by 10.70.131.101 with SMTP id ol5mr40272019pdb.77.1409701049176; Tue, 02 Sep 2014 16:37:29 -0700 (PDT) Received: from tictac.mtv.corp.google.com (tictac.mtv.corp.google.com [172.22.162.15]) by mx.google.com with ESMTPSA id pm1sm7013628pdb.58.2014.09.02.16.37.27 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 02 Sep 2014 16:37:28 -0700 (PDT) From: Doug Anderson To: Seungwon Jeon , Jaehoon Chung , Ulf Hansson Subject: [PATCH] mmc: dw_mmc: Don't enable interrupts until we're ready Date: Tue, 2 Sep 2014 16:37:14 -0700 Message-Id: <1409701034-28526-1-git-send-email-dianders@chromium.org> X-Mailer: git-send-email 2.1.0.rc2.206.gedb03e5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140902_163750_785151_497D434C X-CRM114-Status: GOOD ( 15.40 ) X-Spam-Score: -0.8 (/) Cc: Addy Ke , linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, Doug Anderson , chris@printf.net, Sonny Rao , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On dw_mmc there's a small race if you happen to get a card detect interrupt at just the wrong time during probe. You may have enabled the interrupt but host->slot[0] may be NULL. Fix the race by enabling interrupts all the way at the end of the probe. We can also use free_irq() instead of dw_mmc specific masking to mask the IRQ at removal time. Note that since we're now managing freeing of the irq ourselves, there's no need to use devm. FYI, the crash would look like: dwmmc_rockchip ff0c0000.dwmmc: DW MMC controller at irq 64, 32 bit host data width, 256 deep fifo Unable to handle kernel NULL pointer dereference at virtual address 00000000 pgd = c0004000 [00000000] *pgd=00000000 ... ... [] (dw_mci_work_routine_card) from [] (process_one_work+0x260/0x3c4) [] (process_one_work) from [] (worker_thread+0x240/0x3a8) [] (worker_thread) from [] (kthread+0x100/0x118) [] (kthread) from [] (ret_from_fork+0x14/0x20) Signed-off-by: Doug Anderson --- FYI: making dw_mmc into a module and trying module removal was not tested. I'd appreciate any testing that folks can do there. This code should be the equivalent and makes the error case of probe match the removal case more closely now. drivers/mmc/host/dw_mmc.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index 7f227e9..540ba3c 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -2577,10 +2577,6 @@ int dw_mci_probe(struct dw_mci *host) goto err_dmaunmap; } INIT_WORK(&host->card_work, dw_mci_work_routine_card); - ret = devm_request_irq(host->dev, host->irq, dw_mci_interrupt, - host->irq_flags, "dw-mci", host); - if (ret) - goto err_workqueue; if (host->pdata->num_slots) host->num_slots = host->pdata->num_slots; @@ -2619,11 +2615,21 @@ int dw_mci_probe(struct dw_mci *host) goto err_workqueue; } + ret = request_irq(host->irq, dw_mci_interrupt, host->irq_flags, + "dw-mci", host); + if (ret) + goto err_initted; + if (host->quirks & DW_MCI_QUIRK_IDMAC_DTO) dev_info(host->dev, "Internal DMAC interrupt fix enabled.\n"); return 0; +err_initted: + for (i = 0; i < host->num_slots; i++) + if (host->slot[i]) + dw_mci_cleanup_slot(host->slot[i], i); + err_workqueue: destroy_workqueue(host->card_workqueue); @@ -2649,8 +2655,7 @@ void dw_mci_remove(struct dw_mci *host) { int i; - mci_writel(host, RINTSTS, 0xFFFFFFFF); - mci_writel(host, INTMASK, 0); /* disable all mmc interrupt first */ + free_irq(host->irq, host); for (i = 0; i < host->num_slots; i++) { dev_dbg(host->dev, "remove slot %d\n", i);