Skip to content

Commit 0cbcced

Browse files
charleskeepaxvinodkoul
authored andcommitted
soundwire: stream: Remove unnecessary gotos
There is a lot of code using gotos to skip small sections of code, this is a fairly dubious use of a goto, especially when the level of intentation is really low. Most of this code doesn't even breach 80 characters when naively shifted over. Simplify the code a bit, by replacing these unnecessary gotos with simple ifs. Signed-off-by: Charles Keepax <[email protected]> Reviewed-by: Pierre-Louis Bossart <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent e024064 commit 0cbcced

File tree

1 file changed

+56
-68
lines changed

1 file changed

+56
-68
lines changed

drivers/soundwire/stream.c

Lines changed: 56 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,25 +1355,23 @@ static int _sdw_prepare_stream(struct sdw_stream_runtime *stream,
13551355
return -EINVAL;
13561356
}
13571357

1358-
if (!update_params)
1359-
goto program_params;
1360-
1361-
/* Increment cumulative bus bandwidth */
1362-
/* TODO: Update this during Device-Device support */
1363-
bus->params.bandwidth += m_rt->stream->params.rate *
1364-
m_rt->ch_count * m_rt->stream->params.bps;
1365-
1366-
/* Compute params */
1367-
if (bus->compute_params) {
1368-
ret = bus->compute_params(bus);
1369-
if (ret < 0) {
1370-
dev_err(bus->dev, "Compute params failed: %d\n",
1371-
ret);
1372-
goto restore_params;
1358+
if (update_params) {
1359+
/* Increment cumulative bus bandwidth */
1360+
/* TODO: Update this during Device-Device support */
1361+
bus->params.bandwidth += m_rt->stream->params.rate *
1362+
m_rt->ch_count * m_rt->stream->params.bps;
1363+
1364+
/* Compute params */
1365+
if (bus->compute_params) {
1366+
ret = bus->compute_params(bus);
1367+
if (ret < 0) {
1368+
dev_err(bus->dev, "Compute params failed: %d\n",
1369+
ret);
1370+
goto restore_params;
1371+
}
13731372
}
13741373
}
13751374

1376-
program_params:
13771375
/* Program params */
13781376
ret = sdw_program_params(bus, true);
13791377
if (ret < 0) {
@@ -1876,30 +1874,25 @@ int sdw_stream_add_master(struct sdw_bus *bus,
18761874
* it first), if so skip allocation and go to configuration
18771875
*/
18781876
m_rt = sdw_master_rt_find(bus, stream);
1879-
if (m_rt)
1880-
goto skip_alloc_master_rt;
1881-
1882-
m_rt = sdw_master_rt_alloc(bus, stream);
18831877
if (!m_rt) {
1884-
dev_err(bus->dev, "%s: Master runtime alloc failed for stream:%s\n",
1885-
__func__, stream->name);
1886-
ret = -ENOMEM;
1887-
goto unlock;
1888-
}
1889-
1890-
alloc_master_rt = true;
1891-
skip_alloc_master_rt:
1892-
1893-
if (sdw_master_port_allocated(m_rt))
1894-
goto skip_alloc_master_port;
1878+
m_rt = sdw_master_rt_alloc(bus, stream);
1879+
if (!m_rt) {
1880+
dev_err(bus->dev, "%s: Master runtime alloc failed for stream:%s\n",
1881+
__func__, stream->name);
1882+
ret = -ENOMEM;
1883+
goto unlock;
1884+
}
18951885

1896-
ret = sdw_master_port_alloc(m_rt, num_ports);
1897-
if (ret)
1898-
goto alloc_error;
1886+
alloc_master_rt = true;
1887+
}
18991888

1900-
stream->m_rt_count++;
1889+
if (!sdw_master_port_allocated(m_rt)) {
1890+
ret = sdw_master_port_alloc(m_rt, num_ports);
1891+
if (ret)
1892+
goto alloc_error;
19011893

1902-
skip_alloc_master_port:
1894+
stream->m_rt_count++;
1895+
}
19031896

19041897
ret = sdw_master_rt_config(m_rt, stream_config);
19051898
if (ret < 0)
@@ -1992,46 +1985,41 @@ int sdw_stream_add_slave(struct sdw_slave *slave,
19921985
* and go to configuration
19931986
*/
19941987
m_rt = sdw_master_rt_find(slave->bus, stream);
1995-
if (m_rt)
1996-
goto skip_alloc_master_rt;
1997-
1998-
/*
1999-
* If this API is invoked by Slave first then m_rt is not valid.
2000-
* So, allocate m_rt and add Slave to it.
2001-
*/
2002-
m_rt = sdw_master_rt_alloc(slave->bus, stream);
20031988
if (!m_rt) {
2004-
dev_err(&slave->dev, "%s: Master runtime alloc failed for stream:%s\n",
2005-
__func__, stream->name);
2006-
ret = -ENOMEM;
2007-
goto unlock;
2008-
}
1989+
/*
1990+
* If this API is invoked by Slave first then m_rt is not valid.
1991+
* So, allocate m_rt and add Slave to it.
1992+
*/
1993+
m_rt = sdw_master_rt_alloc(slave->bus, stream);
1994+
if (!m_rt) {
1995+
dev_err(&slave->dev, "%s: Master runtime alloc failed for stream:%s\n",
1996+
__func__, stream->name);
1997+
ret = -ENOMEM;
1998+
goto unlock;
1999+
}
20092000

2010-
alloc_master_rt = true;
2001+
alloc_master_rt = true;
2002+
}
20112003

2012-
skip_alloc_master_rt:
20132004
s_rt = sdw_slave_rt_find(slave, stream);
2014-
if (s_rt)
2015-
goto skip_alloc_slave_rt;
2016-
2017-
s_rt = sdw_slave_rt_alloc(slave, m_rt);
20182005
if (!s_rt) {
2019-
dev_err(&slave->dev, "Slave runtime alloc failed for stream:%s\n", stream->name);
2020-
ret = -ENOMEM;
2021-
goto alloc_error;
2022-
}
2023-
2024-
alloc_slave_rt = true;
2006+
s_rt = sdw_slave_rt_alloc(slave, m_rt);
2007+
if (!s_rt) {
2008+
dev_err(&slave->dev, "Slave runtime alloc failed for stream:%s\n",
2009+
stream->name);
2010+
ret = -ENOMEM;
2011+
goto alloc_error;
2012+
}
20252013

2026-
skip_alloc_slave_rt:
2027-
if (sdw_slave_port_allocated(s_rt))
2028-
goto skip_port_alloc;
2014+
alloc_slave_rt = true;
2015+
}
20292016

2030-
ret = sdw_slave_port_alloc(slave, s_rt, num_ports);
2031-
if (ret)
2032-
goto alloc_error;
2017+
if (!sdw_slave_port_allocated(s_rt)) {
2018+
ret = sdw_slave_port_alloc(slave, s_rt, num_ports);
2019+
if (ret)
2020+
goto alloc_error;
2021+
}
20332022

2034-
skip_port_alloc:
20352023
ret = sdw_master_rt_config(m_rt, stream_config);
20362024
if (ret)
20372025
goto unlock;

0 commit comments

Comments
 (0)