in stream.c [1345:1415]
int sdw_stream_add_slave(struct sdw_slave *slave,
struct sdw_stream_config *stream_config,
struct sdw_port_config *port_config,
unsigned int num_ports,
struct sdw_stream_runtime *stream)
{
struct sdw_slave_runtime *s_rt;
struct sdw_master_runtime *m_rt;
int ret;
mutex_lock(&slave->bus->bus_lock);
/*
* If this API is invoked by Slave first then m_rt is not valid.
* So, allocate m_rt and add Slave to it.
*/
m_rt = sdw_alloc_master_rt(slave->bus, stream_config, stream);
if (!m_rt) {
dev_err(&slave->dev,
"alloc master runtime failed for stream:%s\n",
stream->name);
ret = -ENOMEM;
goto error;
}
s_rt = sdw_alloc_slave_rt(slave, stream_config, stream);
if (!s_rt) {
dev_err(&slave->dev,
"Slave runtime config failed for stream:%s\n",
stream->name);
ret = -ENOMEM;
goto stream_error;
}
ret = sdw_config_stream(&slave->dev, stream, stream_config, true);
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);
ret = sdw_slave_port_config(slave, s_rt, port_config, num_ports);
if (ret)
goto stream_error;
/*
* Change stream state to CONFIGURED on first Slave add.
* Bus is not aware of number of Slave(s) in a stream at this
* point so cannot depend on all Slave(s) to be added in order to
* change stream state to CONFIGURED.
*/
stream->state = SDW_STREAM_CONFIGURED;
goto error;
stream_error:
/*
* we hit error so cleanup the stream, release all Slave(s) and
* Master runtime
*/
sdw_release_master_stream(m_rt, stream);
error:
mutex_unlock(&slave->bus->bus_lock);
return ret;
}