mmc: core: optimize mmc_calc_max_discard
authorSergio Valverde <vlvrdv@gmail.com>
Thu, 8 Feb 2018 17:41:43 +0000 (11:41 -0600)
committerUlf Hansson <ulf.hansson@linaro.org>
Mon, 5 Mar 2018 08:01:00 +0000 (09:01 +0100)
If the max_discard value is zero, the conditional branch that checks the
trim capabilities will never update this value with max_trim.

Change the condition statement to also check the max_discard value in order
to avoid an unnecessary call to mmc_do_calc_max_discard.

Signed-off-by: Sergio Valverde <vlvrdv@gmail.com>
Reviewed-by: Shawn Lin <shawn.lin@rock-chip.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
drivers/mmc/core/core.c

index c0ba6d8..e01910d 100644 (file)
@@ -2369,7 +2369,7 @@ unsigned int mmc_calc_max_discard(struct mmc_card *card)
                return card->pref_erase;
 
        max_discard = mmc_do_calc_max_discard(card, MMC_ERASE_ARG);
-       if (mmc_can_trim(card)) {
+       if (max_discard && mmc_can_trim(card)) {
                max_trim = mmc_do_calc_max_discard(card, MMC_TRIM_ARG);
                if (max_trim < max_discard)
                        max_discard = max_trim;