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

Commit c7fa850d authored by Harsh Shah's avatar Harsh Shah
Browse files

msm: camera: mem: Remove lock from get_cpu_buf unless mapping



This change removes mutex_lock/unlock from get_cpu_buf function
unless mapping is required. This helps to remove lock from most
calls to this function. There are no checks anyway to see if
buffer is still in use or not before release. The alloc/map/release
calls have a mutex lock when modifying the different parameters
of the bufq struct. Having a mutex lock in this function does not
resolve anything. So removing this helps to be able to call this
function from tasklets as long as mapping is already done. This
change is needed to dump ISP packet on error from tasklet.

Change-Id: I48b195ad5c948ce991d8926538d6f61c2e0eef59
Signed-off-by: default avatarHarsh Shah <harshs@codeaurora.org>
parent 2a2caaf0
Loading
Loading
Loading
Loading
+20 −15
Original line number Diff line number Diff line
@@ -201,37 +201,42 @@ int cam_mem_get_cpu_buf(int32_t buf_handle, uintptr_t *vaddr_ptr, size_t *len)
	if (!tbl.bufq[idx].active)
		return -EPERM;

	mutex_lock(&tbl.bufq[idx].q_lock);
	if (buf_handle != tbl.bufq[idx].buf_handle) {
		rc = -EINVAL;
		goto exit_func;
	}

	if (!(tbl.bufq[idx].flags & CAM_MEM_FLAG_KMD_ACCESS)) {
		rc = -EINVAL;
		goto exit_func;
	}

	if (!tbl.bufq[idx].kmdvaddr) {
		mutex_lock(&tbl.bufq[idx].q_lock);
		ion_hdl = tbl.bufq[idx].i_hdl;
		if (!ion_hdl) {
			CAM_ERR(CAM_MEM, "Invalid ION handle");
			rc = -EINVAL;
		goto exit_func;
			goto release_mutex;
		}

	if (tbl.bufq[idx].flags & CAM_MEM_FLAG_KMD_ACCESS) {
		if (!tbl.bufq[idx].kmdvaddr) {
		rc = cam_mem_util_map_cpu_va(ion_hdl,
			&kvaddr, &klen);
		if (rc)
				goto exit_func;
			goto release_mutex;

		tbl.bufq[idx].kmdvaddr = kvaddr;
		}
	} else {
		rc = -EINVAL;
		goto exit_func;
		mutex_unlock(&tbl.bufq[idx].q_lock);
	}

	*vaddr_ptr = tbl.bufq[idx].kmdvaddr;
	*len = tbl.bufq[idx].len;

exit_func:
	return rc;

release_mutex:
	mutex_unlock(&tbl.bufq[idx].q_lock);
exit_func:
	return rc;
}
EXPORT_SYMBOL(cam_mem_get_cpu_buf);