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

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

authored by

Pierre-Louis Bossart and committed by
Mark Brown
e506b2bd 27843208

+7 -27
+7 -23
sound/soc/codecs/rt715.c
··· 765 765 int direction) 766 766 { 767 767 768 - struct sdw_stream_data *stream; 769 - 770 - if (!sdw_stream) 771 - return 0; 772 - 773 - stream = kzalloc(sizeof(*stream), GFP_KERNEL); 774 - if (!stream) 775 - return -ENOMEM; 776 - 777 - stream->sdw_stream = sdw_stream; 778 - 779 - /* Use tx_mask or rx_mask to configure stream tag and set dma_data */ 780 - snd_soc_dai_dma_data_set(dai, direction, stream); 768 + snd_soc_dai_dma_data_set(dai, direction, sdw_stream); 781 769 782 770 return 0; 783 771 } ··· 774 786 struct snd_soc_dai *dai) 775 787 776 788 { 777 - struct sdw_stream_data *stream; 778 - 779 - stream = snd_soc_dai_get_dma_data(dai, substream); 780 789 snd_soc_dai_set_dma_data(dai, substream, NULL); 781 - kfree(stream); 782 790 } 783 791 784 792 static int rt715_pcm_hw_params(struct snd_pcm_substream *substream, ··· 785 801 struct rt715_priv *rt715 = snd_soc_component_get_drvdata(component); 786 802 struct sdw_stream_config stream_config = {0}; 787 803 struct sdw_port_config port_config = {0}; 788 - struct sdw_stream_data *stream; 804 + struct sdw_stream_runtime *sdw_stream; 789 805 int retval; 790 806 unsigned int val = 0; 791 807 792 - stream = snd_soc_dai_get_dma_data(dai, substream); 808 + sdw_stream = snd_soc_dai_get_dma_data(dai, substream); 793 809 794 - if (!stream) 810 + if (!sdw_stream) 795 811 return -EINVAL; 796 812 797 813 if (!rt715->slave) ··· 814 830 } 815 831 816 832 retval = sdw_stream_add_slave(rt715->slave, &stream_config, 817 - &port_config, 1, stream->sdw_stream); 833 + &port_config, 1, sdw_stream); 818 834 if (retval) { 819 835 dev_err(dai->dev, "Unable to configure port\n"); 820 836 return retval; ··· 877 893 { 878 894 struct snd_soc_component *component = dai->component; 879 895 struct rt715_priv *rt715 = snd_soc_component_get_drvdata(component); 880 - struct sdw_stream_data *stream = 896 + struct sdw_stream_runtime *sdw_stream = 881 897 snd_soc_dai_get_dma_data(dai, substream); 882 898 883 899 if (!rt715->slave) 884 900 return -EINVAL; 885 901 886 - sdw_stream_remove_slave(rt715->slave, stream->sdw_stream); 902 + sdw_stream_remove_slave(rt715->slave, sdw_stream); 887 903 return 0; 888 904 } 889 905
-4
sound/soc/codecs/rt715.h
··· 27 27 unsigned int kctl_8ch_vol_ori[8]; 28 28 }; 29 29 30 - struct sdw_stream_data { 31 - struct sdw_stream_runtime *sdw_stream; 32 - }; 33 - 34 30 /* NID */ 35 31 #define RT715_AUDIO_FUNCTION_GROUP 0x01 36 32 #define RT715_MIC_ADC 0x07