Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=d7604d76351f7745d0e62d9f2bbcbb917c9013f3
Commit:     d7604d76351f7745d0e62d9f2bbcbb917c9013f3
Parent:     adf66a0dc5e8be8d4e64f3c2114f9b175558235b
Author:     Pierre Ossman <[EMAIL PROTECTED]>
AuthorDate: Mon Jul 23 00:34:07 2007 +0200
Committer:  Pierre Ossman <[EMAIL PROTECTED]>
CommitDate: Sun Sep 23 09:14:53 2007 +0200

    mmc: read ext_csd version number
    
    Make sure we do not try to parse a structure we do not
    understand.
    
    Signed-off-by: Pierre Ossman <[EMAIL PROTECTED]>
---
 drivers/mmc/core/mmc.c  |   24 +++++++++++++++++-------
 include/linux/mmc/mmc.h |    1 +
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 258fe73..cdc38b4 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -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:
diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
index e3ed9b9..d1d6cbc 100644
--- a/include/linux/mmc/mmc.h
+++ b/include/linux/mmc/mmc.h
@@ -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 */
 
 /*
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to