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

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

authored by

Pierre-Louis Bossart and committed by
Mark Brown
cf1d6a3a e506b2bd

+7 -27
+7 -23
sound/soc/codecs/rt715-sdca.c
··· 784 784 static int rt715_sdca_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, 785 785 int direction) 786 786 { 787 - struct rt715_sdw_stream_data *stream; 788 - 789 - stream = kzalloc(sizeof(*stream), GFP_KERNEL); 790 - if (!stream) 791 - return -ENOMEM; 792 - 793 - stream->sdw_stream = sdw_stream; 794 - 795 - /* Use tx_mask or rx_mask to configure stream tag and set dma_data */ 796 - snd_soc_dai_dma_data_set(dai, direction, stream); 787 + snd_soc_dai_dma_data_set(dai, direction, sdw_stream); 797 788 798 789 return 0; 799 790 } ··· 793 802 struct snd_soc_dai *dai) 794 803 795 804 { 796 - struct rt715_sdw_stream_data *stream; 797 - 798 - stream = snd_soc_dai_get_dma_data(dai, substream); 799 - if (!stream) 800 - return; 801 - 802 805 snd_soc_dai_set_dma_data(dai, substream, NULL); 803 - kfree(stream); 804 806 } 805 807 806 808 static int rt715_sdca_pcm_hw_params(struct snd_pcm_substream *substream, ··· 804 820 struct rt715_sdca_priv *rt715 = snd_soc_component_get_drvdata(component); 805 821 struct sdw_stream_config stream_config = {0}; 806 822 struct sdw_port_config port_config = {0}; 807 - struct rt715_sdw_stream_data *stream; 823 + struct sdw_stream_runtime *sdw_stream; 808 824 int retval; 809 825 unsigned int val; 810 826 811 - stream = snd_soc_dai_get_dma_data(dai, substream); 827 + sdw_stream = snd_soc_dai_get_dma_data(dai, substream); 812 828 813 - if (!stream) 829 + if (!sdw_stream) 814 830 return -EINVAL; 815 831 816 832 if (!rt715->slave) ··· 835 851 } 836 852 837 853 retval = sdw_stream_add_slave(rt715->slave, &stream_config, 838 - &port_config, 1, stream->sdw_stream); 854 + &port_config, 1, sdw_stream); 839 855 if (retval) { 840 856 dev_err(component->dev, "Unable to configure port, retval:%d\n", 841 857 retval); ··· 906 922 { 907 923 struct snd_soc_component *component = dai->component; 908 924 struct rt715_sdca_priv *rt715 = snd_soc_component_get_drvdata(component); 909 - struct rt715_sdw_stream_data *stream = 925 + struct sdw_stream_runtime *sdw_stream = 910 926 snd_soc_dai_get_dma_data(dai, substream); 911 927 912 928 if (!rt715->slave) 913 929 return -EINVAL; 914 930 915 - sdw_stream_remove_slave(rt715->slave, stream->sdw_stream); 931 + sdw_stream_remove_slave(rt715->slave, sdw_stream); 916 932 return 0; 917 933 } 918 934
-4
sound/soc/codecs/rt715-sdca.h
··· 37 37 int kctl_8ch_orig[8]; 38 38 }; 39 39 40 - struct rt715_sdw_stream_data { 41 - struct sdw_stream_runtime *sdw_stream; 42 - }; 43 - 44 40 struct rt715_sdca_kcontrol_private { 45 41 unsigned int reg_base; 46 42 unsigned int count;