diff options
author | Harrison Lingren <hlingren@google.com> | 2020-02-05 16:30:38 -0800 |
---|---|---|
committer | Harrison Lingren <hlingren@google.com> | 2020-02-05 16:30:38 -0800 |
commit | 14752db42697867b5f6156e92ce1a12ca2dbeabd (patch) | |
tree | f066caf376b84d14cbec55d07654a3c5c1fcc2cc | |
parent | 4fe4dd73d0def8e232bc57cbcaa5a37603983560 (diff) | |
parent | 5b584668e841e01f23e4b1f138da004ea6d6a959 (diff) | |
download | msm-extra-14752db42697867b5f6156e92ce1a12ca2dbeabd.tar.gz |
Merge branch 'android-msm-floral-4.14-qt-security-next' into android-msm-floral-4.14-qt
APR 2020.1
Bug: 148866901
Change-Id: I11d50180faa560c0bcb167a2f184a4976ea4fe36
Signed-off-by: Harrison Lingren <hlingren@google.com>
-rw-r--r-- | asoc/msm-pcm-loopback-v2.c | 15 | ||||
-rw-r--r-- | asoc/msm-pcm-q6-noirq.c | 54 | ||||
-rw-r--r-- | asoc/msm-pcm-q6-v2.c | 111 | ||||
-rw-r--r-- | asoc/msm-pcm-q6-v2.h | 1 | ||||
-rw-r--r-- | dsp/msm-cirrus-playback.c | 15 |
5 files changed, 179 insertions, 17 deletions
diff --git a/asoc/msm-pcm-loopback-v2.c b/asoc/msm-pcm-loopback-v2.c index 32c727ac..7bb20bb4 100644 --- a/asoc/msm-pcm-loopback-v2.c +++ b/asoc/msm-pcm-loopback-v2.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2013-2018, The Linux Foundation. All rights reserved. +/* Copyright (c) 2013-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 @@ -136,7 +136,7 @@ static int msm_loopback_session_mute_put(struct snd_kcontrol *kcontrol, ret = -EINVAL; goto done; } - + mutex_lock(&loopback_session_lock); pr_debug("%s: mute=%d\n", __func__, mute); hfp_tx_mute = mute; for (n = 0; n < LOOPBACK_SESSION_MAX; n++) { @@ -149,6 +149,7 @@ static int msm_loopback_session_mute_put(struct snd_kcontrol *kcontrol, pr_err("%s: Send mute command failed rc=%d\n", __func__, ret); } + mutex_unlock(&loopback_session_lock); done: return ret; } @@ -351,6 +352,8 @@ static void stop_pcm(struct msm_pcm_loopback *pcm) if (pcm->audio_client == NULL) return; + + mutex_lock(&loopback_session_lock); q6asm_cmd(pcm->audio_client, CMD_CLOSE); if (pcm->playback_substream != NULL) { @@ -365,6 +368,7 @@ static void stop_pcm(struct msm_pcm_loopback *pcm) } q6asm_audio_client_free(pcm->audio_client); pcm->audio_client = NULL; + mutex_unlock(&loopback_session_lock); } static int msm_pcm_close(struct snd_pcm_substream *substream) @@ -495,12 +499,15 @@ static int msm_pcm_volume_ctl_put(struct snd_kcontrol *kcontrol, rc = -ENODEV; goto exit; } + mutex_lock(&loopback_session_lock); prtd = substream->runtime->private_data; if (!prtd) { rc = -ENODEV; + mutex_unlock(&loopback_session_lock); goto exit; } rc = pcm_loopback_set_volume(prtd, volume); + mutex_unlock(&loopback_session_lock); exit: return rc; @@ -521,13 +528,15 @@ static int msm_pcm_volume_ctl_get(struct snd_kcontrol *kcontrol, rc = -ENODEV; goto exit; } + mutex_lock(&loopback_session_lock); prtd = substream->runtime->private_data; if (!prtd) { rc = -ENODEV; + mutex_unlock(&loopback_session_lock); goto exit; } ucontrol->value.integer.value[0] = prtd->volume; - + mutex_unlock(&loopback_session_lock); exit: return rc; } diff --git a/asoc/msm-pcm-q6-noirq.c b/asoc/msm-pcm-q6-noirq.c index e2abebe8..af2fdff6 100644 --- a/asoc/msm-pcm-q6-noirq.c +++ b/asoc/msm-pcm-q6-noirq.c @@ -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> @@ -615,6 +616,7 @@ static int msm_pcm_prepare(struct snd_pcm_substream *substream) static int msm_pcm_close(struct snd_pcm_substream *substream) { + struct msm_plat_data *pdata = NULL; struct snd_pcm_runtime *runtime = substream->runtime; struct snd_soc_pcm_runtime *soc_prtd = substream->private_data; struct msm_audio *prtd = runtime->private_data; @@ -623,6 +625,20 @@ static int msm_pcm_close(struct snd_pcm_substream *substream) 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; @@ -657,6 +673,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; } @@ -681,8 +698,10 @@ static int msm_pcm_volume_ctl_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_pcm_volume *vol = snd_kcontrol_chip(kcontrol); + struct msm_plat_data *pdata = NULL; struct snd_pcm_substream *substream = vol->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; + struct snd_soc_pcm_runtime *soc_prtd = NULL; struct msm_audio *prtd; pr_debug("%s\n", __func__); @@ -690,13 +709,24 @@ static int msm_pcm_volume_ctl_get(struct snd_kcontrol *kcontrol, pr_err("%s substream not found\n", __func__); return -ENODEV; } - if (!substream->runtime) { - pr_debug("%s substream runtime not found\n", __func__); + soc_prtd = substream->private_data; + if (!substream->runtime || !soc_prtd) { + pr_debug("%s substream runtime or 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); prtd = substream->runtime->private_data; if (prtd) ucontrol->value.integer.value[0] = prtd->volume; + mutex_unlock(&pdata->lock); return 0; } @@ -705,8 +735,10 @@ static int msm_pcm_volume_ctl_put(struct snd_kcontrol *kcontrol, { int rc = 0; struct snd_pcm_volume *vol = snd_kcontrol_chip(kcontrol); + struct msm_plat_data *pdata = NULL; struct snd_pcm_substream *substream = vol->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; + struct snd_soc_pcm_runtime *soc_prtd = NULL; struct msm_audio *prtd; int volume = ucontrol->value.integer.value[0]; @@ -715,15 +747,26 @@ static int msm_pcm_volume_ctl_put(struct snd_kcontrol *kcontrol, pr_err("%s substream not found\n", __func__); return -ENODEV; } - if (!substream->runtime) { - pr_err("%s substream runtime not found\n", __func__); + soc_prtd = substream->private_data; + if (!substream->runtime || !soc_prtd) { + pr_err("%s substream runtime or 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); prtd = substream->runtime->private_data; if (prtd) { rc = msm_pcm_set_volume(prtd, volume); prtd->volume = volume; } + mutex_unlock(&pdata->lock); return rc; } @@ -1303,6 +1346,8 @@ static int msm_pcm_probe(struct platform_device *pdev) pdata->perf_mode = perf_mode; + mutex_init(&pdata->lock); + dev_set_drvdata(&pdev->dev, pdata); dev_dbg(&pdev->dev, "%s: dev name %s\n", @@ -1323,6 +1368,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; diff --git a/asoc/msm-pcm-q6-v2.c b/asoc/msm-pcm-q6-v2.c index ca7caeb6..e4b5732f 100644 --- a/asoc/msm-pcm-q6-v2.c +++ b/asoc/msm-pcm-q6-v2.c @@ -16,6 +16,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> @@ -891,6 +892,14 @@ static int msm_pcm_playback_close(struct snd_pcm_substream *substream) pr_debug("%s: cmd_pending 0x%lx\n", __func__, prtd->cmd_pending); + pdata = (struct msm_plat_data *) + dev_get_drvdata(soc_prtd->platform->dev); + if (!pdata) { + pr_err("%s: platform data is NULL\n", __func__); + return -EINVAL; + } + + mutex_lock(&pdata->lock); if (prtd->audio_client) { dir = IN; @@ -898,8 +907,6 @@ static int msm_pcm_playback_close(struct snd_pcm_substream *substream) * Unvote to downgrade the Rx thread priority from * RT Thread for Low-Latency use case. */ - pdata = (struct msm_plat_data *) - dev_get_drvdata(soc_prtd->platform->dev); if (pdata) { if (pdata->perf_mode == LOW_LATENCY_PCM_MODE) apr_end_rx_rt(prtd->audio_client->apr); @@ -933,6 +940,7 @@ static int msm_pcm_playback_close(struct snd_pcm_substream *substream) msm_adsp_clean_mixer_ctl_pp_event_queue(soc_prtd); kfree(prtd); runtime->private_data = NULL; + mutex_unlock(&pdata->lock); return 0; } @@ -1025,9 +1033,20 @@ static int msm_pcm_capture_close(struct snd_pcm_substream *substream) struct snd_pcm_runtime *runtime = substream->runtime; struct snd_soc_pcm_runtime *soc_prtd = substream->private_data; struct msm_audio *prtd = runtime->private_data; + struct msm_plat_data *pdata; int dir = OUT; pr_debug("%s\n", __func__); + + pdata = (struct msm_plat_data *) + dev_get_drvdata(soc_prtd->platform->dev); + if (!pdata) { + pr_err("%s: platform data is NULL\n", __func__); + return -EINVAL; + } + + mutex_lock(&pdata->lock); + if (prtd->audio_client) { q6asm_cmd(prtd->audio_client, CMD_CLOSE); q6asm_audio_client_buf_free_contiguous(dir, @@ -1039,6 +1058,7 @@ static int msm_pcm_capture_close(struct snd_pcm_substream *substream) SNDRV_PCM_STREAM_CAPTURE); kfree(prtd); runtime->private_data = NULL; + mutex_unlock(&pdata->lock); return 0; } @@ -1176,10 +1196,10 @@ static int msm_pcm_adsp_stream_cmd_put(struct snd_kcontrol *kcontrol, if (!pdata) { pr_err("%s pdata is NULL\n", __func__); - ret = -ENODEV; - goto done; + return -ENODEV; } + mutex_lock(&pdata->lock); substream = pdata->pcm[kcontrol->private_value]-> streams[SNDRV_PCM_STREAM_PLAYBACK].substream; if (!substream) { @@ -1223,6 +1243,7 @@ static int msm_pcm_adsp_stream_cmd_put(struct snd_kcontrol *kcontrol, pr_err("%s: failed to send stream event cmd, err = %d\n", __func__, ret); done: + mutex_unlock(&pdata->lock); return ret; } @@ -1360,8 +1381,10 @@ static int msm_pcm_volume_ctl_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_pcm_volume *vol = snd_kcontrol_chip(kcontrol); + struct msm_plat_data *pdata = NULL; struct snd_pcm_substream *substream = vol->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; + struct snd_soc_pcm_runtime *soc_prtd = NULL; struct msm_audio *prtd; pr_debug("%s\n", __func__); @@ -1369,13 +1392,25 @@ static int msm_pcm_volume_ctl_get(struct snd_kcontrol *kcontrol, pr_err("%s substream not found\n", __func__); return -ENODEV; } - if (!substream->runtime) { - pr_debug("%s substream runtime not found\n", __func__); + soc_prtd = substream->private_data; + if (!substream->runtime || !soc_prtd) { + pr_debug("%s substream runtime or 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); prtd = substream->runtime->private_data; if (prtd) ucontrol->value.integer.value[0] = prtd->volume; + mutex_unlock(&pdata->lock); return 0; } @@ -1386,6 +1421,8 @@ static int msm_pcm_volume_ctl_put(struct snd_kcontrol *kcontrol, struct snd_pcm_volume *vol = snd_kcontrol_chip(kcontrol); struct snd_pcm_substream *substream = vol->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; + struct snd_soc_pcm_runtime *soc_prtd = NULL; + struct msm_plat_data *pdata = NULL; struct msm_audio *prtd; int volume = ucontrol->value.integer.value[0]; @@ -1398,11 +1435,27 @@ static int msm_pcm_volume_ctl_put(struct snd_kcontrol *kcontrol, pr_err("%s substream runtime not found\n", __func__); return 0; } + + soc_prtd = substream->private_data; + if (!soc_prtd) { + pr_err("%s: soc_prtd is NULL\n", __func__); + return -ENODEV; + } + + pdata = (struct msm_plat_data *) + dev_get_drvdata(soc_prtd->platform->dev); + if (!pdata) { + pr_err("%s: platform data is NULL\n", __func__); + return -EINVAL; + } + + 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; } @@ -1461,9 +1514,11 @@ static int msm_pcm_compress_ctl_get(struct snd_kcontrol *kcontrol, pr_debug("%s substream runtime not found\n", __func__); return 0; } + mutex_lock(&pdata->lock); prtd = substream->runtime->private_data; if (prtd) ucontrol->value.integer.value[0] = prtd->compress_enable; + mutex_unlock(&pdata->lock); return 0; } @@ -1493,12 +1548,14 @@ static int msm_pcm_compress_ctl_put(struct snd_kcontrol *kcontrol, pr_err("%s substream runtime not found\n", __func__); return 0; } + mutex_lock(&pdata->lock); prtd = substream->runtime->private_data; if (prtd) { pr_debug("%s: setting compress flag to 0x%x\n", __func__, compress); prtd->compress_enable = compress; } + mutex_unlock(&pdata->lock); return rc; } @@ -1565,15 +1622,32 @@ static int msm_pcm_chmap_ctl_put(struct snd_kcontrol *kcontrol, struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol); unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); struct snd_pcm_substream *substream; + struct snd_soc_pcm_runtime *soc_prtd = NULL; + struct msm_plat_data *pdata = NULL; struct msm_audio *prtd; pr_debug("%s", __func__); substream = snd_pcm_chmap_substream(info, idx); if (!substream) return -ENODEV; + if (!substream->runtime) return 0; + soc_prtd = substream->private_data; + if (!soc_prtd) { + pr_err("%s: soc_prtd is NULL\n", __func__); + return -ENODEV; + } + + pdata = (struct msm_plat_data *) + dev_get_drvdata(soc_prtd->platform->dev); + if (!pdata) { + pr_err("%s: platform data is NULL\n", __func__); + return -EINVAL; + } + + mutex_lock(&pdata->lock); prtd = substream->runtime->private_data; if (prtd) { prtd->set_channel_map = true; @@ -1581,6 +1655,7 @@ static int msm_pcm_chmap_ctl_put(struct snd_kcontrol *kcontrol, prtd->channel_map[i] = (char)(ucontrol->value.integer.value[i]); } + mutex_unlock(&pdata->lock); return 0; } @@ -1591,17 +1666,34 @@ static int msm_pcm_chmap_ctl_get(struct snd_kcontrol *kcontrol, struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol); unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); struct snd_pcm_substream *substream; + struct snd_soc_pcm_runtime *soc_prtd = NULL; + struct msm_plat_data *pdata = NULL; struct msm_audio *prtd; pr_debug("%s", __func__); substream = snd_pcm_chmap_substream(info, idx); if (!substream) return -ENODEV; + memset(ucontrol->value.integer.value, 0, sizeof(ucontrol->value.integer.value)); if (!substream->runtime) return 0; /* no channels set */ + soc_prtd = substream->private_data; + if (!soc_prtd) { + pr_err("%s: soc_prtd is NULL\n", __func__); + return -ENODEV; + } + + pdata = (struct msm_plat_data *) + dev_get_drvdata(soc_prtd->platform->dev); + if (!pdata) { + pr_err("%s: platform data is NULL\n", __func__); + return -EINVAL; + } + + mutex_lock(&pdata->lock); prtd = substream->runtime->private_data; if (prtd && prtd->set_channel_map == true) { @@ -1613,6 +1705,7 @@ static int msm_pcm_chmap_ctl_get(struct snd_kcontrol *kcontrol, ucontrol->value.integer.value[i] = 0; } + mutex_unlock(&pdata->lock); return 0; } @@ -1839,18 +1932,21 @@ static int msm_pcm_path_latency_ctl_get(struct snd_kcontrol *kcontrol, return -EINVAL; } + mutex_lock(&pdata->lock); prtd = substream->runtime->private_data; if (prtd) { rc = q6asm_get_path_delay(prtd->audio_client); if (rc) { pr_err("%s: get_path_delay failed, ret=%d\n", __func__, rc); + mutex_unlock(&pdata->lock); return -EINVAL; } ucontrol->value.integer.value[0] = prtd->audio_client->path_delay; } + mutex_unlock(&pdata->lock); return rc; } @@ -2108,7 +2204,7 @@ static int msm_pcm_probe(struct platform_device *pdev) } else { pdata->perf_mode = LEGACY_PCM_MODE; } - + mutex_init(&pdata->lock); dev_set_drvdata(&pdev->dev, pdata); @@ -2123,6 +2219,7 @@ static int msm_pcm_remove(struct platform_device *pdev) struct msm_plat_data *pdata; pdata = dev_get_drvdata(&pdev->dev); + mutex_destroy(&pdata->lock); kfree(pdata); snd_soc_unregister_platform(&pdev->dev); return 0; diff --git a/asoc/msm-pcm-q6-v2.h b/asoc/msm-pcm-q6-v2.h index a4b42352..e7ed3def 100644 --- a/asoc/msm-pcm-q6-v2.h +++ b/asoc/msm-pcm-q6-v2.h @@ -128,6 +128,7 @@ struct msm_plat_data { int perf_mode; struct snd_pcm *pcm[MSM_FRONTEND_DAI_MAX]; struct msm_pcm_ch_map *ch_map[MSM_FRONTEND_DAI_MAX]; + struct mutex lock; }; struct msm_pcm_ch_map { diff --git a/dsp/msm-cirrus-playback.c b/dsp/msm-cirrus-playback.c index 934793b1..1cbfd9ac 100644 --- a/dsp/msm-cirrus-playback.c +++ b/dsp/msm-cirrus-playback.c @@ -58,6 +58,7 @@ static struct crus_single_data_t crus_enable; static struct crus_sp_ioctl_header crus_sp_hdr; static struct cirrus_cal_result_t crus_sp_cal_rslt; static int32_t *crus_sp_get_buffer; +static int32_t crus_sp_get_buffer_size; static atomic_t crus_sp_get_param_flag; struct mutex crus_sp_get_param_lock; struct mutex crus_sp_lock; @@ -204,8 +205,8 @@ static int crus_afe_get_param(int port, int module, int param, int length, mutex_lock(&crus_sp_get_param_lock); atomic_set(&crus_sp_get_param_flag, 0); - crus_sp_get_buffer = kzalloc(config->param.payload_size + 16, - GFP_KERNEL); + crus_sp_get_buffer_size = config->param.payload_size + 16; + crus_sp_get_buffer = kzalloc(crus_sp_get_buffer_size, GFP_KERNEL); if (!crus_sp_get_buffer) { pr_err("kzalloc failed for crus_sp_get_buffer!\n"); @@ -238,6 +239,7 @@ static int crus_afe_get_param(int port, int module, int param, int length, crus_sp_get_param_err: kfree(crus_sp_get_buffer); crus_sp_get_buffer = NULL; + crus_sp_get_buffer_size = -1; crus_sp_get_buffer_err: mutex_unlock(&crus_sp_get_param_lock); @@ -428,6 +430,7 @@ static int crus_afe_send_delta(const char *data, size_t length) extern int crus_afe_callback(void *payload, int size) { uint32_t *payload32 = payload; + int copysize; pr_debug("Cirrus AFE CALLBACK: size = %d\n", size); if (size < 8) @@ -436,7 +439,13 @@ extern int crus_afe_callback(void *payload, int size) switch (payload32[1]) { case CIRRUS_SP: if (crus_sp_get_buffer != NULL) { - memcpy(crus_sp_get_buffer, payload32, size); + copysize = (crus_sp_get_buffer_size > size)? + size : crus_sp_get_buffer_size; + + if (copysize != size) + pr_warn("size mismatch data may lost\n"); + + memcpy(crus_sp_get_buffer, payload32, copysize); atomic_set(&crus_sp_get_param_flag, 1); } break; |