Skip to content

soundwire: Fix bandwidth leak in multi-link aggregation failure - #5973

Open
bardliao wants to merge 2 commits into
thesofproject:topic/sof-devfrom
bardliao:fix-sdw-bandwidth
Open

bardliao wants to merge 2 commits into
thesofproject:topic/sof-devfrom
bardliao:fix-sdw-bandwidth

Conversation

@bardliao

Copy link
Copy Markdown
Collaborator

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.

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>
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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Rollback leaves port-lane state inconsistent and can desynchronize software bank state from hardware.

1 open finding
What changed in this PR

Fixes SoundWire bandwidth accounting rollback when multi-link stream preparation fails.

Changes:

  • Snapshots and restores parameters for every master bus.
  • Moves per-lane bandwidth accounting into sdw_bus_params.
  • Updates allocation and depreparation paths for the relocated accounting.
File Description
include/​linux/​soundwire/​sdw.h Relocates per-lane bandwidth state.
drivers/​soundwire/​stream.c Adds multi-bus rollback handling.
drivers/​soundwire/​generic_bandwidth_allocation.c Uses relocated lane accounting.
drivers/​soundwire/​bus.h Adds per-master parameter snapshots.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread drivers/soundwire/stream.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants