X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=drivers%2Fmtd%2Fnand%2Fnand.c;h=6aa909fdd9751b3b5a853d7b70c8d5e977fe28ea;hb=c7c553f249f99ae282f1fa5c0e314aae0bce8a26;hp=168bac6055dea6be0b64ebcac20c0136f3e15bab;hpb=203db38a94a424bb1ab6a91e85148e8a8ea795d0;p=oweals%2Fu-boot.git diff --git a/drivers/mtd/nand/nand.c b/drivers/mtd/nand/nand.c index 168bac6055..6aa909fdd9 100644 --- a/drivers/mtd/nand/nand.c +++ b/drivers/mtd/nand/nand.c @@ -19,8 +19,7 @@ DECLARE_GLOBAL_DATA_PTR; int nand_curr_device = -1; - -struct mtd_info *nand_info[CONFIG_SYS_MAX_NAND_DEVICE]; +static struct mtd_info *nand_info[CONFIG_SYS_MAX_NAND_DEVICE]; #ifndef CONFIG_SYS_NAND_SELF_INIT static struct nand_chip nand_chip[CONFIG_SYS_MAX_NAND_DEVICE]; @@ -31,12 +30,21 @@ static char dev_name[CONFIG_SYS_MAX_NAND_DEVICE][8]; static unsigned long total_nand_size; /* in kiB */ +struct mtd_info *get_nand_dev_by_index(int dev) +{ + if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE || !nand_info[dev] || + !nand_info[dev]->name) + return NULL; + + return nand_info[dev]; +} + int nand_mtd_to_devnum(struct mtd_info *mtd) { int i; - for (i = 0; i < ARRAY_SIZE(nand_info); i++) { - if (mtd && nand_info[i] == mtd) + for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) { + if (mtd && get_nand_dev_by_index(i) == mtd) return i; } @@ -101,8 +109,9 @@ static void create_mtd_concat(void) int i; for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) { - if (nand_info[i] != NULL) { - nand_info_list[nand_devices_found] = nand_info[i]; + struct mtd_info *mtd = get_nand_dev_by_index(i); + if (mtd != NULL) { + nand_info_list[nand_devices_found] = mtd; nand_devices_found++; } } @@ -161,7 +170,7 @@ void nand_init(void) /* * Select the chip in the board/cpu specific driver */ - board_nand_select_device(mtd_to_nand(nand_info[nand_curr_device]), + board_nand_select_device(mtd_to_nand(get_nand_dev_by_index(nand_curr_device)), nand_curr_device); #endif