Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 25423157 authored by Deva Ramasubramanian's avatar Deva Ramasubramanian Committed by Gerrit - the friendly Code Review server
Browse files

msm: vidc: Make buffer validity checks stronger



Check for the exact number of planes that we advertised to the client
rather than the worst-case checks.

Change-Id: Ibaf705367db98beb0e01bb2c3087126cf2ba73e8
Signed-off-by: default avatarDeva Ramasubramanian <dramasub@codeaurora.org>
parent 74240891
Loading
Loading
Loading
Loading
+15 −24
Original line number Diff line number Diff line
@@ -670,20 +670,25 @@ int output_buffer_cache_invalidate(struct msm_vidc_inst *inst,
	return 0;
}

static bool valid_v4l2_buffer(struct v4l2_buffer *b,
		struct msm_vidc_inst *inst) {
	enum vidc_ports port =
		!V4L2_TYPE_IS_MULTIPLANAR(b->type) ? MAX_PORT_NUM :
		b->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ? CAPTURE_PORT :
		b->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ? OUTPUT_PORT :
								MAX_PORT_NUM;

	return port != MAX_PORT_NUM &&
		inst->fmts[port]->num_planes == b->length;
}

int msm_vidc_prepare_buf(void *instance, struct v4l2_buffer *b)
{
	struct msm_vidc_inst *inst = instance;

	if (!inst || !b)
	if (!inst || !b || !valid_v4l2_buffer(b, inst))
		return -EINVAL;

	if (!V4L2_TYPE_IS_MULTIPLANAR(b->type) || !b->length ||
		(b->length > VIDEO_MAX_PLANES)) {
		dprintk(VIDC_ERR, "%s: wrong input params\n",
				__func__);
		return -EINVAL;
	}

	if (is_dynamic_output_buffer_mode(b, inst))
		return 0;

@@ -803,15 +808,8 @@ int msm_vidc_qbuf(void *instance, struct v4l2_buffer *b)
	int rc = 0;
	int i;

	if (!inst || !b)
		return -EINVAL;

	if (!V4L2_TYPE_IS_MULTIPLANAR(b->type) || !b->length ||
		(b->length > VIDEO_MAX_PLANES)) {
		dprintk(VIDC_ERR, "%s: wrong input params\n",
				__func__);
	if (!inst || !b || !valid_v4l2_buffer(b, inst))
		return -EINVAL;
	}

	rc = map_and_register_buf(inst, b);
	if (rc == -EEXIST) {
@@ -888,16 +886,9 @@ int msm_vidc_dqbuf(void *instance, struct v4l2_buffer *b)
	struct buffer_info *buffer_info = NULL;
	int i = 0, rc = 0;

	if (!inst || !b)
	if (!inst || !b || !valid_v4l2_buffer(b, inst))
		return -EINVAL;

	if (!V4L2_TYPE_IS_MULTIPLANAR(b->type) || !b->length ||
		(b->length > VIDEO_MAX_PLANES)) {
		dprintk(VIDC_ERR, "%s: wrong input params\n",
				__func__);
		return -EINVAL;
	}

	if (inst->session_type == MSM_VIDC_DECODER)
		rc = msm_vdec_dqbuf(instance, b);
	if (inst->session_type == MSM_VIDC_ENCODER)