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

Commit 1a3178e4 authored by kunleiz's avatar kunleiz Committed by Banajit Goswami
Browse files

ASoC: msm: qdspv2: add mutex to prevent access same memory simultaneously



Add mutex protection to avoid simultaneous access the
same memory by multiple threads.

CRs-Fixed: 2013494
Change-Id: I440ea633ceb7312637c9a3b29d22236166d21a39
Signed-off-by: default avatarkunleiz <kunleiz@codeaurora.org>
parent db415ce3
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -149,6 +149,8 @@ static int audio_effects_shared_ioctl(struct file *file, unsigned int cmd,
	case AUDIO_START: {
		pr_debug("%s: AUDIO_START\n", __func__);

		mutex_lock(&effects->lock);

		rc = q6asm_open_read_write_v2(effects->ac,
					FORMAT_LINEAR_PCM,
					FORMAT_MULTI_CHANNEL_LINEAR_PCM,
@@ -160,6 +162,7 @@ static int audio_effects_shared_ioctl(struct file *file, unsigned int cmd,
			pr_err("%s: Open failed for hw accelerated effects:rc=%d\n",
				__func__, rc);
			rc = -EINVAL;
			mutex_unlock(&effects->lock);
			goto ioctl_fail;
		}
		effects->opened = 1;
@@ -176,6 +179,7 @@ static int audio_effects_shared_ioctl(struct file *file, unsigned int cmd,
			pr_err("%s: Write buffer Allocation failed rc = %d\n",
				__func__, rc);
			rc = -ENOMEM;
			mutex_unlock(&effects->lock);
			goto ioctl_fail;
		}
		atomic_set(&effects->in_count, effects->config.input.num_buf);
@@ -186,6 +190,7 @@ static int audio_effects_shared_ioctl(struct file *file, unsigned int cmd,
			pr_err("%s: Read buffer Allocation failed rc = %d\n",
				__func__, rc);
			rc = -ENOMEM;
			mutex_unlock(&effects->lock);
			goto readbuf_fail;
		}
		atomic_set(&effects->out_count, effects->config.output.num_buf);
@@ -200,6 +205,7 @@ static int audio_effects_shared_ioctl(struct file *file, unsigned int cmd,
		if (rc < 0) {
			pr_err("%s: pcm read block config failed\n", __func__);
			rc = -EINVAL;
			mutex_unlock(&effects->lock);
			goto cfg_fail;
		}
		pr_debug("%s: dec: sample_rate: %d, num_channels: %d, bit_width: %d\n",
@@ -214,6 +220,7 @@ static int audio_effects_shared_ioctl(struct file *file, unsigned int cmd,
			pr_err("%s: pcm write format block config failed\n",
				__func__);
			rc = -EINVAL;
			mutex_unlock(&effects->lock);
			goto cfg_fail;
		}

@@ -226,6 +233,7 @@ static int audio_effects_shared_ioctl(struct file *file, unsigned int cmd,
			effects->started = 0;
			pr_err("%s: ASM run state failed\n", __func__);
		}
		mutex_unlock(&effects->lock);
		break;
	}
	case AUDIO_EFFECTS_WRITE: {
@@ -287,8 +295,11 @@ static int audio_effects_shared_ioctl(struct file *file, unsigned int cmd,
		uint32_t idx = 0;
		uint32_t size = 0;

		mutex_lock(&effects->lock);

		if (!effects->started) {
			rc = -EFAULT;
			mutex_unlock(&effects->lock);
			goto ioctl_fail;
		}

@@ -305,11 +316,13 @@ static int audio_effects_shared_ioctl(struct file *file, unsigned int cmd,
		if (!rc) {
			pr_err("%s: read wait_event_timeout\n", __func__);
			rc = -EFAULT;
			mutex_unlock(&effects->lock);
			goto ioctl_fail;
		}
		if (!atomic_read(&effects->in_count)) {
			pr_err("%s: pcm stopped in_count 0\n", __func__);
			rc = -EFAULT;
			mutex_unlock(&effects->lock);
			goto ioctl_fail;
		}

@@ -317,15 +330,18 @@ static int audio_effects_shared_ioctl(struct file *file, unsigned int cmd,
		if (bufptr) {
			if (!((void *)arg)) {
				rc = -EFAULT;
				mutex_unlock(&effects->lock);
				goto ioctl_fail;
			}
			if ((effects->config.buf_cfg.input_len > size) ||
				copy_to_user((void *)arg, bufptr,
					  effects->config.buf_cfg.input_len)) {
				rc = -EFAULT;
				mutex_unlock(&effects->lock);
				goto ioctl_fail;
			}
		}
		mutex_unlock(&effects->lock);
		break;
	}
	default:
@@ -459,6 +475,7 @@ static long audio_effects_ioctl(struct file *file, unsigned int cmd,
	switch (cmd) {
	case AUDIO_SET_EFFECTS_CONFIG: {
		pr_debug("%s: AUDIO_SET_EFFECTS_CONFIG\n", __func__);
		mutex_lock(&effects->lock);
		memset(&effects->config, 0, sizeof(effects->config));
		if (copy_from_user(&effects->config, (void *)arg,
				   sizeof(effects->config))) {
@@ -476,6 +493,7 @@ static long audio_effects_ioctl(struct file *file, unsigned int cmd,
			 effects->config.input.num_buf,
			 effects->config.input.sample_rate,
			 effects->config.input.num_channels);
		mutex_unlock(&effects->lock);
		break;
	}
	case AUDIO_EFFECTS_SET_BUF_LEN: {
@@ -497,6 +515,7 @@ static long audio_effects_ioctl(struct file *file, unsigned int cmd,

		buf_avail.input_num_avail = atomic_read(&effects->in_count);
		buf_avail.output_num_avail = atomic_read(&effects->out_count);
		mutex_lock(&effects->lock);
		pr_debug("%s: write buf avail: %d, read buf avail: %d\n",
			 __func__, buf_avail.output_num_avail,
			 buf_avail.input_num_avail);
@@ -506,16 +525,20 @@ static long audio_effects_ioctl(struct file *file, unsigned int cmd,
				__func__);
			rc = -EFAULT;
		}
		mutex_unlock(&effects->lock);
		break;
	}
	case AUDIO_EFFECTS_SET_PP_PARAMS: {
		mutex_lock(&effects->lock);
		if (copy_from_user(argvalues, (void *)arg,
				   MAX_PP_PARAMS_SZ*sizeof(long))) {
			pr_err("%s: copy from user for pp params failed\n",
				__func__);
			mutex_unlock(&effects->lock);
			return -EFAULT;
		}
		rc = audio_effects_set_pp_param(effects, argvalues);
		mutex_unlock(&effects->lock);
		break;
	}
	default:
@@ -582,12 +605,14 @@ static long audio_effects_compat_ioctl(struct file *file, unsigned int cmd,
		struct msm_hwacc_effects_config32 config32;
		struct msm_hwacc_effects_config *config = &effects->config;

		mutex_lock(&effects->lock);
		memset(&effects->config, 0, sizeof(effects->config));
		if (copy_from_user(&config32, (void *)arg,
				   sizeof(config32))) {
			pr_err("%s: copy to user for AUDIO_SET_EFFECTS_CONFIG failed\n",
				__func__);
			rc = -EFAULT;
			mutex_unlock(&effects->lock);
			break;
		}
		config->input.buf_size = config32.input.buf_size;
@@ -624,17 +649,20 @@ static long audio_effects_compat_ioctl(struct file *file, unsigned int cmd,
			 effects->config.input.num_buf,
			 effects->config.input.sample_rate,
			 effects->config.input.num_channels);
		mutex_unlock(&effects->lock);
		break;
	}
	case AUDIO_EFFECTS_SET_BUF_LEN32: {
		struct msm_hwacc_buf_cfg32 buf_cfg32;
		struct msm_hwacc_effects_config *config = &effects->config;

		mutex_lock(&effects->lock);
		if (copy_from_user(&buf_cfg32, (void *)arg,
				   sizeof(buf_cfg32))) {
			pr_err("%s: copy from user for AUDIO_EFFECTS_SET_BUF_LEN failed\n",
				__func__);
			rc = -EFAULT;
			mutex_unlock(&effects->lock);
			break;
		}
		config->buf_cfg.input_len = buf_cfg32.input_len;
@@ -642,6 +670,7 @@ static long audio_effects_compat_ioctl(struct file *file, unsigned int cmd,
		pr_debug("%s: write buf len: %d, read buf len: %d\n",
			 __func__, effects->config.buf_cfg.output_len,
			 effects->config.buf_cfg.input_len);
		mutex_unlock(&effects->lock);
		break;
	}
	case AUDIO_EFFECTS_GET_BUF_AVAIL32: {
@@ -649,6 +678,7 @@ static long audio_effects_compat_ioctl(struct file *file, unsigned int cmd,

		memset(&buf_avail, 0, sizeof(buf_avail));

		mutex_lock(&effects->lock);
		buf_avail.input_num_avail = atomic_read(&effects->in_count);
		buf_avail.output_num_avail = atomic_read(&effects->out_count);
		pr_debug("%s: write buf avail: %d, read buf avail: %d\n",
@@ -660,22 +690,26 @@ static long audio_effects_compat_ioctl(struct file *file, unsigned int cmd,
				__func__);
			rc = -EFAULT;
		}
		mutex_unlock(&effects->lock);
		break;
	}
	case AUDIO_EFFECTS_SET_PP_PARAMS32: {
		long argvalues[MAX_PP_PARAMS_SZ] = {0};
		int argvalues32[MAX_PP_PARAMS_SZ] = {0};

		mutex_lock(&effects->lock);
		if (copy_from_user(argvalues32, (void *)arg,
				   MAX_PP_PARAMS_SZ*sizeof(int))) {
			pr_err("%s: copy from user failed for pp params\n",
				__func__);
			mutex_unlock(&effects->lock);
			return -EFAULT;
		}
		for (i = 0; i < MAX_PP_PARAMS_SZ; i++)
			argvalues[i] = argvalues32[i];

		rc = audio_effects_set_pp_param(effects, argvalues);
		mutex_unlock(&effects->lock);
		break;
	}
	case AUDIO_START32: {