mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Gourav Kumar <gourav.kumar@oss.qualcomm.com>
To: Vikash Garodia <vikash.garodia@oss.qualcomm.com>,
	Dikshita Agarwal <dikshita.agarwal@oss.qualcomm.com>,
	Abhinav Kumar <abhinav.kumar@linux.dev>,
	Bryan O'Donoghue <bod@kernel.org>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Stefan Schmidt <stefan.schmidt@linaro.org>,
	Hans Verkuil <hverkuil@kernel.org>,
	Vedang Nagar <quic_vnagar@quicinc.com>,
	Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>,
	Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Cc: linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Bryan O'Donoghue <bryan.odonoghue@linaro.org>,
	Gourav Kumar <gourav.kumar@oss.qualcomm.com>,
	stable@vger.kernel.org
Subject: [PATCH 2/4] media: iris: Fix NULL dereference and leaks in the iris_open error handling
Date: Thu, 03 Dec 2026 15:52:06 +0530	[thread overview]
Message-ID: <20261203-iris-core-open-error-fixes-v1-2-c932ddcee73a@oss.qualcomm.com> (raw)
In-Reply-To: <20261203-iris-core-open-error-fixes-v1-0-c932ddcee73a@oss.qualcomm.com>

The decoder instance init uses the format structures right after
allocating them, without checking for NULL, so a failed allocation
crashes when a decoder node is opened. The open error paths also leak
memory. If the instance init fails after the formats were allocated,
they are not freed. If adding the session fails, the control handler is
not freed.

Return -ENOMEM when an allocation fails and free the control handler
and the formats on the error paths, in reverse order of setup. As open
now frees the formats, drop the free from the encoder instance init so
they are freed only once.

Cc: stable@vger.kernel.org
Fixes: 38fc8beaba55 ("media: iris: implement reqbuf ioctl with vb2_queue_setup")
Fixes: 33be1dde17e3 ("media: iris: implement iris v4l2_ctrl_ops")
Fixes: 397ebadcbc21 ("media: iris: reject open() when the session limit is reached")
Signed-off-by: Gourav Kumar <gourav.kumar@oss.qualcomm.com>
---
 drivers/media/platform/qcom/iris/iris_vdec.c | 2 ++
 drivers/media/platform/qcom/iris/iris_venc.c | 5 +----
 drivers/media/platform/qcom/iris/iris_vidc.c | 9 +++++----
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/media/platform/qcom/iris/iris_vdec.c b/drivers/media/platform/qcom/iris/iris_vdec.c
index 0dd33ff447bb0..2c7d173ebd0b8 100644
--- a/drivers/media/platform/qcom/iris/iris_vdec.c
+++ b/drivers/media/platform/qcom/iris/iris_vdec.c
@@ -24,6 +24,8 @@ int iris_vdec_inst_init(struct iris_inst *inst)
 
 	inst->fmt_src = kzalloc_obj(*inst->fmt_src);
 	inst->fmt_dst = kzalloc_obj(*inst->fmt_dst);
+	if (!inst->fmt_src || !inst->fmt_dst)
+		return -ENOMEM;
 
 	inst->fw_min_count = 0;
 
diff --git a/drivers/media/platform/qcom/iris/iris_venc.c b/drivers/media/platform/qcom/iris/iris_venc.c
index 2f2c56bf9122c..0be34d63ea022 100644
--- a/drivers/media/platform/qcom/iris/iris_venc.c
+++ b/drivers/media/platform/qcom/iris/iris_venc.c
@@ -22,11 +22,8 @@ int iris_venc_inst_init(struct iris_inst *inst)
 
 	inst->fmt_src = kzalloc_obj(*inst->fmt_src);
 	inst->fmt_dst = kzalloc_obj(*inst->fmt_dst);
-	if (!inst->fmt_src || !inst->fmt_dst) {
-		kfree(inst->fmt_src);
-		kfree(inst->fmt_dst);
+	if (!inst->fmt_src || !inst->fmt_dst)
 		return -ENOMEM;
-	}
 
 	f = inst->fmt_dst;
 	f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
diff --git a/drivers/media/platform/qcom/iris/iris_vidc.c b/drivers/media/platform/qcom/iris/iris_vidc.c
index 05aab6e3005d5..b99375d7138cf 100644
--- a/drivers/media/platform/qcom/iris/iris_vidc.c
+++ b/drivers/media/platform/qcom/iris/iris_vidc.c
@@ -221,20 +221,21 @@ int iris_open(struct file *filp)
 	else if (inst->domain == ENCODER)
 		ret = iris_venc_inst_init(inst);
 	if (ret)
-		goto fail_m2m_ctx_release;
+		goto fail_free_fmt;
 
 	ret = iris_add_session(inst);
 	if (ret)
-		goto fail_inst_deinit;
+		goto fail_free_ctrls;
 
 	inst->fh.m2m_ctx = inst->m2m_ctx;
 
 	return 0;
 
-fail_inst_deinit:
+fail_free_ctrls:
+	v4l2_ctrl_handler_free(&inst->ctrl_handler);
+fail_free_fmt:
 	kfree(inst->fmt_src);
 	kfree(inst->fmt_dst);
-fail_m2m_ctx_release:
 	v4l2_m2m_ctx_release(inst->m2m_ctx);
 fail_m2m_release:
 	v4l2_m2m_release(inst->m2m_dev);

-- 
2.34.1


  parent reply	other threads:[~2026-12-03 10:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 10:22 [PATCH 0/4] media: iris: Fix core init failure recovery and " Gourav Kumar
2026-12-03 10:22 ` [PATCH 1/4] media: iris: Tear the core down when the firmware does not become ready Gourav Kumar
2026-12-03 10:22 ` Gourav Kumar [this message]
2026-12-03 10:22 ` [PATCH 3/4] media: iris: Return the real error when the m2m setup in iris_open fails Gourav Kumar
2026-12-03 10:22 ` [PATCH 4/4] media: iris: Drop duplicate defines Gourav Kumar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261203-iris-core-open-error-fixes-v1-2-c932ddcee73a@oss.qualcomm.com \
    --to=gourav.kumar@oss.qualcomm.com \
    --cc=abhinav.kumar@linux.dev \
    --cc=bod@kernel.org \
    --cc=bryan.odonoghue@linaro.org \
    --cc=dikshita.agarwal@oss.qualcomm.com \
    --cc=dmitry.baryshkov@oss.qualcomm.com \
    --cc=hverkuil@kernel.org \
    --cc=konrad.dybcio@oss.qualcomm.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=quic_vnagar@quicinc.com \
    --cc=stable@vger.kernel.org \
    --cc=stefan.schmidt@linaro.org \
    --cc=vikash.garodia@oss.qualcomm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®