]> err.no Git - linux-2.6/commitdiff
mmc: read ext_csd version number
authorPierre Ossman <drzeus@drzeus.cx>
Sun, 22 Jul 2007 22:34:07 +0000 (00:34 +0200)
committerPierre Ossman <drzeus@drzeus.cx>
Sun, 23 Sep 2007 07:14:53 +0000 (09:14 +0200)
Make sure we do not try to parse a structure we do not
understand.

Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
drivers/mmc/core/mmc.c
include/linux/mmc/mmc.h

index 258fe73eeaa7eec20a8c32d1296bcd3a9025556c..cdc38b43b7999e848cb90e79b40c935be7f21d52 100644 (file)
@@ -161,6 +161,7 @@ static int mmc_read_ext_csd(struct mmc_card *card)
 {
        int err;
        u8 *ext_csd;
+       unsigned int ext_csd_struct;
 
        BUG_ON(!card);
 
@@ -209,13 +210,22 @@ static int mmc_read_ext_csd(struct mmc_card *card)
                goto out;
        }
 
-       card->ext_csd.sectors =
-               ext_csd[EXT_CSD_SEC_CNT + 0] << 0 |
-               ext_csd[EXT_CSD_SEC_CNT + 1] << 8 |
-               ext_csd[EXT_CSD_SEC_CNT + 2] << 16 |
-               ext_csd[EXT_CSD_SEC_CNT + 3] << 24;
-       if (card->ext_csd.sectors)
-               mmc_card_set_blockaddr(card);
+       ext_csd_struct = ext_csd[EXT_CSD_REV];
+       if (ext_csd_struct > 2) {
+               printk("%s: unrecognised EXT_CSD structure version %d\n",
+                       mmc_hostname(card->host), ext_csd_struct);
+               return -EINVAL;
+       }
+
+       if (ext_csd_struct >= 2) {
+               card->ext_csd.sectors =
+                       ext_csd[EXT_CSD_SEC_CNT + 0] << 0 |
+                       ext_csd[EXT_CSD_SEC_CNT + 1] << 8 |
+                       ext_csd[EXT_CSD_SEC_CNT + 2] << 16 |
+                       ext_csd[EXT_CSD_SEC_CNT + 3] << 24;
+               if (card->ext_csd.sectors)
+                       mmc_card_set_blockaddr(card);
+       }
 
        switch (ext_csd[EXT_CSD_CARD_TYPE]) {
        case EXT_CSD_CARD_TYPE_52 | EXT_CSD_CARD_TYPE_26:
index e3ed9b95040ee51a4c5fac786b66736df2150b63..d1d6cbcc1514cd417c2683e7ad61a00e69faa2cb 100644 (file)
@@ -227,6 +227,7 @@ struct _mmc_csd {
 #define EXT_CSD_BUS_WIDTH      183     /* R/W */
 #define EXT_CSD_HS_TIMING      185     /* R/W */
 #define EXT_CSD_CARD_TYPE      196     /* RO */
+#define EXT_CSD_REV            192     /* RO */
 #define EXT_CSD_SEC_CNT                212     /* RO, 4 bytes */
 
 /*