Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1477940

[PATCH v5 1/2] mmc: core: Factor out the alignment of erase size

Path csiph.com!aioe.org!bofh.it!news.nic.it!robomod
From Baolin Wang <baolin.wang@linaro.org>
Newsgroups linux.kernel
Subject [PATCH v5 1/2] mmc: core: Factor out the alignment of erase size
Date Wed, 07 Sep 2016 04:40:02 +0200
Message-ID <seAWm-2bR-7@gated-at.bofh.it> (permalink)
X-Original-To ulf.hansson@linaro.org
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=kSEUDRYB1V1PkNgNfIjMkdxxAKbGWHNt8jCefwgo3+4=; b=VsMRrb3fGIRcGfLsNlWI8Kzjvjq/dK6f77U96D8cPqgWMrnI1AG6NLHbuMs83y3MMZ eROKsDuZc9N6cOvCk9TDstVq4BxW/kicUqogchfO566rpTY4/q5Q0gQoeQrYTtZBolHN 60QtQHWduAoJy+b+BWac+2XOuvjfxpRa0REvc=
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; bh=kSEUDRYB1V1PkNgNfIjMkdxxAKbGWHNt8jCefwgo3+4=; b=QasQ/AuWeOxSTSOiBVhbwrlrGlihy7vzHNOkxNcn4+fit6SqnbII07yIC9CEvdUJGl VY+3pA8mowNyiFYTUGzR2wXioBRq2tQDb4QydvCr0I6D/ILObpoPsWEcFgEegadiKZHX Gu+kxfDaJvceZCriCP0EwJy7v+BtNJsHyKXjL9WxoRpmYymi1mK53K9PsKieSHyT5yb+ rXl1urnOJW47m1PkqH8Zl1zlyOLN9pD5vztJ6gxkZWM8GZ/3eDl2VCraF64vtfwNVx+l +K+O6nnYwyCc7rxuJcSBCRomjsIEi+5/Eq1+2z929ZBoF7sUrJ6SeeF3unh7rNuYgnGr 1yEg==
X-Gm-Message-State AE9vXwMdUhZpFaZvUqltyaRNcauoF6MQIVxl06neAaNO00v7KPGhKz05WRRKOIQKZpRnH5UQ
X-Received by 10.66.253.7 with SMTP id zw7mr77743712pac.25.1473215952594; Tue, 06 Sep 2016 19:39:12 -0700 (PDT)
X-Mailer git-send-email 1.7.9.5
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 96
Organization linux.* mail to news gateway
X-Original-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
X-Original-Date Wed, 7 Sep 2016 10:38:24 +0800
X-Original-Message-ID <48ff46b96e01df36aa5d1c2daf1091d2ec2e729f.1473215578.git.baolin.wang@linaro.org>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1477940

Show key headers only | View raw


In order to clean up the mmc_erase() function and do some optimization
for erase size alignment, factor out the guts of erase size alignment
into mmc_align_erase_size() function.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Tested-by: Shawn Lin <shawn.lin@rock-chips.com>
---
Changes since v4:
 - Abandon the patch removing the checking if mmc can erase.
 - Add missing validations in mmc_erase().

Changes since v3:
 - Split into 3 separate patches.
 - Add test tag by Shawn.

Changes since v2:
 - Add nr checking and other optimization in mmc_erase() function.

Changes since v1:
 - Add the alignment if card->erase_size is not power of 2.
---
 drivers/mmc/core/core.c |   48 +++++++++++++++++++++++++++++++----------------
 1 file changed, 32 insertions(+), 16 deletions(-)

diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index e55cde6..11b4897 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -2202,6 +2202,36 @@ 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_new = *from, nr_new = nr, rem;
+
+	rem = from_new % card->erase_size;
+	if (rem) {
+		rem = card->erase_size - rem;
+		from_new += rem;
+		if (nr_new > rem)
+			nr_new -= rem;
+		else
+			return 0;
+	}
+
+	rem = nr_new % card->erase_size;
+	if (rem)
+		nr_new -= rem;
+
+	if (nr_new == 0)
+		return 0;
+
+	*to = from_new + nr_new;
+	*from = from_new;
+
+	return nr_new;
+}
+
 /**
  * mmc_erase - erase sectors.
  * @card: card to erase
@@ -2240,26 +2270,12 @@ int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
 			return -EINVAL;
 	}
 
-	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;
-	}
+	if (arg == MMC_ERASE_ARG)
+		nr = mmc_align_erase_size(card, &from, &to, nr);
 
 	if (nr == 0)
 		return 0;
 
-	to = from + nr;
-
 	if (to <= from)
 		return -EINVAL;
 
-- 
1.7.9.5

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH v5 1/2] mmc: core: Factor out the alignment of erase size Baolin Wang <baolin.wang@linaro.org> - 2016-09-07 04:40 +0200
  Re: [PATCH v5 1/2] mmc: core: Factor out the alignment of erase size Ulf Hansson <ulf.hansson@linaro.org> - 2016-09-09 11:50 +0200

csiph-web