Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: SOF: compress: Dynamically allocate pcm params struct

We need to extend sof_ipc_pcm_parmas with additional data in order
to send compress_params to SOF FW.

The extensions will be done at runtime so we need to dynamically
allocate pcm object of type struct sof_ipc_pcm_params.

Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: Péter Ujfalusi <peter.ujfalusi@linux.intel.com>
Link: https://lore.kernel.org/r/20220712141531.14599-2-daniel.baluta@oss.nxp.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Daniel Baluta and committed by
Mark Brown
d5770dae 388fe2b8

+27 -22
+27 -22
sound/soc/sof/compress.c
··· 168 168 struct snd_compr_runtime *crtd = cstream->runtime; 169 169 struct sof_ipc_pcm_params_reply ipc_params_reply; 170 170 struct snd_compr_tstamp *tstamp; 171 - struct sof_ipc_pcm_params pcm; 171 + struct sof_ipc_pcm_params *pcm; 172 172 struct snd_sof_pcm *spcm; 173 173 int ret; 174 174 ··· 179 179 if (!spcm) 180 180 return -EINVAL; 181 181 182 + pcm = kzalloc(sizeof(*pcm), GFP_KERNEL); 183 + if (!pcm) 184 + return -ENOMEM; 185 + 182 186 cstream->dma_buffer.dev.type = SNDRV_DMA_TYPE_DEV_SG; 183 187 cstream->dma_buffer.dev.dev = sdev->dev; 184 188 ret = snd_compr_malloc_pages(cstream, crtd->buffer_size); 185 189 if (ret < 0) 186 - return ret; 190 + goto out; 187 191 188 192 ret = create_page_table(component, cstream, crtd->dma_area, crtd->dma_bytes); 189 193 if (ret < 0) 190 - return ret; 194 + goto out; 191 195 192 - memset(&pcm, 0, sizeof(pcm)); 196 + pcm->params.buffer.pages = PFN_UP(crtd->dma_bytes); 197 + pcm->hdr.size = sizeof(*pcm); 198 + pcm->hdr.cmd = SOF_IPC_GLB_STREAM_MSG | SOF_IPC_STREAM_PCM_PARAMS; 193 199 194 - pcm.params.buffer.pages = PFN_UP(crtd->dma_bytes); 195 - pcm.hdr.size = sizeof(pcm); 196 - pcm.hdr.cmd = SOF_IPC_GLB_STREAM_MSG | SOF_IPC_STREAM_PCM_PARAMS; 197 - 198 - pcm.comp_id = spcm->stream[cstream->direction].comp_id; 199 - pcm.params.hdr.size = sizeof(pcm.params); 200 - pcm.params.buffer.phy_addr = spcm->stream[cstream->direction].page_table.addr; 201 - pcm.params.buffer.size = crtd->dma_bytes; 202 - pcm.params.direction = cstream->direction; 203 - pcm.params.channels = params->codec.ch_out; 204 - pcm.params.rate = params->codec.sample_rate; 205 - pcm.params.buffer_fmt = SOF_IPC_BUFFER_INTERLEAVED; 206 - pcm.params.frame_fmt = SOF_IPC_FRAME_S32_LE; 207 - pcm.params.sample_container_bytes = 200 + pcm->comp_id = spcm->stream[cstream->direction].comp_id; 201 + pcm->params.hdr.size = sizeof(pcm->params); 202 + pcm->params.buffer.phy_addr = spcm->stream[cstream->direction].page_table.addr; 203 + pcm->params.buffer.size = crtd->dma_bytes; 204 + pcm->params.direction = cstream->direction; 205 + pcm->params.channels = params->codec.ch_out; 206 + pcm->params.rate = params->codec.sample_rate; 207 + pcm->params.buffer_fmt = SOF_IPC_BUFFER_INTERLEAVED; 208 + pcm->params.frame_fmt = SOF_IPC_FRAME_S32_LE; 209 + pcm->params.sample_container_bytes = 208 210 snd_pcm_format_physical_width(SNDRV_PCM_FORMAT_S32) >> 3; 209 - pcm.params.host_period_bytes = params->buffer.fragment_size; 211 + pcm->params.host_period_bytes = params->buffer.fragment_size; 210 212 211 - ret = sof_ipc_tx_message(sdev->ipc, &pcm, sizeof(pcm), 213 + ret = sof_ipc_tx_message(sdev->ipc, pcm, sizeof(*pcm), 212 214 &ipc_params_reply, sizeof(ipc_params_reply)); 213 215 if (ret < 0) { 214 216 dev_err(component->dev, "error ipc failed\n"); 215 - return ret; 217 + goto out; 216 218 } 217 219 218 220 tstamp->byte_offset = sdev->stream_box.offset + ipc_params_reply.posn_offset; ··· 222 220 223 221 spcm->prepared[cstream->direction] = true; 224 222 225 - return 0; 223 + out: 224 + kfree(pcm); 225 + 226 + return ret; 226 227 } 227 228 228 229 static int sof_compr_get_params(struct snd_soc_component *component,