Commit 71085123 authored by Baolin Wang's avatar Baolin Wang Committed by Ulf Hansson

mmc: core: Factor out the alignment of erase size

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: default avatarBaolin Wang <baolin.wang@linaro.org>
Tested-by: default avatarShawn Lin <shawn.lin@rock-chips.com>
Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
parent 902a8a0b
...@@ -2205,6 +2205,36 @@ static int mmc_do_erase(struct mmc_card *card, unsigned int from, ...@@ -2205,6 +2205,36 @@ static int mmc_do_erase(struct mmc_card *card, unsigned int from,
return err; 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. * mmc_erase - erase sectors.
* @card: card to erase * @card: card to erase
...@@ -2243,26 +2273,12 @@ int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr, ...@@ -2243,26 +2273,12 @@ int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
return -EINVAL; return -EINVAL;
} }
if (arg == MMC_ERASE_ARG) { if (arg == MMC_ERASE_ARG)
rem = from % card->erase_size; nr = mmc_align_erase_size(card, &from, &to, nr);
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 (nr == 0) if (nr == 0)
return 0; return 0;
to = from + nr;
if (to <= from) if (to <= from)
return -EINVAL; return -EINVAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment