summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuofei Ma <ruofeim@google.com>2022-04-12 15:19:12 -0700
committerRuofei Ma <ruofeim@google.com>2022-04-12 15:20:03 -0700
commit5036de9318c5ebe18636fc78b1c9103e28024db4 (patch)
treefbc5d17e50ae1de811bf4e2e28e53b2f09bad7ef
parent21acc5540fac61831d31328ea92765a67b32cbce (diff)
downloadgchips-5036de9318c5ebe18636fc78b1c9103e28024db4.tar.gz
PRO: Limit the number of instances
Limit the max number of instances in BO kernel driver to 16. Bug: 226540966 Change-Id: I3f343e3a1f1d9345ad4ba470fc863dd94a214fb7 Signed-off-by: Ruofei Ma <ruofeim@google.com>
-rw-r--r--bigo.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/bigo.c b/bigo.c
index f8295a8..8895c81 100644
--- a/bigo.c
+++ b/bigo.c
@@ -35,6 +35,7 @@
#define DEFAULT_HEIGHT 2160
#define DEFAULT_FPS 60
#define BIGO_SMC_ID 0xd
+#define BIGO_MAX_INST_NUM 16
static int bigo_worker_thread(void *data);
@@ -119,12 +120,29 @@ static inline void on_last_inst_close(struct bigo_core *core)
pr_err("failed to stop worker thread rc = %d\n", rc);
}
+static inline int bigo_count_inst(struct bigo_core *core)
+{
+ int count = 0;
+ struct list_head *pos;
+
+ list_for_each(pos, &core->instances)
+ count++;
+
+ return count;
+}
+
static int bigo_open(struct inode *inode, struct file *file)
{
int rc = 0;
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;