]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.19.31/mmc-fix-a-bug-when-max_discard-is-0.patch
Linux 4.19.31
[thirdparty/kernel/stable-queue.git] / releases / 4.19.31 / mmc-fix-a-bug-when-max_discard-is-0.patch
CommitLineData
df1bfe5f
GKH
1From d4721339dcca7def04909a8e60da43c19a24d8bf Mon Sep 17 00:00:00 2001
2From: Jiong Wu <lohengrin1024@gmail.com>
3Date: Fri, 1 Mar 2019 00:18:33 +0800
4Subject: mmc:fix a bug when max_discard is 0
5
6From: Jiong Wu <lohengrin1024@gmail.com>
7
8commit d4721339dcca7def04909a8e60da43c19a24d8bf upstream.
9
10The original purpose of the code I fix is to replace max_discard with
11max_trim if max_trim is less than max_discard. When max_discard is 0
12we should replace max_discard with max_trim as well, because
13max_discard equals 0 happens only when the max_do_calc_max_discard
14process is overflowed, so if mmc_can_trim(card) is true, max_discard
15should be replaced by an available max_trim.
16However, in the original code, there are two lines of code interfere
17the right process.
181) if (max_discard && mmc_can_trim(card))
19when max_discard is 0, it skips the process checking if max_discard
20needs to be replaced with max_trim.
212) if (max_trim < max_discard)
22the condition is false when max_discard is 0. it also skips the process
23that replaces max_discard with max_trim, in fact, we should replace the
240-valued max_discard with max_trim.
25
26Signed-off-by: Jiong Wu <Lohengrin1024@gmail.com>
27Fixes: b305882fbc87 (mmc: core: optimize mmc_calc_max_discard)
28Cc: stable@vger.kernel.org # v4.17+
29Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
30Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
31
32---
33 drivers/mmc/core/core.c | 4 ++--
34 1 file changed, 2 insertions(+), 2 deletions(-)
35
36--- a/drivers/mmc/core/core.c
37+++ b/drivers/mmc/core/core.c
38@@ -2378,9 +2378,9 @@ unsigned int mmc_calc_max_discard(struct
39 return card->pref_erase;
40
41 max_discard = mmc_do_calc_max_discard(card, MMC_ERASE_ARG);
42- if (max_discard && mmc_can_trim(card)) {
43+ if (mmc_can_trim(card)) {
44 max_trim = mmc_do_calc_max_discard(card, MMC_TRIM_ARG);
45- if (max_trim < max_discard)
46+ if (max_trim < max_discard || max_discard == 0)
47 max_discard = max_trim;
48 } else if (max_discard < card->erase_size) {
49 max_discard = 0;