Repository navigation
Conversation
lane_used_bandwidth is used to store the used bandwidth for each lane. When we restore the bus->params, the lane_used_bandwidth value will not be restored in current code. Move it to sdw_bus_params to fix the issue. Fixes: 366fd59 ("soundwire: generic_bandwidth_allocation: add lane in sdw_group_params") Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
bardliao
requested review from
davidlin923,
plbossart and
ujfalusi
and
a balanced review from Copilot
October 13, 2026 03:17
bardliao
requested review from
jack-cy-yu,
oder-chiou and
shumingfan
as code owners
October 13, 2026 03:17
There was a problem hiding this comment.
🟡 Changes recommended
The rollback path can program the wrong bus and perform invalid or unnecessary bank switches.
1 open finding
What changed in this PR
Fixes SoundWire bandwidth leakage when multi-link stream preparation fails.
Changes:
- Includes per-lane bandwidth in restorable bus parameters.
- Snapshots each master’s parameters before preparation.
- Adds multi-link rollback and bank restoration logic.
| File | Description |
|---|---|
include/linux/soundwire/sdw.h |
Moves lane bandwidth into bus parameters. |
drivers/soundwire/stream.c |
Adds snapshot and rollback handling. |
drivers/soundwire/generic_bandwidth_allocation.c |
Uses relocated lane bandwidth state. |
drivers/soundwire/bus.h |
Stores parameter snapshots per master runtime. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
bardliao
force-pushed
the
for-sdw-bandwidth-leak
branch
from
October 13, 2026 03:23
8f71e3c to
7f32ec1
Compare
bardliao
force-pushed
the
for-sdw-bandwidth-leak
branch
from
October 13, 2026 03:35
7f32ec1 to
b6fad93
Compare
bardliao
force-pushed
the
for-sdw-bandwidth-leak
branch
from
October 13, 2026 03:36
b6fad93 to
dc95264
Compare
Comment on lines
+1579
to
+1581
| ret1 = do_bank_switch(stream); | ||
| if (ret1 < 0) | ||
| pr_err("%s: do_bank_switch failed: %d after restoring params\n", __func__, ret1); |
| dev_err(bus->dev, "Prepare port(s) failed ret = %d\n", | ||
| ret); | ||
| goto restore_params; | ||
| goto revert_bank; |
bardliao
force-pushed
the
for-sdw-bandwidth-leak
branch
from
October 13, 2026 03:51
dc95264 to
18d020e
Compare
Comment on lines
+1571
to
+1572
| m_rt->bus->params = m_rt->params_backup; | ||
| ret1 = sdw_program_params(m_rt->bus, true); |
The bank values are already switched in do_bank_switch(), so we need to switch curr_bank and next_bank back to reflect the actual bank. Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Restoring bus->params alone leaves the hardware programmed with the values from the failed stream preparation. Reprogram the restored params and switch banks so software and hardware use the same bus configuration. Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
When preparing a multi-link aggregation stream, a failure on a subsequent link during _sdw_prepare_stream() causes the stream preparation to fail. However, the bandwidth allocated on the preceding successful links is never released, causing a cumulative bandwidth leak. Fix this by saving a snapshot of each bus's parameters before making any modifications. In case of failure, we iterate through the stream's master list and restore each bus to its original parameter state, ensuring an atomic rollback and preventing any bandwidth leaks. Signed-off-by: David Lin <david.lin@intel.com>
bardliao
force-pushed
the
for-sdw-bandwidth-leak
branch
from
October 13, 2026 04:38
18d020e to
a90934b
Compare
Comment on lines
+1566
to
+1580
| list_for_each_entry(m_rt, &stream->master_list, stream_node) { | ||
| /* | ||
| * Revert all masters to their snapshotted original parameters. | ||
| * Any master that was not modified will safely revert to its own original state. | ||
| */ | ||
| m_rt->bus->params = m_rt->params_backup; | ||
| ret1 = sdw_program_params(m_rt->bus, true); | ||
| if (ret1 < 0) { | ||
| dev_err(m_rt->bus->dev, | ||
| "Program params failed: %d after restoring params\n", | ||
| ret1); | ||
| /* No need to do bank switch and return the original error code */ | ||
| return ret; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



When preparing a multi-link aggregation stream, a failure on a subsequent link during _sdw_prepare_stream() causes the stream preparation to fail. However, the bandwidth allocated on the preceding successful links is never released, causing a cumulative bandwidth leak.
Fix this by restoring the parameters for all buses.