From patchwork Thu Mar 1 15:44:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 7036 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 3DAF123EA8 for ; Thu, 1 Mar 2012 15:44:56 +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 080F9A18360 for ; Thu, 1 Mar 2012 15:44:55 +0000 (UTC) Received: by gglu1 with SMTP id u1so315179ggl.11 for ; Thu, 01 Mar 2012 07:44:55 -0800 (PST) Received: from mr.google.com ([10.50.89.201]) by 10.50.89.201 with SMTP id bq9mr4858520igb.55.1330616695395 (num_hops = 1); Thu, 01 Mar 2012 07:44:55 -0800 (PST) Received: by 10.50.89.201 with SMTP id bq9mr4009413igb.55.1330616695342; Thu, 01 Mar 2012 07:44:55 -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 k18csp20967ibg; Thu, 1 Mar 2012 07:44:54 -0800 (PST) Received: by 10.213.13.205 with SMTP id d13mr315396eba.149.1330616693659; Thu, 01 Mar 2012 07:44:53 -0800 (PST) Received: from eu1sys200aog116.obsmtp.com (eu1sys200aog116.obsmtp.com. [207.126.144.141]) by mx.google.com with SMTP id u15si2193022eeb.192.2012.03.01.07.44.50 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 01 Mar 2012 07:44:53 -0800 (PST) Received-SPF: neutral (google.com: 207.126.144.141 is neither permitted nor denied by best guess record for domain of ulf.hansson@stericsson.com) client-ip=207.126.144.141; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.141 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 eu1sys200aob116.postini.com ([207.126.147.11]) with SMTP ID DSNKT0+ZZsPZrx1Yydq58q5w0hnLpZYNKTYP@postini.com; Thu, 01 Mar 2012 15:44:53 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 465F066; Thu, 1 Mar 2012 15:44:22 +0000 (GMT) Received: from relay1.stm.gmessaging.net (unknown [10.230.100.17]) by zeta.dmz-us.st.com (STMicroelectronics) with ESMTP id BAB4245; Thu, 1 Mar 2012 14:16:05 +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 relay1.stm.gmessaging.net (Postfix) with ESMTPS id 963E924C075; Thu, 1 Mar 2012 16:44:26 +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; Thu, 1 Mar 2012 16:44:34 +0100 From: Ulf Hansson To: , Chris Ball Cc: Per Forlin , Ulf Hansson , Johan Rudholm , Lee Jones Subject: [PATCH] mmc: core: Clean up after mmc_pre_req if card was removed Date: Thu, 1 Mar 2012 16:44:31 +0100 Message-ID: <1330616671-11952-1-git-send-email-ulf.hansson@stericsson.com> X-Mailer: git-send-email 1.7.9 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQnit2fFQQVNWbtXlB00pyzdSGbs8aGTly447m/AaN9GKITBxtDWgH8QADjPDmaFIV5SJETM 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 --- 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 0b317f0..9e562ab 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: + if (err || start_err) { + if (areq) + /* The prepared request was not started, cancel it. */ + mmc_post_req(host, areq->mrq, -EINVAL); + host->areq = NULL; + } else { + host->areq = areq; + } + if (error) *error = err; return data;