forked from Minki/linux
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: Baolin Wang <baolin.wang@linaro.org> Tested-by: Shawn Lin <shawn.lin@rock-chips.com> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
This commit is contained in:
parent
902a8a0b50
commit
71085123d2
@ -2205,6 +2205,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
|
||||
@ -2243,26 +2273,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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user