Skip to content

cdc_host: fix undeclared 'idx' when only LINE_CONTROL_ON_ENUM is defined#3660

Draft
andrewleech wants to merge 1 commit into
hathach:masterfrom
andrewleech:cdch-on-enum-idx-guard
Draft

cdc_host: fix undeclared 'idx' when only LINE_CONTROL_ON_ENUM is defined#3660
andrewleech wants to merge 1 commit into
hathach:masterfrom
andrewleech:cdch-on-enum-idx-guard

Conversation

@andrewleech

Copy link
Copy Markdown
Contributor

A small compile fix in the CDC host on-enum line-state handling.

If you build the CDC host with CFG_TUH_CDC_LINE_CONTROL_ON_ENUM set but CFG_TUH_CDC_LINE_CODING_ON_ENUM unset, it doesn't compile. set_line_state_on_enum() declares idx only under CFG_TUH_CDC_LINE_CODING_ON_ENUM, but it's also used in the ENUM_SET_LINE_CONTROL case (guarded by CFG_TUH_CDC_LINE_CONTROL_ON_ENUM), so idx is left undeclared in that branch.

I ran into it while looking at turning on CFG_TUH_CDC_LINE_CONTROL_ON_ENUM for a host to assert DTR/RTS on enumerate without forcing a fixed line coding, which seems like a pretty reasonable combination but currently won't build.

Fix just guards the declaration under either macro:

#if defined(CFG_TUH_CDC_LINE_CODING_ON_ENUM) || defined(CFG_TUH_CDC_LINE_CONTROL_ON_ENUM)
  const uint8_t idx = get_idx_by_ptr(p_cdc);
#endif

Testing: compile only so far. Built the CDC host class with all four combinations of the two macros (neither, coding only, control only, both); control-only failed before this change and builds after. Haven't runtime-tested the control-only enum path.

idx is used in the ENUM_SET_LINE_CONTROL path guarded by
CFG_TUH_CDC_LINE_CONTROL_ON_ENUM, but was declared only under
CFG_TUH_CDC_LINE_CODING_ON_ENUM. Defining LINE_CONTROL_ON_ENUM without
LINE_CODING_ON_ENUM therefore failed to compile with an undeclared
identifier. Guard the declaration under either macro.

Signed-off-by: Andrew Leech <andrew@alelec.net>
@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected across 2345 targets. View Project Dashboard →

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a compile error in the CDC host enumeration path when CFG_TUH_CDC_LINE_CONTROL_ON_ENUM is enabled without also enabling CFG_TUH_CDC_LINE_CODING_ON_ENUM, by ensuring idx is declared whenever either enum-time line-state feature is compiled in.

Changes:

  • Broaden idx declaration guard to cover both CFG_TUH_CDC_LINE_CODING_ON_ENUM and CFG_TUH_CDC_LINE_CONTROL_ON_ENUM.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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