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

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

authored by

Pierre-Louis Bossart and committed by
Mark Brown
b2790ecc fa55b31f

+7 -27
+7 -23
sound/soc/codecs/rt711-sdca.c
··· 1237 1237 static int rt711_sdca_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, 1238 1238 int direction) 1239 1239 { 1240 - struct sdw_stream_data *stream; 1241 - 1242 - if (!sdw_stream) 1243 - return 0; 1244 - 1245 - stream = kzalloc(sizeof(*stream), GFP_KERNEL); 1246 - if (!stream) 1247 - return -ENOMEM; 1248 - 1249 - stream->sdw_stream = sdw_stream; 1250 - 1251 - /* Use tx_mask or rx_mask to configure stream tag and set dma_data */ 1252 - snd_soc_dai_dma_data_set(dai, direction, stream); 1240 + snd_soc_dai_dma_data_set(dai, direction, sdw_stream); 1253 1241 1254 1242 return 0; 1255 1243 } ··· 1245 1257 static void rt711_sdca_shutdown(struct snd_pcm_substream *substream, 1246 1258 struct snd_soc_dai *dai) 1247 1259 { 1248 - struct sdw_stream_data *stream; 1249 - 1250 - stream = snd_soc_dai_get_dma_data(dai, substream); 1251 1260 snd_soc_dai_set_dma_data(dai, substream, NULL); 1252 - kfree(stream); 1253 1261 } 1254 1262 1255 1263 static int rt711_sdca_pcm_hw_params(struct snd_pcm_substream *substream, ··· 1256 1272 struct rt711_sdca_priv *rt711 = snd_soc_component_get_drvdata(component); 1257 1273 struct sdw_stream_config stream_config = {0}; 1258 1274 struct sdw_port_config port_config = {0}; 1259 - struct sdw_stream_data *stream; 1275 + struct sdw_stream_runtime *sdw_stream; 1260 1276 int retval; 1261 1277 unsigned int sampling_rate; 1262 1278 1263 1279 dev_dbg(dai->dev, "%s %s", __func__, dai->name); 1264 - stream = snd_soc_dai_get_dma_data(dai, substream); 1280 + sdw_stream = snd_soc_dai_get_dma_data(dai, substream); 1265 1281 1266 - if (!stream) 1282 + if (!sdw_stream) 1267 1283 return -EINVAL; 1268 1284 1269 1285 if (!rt711->slave) ··· 1284 1300 } 1285 1301 1286 1302 retval = sdw_stream_add_slave(rt711->slave, &stream_config, 1287 - &port_config, 1, stream->sdw_stream); 1303 + &port_config, 1, sdw_stream); 1288 1304 if (retval) { 1289 1305 dev_err(dai->dev, "Unable to configure port\n"); 1290 1306 return retval; ··· 1335 1351 { 1336 1352 struct snd_soc_component *component = dai->component; 1337 1353 struct rt711_sdca_priv *rt711 = snd_soc_component_get_drvdata(component); 1338 - struct sdw_stream_data *stream = 1354 + struct sdw_stream_runtime *sdw_stream = 1339 1355 snd_soc_dai_get_dma_data(dai, substream); 1340 1356 1341 1357 if (!rt711->slave) 1342 1358 return -EINVAL; 1343 1359 1344 - sdw_stream_remove_slave(rt711->slave, stream->sdw_stream); 1360 + sdw_stream_remove_slave(rt711->slave, sdw_stream); 1345 1361 return 0; 1346 1362 } 1347 1363
-4
sound/soc/codecs/rt711-sdca.h
··· 36 36 bool fu1e_dapm_mute, fu1e_mixer_l_mute, fu1e_mixer_r_mute; 37 37 }; 38 38 39 - struct sdw_stream_data { 40 - struct sdw_stream_runtime *sdw_stream; 41 - }; 42 - 43 39 /* NID */ 44 40 #define RT711_AUDIO_FUNCTION_GROUP 0x01 45 41 #define RT711_DAC_OUT2 0x03