Skip to content

Commit 63fadaa

Browse files
plbossartvinodkoul
authored andcommitted
soundwire: stream: make enable/disable/deprepare idempotent
The stream management currently flags an 'inconsistent state' error when a change is requested multiple times. This was added on purpose to identify programming mistakes. In hindsight, there was no real reason to fail if the logic at the ASoC-DPCM level invokes the same callback multiple times. It's perfectly acceptable to just return and not flag an error when there is nothing to do. The main concern with the state management is to trap errors such as trying to enable a stream that was not prepared first. This patch suggests allowing the stream functions to be idempotent, i.e. they can be called multiple times. Note that the prepare case was already handling multiple calls, this was added in commit c32464c ("soundwire: stream: only prepare stream when it is configured.") 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-20-yung-chuan.liao@linux.intel.com Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent f3016b8 commit 63fadaa

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

drivers/soundwire/stream.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,11 @@ int sdw_enable_stream(struct sdw_stream_runtime *stream)
15051505

15061506
sdw_acquire_bus_lock(stream);
15071507

1508+
if (stream->state == SDW_STREAM_ENABLED) {
1509+
ret = 0;
1510+
goto state_err;
1511+
}
1512+
15081513
if (stream->state != SDW_STREAM_PREPARED &&
15091514
stream->state != SDW_STREAM_DISABLED) {
15101515
pr_err("%s: %s: inconsistent state state %d\n",
@@ -1588,6 +1593,11 @@ int sdw_disable_stream(struct sdw_stream_runtime *stream)
15881593

15891594
sdw_acquire_bus_lock(stream);
15901595

1596+
if (stream->state == SDW_STREAM_DISABLED) {
1597+
ret = 0;
1598+
goto state_err;
1599+
}
1600+
15911601
if (stream->state != SDW_STREAM_ENABLED) {
15921602
pr_err("%s: %s: inconsistent state state %d\n",
15931603
__func__, stream->name, stream->state);
@@ -1663,6 +1673,11 @@ int sdw_deprepare_stream(struct sdw_stream_runtime *stream)
16631673

16641674
sdw_acquire_bus_lock(stream);
16651675

1676+
if (stream->state == SDW_STREAM_DEPREPARED) {
1677+
ret = 0;
1678+
goto state_err;
1679+
}
1680+
16661681
if (stream->state != SDW_STREAM_PREPARED &&
16671682
stream->state != SDW_STREAM_DISABLED) {
16681683
pr_err("%s: %s: inconsistent state state %d\n",

0 commit comments

Comments
 (0)