From patchwork Tue Jul 26 11:27:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 72796 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1634138qga; Tue, 26 Jul 2016 04:28:04 -0700 (PDT) X-Received: by 10.66.154.232 with SMTP id vr8mr38262993pab.104.1469532484845; Tue, 26 Jul 2016 04:28:04 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ef8si298965pac.240.2016.07.26.04.28.01; Tue, 26 Jul 2016 04:28:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755833AbcGZL2A (ORCPT + 3 others); Tue, 26 Jul 2016 07:28:00 -0400 Received: from mail-pf0-f176.google.com ([209.85.192.176]:36569 "EHLO mail-pf0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755802AbcGZL15 (ORCPT ); Tue, 26 Jul 2016 07:27:57 -0400 Received: by mail-pf0-f176.google.com with SMTP id h186so74584853pfg.3 for ; Tue, 26 Jul 2016 04:27:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=R/ftXzkeFkRHD3m+s4rEwCpzwH4kRmBRtO93d/gXMDw=; b=ZdebuuQTxa5IK2zmPl1it0BJghpFBZSOJL3DBQZ0DBT3fG2ue5T2/V1FwIOzMuIDg1 QcW1gurzphfrbku7bjUqK26p4GSzV4uV2HAan0MNaBQadrRSG6wTJzZDhnf5YIHF1+dy SxHVIC1vWQarcfsDB/h8/RNk9/NB6MedSM268= 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=R/ftXzkeFkRHD3m+s4rEwCpzwH4kRmBRtO93d/gXMDw=; b=R0UIcMqUw3BCMkh7l1rqFssWVwtM8YnJ0qXFN0Rg9B6tUq4lrDeqajiWQ+qmf29KAy QYLt0qTm2dpbCZardrNyFEtDqcmNTZhY+T/AJS/5rGx6v+4ayM3Sb1myqc0kF2PbTOrX dbx+M3iyTWA9JQphR4UU67moQL+b5wEJ/2fuCoGq9OSo2gA97PKUR6loJPNgXJlu7roR T6A5yRzP5kYmxDWuItSjRU71A857+Km0xoPbAiTEZGne5SaiXQH1182sM6TjVx7Ja4TH 7AvwX6gJcJ5fOVf8Mq89Z8/3GET5amy+X7YQf0eB7VPBPTEr+cacbHwzCrUnFcUFtf0e 3jCA== X-Gm-Message-State: AEkoousr4Uh5yXYs0WNU/xM9EbK6BDpQjHO03rObfOykTvtv4uJs+nc/ZBzgFDc2uJFZTyQb X-Received: by 10.98.86.154 with SMTP id h26mr38340506pfj.22.1469532476257; Tue, 26 Jul 2016 04:27:56 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id c64sm887598pfg.35.2016.07.26.04.27.52 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 26 Jul 2016 04:27:55 -0700 (PDT) From: Baolin Wang To: ulf.hansson@linaro.org Cc: adrian.hunter@intel.com, rmk+kernel@arm.linux.org.uk, shawn.lin@rock-chips.com, dianders@chromium.org, heiko@sntech.de, david@protonic.nl, hdegoede@redhat.com, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, broonie@kernel.org, linus.walleij@linaro.org, baolin.wang@linaro.org Subject: [PATCH] mmc: core: Optimize the mmc erase size alignment Date: Tue, 26 Jul 2016 19:27:36 +0800 Message-Id: <0366906585240f8123e889527f9eac1e37f9f3d0.1469532291.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Before issuing mmc_erase() function, users always have checked if it can erase with mmc_can_erase/trim/discard() function, thus remove the redundant erase checking in mmc_erase() function. This patch also optimizes the erase start/end sector alignment with round_up()/round_down() function, when erase command is MMC_ERASE_ARG. Signed-off-by: Baolin Wang --- drivers/mmc/core/core.c | 58 +++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 30 deletions(-) -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index b4c08d1a..4dd333e 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -2195,6 +2195,31 @@ out: return err; } +static unsigned int mmc_align_erase_size(struct mmc_card *card, + unsigned int *from, + unsigned int *to, + unsigned int nr) +{ + unsigned int from_old = *from, nr_old = nr; + unsigned int from_new, nr_new; + + from_new = round_up(from_old, card->erase_size); + if (nr_old > from_new - from_old) + nr_old -= from_new - from_old; + else + return 0; + + nr_new = round_down(nr_old, card->erase_size); + if (nr_new == 0) + return 0; + + /* 'from' and 'to' are inclusive */ + *to = from_new + nr_new - 1; + *from = from_new; + + return nr_new; +} + /** * mmc_erase - erase sectors. * @card: card to erase @@ -2210,13 +2235,6 @@ int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr, unsigned int rem, to = from + nr; int err; - if (!(card->host->caps & MMC_CAP_ERASE) || - !(card->csd.cmdclass & CCC_ERASE)) - return -EOPNOTSUPP; - - if (!card->erase_size) - return -EOPNOTSUPP; - if (mmc_card_sd(card) && arg != MMC_ERASE_ARG) return -EOPNOTSUPP; @@ -2234,31 +2252,11 @@ int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr, } if (arg == MMC_ERASE_ARG) { - rem = from % card->erase_size; - if (rem) { - rem = card->erase_size - rem; - from += rem; - if (nr > rem) - nr -= rem; - else - return 0; - } - rem = nr % card->erase_size; - if (rem) - nr -= rem; + rem = mmc_align_erase_size(card, &from, &to, nr); + if (rem == 0) + return 0; } - if (nr == 0) - return 0; - - to = from + nr; - - if (to <= from) - return -EINVAL; - - /* 'from' and 'to' are inclusive */ - to -= 1; - /* * Special case where only one erase-group fits in the timeout budget: * If the region crosses an erase-group boundary on this particular