Skip to content

Linux CEC: verify and re-claim logical address if kernel picks a different one - #771

Open
kofec wants to merge 1 commit into
Pulse-Eight:masterfrom
kofec:linux-verify-claimed-logical-address
Open

kofec wants to merge 1 commit into
Pulse-Eight:masterfrom
kofec:linux-verify-claimed-logical-address

Conversation

@kofec

@kofec kofec commented Nov 27, 2026

Copy link
Copy Markdown

Problem

The Linux CEC framework ignores log_addr[0] in CEC_ADAP_S_LOG_ADDRS and claims the first free logical address of the requested type itself (e.g. 1, 2, 9 for a recorder).

When the kernel's poll and libCEC's poll disagree (e.g. a transient false ACK on the bus), or when the kernel re-claims automatically after a physical address change (HPD / TV power cycle / initial claim without a valid physical address), the kernel can end up on a different logical address than libCEC. Every subsequent CEC_TRANSMIT from libCEC then fails with EINVAL ("initiator has unknown logical address").

Solution

  • Track the logical address libCEC transmits from (m_wantedAddress), guarded by m_mutex.
  • In ClaimLogicalAddress(), verify log_addrs.log_addr_mask after CEC_ADAP_S_LOG_ADDRS and retry clearing and claiming (up to 3 attempts with 500 ms delay) if the kernel claimed a different address.
  • On CEC_EVENT_STATE_CHANGE with a non-zero log_addr_mask, schedule VerifyLogicalAddress() after a 1-second debounce to catch kernel-initiated re-claims that landed on the wrong address.
  • Apply a 30-second cooldown (m_repairTimeout) after a failed repair so state-change events do not trigger a retry loop when the address is genuinely occupied.

…erent one

The Linux CEC framework ignores log_addr[0] in CEC_ADAP_S_LOG_ADDRS and
claims the first free logical address of the requested type itself. When
the kernel's poll and libCEC's poll disagree (e.g. due to a false ACK on
the bus, or after a physical address change / HPD / TV power cycle where
the kernel re-claims on its own), the kernel ends up on a different
logical address than the one libCEC uses as initiator, causing every
subsequent CEC_TRANSMIT ioctl to fail with EINVAL.

Track the logical address libCEC expects, retry clearing and claiming up
to 3 times if the kernel claims a different address, and verify the
claimed address after CEC_EVENT_STATE_CHANGE (with a cooldown timer to
avoid endless loops if the address is genuinely taken).
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for the contribution. Before we can merge it we ask that you accept the Pulse-Eight contributor agreement, which grants us the rights we need to ship your work under every licence libCEC is offered under. It is needed once, not for every pull request.
Accept it with the Accept on GitHub button on that page, or by posting the line below as a comment here. If you are contributing on behalf of a company, the company signs the Entity agreement instead and emails it to contributor-agreement@pulse-eight.com.


I have read the Pulse-Eight Individual Contributor License Agreement, version 2, and I accept it


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

This branch has not been deployed

No deployments
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.

1 participant