From ab7aa02f82cba38d026c501795479cdf1e7d11f2 Mon Sep 17 00:00:00 2001 From: Marcin Pietraszko Date: Thu, 7 Mar 2019 15:06:13 +0100 Subject: [PATCH 27/27] ASoC: Intel: Skl: Virt: Cleanup static analysis issues Change-Id: I3f5a62cbd22dd8788b5416a02e7d110606f12834 Tracked-On: OAM-76847 Signed-off-by: Marcin Pietraszko --- .../soc/intel/skylake/virtio/skl-virtio-be.c | 16 +++++------ .../intel/skylake/virtio/skl-virtio-common.h | 4 +-- .../soc/intel/skylake/virtio/skl-virtio-fe.c | 28 +++++++++---------- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/sound/soc/intel/skylake/virtio/skl-virtio-be.c b/sound/soc/intel/skylake/virtio/skl-virtio-be.c index 7709299f8078..097e6a9c4fb4 100644 --- a/sound/soc/intel/skylake/virtio/skl-virtio-be.c +++ b/sound/soc/intel/skylake/virtio/skl-virtio-be.c @@ -387,9 +387,6 @@ static int vbe_skl_prepare_dma(struct vbe_substream_info *substr_info, static int vbe_skl_assemble_params(struct vfe_pcm_hw_params *vfe_params, struct snd_pcm_hw_params *params) { - hw_param_interval(params, SNDRV_PCM_HW_PARAM_ACCESS)->min = - vfe_params->access; - hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->min = vfe_params->channels; @@ -419,21 +416,22 @@ static int vbe_skl_assemble_params(struct vfe_pcm_hw_params *vfe_params, static int vbe_skl_add_substream_info(struct snd_skl_vbe *vbe, int vm_id, struct snd_pcm_substream *substream) { - struct vbe_substream_info *substr_info = - kzalloc(sizeof(*substr_info), GFP_KERNEL); + struct vbe_substream_info *substr_info; /*TODO: call vbe_client_find with proper client_id*/ struct snd_skl_vbe_client *client = list_first_entry_or_null( &vbe->client_list, struct snd_skl_vbe_client, list); - if (!substr_info) - return -ENOMEM; - if (!client) { dev_err(vbe->dev, "Can not find active client [%d].\n", vm_id); return -EINVAL; } + substr_info = kzalloc(sizeof(*substr_info), GFP_KERNEL); + + if (!substr_info) + return -ENOMEM; + substr_info->pcm = substream->pcm; substr_info->substream = substream; substr_info->direction = substream->stream; @@ -610,7 +608,7 @@ void vbe_skl_pcm_close_all(struct snd_skl_vbe *vbe, ret = vbe_skl_pcm_close(vbe->sdev, 0, info, &msg); if (ret < 0) dev_err(vbe->dev, - "Could not close PCM %.64s\n", info->pcm->id); + "Could not close PCM\n"); } } diff --git a/sound/soc/intel/skylake/virtio/skl-virtio-common.h b/sound/soc/intel/skylake/virtio/skl-virtio-common.h index be2cc77dcd83..7f395ed3bcd1 100644 --- a/sound/soc/intel/skylake/virtio/skl-virtio-common.h +++ b/sound/soc/intel/skylake/virtio/skl-virtio-common.h @@ -7,6 +7,7 @@ * common header for both virtio FE driver and BE service */ +#include #include "../skl.h" #ifndef __SOUND_SOC_SKL_VIRTIO_COMMON_H @@ -28,7 +29,6 @@ #define SKL_VIRTIO_IPC_REPLY 1 #define SKL_VIRTIO_DOMAIN_NAME_LEN 20 -#define SKL_VIRTIO_DOMAIN_TPLG_LEN 40 #define SKL_VIRTIO_TPLG_CHUNK_SIZE 1536 struct vfe_stream_pos_desc { @@ -163,7 +163,7 @@ struct vfe_hw_pos_request { }; struct vfe_tplg_info { - char tplg_name[SKL_VIRTIO_DOMAIN_TPLG_LEN]; + char tplg_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; u32 domain_id; u32 chunk_size; u32 chunks; diff --git a/sound/soc/intel/skylake/virtio/skl-virtio-fe.c b/sound/soc/intel/skylake/virtio/skl-virtio-fe.c index 17d5e3de45f5..c9475a0852e1 100644 --- a/sound/soc/intel/skylake/virtio/skl-virtio-fe.c +++ b/sound/soc/intel/skylake/virtio/skl-virtio-fe.c @@ -157,7 +157,8 @@ static int vfe_send_msg(struct snd_skl_vfe *vfe, return -ENOMEM; strncpy(msg_header->domain_name, domain_name, - ARRAY_SIZE(msg_header->domain_name)); + ARRAY_SIZE(msg_header->domain_name)-1); + msg_header->domain_name[SKL_VIRTIO_DOMAIN_NAME_LEN-1] = '\0'; msg_header->domain_id = domain_id; memcpy(&msg->header, msg_header, sizeof(msg->header)); msg->tx_data = tx_data; @@ -474,19 +475,15 @@ static struct kctl_ops vfe_kctl_ops = { .send_noti = vfe_send_kctl_msg, }; -static struct vfe_msg_header -vfe_get_pcm_msg_header(enum vfe_ipc_msg_type msg_type, - struct snd_pcm_substream *substream) +static void vfe_fill_pcm_msg_header(struct vfe_msg_header *msg_header, + enum vfe_ipc_msg_type msg_type, struct snd_pcm_substream *substream) { - struct vfe_msg_header msg_header; - struct vfe_pcm_info *pcm_desc = &msg_header.desc.pcm; + struct vfe_pcm_info *pcm_desc = &msg_header->desc.pcm; - msg_header.cmd = msg_type; + msg_header->cmd = msg_type; strncpy(pcm_desc->pcm_id, substream->pcm->id, ARRAY_SIZE(pcm_desc->pcm_id)); pcm_desc->direction = substream->stream; - - return msg_header; } int vfe_pcm_open(struct snd_pcm_substream *substream) @@ -507,7 +504,7 @@ int vfe_pcm_open(struct snd_pcm_substream *substream) if (ret) return 0; - msg_header = vfe_get_pcm_msg_header(VFE_MSG_PCM_OPEN, substream); + vfe_fill_pcm_msg_header(&msg_header, VFE_MSG_PCM_OPEN, substream); ret = vfe_send_msg(vfe, &msg_header, NULL, 0, &vbe_result, sizeof(vbe_result)); @@ -562,7 +559,7 @@ int vfe_pcm_close(struct snd_pcm_substream *substream) } spin_unlock_irqrestore(&vfe->substream_info_lock, irq_flags); - msg_header = vfe_get_pcm_msg_header(VFE_MSG_PCM_CLOSE, substream); + vfe_fill_pcm_msg_header(&msg_header, VFE_MSG_PCM_CLOSE, substream); ret = vfe_send_msg(vfe, &msg_header, NULL, 0, &vbe_result, sizeof(vbe_result)); @@ -600,7 +597,7 @@ int vfe_pcm_hw_params(struct snd_pcm_substream *substream, vfe_params.period_size = params_period_size(params); vfe_params.periods = params_periods(params); - msg_header = vfe_get_pcm_msg_header(VFE_MSG_PCM_HW_PARAMS, substream); + vfe_fill_pcm_msg_header(&msg_header, VFE_MSG_PCM_HW_PARAMS, substream); ret = vfe_send_msg(vfe, &msg_header, &vfe_params, sizeof(vfe_params), &vbe_result, sizeof(vbe_result)); @@ -624,7 +621,7 @@ int vfe_pcm_trigger(struct snd_pcm_substream *substream, int cmd) if (ret) return 0; - msg_header = vfe_get_pcm_msg_header(VFE_MSG_PCM_TRIGGER, substream); + vfe_fill_pcm_msg_header(&msg_header, VFE_MSG_PCM_TRIGGER, substream); return vfe_send_msg(vfe, &msg_header, &cmd, sizeof(cmd), NULL, 0); } @@ -644,6 +641,9 @@ int vfe_pcm_prepare(struct snd_pcm_substream *substream) if (ret) return 0; + if (!substr_info) + return -EINVAL; + sg_buf = snd_pcm_substream_sgbuf(substream); dma_conf.addr = (u64)sg_buf->table[0].addr; @@ -654,7 +654,7 @@ int vfe_pcm_prepare(struct snd_pcm_substream *substream) dma_conf.stream_pos_addr = virt_to_phys(substr_info->pos_desc); dma_conf.stream_pos_size = sizeof(struct vfe_stream_pos_desc); - msg_header = vfe_get_pcm_msg_header(VFE_MSG_PCM_PREPARE, substream); + vfe_fill_pcm_msg_header(&msg_header, VFE_MSG_PCM_PREPARE, substream); ret = vfe_send_msg(vfe, &msg_header, &dma_conf, sizeof(dma_conf), &vbe_result, sizeof(vbe_result)); -- 2.17.1