diff options
author | Baolin Wang <baolin.wang@linaro.org> | 2016-09-07 04:38:24 +0200 |
---|---|---|
committer | Ulf Hansson <ulf.hansson@linaro.org> | 2016-09-26 21:31:25 +0200 |
commit | 71085123d27dc5d28ce523344f32ac0d20c5f0a5 (patch) | |
tree | 950fd211bf33e0f414c27e3bf8c821ef22034ba4 /drivers | |
parent | mmc: davinci: remove incorrect NO_IRQ use (diff) | |
download | linux-71085123d27dc5d28ce523344f32ac0d20c5f0a5.tar.xz linux-71085123d27dc5d28ce523344f32ac0d20c5f0a5.zip |
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>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/mmc/core/core.c | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 59b452d5dc81..9ce6c25a8f54 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -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; |