diff --git a/env/fat.c b/env/fat.c index b04b1d9c315..1ad301eaaff 100644 --- a/env/fat.c +++ b/env/fat.c @@ -41,14 +41,12 @@ __weak const char *env_fat_get_intf(void) __weak char *env_fat_get_dev_part(void) { #ifdef CONFIG_MMC - static char *part_str; + /* reserve one more char for the manipulation below */ + static char part_str[] = CONFIG_ENV_FAT_DEVICE_AND_PART "\0"; - if (!part_str) { - part_str = CONFIG_ENV_FAT_DEVICE_AND_PART; - if (!strcmp(CONFIG_ENV_FAT_INTERFACE, "mmc") && part_str[0] == ':') { - part_str = "0" CONFIG_ENV_FAT_DEVICE_AND_PART; - part_str[0] += mmc_get_env_dev(); - } + if (!strcmp(CONFIG_ENV_FAT_INTERFACE, "mmc") && part_str[0] == ':') { + part_str[0] = '0' + mmc_get_env_dev(); + strcpy(&part_str[1], CONFIG_ENV_FAT_DEVICE_AND_PART); } return part_str;