Skip to content

Commit

Permalink
ASoC: msm: lock read/write when add/free audio ion memory
Browse files Browse the repository at this point in the history
As read/write get access to ion memory region as well, it's
necessary to lock them when ion memory is about to be added/freed
to avoid racing cases.

CRs-Fixed: 1071809
Change-Id: I436ead23c93384961b38ca99b9312a40c50ad03a
Signed-off-by: Walter Yang <yandongy@codeaurora.org>
[GabrieleM: Adapted for msm8226 kernel]
  • Loading branch information
Walter Yang authored and mdmower committed Dec 17, 2016
1 parent c522746 commit 89a5623
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions arch/arm/mach-msm/qdsp6v2/audio_utils_aio.c
Expand Up @@ -562,6 +562,8 @@ int audio_aio_release(struct inode *inode, struct file *file)
struct q6audio_aio *audio = file->private_data;
pr_debug("%s[%p]\n", __func__, audio);
mutex_lock(&audio->lock);
mutex_lock(&audio->read_lock);
mutex_lock(&audio->write_lock);
audio->wflush = 1;
if (audio->enabled)
audio_aio_flush(audio);
Expand All @@ -576,6 +578,8 @@ int audio_aio_release(struct inode *inode, struct file *file)
wake_up(&audio->event_wait);
audio_aio_reset_event_queue(audio);
q6asm_audio_client_free(audio->ac);
mutex_unlock(&audio->write_lock);
mutex_unlock(&audio->read_lock);
mutex_unlock(&audio->lock);
mutex_destroy(&audio->lock);
mutex_destroy(&audio->read_lock);
Expand Down Expand Up @@ -1349,8 +1353,13 @@ long audio_aio_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
mutex_lock(&audio->lock);
if (copy_from_user(&info, (void *)arg, sizeof(info)))
rc = -EFAULT;
else
else {
mutex_lock(&audio->read_lock);
mutex_lock(&audio->write_lock);
rc = audio_aio_ion_add(audio, &info);
mutex_unlock(&audio->write_lock);
mutex_unlock(&audio->read_lock);
}
mutex_unlock(&audio->lock);
break;
}
Expand All @@ -1360,8 +1369,13 @@ long audio_aio_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
pr_debug("%s[%p]:AUDIO_DEREGISTER_ION\n", __func__, audio);
if (copy_from_user(&info, (void *)arg, sizeof(info)))
rc = -EFAULT;
else
else {
mutex_lock(&audio->read_lock);
mutex_lock(&audio->write_lock);
rc = audio_aio_ion_remove(audio, &info);
mutex_unlock(&audio->write_lock);
mutex_unlock(&audio->read_lock);
}
mutex_unlock(&audio->lock);
break;
}
Expand Down

0 comments on commit 89a5623

Please sign in to comment.