Skip to content

Fix slave FSM starvation and EoE NULL pointer dereference in master#161

Merged
sittner merged 5 commits intoparallel-slave-configfrom
copilot/fix-ec-master-fsm-issues
Mar 2, 2026
Merged

Fix slave FSM starvation and EoE NULL pointer dereference in master#161
sittner merged 5 commits intoparallel-slave-configfrom
copilot/fix-ec-master-fsm-issues

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 2, 2026

Two independent bugs in the EtherCAT master: one causing all slave FSMs after a pending datagram to be silently skipped, and one causing a NULL pointer dereference in the EoE failure path.

Changes

  • master/master.cec_master_exec_slave_fsms(): returncontinue when a slave FSM's datagram is still in INIT/QUEUED/SENT state. Using return caused the entire loop to exit early, starving all subsequent FSMs in fsm_exec_list for that cycle.
// Before: bails out of the entire loop
if (fsm->datagram->state == EC_DATAGRAM_INIT || ...) {
    return;  // all remaining FSMs skipped
}

// After: skips only the blocked FSM
    continue;
  • master/fsm_slave.c — EoE failure path: Fixed typo where fsm->soe_request->state was written inside the if (fsm->eoe_request) guard. When fsm->soe_request is NULL (but fsm->eoe_request is not), this dereferences a NULL pointer.
// Before (wrong pointer):
if (fsm->eoe_request) {
    fsm->soe_request->state = EC_INT_REQUEST_FAILURE;  // NULL deref if soe_request == NULL
}

// After:
if (fsm->eoe_request) {
    fsm->eoe_request->state = EC_INT_REQUEST_FAILURE;
}
Original prompt

Two bugs to fix:

Bug 1: ec_master_exec_slave_fsms() in master/master.c (line ~1276)

The function iterates over master->fsm_exec_list but uses return when a FSM's datagram is still pending (states INIT/QUEUED/SENT). This blocks ALL remaining FSMs in the list from executing. It should use continue instead to skip that FSM and process the rest.

Current problematic code (around line 1293-1298):

if (fsm->datagram->state == EC_DATAGRAM_INIT ||
        fsm->datagram->state == EC_DATAGRAM_QUEUED ||
        fsm->datagram->state == EC_DATAGRAM_SENT) {
    // previous datagram was not sent or received yet.
    // wait until next thread execution
    return;  // BUG: should be continue
}

Change return; to continue; so other slave FSMs can still be processed.

Bug 2: EoE typo in master/fsm_slave.c

There is a typo where fsm->soe_request->state is used instead of fsm->eoe_request->state when checking EoE request state. This causes a potential NULL pointer dereference. Find the EoE request handling section and fix soe_request to eoe_request where it's clearly in an EoE context.

This pull request was created from Copilot chat.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 4 commits March 2, 2026 08:34
… non-TTY builds

Co-authored-by: sittner <1475582+sittner@users.noreply.github.com>
…g-files

Exclude service scripts, config files, and ectty.h from userspace master installs
…slave.c

Co-authored-by: sittner <1475582+sittner@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix bugs in ec_master_exec_slave_fsms function and type error Fix slave FSM starvation and EoE NULL pointer dereference in master Mar 2, 2026
@sittner sittner marked this pull request as ready for review March 2, 2026 13:50
@sittner sittner changed the base branch from uspace to parallel-slave-config March 2, 2026 13:51
@sittner sittner merged commit 5ef40d1 into parallel-slave-config Mar 2, 2026
@sittner sittner deleted the copilot/fix-ec-master-fsm-issues branch March 4, 2026 08:19
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.

2 participants