From patchwork Wed Jan 15 10:07:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangfei Gao X-Patchwork-Id: 3491091 Return-Path: X-Original-To: patchwork-linux-mmc@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 41B079F381 for ; Wed, 15 Jan 2014 10:10:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 343D0201C8 for ; Wed, 15 Jan 2014 10:10:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5FBAB201C7 for ; Wed, 15 Jan 2014 10:10:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751789AbaAOKKR (ORCPT ); Wed, 15 Jan 2014 05:10:17 -0500 Received: from mail-pd0-f175.google.com ([209.85.192.175]:51646 "EHLO mail-pd0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751511AbaAOKKO (ORCPT ); Wed, 15 Jan 2014 05:10:14 -0500 Received: by mail-pd0-f175.google.com with SMTP id r10so915920pdi.20 for ; Wed, 15 Jan 2014 02:10:12 -0800 (PST) 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:in-reply-to :references; bh=1S4PNcbihPCUE4hHYqYy0CydYRiOXgNbFXE9hHkpIb4=; b=OVdi0SEhqk170+EPZGQxh0vyJUApCvtg7zR+QwvE71yRXIlt6UfPoXeFh+DkgTVjrl mVjOaUmqVhtqIIFnB/ZIA8EM5xayY8AtPJN+tJboDJh4aYKGuC6532VSnY3zM5UmLFMa FRTSUjROdTvpQIG79UCo1snTkZpPqi2qE52EGY7AoWDdj5Dh9TvMLZBJ72c30rabVPc2 NwLXEXpAWlBeb5wealxs4nW3sICAyBMDdbU3K0zYe7mYj5pQdCQtoNNhulRA0a06zWU1 I/M1qS7FTM9rXbTK13ul196sJ5SmfU1aEgk+5rP9XNY83v3UqGh0NRhK8R7uFkuUS0Wn M4+A== X-Gm-Message-State: ALoCoQntaEj/Zd0StcqbRXgWzNbVlpPK4rMpf7/nsdP3gXbhjpssVhLcPZWQoOOrY2kRtSgmYqgS X-Received: by 10.68.191.130 with SMTP id gy2mr1527164pbc.129.1389780611502; Wed, 15 Jan 2014 02:10:11 -0800 (PST) Received: from localhost.localdomain ([124.73.90.72]) by mx.google.com with ESMTPSA id iq10sm7023059pbc.14.2014.01.15.02.10.01 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 15 Jan 2014 02:10:10 -0800 (PST) From: Zhangfei Gao To: Kevin Hilman , Sachin Kamat , Chris Ball , Arnd Bergmann , Mike Turquette , Jaehoon Chung , Seungwon Jeon Cc: linux-mmc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, patches@linaro.org, Zhangfei Gao Subject: [PATCH] mmc: dw_mmc: fix dw_mci_get_cd Date: Wed, 15 Jan 2014 18:07:49 +0800 Message-Id: <1389780469-32633-1-git-send-email-zhangfei.gao@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1389770159-21125-1-git-send-email-zhangfei.gao@linaro.org> References: <1389770159-21125-1-git-send-email-zhangfei.gao@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 Introduced from commit bf626e5550f24aec24975a0e85ad8e572ca76a6b CDETECT is ignored since negated return value of mmc_gpio_get_cd(mmc) can not be checked by IS_ERR_VALUE. Add spin_lock_bh(&host->lock) for atomic accessing DW_MMC_CARD_PRESENT, otherwise sd detect may occasionally fail. Signed-off-by: Zhangfei Gao Reported-by: Kevin Hilman Reviewed-by: Sachin Kamat Tested-by: Sachin Kamat --- drivers/mmc/host/dw_mmc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index a776f24f4311..9ded62c8225e 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -1033,7 +1033,8 @@ static int dw_mci_get_cd(struct mmc_host *mmc) int present; struct dw_mci_slot *slot = mmc_priv(mmc); struct dw_mci_board *brd = slot->host->pdata; - int gpio_cd = !mmc_gpio_get_cd(mmc); + struct dw_mci *host = slot->host; + int gpio_cd = mmc_gpio_get_cd(mmc); /* Use platform get_cd function, else try onboard card detect */ if (brd->quirks & DW_MCI_QUIRK_BROKEN_CARD_DETECTION) @@ -1041,11 +1042,12 @@ static int dw_mci_get_cd(struct mmc_host *mmc) else if (brd->get_cd) present = !brd->get_cd(slot->id); else if (!IS_ERR_VALUE(gpio_cd)) - present = !!gpio_cd; + present = !gpio_cd; else present = (mci_readl(slot->host, CDETECT) & (1 << slot->id)) == 0 ? 1 : 0; + spin_lock_bh(&host->lock); if (present) { set_bit(DW_MMC_CARD_PRESENT, &slot->flags); dev_dbg(&mmc->class_dev, "card is present\n"); @@ -1053,6 +1055,7 @@ static int dw_mci_get_cd(struct mmc_host *mmc) clear_bit(DW_MMC_CARD_PRESENT, &slot->flags); dev_dbg(&mmc->class_dev, "card is not present\n"); } + spin_unlock_bh(&host->lock); return present; } @@ -2081,7 +2084,7 @@ static int dw_mci_of_get_wp_gpio(struct device *dev, u8 slot) return gpio; } -/* find the cd gpio for a given slot; or -1 if none specified */ +/* find the cd gpio for a given slot */ static void dw_mci_of_get_cd_gpio(struct device *dev, u8 slot, struct mmc_host *mmc) {