drivers/touch/cst816: take the i2c lock around the hardware reset - #2042
Merged
Merged
Conversation
cst816_hw_reset toggles the chip's reset pin with no synchronisation against the bus: touch_sensor_set_enabled is reached synchronously from arbitrary tasks (subscribe/unsubscribe callbacks, the backlight and system-hold toggles) and calls the reset as its first statement, while the system task may be mid-transfer inside prv_read_data clocking the same chip. A chip hit by reset mid-byte stops ACKing and corrupts the in-flight transfer. Take s_i2c_lock inside cst816_hw_reset, the same per-transfer lock the read/write paths use. No caller holds it already -- the only lock-takers are prv_read_data and prv_write_data, neither of which resets -- so the acquisition cannot self-deadlock, and the bootmode/fw-update sequences keep their existing per-operation interleaving. Not unit-testable: the driver has no test target (it sits on real I2C, GPIO and EXTI), and the race is a cross-task timing window against hardware. Validated by call-site audit and a full firmware build. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Joseph Mearman <joseph@mearman.co.uk> Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
gmarull
force-pushed
the
fix/cst816-reset-under-i2c-lock
branch
from
September 8, 2026 12:05
ad2442f to
3f87860
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #1896 (originally by @Mearman) with review feedback applied: the verbose inline comment explaining the race is dropped, since the same rationale is already in the commit message.
cst816_hw_reset toggles the chip's reset pin with no synchronisation against the bus: touch_sensor_set_enabled is reached synchronously from arbitrary tasks (subscribe/unsubscribe callbacks, the backlight and system-hold toggles) and calls the reset as its first statement, while the system task may be mid-transfer inside prv_read_data clocking the same chip. A chip hit by reset mid-byte stops ACKing and corrupts the in-flight transfer.
This takes s_i2c_lock inside cst816_hw_reset, the same per-transfer lock the read/write paths use. No caller holds it already, so the acquisition cannot self-deadlock, and the bootmode/fw-update sequences keep their existing per-operation interleaving.
No unit test: the driver has no test target (it sits on real I2C, GPIO and EXTI) and the race is a cross-task timing window against hardware.
🤖 Generated with Claude Code