From patchwork Sun Feb 17 08:24:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiong Wu X-Patchwork-Id: 10816817 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 AC3B91390 for ; Sun, 17 Feb 2019 08:26:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94F6D2A6DC for ; Sun, 17 Feb 2019 08:26:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 85A832A6F0; Sun, 17 Feb 2019 08:26:03 +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 356E92A6DC for ; Sun, 17 Feb 2019 08:26:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725810AbfBQI0C (ORCPT ); Sun, 17 Feb 2019 03:26:02 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:45333 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725799AbfBQI0B (ORCPT ); Sun, 17 Feb 2019 03:26:01 -0500 Received: by mail-pl1-f193.google.com with SMTP id r14so7188823pls.12 for ; Sun, 17 Feb 2019 00:26:01 -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=JHL4U4ktqd0q7Ed7b5ujVa+ERROYfnuwS+n8tF3Hu1w=; b=XzYjXcB0xoJlPMSdttFskf8ZV9UZL9djwZ6diJSnpGmAvdaPsNxP3pu8ldPfJhNUw/ 6FULXtVuZA+IIT9fY6T2BG6W5wFgMW3XTcNNfaUWK70zwS7AbNIHHip/V278FKDUUjOb 0gdUvF80E6UoJnseHiV1/J7fBMjE5rsa5nNCaon7XkyKI1pGPiJ9XpGcew3cBm2lvXcP Xvu4NXdZg6jg6ANHvlucDvRhS7H+Qs5rwuU1wlb83F6ArpLoazxJNFrrRJzWb1tEC5sH 1abwEloUf1xDIg7ubRjugT0KMdx7AqEJnR2+7BKJabztmyjnKKFERdM/6mImDjm+tzGn fHLg== 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=JHL4U4ktqd0q7Ed7b5ujVa+ERROYfnuwS+n8tF3Hu1w=; b=kyp0CllLwl8kaz37b+bmp5V/0fCgDEZ1WERGINRisvj8BtxpjDVgPybQ03m6KKRnP4 Z8mv9Qu+oHWYFdgloSB+GXziN1BgBoZyQDrPVNHy4Wsf3R/ol6wnC6odYlDTiLloykKk qf0wmkPUPRqxS1Mw8pIh+Kr2398CVkgGLDTJdvS2+0GXDGsZKo/V5KbDQnPNhRFCz53W 9XdiipqhgX1BuHaUGQhrbmfmYp5P0cE56KDbai22Nux+uZ1TGWUpEnaONbUA5EeftkbS 61zJ6v10CiltF6GRvwRupmY0Ta6gLx5GV8vnOgtaypAH+VA+782K6li0HMUzHLCssRaY ri4w== X-Gm-Message-State: AHQUAuZb1ndx9bjG4YAMB4V6KDDpphFlx7bjO/2T3AVoCj35rnt+oYrA StR+/7DRmLlMYdc03Wz6bu8= X-Google-Smtp-Source: AHgI3Ia7yNfrD62SQnwbSEgDyn0nkG14DystqugMKtl8cNfipbivIATfhKlHYV7VXEMpqiVRs+rfbg== X-Received: by 2002:a17:902:f01:: with SMTP id 1mr18764717ply.41.1550391961339; Sun, 17 Feb 2019 00:26:01 -0800 (PST) Received: from localhost.localdomain ([101.86.70.53]) by smtp.gmail.com with ESMTPSA id u5sm11047616pgp.2.2019.02.17.00.25.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 17 Feb 2019 00:26:00 -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 Subject: [PATCH] mmc:fix a bug when max_discard is 0 Date: Sun, 17 Feb 2019 16:24:32 +0800 Message-Id: <1550391872-6668-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 The original purpose of the code I fix is to choose max_trim as the final parameter instead of max_discard if max_trim is less than max_discard. But there is a uncommon case that max_discard is 0 because max_discard is overflow the maximum threshold. In this case, we should still choose max_trim instead of max_discard, however, in the original code(if(max_trim < max_discard)), the conditio is false when max_discard is 0. So I fix it by add "|| max_discard == 0" to cover this case. Signed-off-by: Jiong Wu --- drivers/mmc/core/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 5bd58b9..7b1bd95 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -2383,7 +2383,7 @@ unsigned int mmc_calc_max_discard(struct mmc_card *card) max_discard = mmc_do_calc_max_discard(card, MMC_ERASE_ARG); if (max_discard && 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;