mmc: reworked version lookup in mmc_startup_v4

Using a table versus a switch() structure saves a bit of space

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
This commit is contained in:
Jean-Jacques Hiblot 2018-01-04 15:23:31 +01:00 committed by Jaehoon Chung
parent baef2070a4
commit 58a6fb7b04

View File

@ -1940,6 +1940,17 @@ static int mmc_startup_v4(struct mmc *mmc)
u64 capacity;
bool has_parts = false;
bool part_completed;
static const u32 mmc_versions[] = {
MMC_VERSION_4,
MMC_VERSION_4_1,
MMC_VERSION_4_2,
MMC_VERSION_4_3,
MMC_VERSION_4_41,
MMC_VERSION_4_5,
MMC_VERSION_5_0,
MMC_VERSION_5_1
};
ALLOC_CACHE_ALIGN_BUFFER(u8, ext_csd, MMC_MAX_BLOCK_LEN);
if (IS_SD(mmc) || (mmc->version < MMC_VERSION_4))
@ -1957,7 +1968,12 @@ static int mmc_startup_v4(struct mmc *mmc)
return -ENOMEM;
memcpy(mmc->ext_csd, ext_csd, MMC_MAX_BLOCK_LEN);
if (ext_csd[EXT_CSD_REV] >= 2) {
if (ext_csd[EXT_CSD_REV] > ARRAY_SIZE(mmc_versions))
return -EINVAL;
mmc->version = mmc_versions[ext_csd[EXT_CSD_REV]];
if (mmc->version >= MMC_VERSION_4_2) {
/*
* According to the JEDEC Standard, the value of
* ext_csd's capacity is valid if the value is more
@ -1972,30 +1988,6 @@ static int mmc_startup_v4(struct mmc *mmc)
mmc->capacity_user = capacity;
}
switch (ext_csd[EXT_CSD_REV]) {
case 1:
mmc->version = MMC_VERSION_4_1;
break;
case 2:
mmc->version = MMC_VERSION_4_2;
break;
case 3:
mmc->version = MMC_VERSION_4_3;
break;
case 5:
mmc->version = MMC_VERSION_4_41;
break;
case 6:
mmc->version = MMC_VERSION_4_5;
break;
case 7:
mmc->version = MMC_VERSION_5_0;
break;
case 8:
mmc->version = MMC_VERSION_5_1;
break;
}
/* The partition data may be non-zero but it is only
* effective if PARTITION_SETTING_COMPLETED is set in
* EXT_CSD, so ignore any data if this bit is not set,