nand: fix nand key read issue
authoryi.zeng <yi.zeng@amlogic.com>
Thu, 17 Aug 2017 02:25:35 +0000 (10:25 +0800)
committerJianxin Pan <jianxin.pan@amlogic.com>
Mon, 28 Aug 2017 06:01:25 +0000 (23:01 -0700)
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>
drivers/amlogic/mtd/aml_key.c
drivers/amlogic/mtd/rsv_manage.c

index 0cc93ae..b738b2f 100644 (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;
index e80a19d..674c13c 100644 (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;