Commit 7e928263 authored by Miquel Raynal's avatar Miquel Raynal

mtd: rawnand: onfi: Avoid doing a copy of the parameter page

There is no need for copying the parameter page, playing with
pointers does the trick.

There is not functional change.
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: default avatarBoris Brezillon <boris.brezillon@collabora.com>
Link: https://lore.kernel.org/linux-mtd/20200428094302.14624-7-miquel.raynal@bootlin.com
parent dacd1a12
...@@ -143,7 +143,7 @@ int nand_onfi_detect(struct nand_chip *chip) ...@@ -143,7 +143,7 @@ int nand_onfi_detect(struct nand_chip *chip)
{ {
struct mtd_info *mtd = nand_to_mtd(chip); struct mtd_info *mtd = nand_to_mtd(chip);
struct nand_memory_organization *memorg; struct nand_memory_organization *memorg;
struct nand_onfi_params *p; struct nand_onfi_params *p = NULL, *pbuf;
struct onfi_params *onfi; struct onfi_params *onfi;
int onfi_version = 0; int onfi_version = 0;
char id[4]; char id[4];
...@@ -158,8 +158,8 @@ int nand_onfi_detect(struct nand_chip *chip) ...@@ -158,8 +158,8 @@ int nand_onfi_detect(struct nand_chip *chip)
return 0; return 0;
/* ONFI chip: allocate a buffer to hold its parameter page */ /* ONFI chip: allocate a buffer to hold its parameter page */
p = kzalloc((sizeof(*p) * ONFI_PARAM_PAGES), GFP_KERNEL); pbuf = kzalloc((sizeof(*pbuf) * ONFI_PARAM_PAGES), GFP_KERNEL);
if (!p) if (!pbuf)
return -ENOMEM; return -ENOMEM;
ret = nand_read_param_page_op(chip, 0, NULL, 0); ret = nand_read_param_page_op(chip, 0, NULL, 0);
...@@ -169,16 +169,15 @@ int nand_onfi_detect(struct nand_chip *chip) ...@@ -169,16 +169,15 @@ int nand_onfi_detect(struct nand_chip *chip)
} }
for (i = 0; i < ONFI_PARAM_PAGES; i++) { for (i = 0; i < ONFI_PARAM_PAGES; i++) {
ret = nand_read_data_op(chip, &p[i], sizeof(*p), true); ret = nand_read_data_op(chip, &pbuf[i], sizeof(*pbuf), true);
if (ret) { if (ret) {
ret = 0; ret = 0;
goto free_onfi_param_page; goto free_onfi_param_page;
} }
crc = onfi_crc16(ONFI_CRC_BASE, (u8 *)&p[i], 254); crc = onfi_crc16(ONFI_CRC_BASE, (u8 *)&pbuf[i], 254);
if (crc == le16_to_cpu(p[i].crc)) { if (crc == le16_to_cpu(pbuf[i].crc)) {
if (i) p = &pbuf[i];
memcpy(p, &p[i], sizeof(*p));
break; break;
} }
} }
...@@ -188,17 +187,18 @@ int nand_onfi_detect(struct nand_chip *chip) ...@@ -188,17 +187,18 @@ int nand_onfi_detect(struct nand_chip *chip)
unsigned int j; unsigned int j;
for (j = 0; j < ONFI_PARAM_PAGES; j++) for (j = 0; j < ONFI_PARAM_PAGES; j++)
srcbufs[j] = p + j; srcbufs[j] = pbuf + j;
pr_warn("Could not find a valid ONFI parameter page, trying bit-wise majority to recover it\n"); pr_warn("Could not find a valid ONFI parameter page, trying bit-wise majority to recover it\n");
nand_bit_wise_majority(srcbufs, ONFI_PARAM_PAGES, p, nand_bit_wise_majority(srcbufs, ONFI_PARAM_PAGES, pbuf,
sizeof(*p)); sizeof(*pbuf));
crc = onfi_crc16(ONFI_CRC_BASE, (u8 *)p, 254); crc = onfi_crc16(ONFI_CRC_BASE, (u8 *)pbuf, 254);
if (crc != le16_to_cpu(p->crc)) { if (crc != le16_to_cpu(pbuf->crc)) {
pr_err("ONFI parameter recovery failed, aborting\n"); pr_err("ONFI parameter recovery failed, aborting\n");
goto free_onfi_param_page; goto free_onfi_param_page;
} }
p = pbuf;
} }
if (chip->manufacturer.desc && chip->manufacturer.desc->ops && if (chip->manufacturer.desc && chip->manufacturer.desc->ops &&
...@@ -306,14 +306,14 @@ int nand_onfi_detect(struct nand_chip *chip) ...@@ -306,14 +306,14 @@ int nand_onfi_detect(struct nand_chip *chip)
chip->parameters.onfi = onfi; chip->parameters.onfi = onfi;
/* Identification done, free the full ONFI parameter page and exit */ /* Identification done, free the full ONFI parameter page and exit */
kfree(p); kfree(pbuf);
return 1; return 1;
free_model: free_model:
kfree(chip->parameters.model); kfree(chip->parameters.model);
free_onfi_param_page: free_onfi_param_page:
kfree(p); kfree(pbuf);
return ret; return ret;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment