Skip to content

fix(i2c_master): yield from ISR when no matching device is found (IDFGH-17648)#18569

Open
DatanoiseTV wants to merge 1 commit into
espressif:masterfrom
DatanoiseTV:fix/i2c-master-isr-missing-yield
Open

fix(i2c_master): yield from ISR when no matching device is found (IDFGH-17648)#18569
DatanoiseTV wants to merge 1 commit into
espressif:masterfrom
DatanoiseTV:fix/i2c-master-isr-missing-yield

Conversation

@DatanoiseTV
Copy link
Copy Markdown
Contributor

Summary

i2c_master_isr_handler_default() may set HPTaskAwoken to pdTRUE
through the FromISR primitives it calls earlier in the handler:

  • xQueueSendFromISR(i2c_master->event_queue, ...) near the top of the
    handler when an event needs to be reported,
  • xSemaphoreTakeFromISR(i2c_master->bus_lock_mux, ...) /
    xSemaphoreGiveFromISR(i2c_master->bus_lock_mux, ...) around the
    device-list lookup in the async_trans branch.

When the device-list lookup at lines 822-828 fails to find a device
matching i2c_trans.device_address, the handler took an early
return; at line 830, skipping the portYIELD_FROM_ISR() at the
bottom of the function. A higher-priority task waiting on the bus
lock or on the event queue would therefore have to wait for the next
scheduler tick instead of being preempted into immediately, inflating
worst-case event latency on this path.

Fix

Replace the early return with a goto out to the existing yield
check at the end of the ISR. Behavior is otherwise unchanged.

Reproduction

The path is exercised whenever an interrupt fires for a transaction
whose configured device is no longer present in the device list (for
example after i2c_master_bus_rm_device() removes a device while a
transaction is in flight, or under fault conditions where the address
in i2c_trans doesn't match any registered handle). The fix is a
correctness improvement on a latency-critical path; behavior is
verifiable by tracing the out: path with an instrumented build.

Test plan

  • Build passes with the fix on top of master.
  • Existing components/esp_driver_i2c/test_apps/i2c_test_apps
    regression suite continues to pass on supported targets.

`i2c_master_isr_handler_default()` may set HPTaskAwoken to pdTRUE via
`xQueueSendFromISR()` (event_queue), `xSemaphoreTakeFromISR()` and
`xSemaphoreGiveFromISR()` on `bus_lock_mux`. When the device list lookup
returns no matching device, the function returned directly, skipping
the `portYIELD_FROM_ISR()` at the bottom of the handler. A higher-
priority task waiting on the bus mux or the event queue would then have
to wait for the next scheduler tick instead of being preempted into
immediately, inflating worst-case event latency.

Replace the early return with a goto to the existing yield check at the
end of the ISR.
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 9, 2026

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions Bot changed the title fix(i2c_master): yield from ISR when no matching device is found fix(i2c_master): yield from ISR when no matching device is found (IDFGH-17648) May 9, 2026
@espressif-bot espressif-bot added the Status: Opened Issue is new label May 9, 2026
@suda-morris
Copy link
Copy Markdown
Collaborator

sha=0f0d7a758ee3f591515e5cd9173a78236490452b

@suda-morris suda-morris added the PR-Sync-Merge Pull request sync as merge commit label May 11, 2026
@espressif-bot espressif-bot added Status: In Progress Work is in progress Status: Reviewing Issue is being reviewed Status: Done Issue is done internally Resolution: NA Issue resolution is unavailable Resolution: Done Issue is done internally and removed Status: Opened Issue is new Status: In Progress Work is in progress Status: Reviewing Issue is being reviewed Resolution: NA Issue resolution is unavailable labels May 12, 2026
espressif-bot pushed a commit that referenced this pull request May 14, 2026
`i2c_master_isr_handler_default()` may set HPTaskAwoken to pdTRUE via
`xQueueSendFromISR()` (event_queue), `xSemaphoreTakeFromISR()` and
`xSemaphoreGiveFromISR()` on `bus_lock_mux`. When the device list lookup
returns no matching device, the function returned directly, skipping
the `portYIELD_FROM_ISR()` at the bottom of the handler. A higher-
priority task waiting on the bus mux or the event queue would then have
to wait for the next scheduler tick instead of being preempted into
immediately, inflating worst-case event latency.

Replace the early return with a goto to the existing yield check at the
end of the ISR.

Merges #18569
espressif-bot pushed a commit that referenced this pull request May 29, 2026
`i2c_master_isr_handler_default()` may set HPTaskAwoken to pdTRUE via
`xQueueSendFromISR()` (event_queue), `xSemaphoreTakeFromISR()` and
`xSemaphoreGiveFromISR()` on `bus_lock_mux`. When the device list lookup
returns no matching device, the function returned directly, skipping
the `portYIELD_FROM_ISR()` at the bottom of the handler. A higher-
priority task waiting on the bus mux or the event queue would then have
to wait for the next scheduler tick instead of being preempted into
immediately, inflating worst-case event latency.

Replace the early return with a goto to the existing yield check at the
end of the ISR.

Merges #18569
espressif-bot pushed a commit that referenced this pull request Jun 1, 2026
`i2c_master_isr_handler_default()` may set HPTaskAwoken to pdTRUE via
`xQueueSendFromISR()` (event_queue), `xSemaphoreTakeFromISR()` and
`xSemaphoreGiveFromISR()` on `bus_lock_mux`. When the device list lookup
returns no matching device, the function returned directly, skipping
the `portYIELD_FROM_ISR()` at the bottom of the handler. A higher-
priority task waiting on the bus mux or the event queue would then have
to wait for the next scheduler tick instead of being preempted into
immediately, inflating worst-case event latency.

Replace the early return with a goto to the existing yield check at the
end of the ISR.

Merges #18569
espressif-bot pushed a commit that referenced this pull request Jun 2, 2026
`i2c_master_isr_handler_default()` may set HPTaskAwoken to pdTRUE via
`xQueueSendFromISR()` (event_queue), `xSemaphoreTakeFromISR()` and
`xSemaphoreGiveFromISR()` on `bus_lock_mux`. When the device list lookup
returns no matching device, the function returned directly, skipping
the `portYIELD_FROM_ISR()` at the bottom of the handler. A higher-
priority task waiting on the bus mux or the event queue would then have
to wait for the next scheduler tick instead of being preempted into
immediately, inflating worst-case event latency.

Replace the early return with a goto to the existing yield check at the
end of the ISR.

Merges #18569
espressif-bot pushed a commit that referenced this pull request Jun 2, 2026
`i2c_master_isr_handler_default()` may set HPTaskAwoken to pdTRUE via
`xQueueSendFromISR()` (event_queue), `xSemaphoreTakeFromISR()` and
`xSemaphoreGiveFromISR()` on `bus_lock_mux`. When the device list lookup
returns no matching device, the function returned directly, skipping
the `portYIELD_FROM_ISR()` at the bottom of the handler. A higher-
priority task waiting on the bus mux or the event queue would then have
to wait for the next scheduler tick instead of being preempted into
immediately, inflating worst-case event latency.

Replace the early return with a goto to the existing yield check at the
end of the ISR.

Merges #18569
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR-Sync-Merge Pull request sync as merge commit Resolution: Done Issue is done internally Status: Done Issue is done internally

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants