nand: fix nand key read issue

PD#146835: nand: fix the nand key read issue caused by overload memory

Change-Id: I53ce06da8ddf5f691898a7546b1b96bb9af486cd
Signed-off-by: yi.zeng <yi.zeng@amlogic.com>
This commit is contained in:
yi.zeng
2017-08-17 10:25:35 +08:00
committed by Jianxin Pan
parent 3ad6cafbff
commit 14ffc2f9d8
2 changed files with 10 additions and 7 deletions

View File

@@ -30,7 +30,7 @@ static struct aml_nand_chip *aml_chip_key;
int32_t amlnf_key_read(uint8_t *buf, uint32_t len, uint32_t *actual_length)
{
struct aml_nand_chip *aml_chip = aml_chip_key;
struct nand_menson_key *key_ptr = NULL;
uint8_t *key_ptr = NULL;
u32 keysize = aml_chip->keysize - sizeof(u32);
size_t offset = 0;
struct mtd_info *mtd = aml_chip->mtd;
@@ -57,9 +57,8 @@ int32_t amlnf_key_read(uint8_t *buf, uint32_t len, uint32_t *actual_length)
if (key_ptr == NULL)
return -ENOMEM;
aml_nand_read_key(mtd, offset, (u8 *)key_ptr->data);
memcpy(buf, key_ptr->data, keysize);
aml_nand_read_key(mtd, offset, key_ptr);
memcpy(buf, key_ptr, keysize);
kfree(key_ptr);
return 0;
@@ -72,10 +71,11 @@ int32_t amlnf_key_write(uint8_t *buf, uint32_t len, uint32_t *actual_length)
{
struct aml_nand_chip *aml_chip = aml_chip_key;
struct mtd_info *mtd = aml_chip->mtd;
struct nand_menson_key *key_ptr = NULL;
uint8_t *key_ptr = NULL;
u32 keysize = aml_chip->keysize - sizeof(u32);
int error = 0;
*actual_length = keysize;
if (aml_chip == NULL) {
pr_info("%s(): amlnf key not ready yet!", __func__);
return -EFAULT;
@@ -94,8 +94,9 @@ int32_t amlnf_key_write(uint8_t *buf, uint32_t len, uint32_t *actual_length)
if (key_ptr == NULL)
return -ENOMEM;
memcpy(key_ptr->data + 0, buf, keysize);
aml_nand_save_key(mtd, buf);
memset(key_ptr, 0, aml_chip->keysize);
memcpy(key_ptr, buf, keysize);
error = aml_nand_save_key(mtd, key_ptr);
kfree(key_ptr);
return error;

View File

@@ -470,6 +470,7 @@ int aml_nand_read_rsv_info(struct mtd_info *mtd,
#endif
/* if(data_buf) */
/* kfree(data_buf); */
return 0;
}
@@ -499,6 +500,7 @@ int aml_nand_read_key(struct mtd_info *mtd, size_t offset, u_char *buf)
aml_chip->aml_nandkey_info->name);
return 1;
}
if (aml_nand_read_rsv_info(mtd,
aml_chip->aml_nandkey_info, offset, (u_char *)buf))
return 1;