Skip to content

Commit a1a71ef

Browse files
cloehlesmb49
authored andcommitted
mmc: core: Fix ambiguous TRIM and DISCARD arg
BugLink: https://bugs.launchpad.net/bugs/2003896 commit 489d144 upstream. Clean up the MMC_TRIM_ARGS define that became ambiguous with DISCARD introduction. While at it, let's fix one usage where MMC_TRIM_ARGS falsely included DISCARD too. Fixes: b3bf915 ("mmc: core: new discard feature support at eMMC v4.5") Signed-off-by: Christian Loehle <[email protected]> Acked-by: Adrian Hunter <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ulf Hansson <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Kamal Mostafa <[email protected]> Signed-off-by: Stefan Bader <[email protected]>
1 parent a5e610e commit a1a71ef

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

drivers/mmc/core/core.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,11 @@ void mmc_init_erase(struct mmc_card *card)
15561556
card->pref_erase = 0;
15571557
}
15581558

1559+
static bool is_trim_arg(unsigned int arg)
1560+
{
1561+
return (arg & MMC_TRIM_OR_DISCARD_ARGS) && arg != MMC_DISCARD_ARG;
1562+
}
1563+
15591564
static unsigned int mmc_mmc_erase_timeout(struct mmc_card *card,
15601565
unsigned int arg, unsigned int qty)
15611566
{
@@ -1887,7 +1892,7 @@ int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
18871892
!(card->ext_csd.sec_feature_support & EXT_CSD_SEC_ER_EN))
18881893
return -EOPNOTSUPP;
18891894

1890-
if (mmc_card_mmc(card) && (arg & MMC_TRIM_ARGS) &&
1895+
if (mmc_card_mmc(card) && is_trim_arg(arg) &&
18911896
!(card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN))
18921897
return -EOPNOTSUPP;
18931898

@@ -1917,7 +1922,7 @@ int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
19171922
* identified by the card->eg_boundary flag.
19181923
*/
19191924
rem = card->erase_size - (from % card->erase_size);
1920-
if ((arg & MMC_TRIM_ARGS) && (card->eg_boundary) && (nr > rem)) {
1925+
if ((arg & MMC_TRIM_OR_DISCARD_ARGS) && card->eg_boundary && nr > rem) {
19211926
err = mmc_do_erase(card, from, from + rem - 1, arg);
19221927
from += rem;
19231928
if ((err) || (to <= from))

include/linux/mmc/mmc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ static inline bool mmc_op_multi(u32 opcode)
434434
#define MMC_SECURE_TRIM1_ARG 0x80000001
435435
#define MMC_SECURE_TRIM2_ARG 0x80008000
436436
#define MMC_SECURE_ARGS 0x80000000
437-
#define MMC_TRIM_ARGS 0x00008001
437+
#define MMC_TRIM_OR_DISCARD_ARGS 0x00008003
438438

439439
#define mmc_driver_type_mask(n) (1 << (n))
440440

0 commit comments

Comments
 (0)