]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
media: venus: Limit HFI sessions to the maximum supported
authorStanimir Varbanov <stanimir.varbanov@linaro.org>
Fri, 4 Dec 2020 10:01:37 +0000 (11:01 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 2 May 2025 05:41:11 +0000 (07:41 +0200)
[ Upstream commit 20891170f339a8754312a877f3d17f0e5dadd599 ]

Currently we rely on firmware to return error when we reach the maximum
supported number of sessions. But this errors are happened at reqbuf
time which is a bit later. The more reasonable way looks like is to
return the error on driver open.

To achieve that modify hfi_session_create to return error when we reach
maximum count of sessions and thus refuse open.

Tested-by: Fritz Koenig <frkoenig@chromium.org>
Signed-off-by: Stanimir Varbanov <stanimir.varbanov@linaro.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Stable-dep-of: 9edaaa8e3e15 ("media: venus: hfi_parser: refactor hfi packet parsing logic")
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/media/platform/qcom/venus/core.h
drivers/media/platform/qcom/venus/hfi.c
drivers/media/platform/qcom/venus/hfi_parser.c

index 75d0068033276dcf086e86c6b66959f6329b4222..e56d7b8142152cd46612a51a011019ffaa4070a0 100644 (file)
@@ -96,6 +96,7 @@ struct venus_format {
 #define MAX_CAP_ENTRIES                32
 #define MAX_ALLOC_MODE_ENTRIES 16
 #define MAX_CODEC_NUM          32
+#define MAX_SESSIONS           16
 
 struct raw_formats {
        u32 buftype;
index 966b4d9b57a977cf909f92aa6dde53852e6a9d6d..17da555905e98f85f648ef6787223248bcdb9b49 100644 (file)
@@ -178,6 +178,8 @@ static int wait_session_msg(struct venus_inst *inst)
 int hfi_session_create(struct venus_inst *inst, const struct hfi_inst_ops *ops)
 {
        struct venus_core *core = inst->core;
+       bool max;
+       int ret;
 
        if (!ops)
                return -EINVAL;
@@ -187,11 +189,19 @@ int hfi_session_create(struct venus_inst *inst, const struct hfi_inst_ops *ops)
        inst->ops = ops;
 
        mutex_lock(&core->lock);
-       list_add_tail(&inst->list, &core->instances);
-       atomic_inc(&core->insts_count);
+
+       max = atomic_add_unless(&core->insts_count, 1,
+                               core->max_sessions_supported);
+       if (!max) {
+               ret = -EAGAIN;
+       } else {
+               list_add_tail(&inst->list, &core->instances);
+               ret = 0;
+       }
+
        mutex_unlock(&core->lock);
 
-       return 0;
+       return ret;
 }
 EXPORT_SYMBOL_GPL(hfi_session_create);
 
index 32d2a9ed44003d138f29cd44a73289e3ff180769..94981a5e8e9aff7759bdf23bb18b4229668af8ef 100644 (file)
@@ -295,6 +295,9 @@ u32 hfi_parser(struct venus_core *core, struct venus_inst *inst, void *buf,
                words_count--;
        }
 
+       if (!core->max_sessions_supported)
+               core->max_sessions_supported = MAX_SESSIONS;
+
        parser_fini(inst, codecs, domain);
 
        return HFI_ERR_NONE;