Skip to contentSkip to conversation

ASoC: codecs: rt*-sdw: memory leaks and simplifications

PATCH In review Pierre-Louis Bossart 2 participants 5 messages May 15, 2020 – May 18, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover ASoC: codecs: rt*-sdw: memory leaks and simplifications

While debugging unrelated memory corruption errors, I detected issues related to the interaction with the SoundWire and ASoC cores, here are 3 small patches to fix all this.

Pierre-Louis Bossart (3):
ASoC: codecs: rt*-sdw: don't assign slave_ops
ASoC: codecs: rt*-sdw: fix memory leak in set_sdw_stream()
ASoC: codecs: rt1308-sdw: remove duplicate allocation

 sound/soc/codecs/rt1308-sdw.c | 11 +++--------
 sound/soc/codecs/rt5682-sdw.c |  3 ---
 sound/soc/codecs/rt5682.c     |  3 +++
 sound/soc/codecs/rt700-sdw.c  |  3 ---
 sound/soc/codecs/rt700.c      |  3 +++
 sound/soc/codecs/rt711-sdw.c  |  3 ---
 sound/soc/codecs/rt711.c      |  3 +++
 sound/soc/codecs/rt715-sdw.c  |  3 ---
 sound/soc/codecs/rt715.c      |  3 +++
 9 files changed, 15 insertions(+), 20 deletions(-)

base-commit: d731c1a0f935dbebf4a851e072f8c7309eb2b8c5

Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/3 ASoC: codecs: rt*-sdw: don't assign slave_ops

The SoundWire bus core already assigns the slave ops, no need to set them a second time manually in each driver.

---
 sound/soc/codecs/rt1308-sdw.c | 3 ---
 sound/soc/codecs/rt5682-sdw.c | 3 ---
 sound/soc/codecs/rt700-sdw.c  | 3 ---
 sound/soc/codecs/rt711-sdw.c  | 3 ---
 sound/soc/codecs/rt715-sdw.c  | 3 ---
 5 files changed, 15 deletions(-)
sound/soc/codecs/rt1308-sdw.c +0 -3
index 1502a22b0d4a..4b88fa8efb27 100644
@@ -684,9 +684,6 @@ static int rt1308_sdw_probe(struct sdw_slave *slave,
 {
 	struct regmap *regmap;
 
-	/* Assign ops */
-	slave->ops = &rt1308_slave_ops;
-
 	/* Regmap Initialization */
 	regmap = devm_regmap_init_sdw(slave, &rt1308_sdw_regmap);
 	if (!regmap)
sound/soc/codecs/rt5682-sdw.c +0 -3
index a2d1d3ae1e31..99dd48d2a1d6 100644
@@ -241,9 +241,6 @@ static int rt5682_sdw_probe(struct sdw_slave *slave,
 {
 	struct regmap *regmap;
 
-	/* Assign ops */
-	slave->ops = &rt5682_slave_ops;
-
 	/* Regmap Initialization */
 	regmap = devm_regmap_init_sdw(slave, &rt5682_sdw_regmap);
 	if (IS_ERR(regmap))
sound/soc/codecs/rt700-sdw.c +0 -3
index d4e0f953bcce..4d14048d1197 100644
@@ -450,9 +450,6 @@ static int rt700_sdw_probe(struct sdw_slave *slave,
 {
 	struct regmap *sdw_regmap, *regmap;
 
-	/* Assign ops */
-	slave->ops = &rt700_slave_ops;
-
 	/* Regmap Initialization */
 	sdw_regmap = devm_regmap_init_sdw(slave, &rt700_sdw_regmap);
 	if (!sdw_regmap)
sound/soc/codecs/rt711-sdw.c +0 -3
index fc3a3fa3d51b..45b928954b58 100644
@@ -450,9 +450,6 @@ static int rt711_sdw_probe(struct sdw_slave *slave,
 {
 	struct regmap *sdw_regmap, *regmap;
 
-	/* Assign ops */
-	slave->ops = &rt711_slave_ops;
-
 	/* Regmap Initialization */
 	sdw_regmap = devm_regmap_init_sdw(slave, &rt711_sdw_regmap);
 	if (!sdw_regmap)
sound/soc/codecs/rt715-sdw.c +0 -3
index 64ef56ef0318..d11b23d6b240 100644
@@ -525,9 +525,6 @@ static int rt715_sdw_probe(struct sdw_slave *slave,
 {
 	struct regmap *sdw_regmap, *regmap;
 
-	/* Assign ops */
-	slave->ops = &rt715_slave_ops;
-
 	/* Regmap Initialization */
 	sdw_regmap = devm_regmap_init_sdw(slave, &rt715_sdw_regmap);
 	if (!sdw_regmap)
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/3 ASoC: codecs: rt*-sdw: fix memory leak in set_sdw_stream()

In reply to Pierre-Louis Bossart

Now that the sdw_stream is allocated in machine driver, set_sdw_stream() is also called with a NULL argument during the dailink shutdown.

In this case, the drivers should not allocate any memory, and just return.

Detected with KASAN/kmemleak.

---
 sound/soc/codecs/rt1308-sdw.c | 3 +++
 sound/soc/codecs/rt5682.c     | 3 +++
 sound/soc/codecs/rt700.c      | 3 +++
 sound/soc/codecs/rt711.c      | 3 +++
 sound/soc/codecs/rt715.c      | 3 +++
 5 files changed, 15 insertions(+)
sound/soc/codecs/rt1308-sdw.c +3 -0
index 4b88fa8efb27..91cc5a15c211 100644
@@ -482,6 +482,9 @@ static int rt1308_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream,
 {
 	struct sdw_stream_data *stream;
 
+	if (!sdw_stream)
+		return 0;
+
 	stream = kzalloc(sizeof(*stream), GFP_KERNEL);
 	if (!stream)
 		return -ENOMEM;
sound/soc/codecs/rt5682.c +3 -0
index 5d3b11756a34..046e6110de73 100644
@@ -2935,6 +2935,9 @@ static int rt5682_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream,
 {
 	struct sdw_stream_data *stream;
 
+	if (!sdw_stream)
+		return 0;
+
 	stream = kzalloc(sizeof(*stream), GFP_KERNEL);
 	if (!stream)
 		return -ENOMEM;
sound/soc/codecs/rt700.c +3 -0
index ff68f0e4f629..687ac2153666 100644
@@ -860,6 +860,9 @@ static int rt700_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream,
 {
 	struct sdw_stream_data *stream;
 
+	if (!sdw_stream)
+		return 0;
+
 	stream = kzalloc(sizeof(*stream), GFP_KERNEL);
 	if (!stream)
 		return -ENOMEM;
sound/soc/codecs/rt711.c +3 -0
index 2daed7692a3b..65b59dbfb43c 100644
@@ -906,6 +906,9 @@ static int rt711_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream,
 {
 	struct sdw_stream_data *stream;
 
+	if (!sdw_stream)
+		return 0;
+
 	stream = kzalloc(sizeof(*stream), GFP_KERNEL);
 	if (!stream)
 		return -ENOMEM;
sound/soc/codecs/rt715.c +3 -0
index 2cbc57b16b13..099c8bd20006 100644
@@ -530,6 +530,9 @@ static int rt715_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream,
 
 	struct sdw_stream_data *stream;
 
+	if (!sdw_stream)
+		return 0;
+
 	stream = kzalloc(sizeof(*stream), GFP_KERNEL);
 	if (!stream)
 		return -ENOMEM;
Signature · 1 line
2.20.1
#3 lore raw

PATCH 3/3 ASoC: codecs: rt1308-sdw: remove duplicate allocation

In reply to Pierre-Louis Bossart

The .read_prop callback is supposed to be called by the SoundWire core only. Calling it again from this driver results in an additional memory allocation for no good reason.

---
 sound/soc/codecs/rt1308-sdw.c | 5 -----
 1 file changed, 5 deletions(-)
sound/soc/codecs/rt1308-sdw.c +0 -5
index 91cc5a15c211..b0ba0d2acbdd 100644
@@ -178,10 +178,6 @@ static int rt1308_io_init(struct device *dev, struct sdw_slave *slave)
 	if (rt1308->hw_init)
 		return 0;
 
-	ret = rt1308_read_prop(slave);
-	if (ret < 0)
-		goto _io_init_err_;
-
 	if (rt1308->first_hw_init) {
 		regcache_cache_only(rt1308->regmap, false);
 		regcache_cache_bypass(rt1308->regmap, true);
@@ -282,7 +278,6 @@ static int rt1308_io_init(struct device *dev, struct sdw_slave *slave)
 
 	dev_dbg(&slave->dev, "%s hw_init complete\n", __func__);
 
-_io_init_err_:
 	return ret;
 }
 
Signature · 1 line
2.20.1
maintainer
#4 lore raw
In reply to Pierre-Louis Bossart
Quoted 10 lines · Pierre-Louis Bossart

While debugging unrelated memory corruption errors, I detected issues related to the interaction with the SoundWire and ASoC cores, here are 3 small patches to fix all this.

Pierre-Louis Bossart (3):
ASoC: codecs: rt*-sdw: don't assign slave_ops
ASoC: codecs: rt*-sdw: fix memory leak in set_sdw_stream()
ASoC: codecs: rt1308-sdw: remove duplicate allocation

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.8

Thanks!

[1/3] ASoC: codecs: rt*-sdw: don't assign slave_ops

      commit: b5dff6ec13260585164d4cd13d7a3ec79bd26acb
[2/3] ASoC: codecs: rt*-sdw: fix memory leak in set_sdw_stream()
      commit: 07b542fe831cbefce163ad1b3aa7292c8a6332b8
[3/3] ASoC: codecs: rt1308-sdw: remove duplicate allocation
      commit: ee5866222ab58531c988492ea54931c1346d4fd4

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark