mirror of
git://nv-tegra.nvidia.com/linux-nv-oot.git
synced 2025-12-22 17:25:35 +03:00
crypto: open nvvse node only once during operation
open nvvse node only once during vse operation, if another thread try to open then return error. Bug 4075005 Change-Id: Iea88799bf761442cecc8e6336e9743e0fe7cd6e2 Signed-off-by: Manish Bhardwaj <mbhardwaj@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/2891721 Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com> Reviewed-by: svc-mobile-cert <svc-mobile-cert@nvidia.com> Reviewed-by: Advaya Andhare <aandhare@nvidia.com> Reviewed-by: Sandeep Trasi <strasi@nvidia.com> Reviewed-by: svcacv <svcacv@nvidia.com> GVS: Gerrit_Virtual_Submit <buildbot_gerritrpt@nvidia.com>
This commit is contained in:
committed by
mobile promotions
parent
15d1f96bd8
commit
e7075688b1
@@ -67,7 +67,11 @@
|
|||||||
#define NVVSE_MAX_ALLOCATED_SHA_RESULT_BUFF_SIZE 256U
|
#define NVVSE_MAX_ALLOCATED_SHA_RESULT_BUFF_SIZE 256U
|
||||||
|
|
||||||
#define MISC_DEVICE_NAME_LEN 32U
|
#define MISC_DEVICE_NAME_LEN 32U
|
||||||
static struct miscdevice *g_misc_devices[MAX_NUMBER_MISC_DEVICES];
|
|
||||||
|
struct nvvse_devnode {
|
||||||
|
struct miscdevice *g_misc_devices;
|
||||||
|
bool is_node_open;
|
||||||
|
} nvvse_devnode[MAX_NUMBER_MISC_DEVICES];
|
||||||
|
|
||||||
/* SHA Algorithm Names */
|
/* SHA Algorithm Names */
|
||||||
static const char *sha_alg_names[] = {
|
static const char *sha_alg_names[] = {
|
||||||
@@ -1797,11 +1801,31 @@ static int tnvvse_crypto_dev_open(struct inode *inode, struct file *filp)
|
|||||||
char root_path_buf[512];
|
char root_path_buf[512];
|
||||||
const char *root_path, *str;
|
const char *root_path, *str;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
uint32_t node_id;
|
||||||
|
|
||||||
|
/* get the node id from file name */
|
||||||
|
root_path = dentry_path_raw(filp->f_path.dentry, root_path_buf, sizeof(root_path_buf));
|
||||||
|
str = strrchr(root_path, '-');
|
||||||
|
if (str == NULL) {
|
||||||
|
pr_err("%s: invalid dev node name\n", __func__);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (kstrtou32(str+1, 10, &node_id)) {
|
||||||
|
pr_err("%s: invalid crypto dev instance passed\n", __func__);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nvvse_devnode[node_id].is_node_open) {
|
||||||
|
pr_err("%s: Trying to open already opened node. node_id %u\n", __func__, node_id);
|
||||||
|
return -EAGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
ctx = kzalloc(sizeof(struct tnvvse_crypto_ctx), GFP_KERNEL);
|
ctx = kzalloc(sizeof(struct tnvvse_crypto_ctx), GFP_KERNEL);
|
||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
ctx->node_id = node_id;
|
||||||
|
|
||||||
mutex_init(&ctx->lock);
|
mutex_init(&ctx->lock);
|
||||||
|
|
||||||
@@ -1819,27 +1843,11 @@ static int tnvvse_crypto_dev_open(struct inode *inode, struct file *filp)
|
|||||||
goto free_rng_buf;
|
goto free_rng_buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get the node id from file name */
|
|
||||||
root_path = dentry_path_raw(filp->f_path.dentry, root_path_buf, sizeof(root_path_buf));
|
|
||||||
str = strrchr(root_path, '-');
|
|
||||||
if (str == NULL) {
|
|
||||||
pr_err("%s: invalid dev node name\n", __func__);
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto free_sha_buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (kstrtou32(str+1, 10, &ctx->node_id)) {
|
|
||||||
pr_err("%s: invalid crypto dev instance passed\n", __func__);
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto free_sha_buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
filp->private_data = ctx;
|
filp->private_data = ctx;
|
||||||
|
nvvse_devnode[node_id].is_node_open = true;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
free_sha_buf:
|
|
||||||
kfree(ctx->sha_result);
|
|
||||||
free_rng_buf:
|
free_rng_buf:
|
||||||
kfree(ctx->rng_buff);
|
kfree(ctx->rng_buff);
|
||||||
free_mutex:
|
free_mutex:
|
||||||
@@ -1858,6 +1866,7 @@ static int tnvvse_crypto_dev_release(struct inode *inode, struct file *filp)
|
|||||||
kfree(ctx->rng_buff);
|
kfree(ctx->rng_buff);
|
||||||
kfree(ctx);
|
kfree(ctx);
|
||||||
filp->private_data = NULL;
|
filp->private_data = NULL;
|
||||||
|
nvvse_devnode[ctx->node_id].is_node_open = false;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -2154,17 +2163,17 @@ static int __init tnvvse_crypto_device_init(void)
|
|||||||
pr_err("%s: misc dev %u registeration failed err %d\n", __func__, cnt, ret);
|
pr_err("%s: misc dev %u registeration failed err %d\n", __func__, cnt, ret);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
g_misc_devices[cnt] = misc;
|
nvvse_devnode[cnt].g_misc_devices = misc;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
for (ctr = 0; ctr < cnt; ctr++) {
|
for (ctr = 0; ctr < cnt; ctr++) {
|
||||||
misc_deregister(g_misc_devices[ctr]);
|
misc_deregister(nvvse_devnode[ctr].g_misc_devices);
|
||||||
kfree(g_misc_devices[ctr]->name);
|
kfree(nvvse_devnode[ctr].g_misc_devices->name);
|
||||||
kfree(g_misc_devices[ctr]);
|
kfree(nvvse_devnode[ctr].g_misc_devices);
|
||||||
g_misc_devices[ctr] = NULL;
|
nvvse_devnode[ctr].g_misc_devices = NULL;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -2175,11 +2184,11 @@ static void __exit tnvvse_crypto_device_exit(void)
|
|||||||
uint32_t ctr;
|
uint32_t ctr;
|
||||||
|
|
||||||
for (ctr = 0; ctr < MAX_NUMBER_MISC_DEVICES; ctr++) {
|
for (ctr = 0; ctr < MAX_NUMBER_MISC_DEVICES; ctr++) {
|
||||||
if (g_misc_devices[ctr] != NULL) {
|
if (nvvse_devnode[ctr].g_misc_devices != NULL) {
|
||||||
misc_deregister(g_misc_devices[ctr]);
|
misc_deregister(nvvse_devnode[ctr].g_misc_devices);
|
||||||
kfree(g_misc_devices[ctr]->name);
|
kfree(nvvse_devnode[ctr].g_misc_devices->name);
|
||||||
kfree(g_misc_devices[ctr]);
|
kfree(nvvse_devnode[ctr].g_misc_devices);
|
||||||
g_misc_devices[ctr] = NULL;
|
nvvse_devnode[ctr].g_misc_devices = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user