diff options
author | Ruofei Ma <ruofeim@google.com> | 2022-04-25 17:15:49 -0700 |
---|---|---|
committer | Ruofei Ma <ruofeim@google.com> | 2022-05-13 22:06:27 +0000 |
commit | 1a4c201bca53689c4b10e1b73e4d1c72ffa01df2 (patch) | |
tree | dfc5e900f596a663c50997d509ced6b37b90e6b0 | |
parent | 115b7be27c38908612871f65673cdb09fdba76fd (diff) | |
download | gchips-1a4c201bca53689c4b10e1b73e4d1c72ffa01df2.tar.gz |
Move bigo_count_inst into critical section
Lock is needed when accessing core struct.
Bug: 231912091
Change-Id: Ie63352ca64df3469fb86121d621fda9dd37d66e6
Signed-off-by: Ruofei Ma <ruofeim@google.com>
-rw-r--r-- | bigo.c | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -132,12 +132,6 @@ static int bigo_open(struct inode *inode, struct file *file) struct bigo_core *core = container_of(inode->i_cdev, struct bigo_core, cdev); struct bigo_inst *inst; - if (bigo_count_inst(core) >= BIGO_MAX_INST_NUM) { - rc = -ENOMEM; - pr_err("Reaches max number of supported instances\n"); - goto err; - } - inst = kzalloc(sizeof(*inst), GFP_KERNEL); if (!inst) { rc = -ENOMEM; @@ -162,6 +156,12 @@ static int bigo_open(struct inode *inode, struct file *file) goto err_first_inst; } mutex_lock(&core->lock); + if (bigo_count_inst(core) >= BIGO_MAX_INST_NUM) { + rc = -ENOMEM; + pr_err("Reaches max number of supported instances\n"); + mutex_unlock(&core->lock); + goto err_inst_open; + } if (list_empty(&core->instances)) { rc = on_first_instance_open(core); if (rc) { |