drivers/touch/cst816: take the i2c lock around the hardware reset - #1896
Draft
Mearman wants to merge 1 commit into
Draft
drivers/touch/cst816: take the i2c lock around the hardware reset#1896Mearman wants to merge 1 commit into
Mearman wants to merge 1 commit into
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>
Mearman
force-pushed
the
fix/cst816-reset-under-i2c-lock
branch
from
August 19, 2026 21:04
eea8d9c to
a6fd810
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.
Draft — still validating on hardware.
The vaguest of the failures I saw while playing with touch a few weeks ago: very occasional glitched or dropped touch input, never reproducible on demand. Looking at the driver, there is a real unsynchronised window for it.
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 (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.
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. Validated by call-site audit and a full firmware build.