All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mmc: core: Fix ambiguous TRIM and DISCARD arg
@ 2022-11-17 10:51 Christian Löhle
  2022-11-17 14:26 ` Adrian Hunter
  0 siblings, 1 reply; 2+ messages in thread
From: Christian Löhle @ 2022-11-17 10:51 UTC (permalink / raw)
  To: adrian.hunter, ulf.hansson; +Cc: linux-mmc, linux-kernel

Clean up the MMC_TRIM_ARGS define that became ambiguous with
DISCARD introduction.
While at it fix one usage where MMC_TRIM_ARGS falsely included
DISCARD, too.

Fixes: b3bf915308ca ("mmc: core: new discard feature support at eMMC v4.5")

Signed-off-by: Christian Loehle <cloehle@hyperstone.com>
---
Previously submitted as mmc: core: Do not require secure trim for discard
 drivers/mmc/core/core.c | 10 ++++++++--
 include/linux/mmc/mmc.h |  2 +-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 95fa8fb1d45f..7ce26dbd5879 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -1478,6 +1478,11 @@ void mmc_init_erase(struct mmc_card *card)
 		card->pref_erase = 0;
 }
 
+static bool is_trim_arg(unsigned int arg)
+{
+	return (arg & MMC_TRIM_OR_DISCARD_ARGS) && arg != MMC_DISCARD_ARG;
+}
+
 static unsigned int mmc_mmc_erase_timeout(struct mmc_card *card,
 				          unsigned int arg, unsigned int qty)
 {
@@ -1760,7 +1765,7 @@ int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
 	    !(card->ext_csd.sec_feature_support & EXT_CSD_SEC_ER_EN))
 		return -EOPNOTSUPP;
 
-	if (mmc_card_mmc(card) && (arg & MMC_TRIM_ARGS) &&
+	if (mmc_card_mmc(card) && is_trim_arg(arg) &&
 	    !(card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN))
 		return -EOPNOTSUPP;
 
@@ -1790,7 +1795,8 @@ int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
 	 * identified by the card->eg_boundary flag.
 	 */
 	rem = card->erase_size - (from % card->erase_size);
-	if ((arg & MMC_TRIM_ARGS) && (card->eg_boundary) && (nr > rem)) {
+	if ((arg & MMC_TRIM_OR_DISCARD_ARGS) && (card->eg_boundary) &&
+	    (nr > rem)) {
 		err = mmc_do_erase(card, from, from + rem - 1, arg);
 		from += rem;
 		if ((err) || (to <= from))
diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
index 9c50bc40f8ff..6f7993803ee7 100644
--- a/include/linux/mmc/mmc.h
+++ b/include/linux/mmc/mmc.h
@@ -451,7 +451,7 @@ static inline bool mmc_ready_for_data(u32 status)
 #define MMC_SECURE_TRIM1_ARG		0x80000001
 #define MMC_SECURE_TRIM2_ARG		0x80008000
 #define MMC_SECURE_ARGS			0x80000000
-#define MMC_TRIM_ARGS			0x00008001
+#define MMC_TRIM_OR_DISCARD_ARGS	0x00008003
 
 #define mmc_driver_type_mask(n)		(1 << (n))
 
-- 
2.37.3

Hyperstone GmbH | Reichenaustr. 39a  | 78467 Konstanz
Managing Director: Dr. Jan Peter Berns.
Commercial register of local courts: Freiburg HRB381782


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mmc: core: Fix ambiguous TRIM and DISCARD arg
  2022-11-17 10:51 [PATCH] mmc: core: Fix ambiguous TRIM and DISCARD arg Christian Löhle
@ 2022-11-17 14:26 ` Adrian Hunter
  0 siblings, 0 replies; 2+ messages in thread
From: Adrian Hunter @ 2022-11-17 14:26 UTC (permalink / raw)
  To: Christian Löhle, ulf.hansson; +Cc: linux-mmc, linux-kernel

On 17/11/22 12:51, Christian Löhle wrote:
> Clean up the MMC_TRIM_ARGS define that became ambiguous with
> DISCARD introduction.
> While at it fix one usage where MMC_TRIM_ARGS falsely included
> DISCARD, too.
> 
> Fixes: b3bf915308ca ("mmc: core: new discard feature support at eMMC v4.5")
> 

A blank line is unusual here

> Signed-off-by: Christian Loehle <cloehle@hyperstone.com>

One nitpick below otherwise:

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
> Previously submitted as mmc: core: Do not require secure trim for discard
>  drivers/mmc/core/core.c | 10 ++++++++--
>  include/linux/mmc/mmc.h |  2 +-
>  2 files changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
> index 95fa8fb1d45f..7ce26dbd5879 100644
> --- a/drivers/mmc/core/core.c
> +++ b/drivers/mmc/core/core.c
> @@ -1478,6 +1478,11 @@ void mmc_init_erase(struct mmc_card *card)
>  		card->pref_erase = 0;
>  }
>  
> +static bool is_trim_arg(unsigned int arg)
> +{
> +	return (arg & MMC_TRIM_OR_DISCARD_ARGS) && arg != MMC_DISCARD_ARG;
> +}
> +
>  static unsigned int mmc_mmc_erase_timeout(struct mmc_card *card,
>  				          unsigned int arg, unsigned int qty)
>  {
> @@ -1760,7 +1765,7 @@ int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
>  	    !(card->ext_csd.sec_feature_support & EXT_CSD_SEC_ER_EN))
>  		return -EOPNOTSUPP;
>  
> -	if (mmc_card_mmc(card) && (arg & MMC_TRIM_ARGS) &&
> +	if (mmc_card_mmc(card) && is_trim_arg(arg) &&
>  	    !(card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN))
>  		return -EOPNOTSUPP;
>  
> @@ -1790,7 +1795,8 @@ int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
>  	 * identified by the card->eg_boundary flag.
>  	 */
>  	rem = card->erase_size - (from % card->erase_size);
> -	if ((arg & MMC_TRIM_ARGS) && (card->eg_boundary) && (nr > rem)) {
> +	if ((arg & MMC_TRIM_OR_DISCARD_ARGS) && (card->eg_boundary) &&
> +	    (nr > rem)) {

Parenthesis are not needed around "card->eg_boundary)" nor "nr > rem"
If you take them out, then the line doesn't need wrapping either.

>  		err = mmc_do_erase(card, from, from + rem - 1, arg);
>  		from += rem;
>  		if ((err) || (to <= from))
> diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
> index 9c50bc40f8ff..6f7993803ee7 100644
> --- a/include/linux/mmc/mmc.h
> +++ b/include/linux/mmc/mmc.h
> @@ -451,7 +451,7 @@ static inline bool mmc_ready_for_data(u32 status)
>  #define MMC_SECURE_TRIM1_ARG		0x80000001
>  #define MMC_SECURE_TRIM2_ARG		0x80008000
>  #define MMC_SECURE_ARGS			0x80000000
> -#define MMC_TRIM_ARGS			0x00008001
> +#define MMC_TRIM_OR_DISCARD_ARGS	0x00008003
>  
>  #define mmc_driver_type_mask(n)		(1 << (n))
>  


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-17 14:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-17 10:51 [PATCH] mmc: core: Fix ambiguous TRIM and DISCARD arg Christian Löhle
2022-11-17 14:26 ` Adrian Hunter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.