summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuofei Ma <ruofeim@google.com>2022-04-25 17:15:49 -0700
committerRuofei Ma <ruofeim@google.com>2022-05-13 22:06:27 +0000
commit1a4c201bca53689c4b10e1b73e4d1c72ffa01df2 (patch)
treedfc5e900f596a663c50997d509ced6b37b90e6b0
parent115b7be27c38908612871f65673cdb09fdba76fd (diff)
downloadgchips-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.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/bigo.c b/bigo.c
index 38fc62d..24722ac 100644
--- a/bigo.c
+++ b/bigo.c
@@ -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) {