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

ASoC: codecs: rt700-sdw: 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-8-yung-chuan.liao@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Pierre-Louis Bossart and committed by
Mark Brown
3bcced01 be8e5a85

+7 -27
+7 -23
sound/soc/codecs/rt700.c
··· 875 875 static int rt700_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, 876 876 int direction) 877 877 { 878 - struct sdw_stream_data *stream; 879 - 880 - if (!sdw_stream) 881 - return 0; 882 - 883 - stream = kzalloc(sizeof(*stream), GFP_KERNEL); 884 - if (!stream) 885 - return -ENOMEM; 886 - 887 - stream->sdw_stream = sdw_stream; 888 - 889 - /* Use tx_mask or rx_mask to configure stream tag and set dma_data */ 890 - snd_soc_dai_dma_data_set(dai, direction, stream); 878 + snd_soc_dai_dma_data_set(dai, direction, sdw_stream); 891 879 892 880 return 0; 893 881 } ··· 883 895 static void rt700_shutdown(struct snd_pcm_substream *substream, 884 896 struct snd_soc_dai *dai) 885 897 { 886 - struct sdw_stream_data *stream; 887 - 888 - stream = snd_soc_dai_get_dma_data(dai, substream); 889 898 snd_soc_dai_set_dma_data(dai, substream, NULL); 890 - kfree(stream); 891 899 } 892 900 893 901 static int rt700_pcm_hw_params(struct snd_pcm_substream *substream, ··· 894 910 struct rt700_priv *rt700 = snd_soc_component_get_drvdata(component); 895 911 struct sdw_stream_config stream_config = {0}; 896 912 struct sdw_port_config port_config = {0}; 897 - struct sdw_stream_data *stream; 913 + struct sdw_stream_runtime *sdw_stream; 898 914 int retval; 899 915 unsigned int val = 0; 900 916 901 917 dev_dbg(dai->dev, "%s %s", __func__, dai->name); 902 - stream = snd_soc_dai_get_dma_data(dai, substream); 918 + sdw_stream = snd_soc_dai_get_dma_data(dai, substream); 903 919 904 - if (!stream) 920 + if (!sdw_stream) 905 921 return -EINVAL; 906 922 907 923 if (!rt700->slave) ··· 928 944 } 929 945 930 946 retval = sdw_stream_add_slave(rt700->slave, &stream_config, 931 - &port_config, 1, stream->sdw_stream); 947 + &port_config, 1, sdw_stream); 932 948 if (retval) { 933 949 dev_err(dai->dev, "Unable to configure port\n"); 934 950 return retval; ··· 975 991 { 976 992 struct snd_soc_component *component = dai->component; 977 993 struct rt700_priv *rt700 = snd_soc_component_get_drvdata(component); 978 - struct sdw_stream_data *stream = 994 + struct sdw_stream_runtime *sdw_stream = 979 995 snd_soc_dai_get_dma_data(dai, substream); 980 996 981 997 if (!rt700->slave) 982 998 return -EINVAL; 983 999 984 - sdw_stream_remove_slave(rt700->slave, stream->sdw_stream); 1000 + sdw_stream_remove_slave(rt700->slave, sdw_stream); 985 1001 return 0; 986 1002 } 987 1003
-4
sound/soc/codecs/rt700.h
··· 27 27 bool disable_irq; 28 28 }; 29 29 30 - struct sdw_stream_data { 31 - struct sdw_stream_runtime *sdw_stream; 32 - }; 33 - 34 30 /* NID */ 35 31 #define RT700_AUDIO_FUNCTION_GROUP 0x01 36 32 #define RT700_DAC_OUT1 0x02