|
@@ -5101,7 +5101,7 @@ ext_out:
|
|
|
static int nand_flash_detect_onfi(struct nand_chip *chip)
|
|
|
{
|
|
|
struct mtd_info *mtd = nand_to_mtd(chip);
|
|
|
- struct nand_onfi_params *p = &chip->onfi_params;
|
|
|
+ struct nand_onfi_params *p;
|
|
|
char id[4];
|
|
|
int i, ret, val;
|
|
|
|
|
@@ -5110,14 +5110,23 @@ static int nand_flash_detect_onfi(struct nand_chip *chip)
|
|
|
if (ret || strncmp(id, "ONFI", 4))
|
|
|
return 0;
|
|
|
|
|
|
+ /* ONFI chip: allocate a buffer to hold its parameter page */
|
|
|
+ p = kzalloc(sizeof(*p), GFP_KERNEL);
|
|
|
+ if (!p)
|
|
|
+ return -ENOMEM;
|
|
|
+
|
|
|
ret = nand_read_param_page_op(chip, 0, NULL, 0);
|
|
|
- if (ret)
|
|
|
- return 0;
|
|
|
+ if (ret) {
|
|
|
+ ret = 0;
|
|
|
+ goto free_onfi_param_page;
|
|
|
+ }
|
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
ret = nand_read_data_op(chip, p, sizeof(*p), true);
|
|
|
- if (ret)
|
|
|
- return 0;
|
|
|
+ if (ret) {
|
|
|
+ ret = 0;
|
|
|
+ goto free_onfi_param_page;
|
|
|
+ }
|
|
|
|
|
|
if (onfi_crc16(ONFI_CRC_BASE, (uint8_t *)p, 254) ==
|
|
|
le16_to_cpu(p->crc)) {
|
|
@@ -5127,7 +5136,7 @@ static int nand_flash_detect_onfi(struct nand_chip *chip)
|
|
|
|
|
|
if (i == 3) {
|
|
|
pr_err("Could not find valid ONFI parameter page; aborting\n");
|
|
|
- return 0;
|
|
|
+ goto free_onfi_param_page;
|
|
|
}
|
|
|
|
|
|
/* Check version */
|
|
@@ -5145,7 +5154,9 @@ static int nand_flash_detect_onfi(struct nand_chip *chip)
|
|
|
|
|
|
if (!chip->parameters.onfi.version) {
|
|
|
pr_info("unsupported ONFI version: %d\n", val);
|
|
|
- return 0;
|
|
|
+ goto free_onfi_param_page;
|
|
|
+ } else {
|
|
|
+ ret = 1;
|
|
|
}
|
|
|
|
|
|
sanitize_string(p->manufacturer, sizeof(p->manufacturer));
|
|
@@ -5217,7 +5228,9 @@ static int nand_flash_detect_onfi(struct nand_chip *chip)
|
|
|
memcpy(chip->parameters.onfi.vendor, p->vendor,
|
|
|
sizeof(p->vendor));
|
|
|
|
|
|
- return 1;
|
|
|
+free_onfi_param_page:
|
|
|
+ kfree(p);
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -5612,7 +5625,10 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)
|
|
|
chip->parameters.onfi.version = 0;
|
|
|
if (!type->name || !type->pagesize) {
|
|
|
/* Check if the chip is ONFI compliant */
|
|
|
- if (nand_flash_detect_onfi(chip))
|
|
|
+ ret = nand_flash_detect_onfi(chip);
|
|
|
+ if (ret < 0)
|
|
|
+ return ret;
|
|
|
+ else if (ret)
|
|
|
goto ident_done;
|
|
|
|
|
|
/* Check if the chip is JEDEC compliant */
|