From patchwork Mon Mar 5 14:52:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 7086 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 BFECA23DE1 for ; Mon, 5 Mar 2012 14:53:06 +0000 (UTC) Received: from mail-gx0-f180.google.com (mail-gx0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id 8ABA6A1813E for ; Mon, 5 Mar 2012 14:53:06 +0000 (UTC) Received: by gglu1 with SMTP id u1so1883047ggl.11 for ; Mon, 05 Mar 2012 06:53:06 -0800 (PST) Received: by 10.50.158.133 with SMTP id wu5mr5787803igb.50.1330959185964; Mon, 05 Mar 2012 06:53:05 -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.231.53.18 with SMTP id k18csp27683ibg; Mon, 5 Mar 2012 06:53:05 -0800 (PST) Received: by 10.14.47.130 with SMTP id t2mr8693775eeb.100.1330959184176; Mon, 05 Mar 2012 06:53:04 -0800 (PST) Received: from eu1sys200aog103.obsmtp.com (eu1sys200aog103.obsmtp.com. [207.126.144.115]) by mx.google.com with SMTP id x55si12995900eea.113.2012.03.05.06.53.00 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 05 Mar 2012 06:53:04 -0800 (PST) Received-SPF: neutral (google.com: 207.126.144.115 is neither permitted nor denied by best guess record for domain of ulf.hansson@stericsson.com) client-ip=207.126.144.115; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.115 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-eu.st.com ([164.129.1.35]) (using TLSv1) by eu1sys200aob103.postini.com ([207.126.147.11]) with SMTP ID DSNKT1TTQQAT8A4E9u5JN1AuEKUS9fW9ykub@postini.com; Mon, 05 Mar 2012 14:53:03 UTC Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 73D2911E; Mon, 5 Mar 2012 14:52:48 +0000 (GMT) Received: from relay2.stm.gmessaging.net (unknown [10.230.100.18]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id F1A732512; Mon, 5 Mar 2012 14:52:47 +0000 (GMT) Received: from exdcvycastm004.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm004", Issuer "exdcvycastm004" (not verified)) by relay2.stm.gmessaging.net (Postfix) with ESMTPS id 129C2A8072; Mon, 5 Mar 2012 15:52:42 +0100 (CET) Received: from steludxu4020.lud.stericsson.com (10.230.100.153) by smtp.stericsson.com (10.230.100.2) with Microsoft SMTP Server (TLS) id 8.3.83.0; Mon, 5 Mar 2012 15:52:47 +0100 From: Ulf Hansson To: , Chris Ball Cc: Per Forlin , Ulf Hansson , Johan Rudholm , Lee Jones Subject: [PATCH V2] mmc: core: Clean up after mmc_pre_req if card was removed Date: Mon, 5 Mar 2012 15:52:43 +0100 Message-ID: <1330959163-21796-1-git-send-email-ulf.hansson@stericsson.com> X-Mailer: git-send-email 1.7.9 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQlfi1s9aP7p+qKmlNXtSXUN7lT0r4nOo/eLxsfAOw8uBs20g/gCSlNDmECkdJgXSjArwnTr Make sure mmc_start_req cancel the prepared job, if the request was prevented to be started due to the card has been removed. This bug was introduced in commit: mmc: allow upper layers to know immediately if card has been removed Signed-off-by: Ulf Hansson Reviewed-by: Per Forlin --- Changes in v2: - Maintain handling of host->areq (host->areq must not be NULL when "start_err"), to make sure the block layer is able to respond to all of the started requests. --- drivers/mmc/core/core.c | 35 +++++++++++++++-------------------- 1 files changed, 15 insertions(+), 20 deletions(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index faa0af1..56b7a24 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -249,16 +249,17 @@ static void mmc_wait_done(struct mmc_request *mrq) complete(&mrq->completion); } -static void __mmc_start_req(struct mmc_host *host, struct mmc_request *mrq) +static int __mmc_start_req(struct mmc_host *host, struct mmc_request *mrq) { init_completion(&mrq->completion); mrq->done = mmc_wait_done; if (mmc_card_removed(host->card)) { mrq->cmd->error = -ENOMEDIUM; complete(&mrq->completion); - return; + return -ENOMEDIUM; } mmc_start_request(host, mrq); + return 0; } static void mmc_wait_for_req_done(struct mmc_host *host, @@ -342,6 +343,7 @@ struct mmc_async_req *mmc_start_req(struct mmc_host *host, struct mmc_async_req *areq, int *error) { int err = 0; + int start_err = 0; struct mmc_async_req *data = host->areq; /* Prepare a new request */ @@ -351,30 +353,23 @@ struct mmc_async_req *mmc_start_req(struct mmc_host *host, if (host->areq) { mmc_wait_for_req_done(host, host->areq->mrq); err = host->areq->err_check(host->card, host->areq); - if (err) { - /* post process the completed failed request */ - mmc_post_req(host, host->areq->mrq, 0); - if (areq) - /* - * Cancel the new prepared request, because - * it can't run until the failed - * request has been properly handled. - */ - mmc_post_req(host, areq->mrq, -EINVAL); - - host->areq = NULL; - goto out; - } } - if (areq) - __mmc_start_req(host, areq->mrq); + if (!err && areq) + start_err = __mmc_start_req(host, areq->mrq); if (host->areq) mmc_post_req(host, host->areq->mrq, 0); - host->areq = areq; - out: + /* Cancel a prepared request if it was not started. */ + if ((err || start_err) && areq) + mmc_post_req(host, areq->mrq, -EINVAL); + + if (err) + host->areq = NULL; + else + host->areq = areq; + if (error) *error = err; return data;