diff mbox series

mmc: core: set read only with permanent write protect

Message ID 20210222083156.19158-1-sh043.lee@samsung.com (mailing list archive)
State New, archived
Headers show
Series mmc: core: set read only with permanent write protect | expand

Commit Message

이승희 Feb. 22, 2021, 8:31 a.m. UTC
Some of SD cards sets permanent write protection
due to lifespan or internal problem.
Host can find out it's protected permanantly during initialization.
Once set read only during initialization,
it could prevent unnecessary write operation in it.

Signed-off-by: Seunghui Lee <sh043.lee@samsung.com>
---
 drivers/mmc/core/sd.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

이승희 Feb. 25, 2021, 7:17 a.m. UTC | #1
Dear Maintainer & commiters,

Please review the patch for updating.
I'm not sure if it's reviewed or not.

As you know, there are lots of defect SD cards in the market.
It's one of solution that reduces the system load.
The CSD register shows that it's permanent write protected
due to lifespan or internal problem.

Once host sets read only field, the upper layer doesn't issue
unnecessary write operation in it.

Thanks and regards,
Seunghui Lee.

> -----Original Message-----
> From: Seunghui Lee <sh043.lee@samsung.com>
> Sent: Monday, February 22, 2021 5:32 PM
> To: ulf.hansson@linaro.org; pali@kernel.org; huyue2@yulong.com;
> tiantao6@hisilicon.com; linux-mmc@vger.kernel.org; linux-
> kernel@vger.kernel.org
> Cc: grant.jung@samsung.com; jt77.jang@samsung.com;
> dh0421.hwang@samsung.com; junwoo80.lee@samsung.com; jangsub.yi@samsung.com;
> cw9316.lee@samsung.com; sh8267.baek@samsung.com; wkon.kim@samsung.com;
> Seunghui Lee <sh043.lee@samsung.com>
> Subject: [PATCH] mmc: core: set read only with permanent write protect
> 
> Some of SD cards sets permanent write protection due to lifespan or
> internal problem.
> Host can find out it's protected permanantly during initialization.
> Once set read only during initialization, it could prevent unnecessary
> write operation in it.
> 
> Signed-off-by: Seunghui Lee <sh043.lee@samsung.com>
> ---
>  drivers/mmc/core/sd.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index
> 6fa51a6ed058..2c48d6504101 100644
> --- a/drivers/mmc/core/sd.c
> +++ b/drivers/mmc/core/sd.c
> @@ -135,6 +135,9 @@ static int mmc_decode_csd(struct mmc_card *card)
>  			csd->erase_size = UNSTUFF_BITS(resp, 39, 7) + 1;
>  			csd->erase_size <<= csd->write_blkbits - 9;
>  		}
> +
> +		if (UNSTUFF_BITS(resp, 13, 1))
> +			mmc_card_set_readonly(card);
>  		break;
>  	case 1:
>  		/*
> @@ -169,6 +172,9 @@ static int mmc_decode_csd(struct mmc_card *card)
>  		csd->write_blkbits = 9;
>  		csd->write_partial = 0;
>  		csd->erase_size = 1;
> +
> +		if (UNSTUFF_BITS(resp, 13, 1))
> +			mmc_card_set_readonly(card);
>  		break;
>  	default:
>  		pr_err("%s: unrecognised CSD structure version %d\n",
> --
> 2.29.0
Ulf Hansson March 2, 2021, 10:39 a.m. UTC | #2
On Mon, 22 Feb 2021 at 09:15, Seunghui Lee <sh043.lee@samsung.com> wrote:
>
> Some of SD cards sets permanent write protection
> due to lifespan or internal problem.
> Host can find out it's protected permanantly during initialization.
> Once set read only during initialization,
> it could prevent unnecessary write operation in it.
>
> Signed-off-by: Seunghui Lee <sh043.lee@samsung.com>

Applied for next and by adding a stable tag, thanks!

Kind regards
Uffe


> ---
>  drivers/mmc/core/sd.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
> index 6fa51a6ed058..2c48d6504101 100644
> --- a/drivers/mmc/core/sd.c
> +++ b/drivers/mmc/core/sd.c
> @@ -135,6 +135,9 @@ static int mmc_decode_csd(struct mmc_card *card)
>                         csd->erase_size = UNSTUFF_BITS(resp, 39, 7) + 1;
>                         csd->erase_size <<= csd->write_blkbits - 9;
>                 }
> +
> +               if (UNSTUFF_BITS(resp, 13, 1))
> +                       mmc_card_set_readonly(card);
>                 break;
>         case 1:
>                 /*
> @@ -169,6 +172,9 @@ static int mmc_decode_csd(struct mmc_card *card)
>                 csd->write_blkbits = 9;
>                 csd->write_partial = 0;
>                 csd->erase_size = 1;
> +
> +               if (UNSTUFF_BITS(resp, 13, 1))
> +                       mmc_card_set_readonly(card);
>                 break;
>         default:
>                 pr_err("%s: unrecognised CSD structure version %d\n",
> --
> 2.29.0
>
diff mbox series

Patch

diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
index 6fa51a6ed058..2c48d6504101 100644
--- a/drivers/mmc/core/sd.c
+++ b/drivers/mmc/core/sd.c
@@ -135,6 +135,9 @@  static int mmc_decode_csd(struct mmc_card *card)
 			csd->erase_size = UNSTUFF_BITS(resp, 39, 7) + 1;
 			csd->erase_size <<= csd->write_blkbits - 9;
 		}
+
+		if (UNSTUFF_BITS(resp, 13, 1))
+			mmc_card_set_readonly(card);
 		break;
 	case 1:
 		/*
@@ -169,6 +172,9 @@  static int mmc_decode_csd(struct mmc_card *card)
 		csd->write_blkbits = 9;
 		csd->write_partial = 0;
 		csd->erase_size = 1;
+
+		if (UNSTUFF_BITS(resp, 13, 1))
+			mmc_card_set_readonly(card);
 		break;
 	default:
 		pr_err("%s: unrecognised CSD structure version %d\n",