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

ASoC: codecs: sdw-mockup: simplify set_stream

Using a dynamic allocation to store a single pointer is not very
efficient/useful.

Worse, the memory is released in the SoundWire stream.c file, but
still accessed in the DAI shutdown, leading to kmemleak reports.

And last the API requires the previous stream information to be
cleared when the argument is NULL.

Simplify the code to address all 3 problems.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Péter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: Rander Wang <rander.wang@intel.com>
Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Link: https://lore.kernel.org/r/20230324014408.1677505-3-yung-chuan.liao@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Pierre-Louis Bossart and committed by
Mark Brown
f3def177 892855d5

+6 -28
+6 -28
sound/soc/codecs/sdw-mockup.c
··· 23 23 struct sdw_slave *slave; 24 24 }; 25 25 26 - struct sdw_stream_data { 27 - struct sdw_stream_runtime *sdw_stream; 28 - }; 29 - 30 26 static int sdw_mockup_component_probe(struct snd_soc_component *component) 31 27 { 32 28 return 0; ··· 41 45 static int sdw_mockup_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, 42 46 int direction) 43 47 { 44 - struct sdw_stream_data *stream; 45 - 46 - if (!sdw_stream) 47 - return 0; 48 - 49 - stream = kzalloc(sizeof(*stream), GFP_KERNEL); 50 - if (!stream) 51 - return -ENOMEM; 52 - 53 - stream->sdw_stream = sdw_stream; 54 - 55 - /* Use tx_mask or rx_mask to configure stream tag and set dma_data */ 56 - snd_soc_dai_dma_data_set(dai, direction, stream); 48 + snd_soc_dai_dma_data_set(dai, direction, sdw_stream); 57 49 58 50 return 0; 59 51 } ··· 49 65 static void sdw_mockup_shutdown(struct snd_pcm_substream *substream, 50 66 struct snd_soc_dai *dai) 51 67 { 52 - struct sdw_stream_data *stream; 53 - 54 - stream = snd_soc_dai_get_dma_data(dai, substream); 55 68 snd_soc_dai_set_dma_data(dai, substream, NULL); 56 - kfree(stream); 57 69 } 58 70 59 71 static int sdw_mockup_pcm_hw_params(struct snd_pcm_substream *substream, ··· 60 80 struct sdw_mockup_priv *sdw_mockup = snd_soc_component_get_drvdata(component); 61 81 struct sdw_stream_config stream_config = {0}; 62 82 struct sdw_port_config port_config = {0}; 63 - struct sdw_stream_data *stream; 83 + struct sdw_stream_runtime *sdw_stream = snd_soc_dai_get_dma_data(dai, substream); 64 84 int ret; 65 85 66 - stream = snd_soc_dai_get_dma_data(dai, substream); 67 - if (!stream) 86 + if (!sdw_stream) 68 87 return -EINVAL; 69 88 70 89 if (!sdw_mockup->slave) ··· 78 99 port_config.num = 8; 79 100 80 101 ret = sdw_stream_add_slave(sdw_mockup->slave, &stream_config, 81 - &port_config, 1, stream->sdw_stream); 102 + &port_config, 1, sdw_stream); 82 103 if (ret) 83 104 dev_err(dai->dev, "Unable to configure port\n"); 84 105 ··· 90 111 { 91 112 struct snd_soc_component *component = dai->component; 92 113 struct sdw_mockup_priv *sdw_mockup = snd_soc_component_get_drvdata(component); 93 - struct sdw_stream_data *stream = 94 - snd_soc_dai_get_dma_data(dai, substream); 114 + struct sdw_stream_runtime *sdw_stream = snd_soc_dai_get_dma_data(dai, substream); 95 115 96 116 if (!sdw_mockup->slave) 97 117 return -EINVAL; 98 118 99 - sdw_stream_remove_slave(sdw_mockup->slave, stream->sdw_stream); 119 + sdw_stream_remove_slave(sdw_mockup->slave, sdw_stream); 100 120 return 0; 101 121 } 102 122