From patchwork Thu Feb 28 16:18:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiong Wu X-Patchwork-Id: 10833425 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 79C07180E for ; Thu, 28 Feb 2019 16:19:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 651792EECC for ; Thu, 28 Feb 2019 16:19:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 585702F3A8; Thu, 28 Feb 2019 16:19:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 34A612EECC for ; Thu, 28 Feb 2019 16:19:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731463AbfB1QTe (ORCPT ); Thu, 28 Feb 2019 11:19:34 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:32893 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726269AbfB1QTe (ORCPT ); Thu, 28 Feb 2019 11:19:34 -0500 Received: by mail-pf1-f193.google.com with SMTP id i19so9964354pfd.0 for ; Thu, 28 Feb 2019 08:19:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=wLqLGwVzN9PdFlhPMWnqRjnd0YyV8K+vnAil2MudBfM=; b=bllRmgIOYhNXvNQED9zM2If8/Z3Vud5DRmwQo+8YdWuwMSrAMN6BaxcOAEPZ3IhFT/ d4E5KveNFKp7Lq7pHrW9je+EwPrWjr44goxEccA/dpaXqua02z3kViEewDWnCQeG6qkS Ns0fBUfYLBqYH4t/d5y5nzNB6Wa20aDmzaw9NnP0gqncQrKiby2uquoXXBHhSUKImk4q mCN1SBYMMCuFKlprH5l/EYeO84uTA/6CJ5vqU1ba+FS7vPudD4QuDSRHlX7mW5V14Ka/ Dxy2EE+uBvVAT0mvc88R10qlDu2GWxRWcdvWLTdp3KdV46npy8+2YTahPFR5d8QpBe6/ MoJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=wLqLGwVzN9PdFlhPMWnqRjnd0YyV8K+vnAil2MudBfM=; b=U7SPF32xh1e7vo/dqIlkDizvDbowW2aV7DOu7is6tRf7xWeTB4SoCbmVZYleUPysbP hrT/P9atYmm9Y5F2rDqe1nLQT12Zi4TpLlsc3RUJHcKMG7HWZXdPDY43Xe0x0WborWwk bYjlAQIZ/BbjFcm4xld2qdFGXOPGeKhKqYbapau/Fd3YywEHokCRK6l57H8MrbJg3TzD c6ZaJDYuhkdBmRXRvh37FAvHmdVXWF+5siR0PV1sKOQY7MVWJq0p5VL/qBVQtAqK1vGx 9zIEL3YFI5x/2pojdwZo6Rjv7OKHzCEtSXN6tBJ/BqNSc9JAERYVRHW6+Hny8LwHoqAz JRyg== X-Gm-Message-State: AHQUAuZd7s2qnsoVa61+v5cKV/fJ0E2tsP8rP/wuEzW6cK2etU6cUdHt YQHzbaRgkBCXqPrAKTRwvLU= X-Google-Smtp-Source: AHgI3IadhfQkUpDh2hwaYatzflTIzOkOqfIG9jqsQwiU8p52RFRRsT2PiLgbahfNx5oAE3yJVVXwrA== X-Received: by 2002:a63:d703:: with SMTP id d3mr9262467pgg.167.1551370773243; Thu, 28 Feb 2019 08:19:33 -0800 (PST) Received: from localhost.localdomain ([180.159.70.68]) by smtp.gmail.com with ESMTPSA id h64sm38371154pfj.40.2019.02.28.08.19.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Feb 2019 08:19:32 -0800 (PST) From: Jiong Wu X-Google-Original-From: Jiong Wu To: ulf.hansson@linaro.org Cc: shawn.lin@rock-chips.com, adrian.hunter@intel.com, avri.altman@wdc.com, wsa+renesas@sang-engineering.com, vlvrdv@gmail.com, mort@bork.org, linux-mmc@vger.kernel.org, Lohengrin1024@gmail.com, Jiong Wu Subject: [PATCH] mmc:fix a bug when max_discard is 0 Date: Fri, 1 Mar 2019 00:18:33 +0800 Message-Id: <1551370713-17337-1-git-send-email-Lohengrin1024@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jiong Wu The original purpose of the code I fix is to replace max_discard with max_trim if max_trim is less than max_discard. When max_discard is 0 we should replace max_discard with max_trim as well, because max_discard equals 0 happens only when the max_do_calc_max_discard process is overflowed, so if mmc_can_trim(card) is true, max_discard should be replaced by an available max_trim. However, in the original code, there are two lines of code interfere the right process. 1) if (max_discard && mmc_can_trim(card)) when max_discard is 0, it skips the process checking if max_discard needs to be replaced with max_trim. 2) if (max_trim < max_discard) the condition is false when max_discard is 0. it also skips the process that replaces max_discard with max_trim, in fact, we should replace the 0-valued max_discard with max_trim. Signed-off-by: Jiong Wu --- drivers/mmc/core/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 5bd58b9..caaefc0 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -2381,9 +2381,9 @@ 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 (max_discard && mmc_can_trim(card)) { + if (mmc_can_trim(card)) { max_trim = mmc_do_calc_max_discard(card, MMC_TRIM_ARG); - if (max_trim < max_discard) + if (max_trim < max_discard || max_discard == 0) max_discard = max_trim; } else if (max_discard < card->erase_size) { max_discard = 0;