Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp618918img; Fri, 22 Mar 2019 05:16:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqwf+aBUZKzLAme0P51qiukM3e2S8ugHDT5JeJ5zOrWgdUVLuw/aAa5xiMl00Er84tAMSgD9 X-Received: by 2002:a62:29c5:: with SMTP id p188mr8621144pfp.203.1553256999218; Fri, 22 Mar 2019 05:16:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553256999; cv=none; d=google.com; s=arc-20160816; b=XmzqDOShLRZWLX8W3ASciQWolekXEcJhEkWlw3Pu2xoc54dny0cPSeZ0fhx5KU3lJO lEh+Uy2Obdj/f5bmOnIpmHwSogYi32UHAoNKto9AgArk8odZaMTZl1o60ungaA1Mneyr RPdi1VzwYYFBME3tAYEuJQiyxL1usPr0R7CRpTVTnK/axGMtMwnkE28hNFwfzwEh/VQy 490sninRSVOiuNFSelniotejJ/byK6uT7JRDNWlto5EkQGcSBgbWN1Csxc1GOC3e6441 ECuW1SS/GQKPv2jhuldMhIB2iM9uYnTusZFky1YLvEq0h7LiD9NhsLPT3YjfMyMnloFf Jpzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3LX2IBy00VRXCObZukOULZ+Tj+6SWC9ZtS1Q7kKxZMY=; b=ffIFmGkNDqD7dJ/acEI9O1T9yXSM5gL0rBMYz3u9nJTk0XUeFo+M6L0euwFH/C/Lz+ IUMLKxl78x/TVjgT9E+vn1l663E9xwQqNZeNcNi4vzxCs0Yadfv1y+x7vmzs4EZPR1cm 3GRtveqzcAxrxWk38oo+k26diAh3KeG78ievAjWmxmWSUj0oquekYvU6Zv8HwwZDDIVM AD6kTgg4KcqkxEVJC7BAnRt4DYjonnD1fU2qVx+DV+Sm3Q+ozhzq5wOkmnXzfFdAu6yG h6NMavEuuR5V6GtQ9ZbiPdhC4i14eAm0Q4FhUrK5HKdzxP85IJvpQfexHFYC43SQyt1S 612A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oAgblGnf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m24si6813406pgh.485.2019.03.22.05.16.24; Fri, 22 Mar 2019 05:16:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oAgblGnf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389934AbfCVMOj (ORCPT + 99 others); Fri, 22 Mar 2019 08:14:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:52838 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389215AbfCVMOg (ORCPT ); Fri, 22 Mar 2019 08:14:36 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 807682083D; Fri, 22 Mar 2019 12:14:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553256876; bh=FX/TvHuBurcW/orFJCjrgAD73kg+1PAxSTM2BOCNl3g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oAgblGnf6Dgcq5vZA9nycDHeIEKZ07iJikO7WvFJQSmjYy9e1DmbawcG5WG/Sw25n dAr2NMtAD0MV4PfNyyij3v5xyR1yTixi4j3CFkDC3NNNILL60fiq80OdtO6gPRZZhJ w34kaa6s0IZUw/yuYrLIWDUypnyb1coZkrLFUc4w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiong Wu , Ulf Hansson Subject: [PATCH 5.0 064/238] mmc:fix a bug when max_discard is 0 Date: Fri, 22 Mar 2019 12:14:43 +0100 Message-Id: <20190322111302.359209256@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111258.383569278@linuxfoundation.org> References: <20190322111258.383569278@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 5.0-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiong Wu commit d4721339dcca7def04909a8e60da43c19a24d8bf upstream. 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 Fixes: b305882fbc87 (mmc: core: optimize mmc_calc_max_discard) Cc: stable@vger.kernel.org # v4.17+ Signed-off-by: Ulf Hansson Signed-off-by: Greg Kroah-Hartman --- drivers/mmc/core/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -2381,9 +2381,9 @@ unsigned int mmc_calc_max_discard(struct 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;