From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754335AbcIFEej (ORCPT ); Tue, 6 Sep 2016 00:34:39 -0400 Received: from rhlx01.hs-esslingen.de ([129.143.116.10]:40308 "EHLO rhlx01.hs-esslingen.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752629AbcIFEei (ORCPT ); Tue, 6 Sep 2016 00:34:38 -0400 Date: Tue, 6 Sep 2016 06:34:35 +0200 From: Andreas Mohr To: Baolin Wang Cc: ulf.hansson@linaro.org, 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 Subject: Re: [PATCH v4 2/3] mmc: core: Factor out the alignment of erase size Message-ID: <20160906043435.GA10158@rhlx01.hs-esslingen.de> References: <2b6b5b930d0f37a219d5786a6b56b17516a90abd.1473130123.git.baolin.wang@linaro.org> <48c332c9c688796b7ea157046b8feb68a11e60d4.1473130123.git.baolin.wang@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <48c332c9c688796b7ea157046b8feb68a11e60d4.1473130123.git.baolin.wang@linaro.org> X-Priority: none User-Agent: Mutt/1.7.0 (2016-08-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 06, 2016 at 10:55:11AM +0800, Baolin Wang wrote: > 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 > Tested-by: Shawn Lin > --- > drivers/mmc/core/core.c | 60 +++++++++++++++++++++++++++++------------------ > 1 file changed, 37 insertions(+), 23 deletions(-) > > diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c > index 7d7209d..5f93eef 100644 > --- a/drivers/mmc/core/core.c > +++ b/drivers/mmc/core/core.c > @@ -2202,6 +2202,37 @@ 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; > + > + /* '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 > @@ -2234,31 +2265,14 @@ 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; > + nr = mmc_align_erase_size(card, &from, &to, nr); > + if (nr == 0) > + return 0; > + } else { > + /* 'from' and 'to' are inclusive */ > + to -= 1; > } > > - if (nr == 0) > - return 0; > - > - to = from + nr; > - > - if (to <= from) > - return -EINVAL; Hmm, this is swallowing -EINVAL behaviour i.e., now possibly violating protocol? (this may easily be ok - haven't done an extensive review - but since the commit has that characteristic change, the commit message should contain that detail) Thanks for the cleanup work & HTH, Andreas Mohr