Skip to content

Commit f3016b8

Browse files
plbossartvinodkoul
authored andcommitted
soundwire: stream: sdw_stream_add_ functions can be called multiple times
The sdw_stream_add_slave/master() functions are called from the .hw_params stage. We need to make sure the functions can be called multiple times. In this version, we assume that only 'audio' parameters provide in the hw_params() can change. If the number of ports could change dynamically depending on the stream configuration (number of channels, etc), we would need to free-up all the stream resources and reallocate them. Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@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/20220126011715.28204-19-yung-chuan.liao@linux.intel.com Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent 5e1df54 commit f3016b8

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

drivers/soundwire/stream.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,11 @@ static void sdw_port_free(struct sdw_port_runtime *p_rt)
898898
kfree(p_rt);
899899
}
900900

901+
static bool sdw_slave_port_allocated(struct sdw_slave_runtime *s_rt)
902+
{
903+
return !list_empty(&s_rt->port_list);
904+
}
905+
901906
static void sdw_slave_port_free(struct sdw_slave *slave,
902907
struct sdw_stream_runtime *stream)
903908
{
@@ -972,6 +977,11 @@ static int sdw_slave_port_config(struct sdw_slave *slave,
972977
return 0;
973978
}
974979

980+
static bool sdw_master_port_allocated(struct sdw_master_runtime *m_rt)
981+
{
982+
return !list_empty(&m_rt->port_list);
983+
}
984+
975985
static void sdw_master_port_free(struct sdw_master_runtime *m_rt)
976986
{
977987
struct sdw_port_runtime *p_rt, *_p_rt;
@@ -1856,12 +1866,17 @@ int sdw_stream_add_master(struct sdw_bus *bus,
18561866
}
18571867
skip_alloc_master_rt:
18581868

1869+
if (sdw_master_port_allocated(m_rt))
1870+
goto skip_alloc_master_port;
1871+
18591872
ret = sdw_master_port_alloc(m_rt, num_ports);
18601873
if (ret)
18611874
goto alloc_error;
18621875

18631876
stream->m_rt_count++;
18641877

1878+
skip_alloc_master_port:
1879+
18651880
ret = sdw_master_rt_config(m_rt, stream_config);
18661881
if (ret < 0)
18671882
goto unlock;
@@ -1970,6 +1985,10 @@ int sdw_stream_add_slave(struct sdw_slave *slave,
19701985
}
19711986

19721987
skip_alloc_master_rt:
1988+
s_rt = sdw_slave_rt_find(slave, stream);
1989+
if (s_rt)
1990+
goto skip_alloc_slave_rt;
1991+
19731992
s_rt = sdw_slave_rt_alloc(slave, m_rt);
19741993
if (!s_rt) {
19751994
dev_err(&slave->dev, "Slave runtime alloc failed for stream:%s\n", stream->name);
@@ -1978,10 +1997,15 @@ int sdw_stream_add_slave(struct sdw_slave *slave,
19781997
goto alloc_error;
19791998
}
19801999

2000+
skip_alloc_slave_rt:
2001+
if (sdw_slave_port_allocated(s_rt))
2002+
goto skip_port_alloc;
2003+
19812004
ret = sdw_slave_port_alloc(slave, s_rt, num_ports);
19822005
if (ret)
19832006
goto alloc_error;
19842007

2008+
skip_port_alloc:
19852009
ret = sdw_master_rt_config(m_rt, stream_config);
19862010
if (ret)
19872011
goto unlock;

0 commit comments

Comments
 (0)