Skip to contentSkip to conversation

ASoC: rt712: fix uninitialized stream_config->type

PATCH Superseded [email protected] 2 participants 2 messages Sep 3

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 2/3 ASoC: rt712: fix uninitialized stream_config->type

From: Shuming Fan <[email protected]>

The stream_config variable was not initialized before being passed to sdw_stream_add_slave().
This may cause unexpected behavior when configuring the SoundWire stream.

---
 sound/soc/codecs/rt712-sdca.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
sound/soc/codecs/rt712-sdca.c +5 -9
index 13574513b181..588f2dc7f858 100644
@@ -23,6 +23,7 @@
 #include <linux/soundwire/sdw_registers.h>
 #include <linux/slab.h>
 #include <sound/soc-dapm.h>
+#include <sound/sdw.h>
 #include <sound/tlv.h>
 #include "rt712-sdca.h"
 
@@ -1449,11 +1450,11 @@ static int rt712_sdca_pcm_hw_params(struct snd_pcm_substream *substream,
 {
 	struct snd_soc_component *component = dai->component;
 	struct rt712_sdca_priv *rt712 = snd_soc_component_get_drvdata(component);
-	struct sdw_stream_config stream_config;
+	struct sdw_stream_config stream_config = {0};
 	struct sdw_port_config port_config;
 	enum sdw_data_direction direction;
 	struct sdw_stream_runtime *sdw_stream;
-	int retval, port, num_channels;
+	int retval, port;
 	unsigned int sampling_rate;
 
 	dev_dbg(dai->dev, "%s %s id %d", __func__, dai->name, dai->id);
@@ -1488,13 +1489,8 @@ static int rt712_sdca_pcm_hw_params(struct snd_pcm_substream *substream,
 			return -EINVAL;
 	}
 
-	stream_config.frame_rate = params_rate(params);
-	stream_config.ch_count = params_channels(params);
-	stream_config.bps = snd_pcm_format_width(params_format(params));
-	stream_config.direction = direction;
-
-	num_channels = params_channels(params);
-	port_config.ch_mask = GENMASK(num_channels - 1, 0);
+	/* SoundWire specific configuration */
+	snd_sdw_params_to_config(substream, params, &stream_config, &port_config);
 	port_config.num = port;
 
 	retval = sdw_stream_add_slave(rt712->slave, &stream_config,
Signature · 1 line
2.54.0
maintainer
#1 lore raw
Quoted 8 lines · On Thu, Sep 03, 2026 at 07:13:00PM +0800, [email protected] wrote:

From: Shuming Fan <[email protected]>

The stream_config variable was not initialized before being passed to sdw_stream_add_slave().
This may cause unexpected behavior when configuring the SoundWire stream.

sound/soc/codecs/rt712-sdca.c static int rt712_sdca_pcm_hw_params(struct snd_pcm_substream *substream, · line 1455

Quoted 7 lines
sound/soc/codecs/rt712-sdca.c +1 -1
@@ -1449,11 +1450,11 @@ static int rt712_sdca_pcm_hw_params(struct snd_pcm_substream *substream,
 {
 	struct snd_soc_component *component = dai->component;
 	struct rt712_sdca_priv *rt712 = snd_soc_component_get_drvdata(component);
-	struct sdw_stream_config stream_config;
+	struct sdw_stream_config stream_config = {0};
 	struct sdw_port_config port_config;
 	enum sdw_data_direction direction;

Do we still use direction after...

sound/soc/codecs/rt712-sdca.c static int rt712_sdca_pcm_hw_params(struct snd_pcm_substream *substream, · line 1494

Quoted 4 lines
sound/soc/codecs/rt712-sdca.c +0 -4
-	stream_config.frame_rate = params_rate(params);
-	stream_config.ch_count = params_channels(params);
-	stream_config.bps = snd_pcm_format_width(params_format(params));
-	stream_config.direction = direction;

...this? Some compilers will warn on write only variables, not just completely unused ones.