]>
Commit | Line | Data |
---|---|---|
df1bfe5f GKH |
1 | From d4721339dcca7def04909a8e60da43c19a24d8bf Mon Sep 17 00:00:00 2001 |
2 | From: Jiong Wu <lohengrin1024@gmail.com> | |
3 | Date: Fri, 1 Mar 2019 00:18:33 +0800 | |
4 | Subject: mmc:fix a bug when max_discard is 0 | |
5 | ||
6 | From: Jiong Wu <lohengrin1024@gmail.com> | |
7 | ||
8 | commit d4721339dcca7def04909a8e60da43c19a24d8bf upstream. | |
9 | ||
10 | The original purpose of the code I fix is to replace max_discard with | |
11 | max_trim if max_trim is less than max_discard. When max_discard is 0 | |
12 | we should replace max_discard with max_trim as well, because | |
13 | max_discard equals 0 happens only when the max_do_calc_max_discard | |
14 | process is overflowed, so if mmc_can_trim(card) is true, max_discard | |
15 | should be replaced by an available max_trim. | |
16 | However, in the original code, there are two lines of code interfere | |
17 | the right process. | |
18 | 1) if (max_discard && mmc_can_trim(card)) | |
19 | when max_discard is 0, it skips the process checking if max_discard | |
20 | needs to be replaced with max_trim. | |
21 | 2) if (max_trim < max_discard) | |
22 | the condition is false when max_discard is 0. it also skips the process | |
23 | that replaces max_discard with max_trim, in fact, we should replace the | |
24 | 0-valued max_discard with max_trim. | |
25 | ||
26 | Signed-off-by: Jiong Wu <Lohengrin1024@gmail.com> | |
27 | Fixes: b305882fbc87 (mmc: core: optimize mmc_calc_max_discard) | |
28 | Cc: stable@vger.kernel.org # v4.17+ | |
29 | Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> | |
30 | Signed-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; |