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

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

authored by

Pierre-Louis Bossart and committed by
Mark Brown
ce8ffc1b 658d6f73

+7 -27
+7 -23
sound/soc/codecs/rt1308-sdw.c
··· 496 496 static int rt1308_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, 497 497 int direction) 498 498 { 499 - struct sdw_stream_data *stream; 500 - 501 - if (!sdw_stream) 502 - return 0; 503 - 504 - stream = kzalloc(sizeof(*stream), GFP_KERNEL); 505 - if (!stream) 506 - return -ENOMEM; 507 - 508 - stream->sdw_stream = sdw_stream; 509 - 510 - /* Use tx_mask or rx_mask to configure stream tag and set dma_data */ 511 - snd_soc_dai_dma_data_set(dai, direction, stream); 499 + snd_soc_dai_dma_data_set(dai, direction, sdw_stream); 512 500 513 501 return 0; 514 502 } ··· 504 516 static void rt1308_sdw_shutdown(struct snd_pcm_substream *substream, 505 517 struct snd_soc_dai *dai) 506 518 { 507 - struct sdw_stream_data *stream; 508 - 509 - stream = snd_soc_dai_get_dma_data(dai, substream); 510 519 snd_soc_dai_set_dma_data(dai, substream, NULL); 511 - kfree(stream); 512 520 } 513 521 514 522 static int rt1308_sdw_set_tdm_slot(struct snd_soc_dai *dai, ··· 537 553 snd_soc_component_get_drvdata(component); 538 554 struct sdw_stream_config stream_config = {0}; 539 555 struct sdw_port_config port_config = {0}; 540 - struct sdw_stream_data *stream; 556 + struct sdw_stream_runtime *sdw_stream; 541 557 int retval; 542 558 543 559 dev_dbg(dai->dev, "%s %s", __func__, dai->name); 544 - stream = snd_soc_dai_get_dma_data(dai, substream); 560 + sdw_stream = snd_soc_dai_get_dma_data(dai, substream); 545 561 546 - if (!stream) 562 + if (!sdw_stream) 547 563 return -EINVAL; 548 564 549 565 if (!rt1308->sdw_slave) ··· 564 580 } 565 581 566 582 retval = sdw_stream_add_slave(rt1308->sdw_slave, &stream_config, 567 - &port_config, 1, stream->sdw_stream); 583 + &port_config, 1, sdw_stream); 568 584 if (retval) { 569 585 dev_err(dai->dev, "Unable to configure port\n"); 570 586 return retval; ··· 579 595 struct snd_soc_component *component = dai->component; 580 596 struct rt1308_sdw_priv *rt1308 = 581 597 snd_soc_component_get_drvdata(component); 582 - struct sdw_stream_data *stream = 598 + struct sdw_stream_runtime *sdw_stream = 583 599 snd_soc_dai_get_dma_data(dai, substream); 584 600 585 601 if (!rt1308->sdw_slave) 586 602 return -EINVAL; 587 603 588 - sdw_stream_remove_slave(rt1308->sdw_slave, stream->sdw_stream); 604 + sdw_stream_remove_slave(rt1308->sdw_slave, sdw_stream); 589 605 return 0; 590 606 } 591 607
-4
sound/soc/codecs/rt1308-sdw.h
··· 170 170 unsigned int bq_params_cnt; 171 171 }; 172 172 173 - struct sdw_stream_data { 174 - struct sdw_stream_runtime *sdw_stream; 175 - }; 176 - 177 173 #endif /* __RT1308_SDW_H__ */