From patchwork Tue Jan 3 10:33:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 6030 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id DD20C23E0E for ; Tue, 3 Jan 2012 10:34:18 +0000 (UTC) Received: from mail-ey0-f180.google.com (mail-ey0-f180.google.com [209.85.215.180]) by fiordland.canonical.com (Postfix) with ESMTP id BAE91A18016 for ; Tue, 3 Jan 2012 10:34:18 +0000 (UTC) Received: by eaac11 with SMTP id c11so15441021eaa.11 for ; Tue, 03 Jan 2012 02:34:18 -0800 (PST) Received: by 10.205.120.11 with SMTP id fw11mr6187993bkc.89.1325586858472; Tue, 03 Jan 2012 02:34:18 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.205.82.144 with SMTP id ac16cs335247bkc; Tue, 3 Jan 2012 02:34:18 -0800 (PST) Received: by 10.213.28.83 with SMTP id l19mr5634727ebc.50.1325586856692; Tue, 03 Jan 2012 02:34:16 -0800 (PST) Received: from eu1sys200aog107.obsmtp.com (eu1sys200aog107.obsmtp.com. [207.126.144.123]) by mx.google.com with SMTP id p3si21495223eef.197.2012.01.03.02.34.13 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 03 Jan 2012 02:34:16 -0800 (PST) Received-SPF: neutral (google.com: 207.126.144.123 is neither permitted nor denied by best guess record for domain of ulf.hansson@stericsson.com) client-ip=207.126.144.123; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.123 is neither permitted nor denied by best guess record for domain of ulf.hansson@stericsson.com) smtp.mail=ulf.hansson@stericsson.com Received: from beta.dmz-us.st.com ([167.4.1.35]) (using TLSv1) by eu1sys200aob107.postini.com ([207.126.147.11]) with SMTP ID DSNKTwLZlealrKIfRphf0nwsvUwZFU5svrit@postini.com; Tue, 03 Jan 2012 10:34:16 UTC Received: from zeta.dmz-us.st.com (ns4.st.com [167.4.16.71]) by beta.dmz-us.st.com (STMicroelectronics) with ESMTP id B68CB4E; Tue, 3 Jan 2012 10:33:19 +0000 (GMT) Received: from relay2.stm.gmessaging.net (unknown [10.230.100.18]) by zeta.dmz-us.st.com (STMicroelectronics) with ESMTP id 27B5B49; Tue, 3 Jan 2012 09:50:02 +0000 (GMT) Received: from exdcvycastm003.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm003", Issuer "exdcvycastm003" (not verified)) by relay2.stm.gmessaging.net (Postfix) with ESMTPS id E032FA8094; Tue, 3 Jan 2012 11:33:19 +0100 (CET) Received: from localhost.localdomain (10.230.100.153) by smtp.stericsson.com (10.230.100.1) with Microsoft SMTP Server (TLS) id 8.3.83.0; Tue, 3 Jan 2012 11:33:23 +0100 From: Ulf Hansson To: , Chris Ball Cc: Adrian Hunter , Per Forlin , Ulf Hansson , Johan Rudholm , Lee Jones Subject: [PATCH] mmc: core: Force a "detect" to handle non-properly removed cards Date: Tue, 3 Jan 2012 11:33:18 +0100 Message-ID: <1325586798-16276-1-git-send-email-ulf.hansson@stericsson.com> X-Mailer: git-send-email 1.7.5.4 MIME-Version: 1.0 Removing a card "slowly" can trigger a GPIO irq to be raised far before the card is actually removed. This means the scheduled detect work will not find out that the card were removed and thus the card and the block device will not be unregistered. Let the mmc_detect_card_removed function trigger a new detect work immediately when it discovers that a card has been removed. This will solve the described issue above. Moreover we make sure the detect work is executed as soon as possible, since there is no reason for waiting for a "delayed" detect to happen. Signed-off-by: Ulf Hansson --- drivers/mmc/core/core.c | 24 +++++++++++++----------- include/linux/mmc/host.h | 1 - 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 4770807..7bc02f4 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -1462,7 +1462,6 @@ void mmc_detect_change(struct mmc_host *host, unsigned long delay) WARN_ON(host->removed); spin_unlock_irqrestore(&host->lock, flags); #endif - host->detect_change = 1; mmc_schedule_delayed_work(&host->detect, delay); } @@ -2077,18 +2076,23 @@ int _mmc_detect_card_removed(struct mmc_host *host) int mmc_detect_card_removed(struct mmc_host *host) { struct mmc_card *card = host->card; + int ret = 1; WARN_ON(!host->claimed); - /* - * The card will be considered unchanged unless we have been asked to - * detect a change or host requires polling to provide card detection. - */ - if (card && !host->detect_change && !(host->caps & MMC_CAP_NEEDS_POLL)) - return mmc_card_removed(card); - host->detect_change = 0; + if (card && !mmc_card_removed(card)) { + if (_mmc_detect_card_removed(host)) { + /* + * Make sure a detect work is always executed and also + * do it as soon as possible. + */ + cancel_delayed_work(&host->detect); + mmc_detect_change(host, 0); + } + ret = mmc_card_removed(card); + } - return _mmc_detect_card_removed(host); + return ret; } EXPORT_SYMBOL(mmc_detect_card_removed); @@ -2112,8 +2116,6 @@ void mmc_rescan(struct work_struct *work) && !(host->caps & MMC_CAP_NONREMOVABLE)) host->bus_ops->detect(host); - host->detect_change = 0; - /* * Let mmc_bus_put() free the bus/bus_ops if we've found that * the card is no longer present. diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index 031d865..09fa5e6 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -305,7 +305,6 @@ struct mmc_host { int claim_cnt; /* "claim" nesting count */ struct delayed_work detect; - int detect_change; /* card detect flag */ struct mmc_hotplug hotplug; const struct mmc_bus_ops *bus_ops; /* current bus driver */