From 178d20b9c90e5dcafa6f6d32289c678be306f6e5 Mon Sep 17 00:00:00 2001 From: Zhongfu Luo Date: Fri, 13 Jul 2018 18:21:59 +0800 Subject: [PATCH] unifykey: fix bug for read/write efuse key PD#168551: need to use unifykey to read/write efuse key 1.fix efuse config name to CONFIG_AMLOGIC_EFUSE 2.add correct efuse key read funciton Change-Id: I415f1b68d5de090220b1bd96db299452af176626 Signed-off-by: Zhongfu Luo --- drivers/amlogic/efuse/efuse64.c | 49 +++++++++++++++++++++++++++++ drivers/amlogic/unifykey/unifykey.c | 12 +++---- include/linux/amlogic/efuse.h | 1 + 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/drivers/amlogic/efuse/efuse64.c b/drivers/amlogic/efuse/efuse64.c index de552e7ec680..f1a5c7a4cd30 100644 --- a/drivers/amlogic/efuse/efuse64.c +++ b/drivers/amlogic/efuse/efuse64.c @@ -309,6 +309,11 @@ ssize_t efuse_user_attr_store(char *name, const char *buf, size_t count) } local_buf = kzalloc(sizeof(char)*(count), GFP_KERNEL); + if (!local_buf) { + ret = -ENOMEM; + pr_err("efuse: failed to allocate memory!\n"); + return ret; + } memcpy(local_buf, buf, count); @@ -367,6 +372,12 @@ ssize_t efuse_user_attr_show(char *name, char *buf) } local_buf = kzalloc(sizeof(char)*(info.size), GFP_KERNEL); + if (!local_buf) { + ret = -ENOMEM; + pr_err("efuse: failed to allocate memory!\n"); + return ret; + } + memset(local_buf, 0, info.size); pos = ((loff_t)(info.offset)) & 0xffffffff; @@ -394,6 +405,44 @@ error_exit: return ret; } +ssize_t efuse_user_attr_read(char *name, char *buf) +{ + char *local_buf; + ssize_t ret; + struct efusekey_info info; + loff_t pos; + + if (efuse_getinfo(name, &info) < 0) { + pr_err("%s is not found\n", name); + return -EFAULT; + } + + local_buf = kzalloc(sizeof(char)*(info.size), GFP_KERNEL); + if (!local_buf) { + ret = -ENOMEM; + pr_err("efuse: failed to allocate memory!\n"); + return ret; + } + + memset(local_buf, 0, info.size); + + pos = ((loff_t)(info.offset)) & 0xffffffff; + ret = efuse_read_usr(local_buf, info.size, &pos); + if (ret == -1) { + pr_err("ERROR: efuse read user data fail!\n"); + goto error_exit; + } + if (ret != info.size) + pr_err("ERROR: read %zd byte(s) not %d byte(s) data\n", + ret, info.size); + + memcpy(buf, local_buf, info.size); + +error_exit: + kfree(local_buf); + return ret; +} + static ssize_t userdata_show(struct class *cla, struct class_attribute *attr, char *buf) { diff --git a/drivers/amlogic/unifykey/unifykey.c b/drivers/amlogic/unifykey/unifykey.c index 74ca4ae0773e..0f602b2edf8f 100644 --- a/drivers/amlogic/unifykey/unifykey.c +++ b/drivers/amlogic/unifykey/unifykey.c @@ -283,7 +283,7 @@ static int key_efuse_init(struct key_info_t *uk_info, static int key_efuse_write(char *keyname, unsigned char *keydata, unsigned int datalen) { -#ifdef CONFIG_EFUSE +#if defined(CONFIG_ARM64) && defined(CONFIG_AMLOGIC_EFUSE) char *title = keyname; struct efusekey_info info; @@ -306,7 +306,7 @@ static int key_efuse_write(char *keyname, unsigned char *keydata, static int key_efuse_read(char *keyname, unsigned char *keydata, unsigned int datalen, unsigned int *reallen) { -#ifdef CONFIG_EFUSE +#if defined(CONFIG_ARM64) && defined(CONFIG_AMLOGIC_EFUSE) char *title = keyname; struct efusekey_info info; int err = 0; @@ -320,7 +320,7 @@ static int key_efuse_read(char *keyname, unsigned char *keydata, return -ENOMEM; memset(buf, 0, info.size); - err = efuse_user_attr_show(title, buf); + err = efuse_user_attr_read(title, buf); if (err >= 0) { *reallen = info.size; if (datalen > info.size) @@ -337,7 +337,7 @@ static int key_efuse_read(char *keyname, unsigned char *keydata, static int key_efuse_query(char *keyname, unsigned int *keystate) { int err = -EINVAL; -#ifdef CONFIG_EFUSE +#if defined(CONFIG_ARM64) && defined(CONFIG_AMLOGIC_EFUSE) int i; char *title = keyname; struct efusekey_info info; @@ -351,7 +351,7 @@ static int key_efuse_query(char *keyname, unsigned int *keystate) return -ENOMEM; } memset(buf, 0, info.size); - err = efuse_user_attr_show(title, buf); + err = efuse_user_attr_read(title, buf); *keystate = KEY_NO_EXIST; if (err > 0) { for (i = 0; i < info.size; i++) { @@ -543,7 +543,7 @@ int key_unify_size(struct aml_unifykey_dev *ukdev, if (unifykey->permit & KEY_M_PERMIT_READ) { switch (unifykey->dev) { -#ifdef CONFIG_EFUSE +#if defined(CONFIG_ARM64) && defined(CONFIG_AMLOGIC_EFUSE) case KEY_M_EFUSE: { struct efusekey_info info; diff --git a/include/linux/amlogic/efuse.h b/include/linux/amlogic/efuse.h index 11f20be00cae..4e51fd6852c3 100644 --- a/include/linux/amlogic/efuse.h +++ b/include/linux/amlogic/efuse.h @@ -30,6 +30,7 @@ extern int efusekeynum; int efuse_getinfo(char *item, struct efusekey_info *info); ssize_t efuse_user_attr_show(char *name, char *buf); ssize_t efuse_user_attr_store(char *name, const char *buf, size_t count); +ssize_t efuse_user_attr_read(char *name, char *buf); #else int efuse_read_intlItem(char *intl_item, char *buf, int size); #endif -- 2.20.1