Skip to content

soundwire: fix restore_params to recover all buses on prepare failure#5829

Closed
Copilot wants to merge 3 commits into
topic/sof-devfrom
copilot/fix-review-comment-5604
Closed

soundwire: fix restore_params to recover all buses on prepare failure#5829
Copilot wants to merge 3 commits into
topic/sof-devfrom
copilot/fix-review-comment-5604

Conversation

Copilot AI commented Jun 26, 2026

Copy link
Copy Markdown

In _sdw_prepare_stream(), the restore_params: error path restores state only for the last bus iterated. In multi-link streams, earlier buses' params (and the new bpt_hstop added by PR #5604) are left partially modified after failures from do_bank_switch() or port-prepare — inconsistent state that affects subsequent compute_params() calls.

Changes

  • include/linux/soundwire/sdw.h: Add bpt_hstop to sdw_bus — the per-bus column-stop index for the BPT DP0 port referenced by the review comment.

  • drivers/soundwire/bus.h: Add saved_params and saved_bpt_hstop to sdw_master_runtime for per-bus backup storage without dynamic allocation.

  • drivers/soundwire/stream.c: Restructure _sdw_prepare_stream() error recovery:

    • Add a pre-save pass over stream->master_list before any modifications, snapshotting each bus's params and bpt_hstop into the corresponding m_rt.
    • Rewrite restore_params: to iterate all masters and restore from per-m_rt snapshots, ensuring every bus is rolled back regardless of where the failure occurs.
/* before: only last bus restored */
restore_params:
    memcpy(&bus->params, &params, sizeof(params));
    return ret;

/* after: all buses restored */
restore_params:
    list_for_each_entry(m_rt, &stream->master_list, stream_node) {
        bus = m_rt->bus;
        memcpy(&bus->params, &m_rt->saved_params, sizeof(bus->params));
        bus->bpt_hstop = m_rt->saved_bpt_hstop;
    }
    return ret;

@sofci

sofci commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

reply test this please to run this test once

Copilot AI added 2 commits June 26, 2026 12:14
The restore_params block in _sdw_prepare_stream() was restoring only
the last bus iterated when an error occurred. For multi-link streams
with multiple buses, this left other buses in a partially reconfigured
state.

Fix this by:
1. Adding bpt_hstop to sdw_bus to track the BPT stream hstop value.
2. Adding saved_params and saved_bpt_hstop to sdw_master_runtime to
   store per-bus backup state.
3. Pre-saving all buses' params and bpt_hstop before the modify loop.
4. Restoring all buses from their per-bus saved state in restore_params.

Addresses review comment: #5604 (comment)
Copilot AI changed the title [WIP] Fix code as per review comment 5604 soundwire: fix restore_params to recover all buses on prepare failure Jun 26, 2026
Copilot AI requested a review from bardliao June 26, 2026 12:16
@bardliao

Copy link
Copy Markdown
Collaborator

This looks like a hack.

@bardliao bardliao closed this Jun 26, 2026
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