diff --git a/drivers/mtd/spiflash/spi020_nand.c b/drivers/mtd/spiflash/spi020_nand.c index 8ae3c8f081..36da5276cd 100644 --- a/drivers/mtd/spiflash/spi020_nand.c +++ b/drivers/mtd/spiflash/spi020_nand.c @@ -383,6 +383,7 @@ static struct nand_flash_dev spinand_flash_ids[] = { {"DS35Q1GA 1GiB 3.3V", { .id = {MFG_ID_DOSILICON, 0x71} }, SZ_2K, SZ_128, SZ_128K, 0, 2, 64 }, + { NULL } }; #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) @@ -673,7 +674,7 @@ static int drv_nand_read_id(struct drv_nand_dev_info *info, uint32_t *id) pr_debug("id = 0x%02x 0x%02x 0x%02x 0x%02x\n", card_id[0], card_id[1], card_id[2], card_id[3]); - for (i = 0; i < ARRAY_SIZE(spinand_flash_ids); i++) { + for (i = 0; spinand_flash_ids[i].name; i++) { if ((card_id[0] == spinand_flash_ids[i].mfr_id) && \ (card_id[1] == spinand_flash_ids[i].dev_id)) { id_count = spinand_flash_ids[i].id_len; @@ -681,10 +682,16 @@ static int drv_nand_read_id(struct drv_nand_dev_info *info, uint32_t *id) break; } } - *id = card_id[0] | (card_id[1] << 8) | (card_id[2] << 16) | \ - (card_id[3] << 24); - - ret = E_OK; + if (spinand_flash_ids[i].name) { + *id = card_id[0] | (card_id[1] << 8) | + (card_id[2] << 16) | (card_id[3] << 24); + ret = E_OK; + } else { + dev_err(&info->pdev->dev, + "flash ID 0x%02x 0x%02x is not in the ID table\n", + card_id[0], card_id[1]); + ret = -ENODEV; + } } mutex_unlock(&info->lock); @@ -1193,7 +1200,6 @@ static int spinand_probe(struct platform_device *pdev) kfree(info->data_buff); fail_free_mtd: - kfree(mtd); return ret; } diff --git a/drivers/mtd/spiflash/spinand.c b/drivers/mtd/spiflash/spinand.c index 06e679f907..84775b382e 100644 --- a/drivers/mtd/spiflash/spinand.c +++ b/drivers/mtd/spiflash/spinand.c @@ -435,6 +435,7 @@ static struct nand_flash_dev spinand_flash_ids[] = { {"F35SQA512M 512Mbit 3.3V", { .id = {MFG_ID_FORESEE, 0x70} }, SZ_2K, SZ_64, SZ_128K, 0, 2, 64 }, + { NULL } }; #ifdef CONFIG_MTD_SPINAND_HWECC @@ -839,7 +840,7 @@ static int drv_nand_read_id(struct drv_nand_dev_info *info, uint32_t *id) pr_debug("id = 0x%02x 0x%02x 0x%02x 0x%02x\n", card_id[0], card_id[1], card_id[2], card_id[3]); - for (i = 0; i < ARRAY_SIZE(spinand_flash_ids); i++) { + for (i = 0; spinand_flash_ids[i].name; i++) { if ((card_id[0] == spinand_flash_ids[i].mfr_id) && \ (card_id[1] == spinand_flash_ids[i].dev_id)) { id_count = spinand_flash_ids[i].id_len; @@ -853,10 +854,16 @@ static int drv_nand_read_id(struct drv_nand_dev_info *info, uint32_t *id) break; } } - *id = card_id[0] | (card_id[1] << 8) | (card_id[2] << 16) | \ - (card_id[3] << 24); - - ret = E_OK; + if (spinand_flash_ids[i].name) { + *id = card_id[0] | (card_id[1] << 8) | + (card_id[2] << 16) | (card_id[3] << 24); + ret = E_OK; + } else { + dev_err(&info->pdev->dev, + "flash ID 0x%02x 0x%02x is not in the ID table\n", + card_id[0], card_id[1]); + ret = -ENODEV; + } } mutex_unlock(&info->lock); @@ -1445,7 +1452,6 @@ static int spinand_probe(struct platform_device *pdev) kfree(info->data_buff); fail_free_mtd: - kfree(mtd); return ret; }