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

Commit a9022f81 authored by Rahul Ratneshwar Mandal's avatar Rahul Ratneshwar Mandal Committed by Gerrit - the friendly Code Review server
Browse files

Revert "msm: vidc: fix msm_comm_get_vidc_buffer fd race issue"



Change-Id: I7712924bb8da895b294990f444982c398b9e7571
Signed-off-by: default avatarRahul Ratneshwar Mandal <quic_rratnesh@quicinc.com>
parent 557aee51
Loading
Loading
Loading
Loading
+26 −19
Original line number Diff line number Diff line
@@ -6629,24 +6629,25 @@ struct msm_vidc_buffer *msm_comm_get_vidc_buffer(struct msm_vidc_inst *inst,
	struct vb2_v4l2_buffer *vbuf;
	struct vb2_buffer *vb;
	unsigned long dma_planes[VB2_MAX_PLANES] = {0};
	struct msm_vidc_buffer *mbuf = NULL;
	struct msm_vidc_buffer *mbuf;
	bool found = false;
	int i = 0, planes = 0;
	int i;

	if (!inst || !vb2) {
		dprintk(VIDC_ERR, "%s: invalid params\n", __func__);
		return NULL;
	}

	for (planes = 0; planes < vb2->num_planes; planes++) {
	for (i = 0; i < vb2->num_planes; i++) {
		/*
		 * always compare dma_buf addresses which is guaranteed
		 * to be same across the processes (duplicate fds).
		 */
		dma_planes[planes] = (unsigned long)msm_smem_get_dma_buf(
				vb2->planes[planes].m.fd);
		if (!dma_planes[planes])
			goto put_ref;
		dma_planes[i] = (unsigned long)msm_smem_get_dma_buf(
				vb2->planes[i].m.fd);
		if (!dma_planes[i])
			return NULL;
		msm_smem_put_dma_buf((struct dma_buf *)dma_planes[i]);
	}

	mutex_lock(&inst->registeredbufs.lock);
@@ -6749,21 +6750,27 @@ struct msm_vidc_buffer *msm_comm_get_vidc_buffer(struct msm_vidc_inst *inst,
	if (!found)
		list_add_tail(&mbuf->list, &inst->registeredbufs.list);

	mutex_unlock(&inst->registeredbufs.lock);

	/*
	 * Return mbuf if decode batching is enabled as this buffer
	 * may trigger queuing full batch to firmware, also this buffer
	 * will not be queued to firmware while full batch queuing,
	 * it will be queued when rbr event arrived from firmware.
	 */
	if (rc == -EEXIST && !inst->batch.enable)
		return ERR_PTR(rc);

	return mbuf;

exit:
	if (rc == -EEXIST) {
		print_vidc_buffer(VIDC_DBG, "qbuf upon rbr", inst, mbuf);
	} else if (rc) {
	dprintk(VIDC_ERR, "%s: rc %d\n", __func__, rc);
	msm_comm_unmap_vidc_buffer(inst, mbuf);
	if (!found)
		kref_put_mbuf(mbuf);
	}
	mutex_unlock(&inst->registeredbufs.lock);
put_ref:
	while (planes)
		msm_smem_put_dma_buf((struct dma_buf *)dma_planes[--planes]);

	return rc ? ERR_PTR(rc) : mbuf;
	return ERR_PTR(rc);
}

void msm_comm_put_vidc_buffer(struct msm_vidc_inst *inst,