soc: msm-pcm: Add mutex lock to protect prvt data
Add mutex lock to protect private data in _put() and get() calls. Change-Id: I92f5a6515b6d1c4ad650a7dcf22a0a231a84dd30 Signed-off-by: Soumya Managoli <smanag@codeaurora.org>
This commit is contained in:
parent
8b050f4d00
commit
8af369dae9
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
|
||||
/* Copyright (c) 2016-2017, 2019, The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 and
|
||||
|
@ -15,6 +15,7 @@
|
|||
#include <linux/module.h>
|
||||
#include <linux/moduleparam.h>
|
||||
#include <linux/time.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/wait.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/slab.h>
|
||||
|
@ -480,10 +481,24 @@ static int msm_pcm_close(struct snd_pcm_substream *substream)
|
|||
struct snd_soc_pcm_runtime *soc_prtd = substream->private_data;
|
||||
struct msm_audio *prtd = runtime->private_data;
|
||||
struct audio_client *ac = prtd->audio_client;
|
||||
struct msm_plat_data *pdata = NULL;
|
||||
uint32_t timeout;
|
||||
int dir = 0;
|
||||
int ret = 0;
|
||||
|
||||
if (!soc_prtd) {
|
||||
pr_debug("%s private_data not found\n",
|
||||
__func__);
|
||||
return 0;
|
||||
}
|
||||
pdata = (struct msm_plat_data *)
|
||||
dev_get_drvdata(soc_prtd->platform->dev);
|
||||
if (!pdata) {
|
||||
pr_err("%s: pdata not found\n", __func__);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
mutex_lock(&pdata->lock);
|
||||
if (ac) {
|
||||
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
|
||||
dir = IN;
|
||||
|
@ -518,6 +533,7 @@ static int msm_pcm_close(struct snd_pcm_substream *substream)
|
|||
SNDRV_PCM_STREAM_CAPTURE);
|
||||
kfree(prtd);
|
||||
runtime->private_data = NULL;
|
||||
mutex_unlock(&pdata->lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -545,19 +561,32 @@ static int msm_pcm_volume_ctl_get(struct snd_kcontrol *kcontrol,
|
|||
struct snd_pcm_substream *substream =
|
||||
vol->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
|
||||
struct msm_audio *prtd;
|
||||
struct msm_plat_data *pdata = NULL;
|
||||
struct snd_soc_pcm_runtime *soc_prtd = NULL;
|
||||
|
||||
pr_debug("%s\n", __func__);
|
||||
if (!substream) {
|
||||
pr_err("%s substream not found\n", __func__);
|
||||
return -ENODEV;
|
||||
}
|
||||
if (!substream->runtime) {
|
||||
soc_prtd = substream->private_data;
|
||||
if (!substream->runtime || !soc_prtd) {
|
||||
pr_err("%s substream runtime not found\n", __func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pdata = (struct msm_plat_data *)
|
||||
dev_get_drvdata(soc_prtd->platform->dev);
|
||||
if (!pdata) {
|
||||
pr_err("%s: pdata not found\n", __func__);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
mutex_lock(&pdata->lock);
|
||||
prtd = substream->runtime->private_data;
|
||||
if (prtd)
|
||||
ucontrol->value.integer.value[0] = prtd->volume;
|
||||
mutex_unlock(&pdata->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -569,6 +598,8 @@ static int msm_pcm_volume_ctl_put(struct snd_kcontrol *kcontrol,
|
|||
struct snd_pcm_substream *substream =
|
||||
vol->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
|
||||
struct msm_audio *prtd;
|
||||
struct msm_plat_data *pdata = NULL;
|
||||
struct snd_soc_pcm_runtime *soc_prtd = NULL;
|
||||
int volume = ucontrol->value.integer.value[0];
|
||||
|
||||
pr_debug("%s: volume : 0x%x\n", __func__, volume);
|
||||
|
@ -576,15 +607,25 @@ static int msm_pcm_volume_ctl_put(struct snd_kcontrol *kcontrol,
|
|||
pr_err("%s substream not found\n", __func__);
|
||||
return -ENODEV;
|
||||
}
|
||||
if (!substream->runtime) {
|
||||
soc_prtd = substream->private_data;
|
||||
if (!substream->runtime || !soc_prtd) {
|
||||
pr_err("%s substream runtime not found\n", __func__);
|
||||
return 0;
|
||||
}
|
||||
pdata = (struct msm_plat_data *)
|
||||
dev_get_drvdata(soc_prtd->platform->dev);
|
||||
if (!pdata) {
|
||||
pr_err("%s: pdata not found\n", __func__);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
mutex_lock(&pdata->lock);
|
||||
prtd = substream->runtime->private_data;
|
||||
if (prtd) {
|
||||
rc = msm_pcm_set_volume(prtd, volume);
|
||||
prtd->volume = volume;
|
||||
}
|
||||
mutex_unlock(&pdata->lock);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -761,6 +802,7 @@ static int msm_pcm_probe(struct platform_device *pdev)
|
|||
return -ENOMEM;
|
||||
|
||||
pdata->perf_mode = perf_mode;
|
||||
mutex_init(&pdata->lock);
|
||||
|
||||
dev_set_drvdata(&pdev->dev, pdata);
|
||||
|
||||
|
@ -782,6 +824,7 @@ static int msm_pcm_remove(struct platform_device *pdev)
|
|||
|
||||
dev_dbg(&pdev->dev, "Pull mode remove\n");
|
||||
pdata = dev_get_drvdata(&pdev->dev);
|
||||
mutex_destroy(&pdata->lock);
|
||||
devm_kfree(&pdev->dev, pdata);
|
||||
snd_soc_unregister_platform(&pdev->dev);
|
||||
return 0;
|
||||
|
|
|
@ -999,19 +999,30 @@ static int msm_pcm_volume_ctl_get(struct snd_kcontrol *kcontrol,
|
|||
struct snd_pcm_substream *substream =
|
||||
vol->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
|
||||
struct msm_audio *prtd;
|
||||
struct msm_plat_data *pdata = NULL;
|
||||
struct snd_soc_pcm_runtime *soc_prtd = NULL;
|
||||
|
||||
pr_debug("%s\n", __func__);
|
||||
if (!substream) {
|
||||
pr_err("%s substream not found\n", __func__);
|
||||
return -ENODEV;
|
||||
}
|
||||
if (!substream->runtime) {
|
||||
soc_prtd = substream->private_data;
|
||||
if (!substream->runtime || !soc_prtd) {
|
||||
pr_err("%s substream runtime not found\n", __func__);
|
||||
return 0;
|
||||
}
|
||||
pdata = (struct msm_plat_data *)
|
||||
dev_get_drvdata(soc_prtd->platform->dev);
|
||||
if (!pdata) {
|
||||
pr_err("%s: pdata not found\n", __func__);
|
||||
return -ENODEV;
|
||||
}
|
||||
mutex_lock(&pdata->lock);
|
||||
prtd = substream->runtime->private_data;
|
||||
if (prtd)
|
||||
ucontrol->value.integer.value[0] = prtd->volume;
|
||||
mutex_unlock(&pdata->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue