ASoC: codecs: rt*-sdw: memory leaks and simplifications
Subsystems (3)
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
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH 2/3 ASoC: codecs: rt*-sdw: fix memory leak in set_sdw_stream()
In reply to Pierre-Louis BossartNow 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH 3/3 ASoC: codecs: rt1308-sdw: remove duplicate allocation
In reply to Pierre-Louis BossartThe .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
@@ -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
Mark Brown
maintainerQuoted 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 assignslave_ops
ASoC: codecs: rt*-sdw: fix memory leak inset_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: ee5866222ab58531c988492ea54931c1346d4fd4All 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