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

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

authored by

Pierre-Louis Bossart and committed by
Mark Brown
be8e5a85 1294d7d7

+7 -27
+7 -23
sound/soc/codecs/rt1318-sdw.c
··· 562 562 static int rt1318_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, 563 563 int direction) 564 564 { 565 - struct sdw_stream_data *stream; 566 - 567 - if (!sdw_stream) 568 - return 0; 569 - 570 - stream = kzalloc(sizeof(*stream), GFP_KERNEL); 571 - if (!stream) 572 - return -ENOMEM; 573 - 574 - stream->sdw_stream = sdw_stream; 575 - 576 - /* Use tx_mask or rx_mask to configure stream tag and set dma_data */ 577 - snd_soc_dai_dma_data_set(dai, direction, stream); 565 + snd_soc_dai_dma_data_set(dai, direction, sdw_stream); 578 566 579 567 return 0; 580 568 } ··· 570 582 static void rt1318_sdw_shutdown(struct snd_pcm_substream *substream, 571 583 struct snd_soc_dai *dai) 572 584 { 573 - struct sdw_stream_data *stream; 574 - 575 - stream = snd_soc_dai_get_dma_data(dai, substream); 576 585 snd_soc_dai_set_dma_data(dai, substream, NULL); 577 - kfree(stream); 578 586 } 579 587 580 588 static int rt1318_sdw_hw_params(struct snd_pcm_substream *substream, ··· 582 598 struct sdw_stream_config stream_config; 583 599 struct sdw_port_config port_config; 584 600 enum sdw_data_direction direction; 585 - struct sdw_stream_data *stream; 601 + struct sdw_stream_runtime *sdw_stream; 586 602 int retval, port, num_channels, ch_mask; 587 603 unsigned int sampling_rate; 588 604 589 605 dev_dbg(dai->dev, "%s %s", __func__, dai->name); 590 - stream = snd_soc_dai_get_dma_data(dai, substream); 606 + sdw_stream = snd_soc_dai_get_dma_data(dai, substream); 591 607 592 - if (!stream) 608 + if (!sdw_stream) 593 609 return -EINVAL; 594 610 595 611 if (!rt1318->sdw_slave) ··· 617 633 port_config.num = port; 618 634 619 635 retval = sdw_stream_add_slave(rt1318->sdw_slave, &stream_config, 620 - &port_config, 1, stream->sdw_stream); 636 + &port_config, 1, sdw_stream); 621 637 if (retval) { 622 638 dev_err(dai->dev, "Unable to configure port\n"); 623 639 return retval; ··· 663 679 struct snd_soc_component *component = dai->component; 664 680 struct rt1318_sdw_priv *rt1318 = 665 681 snd_soc_component_get_drvdata(component); 666 - struct sdw_stream_data *stream = 682 + struct sdw_stream_runtime *sdw_stream = 667 683 snd_soc_dai_get_dma_data(dai, substream); 668 684 669 685 if (!rt1318->sdw_slave) 670 686 return -EINVAL; 671 687 672 - sdw_stream_remove_slave(rt1318->sdw_slave, stream->sdw_stream); 688 + sdw_stream_remove_slave(rt1318->sdw_slave, sdw_stream); 673 689 return 0; 674 690 } 675 691
-4
sound/soc/codecs/rt1318-sdw.h
··· 94 94 bool first_hw_init; 95 95 }; 96 96 97 - struct sdw_stream_data { 98 - struct sdw_stream_runtime *sdw_stream; 99 - }; 100 - 101 97 #endif /* __RT1318_SDW_H__ */