[PATCH] mci: Do not access ext_csd on SD cards

Sascha Hauer s.hauer at pengutronix.de
Mon Mar 24 01:14:15 PDT 2025


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 at 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




More information about the barebox mailing list