Skip to contentSkip to conversation

soundwire: stream: fix memory leak in stream config error path

PATCH Applied Bard Liao 2 participants 2 messages Mar 31, 2021 – Apr 1, 2021 SoundWire

lore
Share & tools
lore

Bard Liao

author maintainer
#0 lore raw

PATCH 1/1 soundwire: stream: fix memory leak in stream config error path

From: Rander Wang <[email protected]>

When stream config is failed, master runtime will release all slave runtime in the slave_rt_list, but slave runtime is not added to the list at this time. This patch frees slave runtime in the config error path to fix the memory leak.

Fixes bbe7379d8040a ("soundwire: Add support for SoundWire stream management")
---
 drivers/soundwire/stream.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/soundwire/stream.c +9 -1
index 9c064b672745..1eaedaaba094 100644
@@ -1375,8 +1375,16 @@ int sdw_stream_add_slave(struct sdw_slave *slave,
 	}
 
 	ret = sdw_config_stream(&slave->dev, stream, stream_config, true);
-	if (ret)
+	if (ret) {
+		/*
+		 * sdw_release_master_stream will release s_rt in slave_rt_list in
+		 * stream_error case, but s_rt is only added to slave_rt_list
+		 * when sdw_config_stream is successful, so free s_rt explicitly
+		 * when sdw_config_stream is failed.
+		 */
+		kfree(s_rt);
 		goto stream_error;
+	}
 
 	list_add_tail(&s_rt->m_rt_node, &m_rt->slave_rt_list);
 
Signature · 1 line
2.17.1
maintainer Applied
#1 lore raw
Quoted 6 lines · Bard Liao

From: Rander Wang <[email protected]>

When stream config is failed, master runtime will release all slave runtime in the slave_rt_list, but slave runtime is not added to the list at this time. This patch frees slave runtime in the config error path to fix the memory leak.

Applied, thanks

Signature · 1 line
~Vinod