mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] mci: Do not access ext_csd on SD cards
@ 2025-03-24  8:14 Sascha Hauer
  2025-03-24  8:19 ` Sascha Hauer
  2025-03-24  8:21 ` Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Sascha Hauer @ 2025-03-24  8:14 UTC (permalink / raw)
  To: Barebox List

SD cards do not have a ext_csd so accessing it on an SD card results in
a NULL pointer derefence. Move the production year check to
mci_mmc_decode_cid() which is executed for MMC devices only. While at
it do not access ext_csd directly. We have already populated
mci->version, so use this to check for the MMC versions which need the
production year adjustment.

Fixes: a4a78c4f32 ("mci: use struct cid")
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/mci-core.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index c89322f61e..1e49969017 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -2377,6 +2377,12 @@ static int mci_mmc_decode_cid(struct mci *card)
 		return -EINVAL;
 	}
 
+	if (mci->version >= MMC_VERSION_4_41) {
+		/* Adjust production date as per JEDEC JESD84-B451 */
+		if (mci->cid.year < 2010)
+			mci->cid.year += 16;
+	}
+
 	return 0;
 }
 
@@ -2483,12 +2489,6 @@ static void mci_parse_cid(struct mci *mci)
 	else
 		mci_mmc_decode_cid(mci);
 
-	if (mci->ext_csd[EXT_CSD_REV] >= 5) {
-		/* Adjust production date as per JEDEC JESD84-B451 */
-		if (mci->cid.year < 2010)
-			mci->cid.year += 16;
-	}
-
 	dev_add_param_uint32_fixed(dev, "cid_mid", mci->cid.manfid, "0x%02X");
 	dev_add_param_uint32_fixed(dev, "cid_oid", mci->cid.oemid, "0x%04X");
 	dev_add_param_string_fixed(dev, "cid_pnm", mci->cid.prod_name);
-- 
2.39.5




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

* Re: [PATCH] mci: Do not access ext_csd on SD cards
  2025-03-24  8:14 [PATCH] mci: Do not access ext_csd on SD cards Sascha Hauer
@ 2025-03-24  8:19 ` Sascha Hauer
  2025-03-24  8:21 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2025-03-24  8:19 UTC (permalink / raw)
  To: Barebox List

On Mon, Mar 24, 2025 at 09:14:15AM +0100, Sascha Hauer wrote:
> SD cards do not have a ext_csd so accessing it on an SD card results in
> a NULL pointer derefence. Move the production year check to
> mci_mmc_decode_cid() which is executed for MMC devices only. While at
> it do not access ext_csd directly. We have already populated
> mci->version, so use this to check for the MMC versions which need the
> production year adjustment.
> 
> Fixes: a4a78c4f32 ("mci: use struct cid")
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  drivers/mci/mci-core.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
> index c89322f61e..1e49969017 100644
> --- a/drivers/mci/mci-core.c
> +++ b/drivers/mci/mci-core.c
> @@ -2377,6 +2377,12 @@ static int mci_mmc_decode_cid(struct mci *card)
>  		return -EINVAL;
>  	}
>  
> +	if (mci->version >= MMC_VERSION_4_41) {
> +		/* Adjust production date as per JEDEC JESD84-B451 */
> +		if (mci->cid.year < 2010)
> +			mci->cid.year += 16;
> +	}

The variable is named "card" in this function, not "mci". Will fix while
applying.

Sascha


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



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

* Re: [PATCH] mci: Do not access ext_csd on SD cards
  2025-03-24  8:14 [PATCH] mci: Do not access ext_csd on SD cards Sascha Hauer
  2025-03-24  8:19 ` Sascha Hauer
@ 2025-03-24  8:21 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2025-03-24  8:21 UTC (permalink / raw)
  To: Barebox List, Sascha Hauer


On Mon, 24 Mar 2025 09:14:15 +0100, Sascha Hauer wrote:
> SD cards do not have a ext_csd so accessing it on an SD card results in
> a NULL pointer derefence. Move the production year check to
> mci_mmc_decode_cid() which is executed for MMC devices only. While at
> it do not access ext_csd directly. We have already populated
> mci->version, so use this to check for the MMC versions which need the
> production year adjustment.
> 
> [...]

Applied, thanks!

[1/1] mci: Do not access ext_csd on SD cards
      https://git.pengutronix.de/cgit/barebox/commit/?id=a0747210a87d (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




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

end of thread, other threads:[~2025-03-24  8:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-24  8:14 [PATCH] mci: Do not access ext_csd on SD cards Sascha Hauer
2025-03-24  8:19 ` Sascha Hauer
2025-03-24  8:21 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox