Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751868AbbFAJth (ORCPT ); Mon, 1 Jun 2015 05:49:37 -0400 Received: from protonic.xs4all.nl ([83.163.252.89]:4460 "EHLO protonic.xs4all.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751481AbbFAJta (ORCPT ); Mon, 1 Jun 2015 05:49:30 -0400 X-Greylist: delayed 1697 seconds by postgrey-1.27 at vger.kernel.org; Mon, 01 Jun 2015 05:49:29 EDT From: David Jander To: Pierre Ossman , Ulf Hansson , Sascha Hauer Cc: Johan Rudholm , Adrian Hunter , Javier Martinez Canillas , linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, David Jander Subject: [PATCH] mmc: core: Fix off-by-one error in mmc_do_calc_max_discard() Date: Mon, 1 Jun 2015 11:20:35 +0200 Message-Id: <1433150435-19997-1-git-send-email-david@protonic.nl> X-Mailer: git-send-email 2.1.4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1253 Lines: 41 qty is the maximum number of discard that _do_ fit in the timeout, not the first amount that does _not_ fit anymore. This seemingly harmless error has a very severe performance impact when the timeout value is enough for only 1 erase group. Signed-off-by: David Jander --- drivers/mmc/core/core.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 92e7671..1f9573b 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -2234,16 +2234,13 @@ static unsigned int mmc_do_calc_max_discard(struct mmc_card *card, if (!qty) return 0; - if (qty == 1) - return 1; - /* Convert qty to sectors */ if (card->erase_shift) - max_discard = --qty << card->erase_shift; + max_discard = qty << card->erase_shift; else if (mmc_card_sd(card)) max_discard = qty; else - max_discard = --qty * card->erase_size; + max_discard = qty * card->erase_size; return max_discard; } -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/