Skip to content

drivers/touch/cst816: take the i2c lock around the hardware reset - #2042

Merged
gmarull merged 1 commit into
coredevices:mainfrom
teslabs:fix/cst816-reset-under-i2c-lock
Sep 8, 2026
Merged

drivers/touch/cst816: take the i2c lock around the hardware reset#2042
gmarull merged 1 commit into
coredevices:mainfrom
teslabs:fix/cst816-reset-under-i2c-lock

Conversation

@gmarull

@gmarull gmarull commented Sep 8, 2026

Copy link
Copy Markdown
Member

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

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
gmarull force-pushed the fix/cst816-reset-under-i2c-lock branch from ad2442f to 3f87860 Compare September 8, 2026 12:05
@gmarull
gmarull merged commit 89ae58a into coredevices:main Sep 8, 2026
47 checks passed
@gmarull
gmarull deleted the fix/cst816-reset-under-i2c-lock branch September 8, 2026 12:13
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