From patchwork Fri Aug 22 06:55:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song X-Patchwork-Id: 4761381 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 CDC1E9F383 for ; Fri, 22 Aug 2014 06:58:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DB3622018A for ; Fri, 22 Aug 2014 06:58:58 +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 E07302017A for ; Fri, 22 Aug 2014 06:58:57 +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 1XKilg-0004W5-Vv; Fri, 22 Aug 2014 06:56:12 +0000 Received: from cluster-d.mailcontrol.com ([85.115.60.190]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XKild-0004TY-3i for linux-arm-kernel@lists.infradead.org; Fri, 22 Aug 2014 06:56:10 +0000 Received: from shaapppus01.asia.root.pri ([210.13.83.99]) by rly03d.srv.mailcontrol.com (MailControl) with ESMTP id s7M6tdxu022891 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Fri, 22 Aug 2014 07:55:42 +0100 Received: from shaasiexc01.ASIA.ROOT.PRI ([10.125.12.102]) by shaapppus01.asia.root.pri (PGP Universal service); Fri, 22 Aug 2014 14:55:44 +0800 X-PGP-Universal: processed; by shaapppus01.asia.root.pri on Fri, 22 Aug 2014 14:55:44 +0800 Received: from SHAASIEXM01.ASIA.ROOT.PRI ([10.125.12.86]) by shaasiexc01.ASIA.ROOT.PRI ([10.125.12.84]) with mapi id 14.03.0158.001; Fri, 22 Aug 2014 14:55:38 +0800 From: Barry Song To: Ulf Hansson Subject: RE: [PATCH] mmc: core: sd: check card write-protect lock while resuming Thread-Topic: [PATCH] mmc: core: sd: check card write-protect lock while resuming Thread-Index: AQHPuss3ev8tsYvLjEq9DCyXzV4nrZvVu3wAgAZ5ndA= Date: Fri, 22 Aug 2014 06:55:36 +0000 Message-ID: <5EB3BFCD089AD643B9BB63439F5FD5E9012C98252C@SHAASIEXM01.ASIA.ROOT.PRI> References: <1408356012-18867-1-git-send-email-Barry.Song@csr.com> In-Reply-To: Accept-Language: en-US, zh-CN, en-GB X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.125.3.32] MIME-Version: 1.0 X-CFilter-Loop: Reflected Content-Language: en-US X-Scanned-By: MailControl 33066.168 (www.mailcontrol.com) on 10.68.0.113 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140821_235609_500348_105AD095 X-CRM114-Status: GOOD ( 22.29 ) X-Spam-Score: -0.7 (/) Cc: DL-SHA-WorkGroupLinux , linux-mmc , Chris Ball , "linux-arm-kernel@lists.infradead.org" , Minda Chen 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, 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 > -----Original Message----- > From: Ulf Hansson [mailto:ulf.hansson@linaro.org] > Sent: Monday, August 18, 2014 7:58 PM > To: Barry Song > Cc: Chris Ball; linux-mmc; linux-arm-kernel@lists.infradead.org; DL-SHA- > WorkGroupLinux; Minda Chen; Barry Song > Subject: Re: [PATCH] mmc: core: sd: check card write-protect lock while > resuming > > On 18 August 2014 12:00, Barry Song wrote: > > From: Minda Chen > > > > After suspending, unplug the sdcard, and set sd WP lock, insert it > > again, then resume the system. resume codes do not check the the > > sdcard write-proctect lock. now check it. > > > > Signed-off-by: Minda Chen > > Signed-off-by: Barry Song > > --- > > drivers/mmc/core/sd.c | 7 +++++++ > > 1 file changed, 7 insertions(+) > > > > diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index > > 0c44510..890557a 100644 > > --- a/drivers/mmc/core/sd.c > > +++ b/drivers/mmc/core/sd.c > > @@ -910,6 +910,7 @@ static int mmc_sd_init_card(struct mmc_host > *host, u32 ocr, > > int err; > > u32 cid[4]; > > u32 rocr = 0; > > + bool oldro, ro; > > > > BUG_ON(!host); > > WARN_ON(!host->claimed); > > @@ -922,6 +923,12 @@ static int mmc_sd_init_card(struct mmc_host > *host, u32 ocr, > > if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0) > > return -ENOENT; > > > > + if (host->ops->get_ro) { > > + ro = host->ops->get_ro(host) ? true : false; > > + oldro = mmc_card_readonly(oldcard) ? true : false; > > + if (oldro ^ ro) > > + return -ENOENT; > > + } > > Seems like this code belongs better in mmc_sd_setup_card(). Could you try > moving it there. [Barry Song] Well. How about: > > Kind regards > Uffe > > > card = oldcard; > > } else { > > /* -barry Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom More information can be found at www.csr.com. Keep up to date with CSR on our technical blog, www.csr.com/blog, CSR people blog, www.csr.com/people, YouTube, www.youtube.com/user/CSRplc, Facebook, www.facebook.com/pages/CSR/191038434253534, or follow us on Twitter at www.twitter.com/CSR_plc. New for 2014, you can now access the wide range of products powered by aptX at www.aptx.com. diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index 0c44510..643bc82d8 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -815,6 +815,7 @@ int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card, bool reinit) { int err; + int oldro, ro = -1; if (!reinit) { /* @@ -861,23 +862,28 @@ int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card, /* * Check if read-only switch is active. */ - if (!reinit) { - int ro = -1; - if (host->ops->get_ro) { - mmc_host_clk_hold(card->host); - ro = host->ops->get_ro(host); - mmc_host_clk_release(card->host); - } + if (host->ops->get_ro) { + mmc_host_clk_hold(card->host); + ro = host->ops->get_ro(host); + mmc_host_clk_release(card->host); + } - if (ro < 0) { - pr_warning("%s: host does not " - "support reading read-only " - "switch. assuming write-enable.\n", - mmc_hostname(host)); - } else if (ro > 0) { - mmc_card_set_readonly(card); - } + if (ro < 0) + pr_warning("%s: host does not " + "support reading read-only " + "switch. assuming write-enable.\n", + mmc_hostname(host)); + + if (!reinit && (ro > 0)) + mmc_card_set_readonly(card); + else if (reinit && (ro >= 0)) { + /* check if the write-protection lock is changed */ + oldro = mmc_card_readonly(card) ? 1 : 0; + ro = (ro > 0) ? 1 : 0; + + if (oldro ^ ro) + return -ENOENT; } return 0;