media: iris: Fix core init failure recovery and iris_open error handling
Subsystems (5)
cover media: iris: Fix core init failure recovery and iris_open error handling
This series fixes a few issues in the iris driver when the core is brought up and an instance is created in open.
1. Tear the core down when the firmware does not become ready in time, so the next open starts from a clean state.
2. Fix a NULL dereference and memory leaks on the iris_open error paths.
3. Return the real error when the m2m setup in iris_open fails.
4. Drop duplicate defines.
---
Gourav Kumar (4):
media: iris: Tear the core down when the firmware does not become ready
media: iris: Fix NULL dereference and leaks in the iris_open error handling
media: iris: Return the real error when the m2m setup in iris_open fails
media: iris: Drop duplicate defines
drivers/media/platform/qcom/iris/iris_buffer.c | 3 --- drivers/media/platform/qcom/iris/iris_core.c | 6 +++++- 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 | 17 +++++++++-------- drivers/media/platform/qcom/iris/iris_vpu_buffer.h | 6 ------ 6 files changed, 17 insertions(+), 22 deletions(-)
---
base-commit: 799dd936553182df5770dde7f38d94c8337df75a
change-id: 20261130-iris-core-open-error-fixes-f6c32d92aa22
Best regards,
Signature · 1 line
Gourav Kumar <[email protected]>
PATCH 1/4 media: iris: Tear the core down when the firmware does not become ready
If the firmware does not report ready in time, core init returns an error but leaves the core powered, with the firmware loaded and the queues allocated, and the state set to error. The next open only resets the state, and the one after that repeats the whole initialisation on top of the old one. The queue DMA buffers are leaked, clocks and power domains are enabled twice, and the firmware is loaded again while it is still running.
Deinitialise the core when the wait fails, so that the next open starts from a clean state.
--- drivers/media/platform/qcom/iris/iris_core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/media/platform/qcom/iris/iris_core.c +5 -1
@@ -98,7 +98,11 @@ int iris_core_init(struct iris_core *core)mutex_unlock (&core->lock); -return iris_wait_for_system_response (core); + ret =iris_wait_for_system_response (core); +if (ret) +iris_core_deinit (core); + +return ret; error_unload_fw:iris_fw_unload (core);
Signature · 1 line
2.34.1
PATCH 2/4 media: iris: Fix NULL dereference and leaks in the iris_open error handling
In reply to Gourav KumarThe 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.
--- 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(-)
drivers/media/platform/qcom/iris/iris_vdec.c +2 -0
@@ -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 ;
drivers/media/platform/qcom/iris/iris_venc.c +1 -4
@@ -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 ;
drivers/media/platform/qcom/iris/iris_vidc.c +5 -4
@@ -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);
Signature · 1 line
2.34.1
PATCH 3/4 media: iris: Return the real error when the m2m setup in iris_open fails
In reply to Gourav KumarCreating the m2m device and context returns an ERR_PTR() carrying the reason for the failure, but open replaces it with -EINVAL. User space therefore cannot tell an out-of-memory condition from an invalid request, and may treat a transient failure as a programming error.
Neither function returns NULL, so use IS_ERR() instead of IS_ERR_OR_NULL() and return the error from the pointer.
--- drivers/media/platform/qcom/iris/iris_vidc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/media/platform/qcom/iris/iris_vidc.c +4 -4
@@ -205,14 +205,14 @@ int iris_open(struct file *filp)iris_v4l2_fh_init (inst, filp); inst->m2m_dev =v4l2_m2m_init (&iris_m2m_ops); -if (IS_ERR_OR_NULL (inst->m2m_dev)) { - ret = -EINVAL ; +if (IS_ERR (inst->m2m_dev)) { + ret =PTR_ERR (inst->m2m_dev); goto fail_v4l2_fh_deinit; } inst->m2m_ctx =v4l2_m2m_ctx_init (inst->m2m_dev, inst, iris_m2m_queue_init); -if (IS_ERR_OR_NULL (inst->m2m_ctx)) { - ret = -EINVAL ; +if (IS_ERR (inst->m2m_ctx)) { + ret =PTR_ERR (inst->m2m_ctx); goto fail_m2m_release; }
Signature · 1 line
2.34.1
PATCH 4/4 media: iris: Drop duplicate defines
In reply to Gourav KumarSeveral defines are defined twice with the same value, either within iris_vpu_buffer.h or again in iris_buffer.c, which already includes that header.
Remove the second definitions. No functional change.
--- drivers/media/platform/qcom/iris/iris_buffer.c | 3 --- drivers/media/platform/qcom/iris/iris_vpu_buffer.h | 6 ------ 2 files changed, 9 deletions(-)
drivers/media/platform/qcom/iris/iris_buffer.c +0 -3
@@ -12,8 +12,6 @@#include "iris_vpu_buffer.h" #define PIXELS_4K 4096 -#define MAX_WIDTH 4096 -#define MAX_HEIGHT 2304#define Y_STRIDE_ALIGN 128#define Y_STRIDE_ALIGN_P010 256#define UV_STRIDE_ALIGN 128
@@ -24,7 +22,6 @@#define UV_SCANLINE_ALIGN_QC08C 32#define META_STRIDE_ALIGNED 64#define META_SCANLINE_ALIGNED 16 -#define NUM_MBS_4K (DIV_ROUND_UP(MAX_WIDTH, 16) * DIV_ROUND_UP(MAX_HEIGHT, 16))/* * NV12:
drivers/media/platform/qcom/iris/iris_vpu_buffer.h +0 -6
@@ -106,7 +106,6 @@ struct iris_inst;#define MAX_PE_NBR_DATA_LCU16_LINE_BUFFER_SIZE 96#define MAX_PE_NBR_DATA_LCU32_LINE_BUFFER_SIZE 192 -#define MAX_FE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE 64#define MAX_SE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE 16#define MAX_PE_NBR_DATA_LCU64_LINE_BUFFER_SIZE 384#define MAX_PE_NBR_DATA_LCU64_LINE_BUFFER_SIZE_AR50LT 176
@@ -117,8 +116,6 @@ struct iris_inst;#define AV1D_LCU_MAX_SIZE_PELS 128#define AV1D_LCU_MIN_SIZE_PELS 64#define AV1D_MAX_TILE_COLS 64 -#define MAX_PE_NBR_DATA_LCU32_LINE_BUFFER_SIZE 192 -#define MAX_PE_NBR_DATA_LCU16_LINE_BUFFER_SIZE 96#define AV1D_NUM_HW_PIC_BUF 16#define AV1D_NUM_FRAME_HEADERS 16#define SIZE_AV1D_SEQUENCE_HEADER 768
@@ -155,9 +152,6 @@ struct iris_inst;#define BITS_PER_PIX 16#define NUM_LINES_LUMA 10#define NUM_LINES_CHROMA 6 -#define AV1D_LCU_MAX_SIZE_PELS 128 -#define AV1D_LCU_MIN_SIZE_PELS 64 -#define AV1D_MAX_TILE_COLS 64#define BITS_PER_CTRL_PACK 128#define NUM_CTRL_PACK_LCU 10
Signature · 1 line
2.34.1