Re: [PATCH 1/2] hwmon: (ads7871) Add mutex to serialize SPI transactions
From: Tabrez Ahmed
Date: Sun Mar 29 2026 - 01:02:05 EST
On 3/29/26 08:46, Guenter Roeck wrote:
When using the with_info API to register the hwmon device, the subsystem already
serializes sysfs accesses. The next patch converts the driver to use the
with_info API. Pleas explain why the extra protection is necessary.
Ah yes. I originally wrote the mutex patch to fix the race condition in the legacy sysfs code, but totally missed that migrating to with_info handles the serialization for us natively.
Sashiko has the same feedback:
https://sashiko.dev/#/patchset/20260328182015.220298-1- tabreztalks%40gmail.com
Separately, Sashiko flagged a pre-existing bug where ads7871_write_reg8() passes a stack-allocated array (u8 tmp[2]) to spi_write(), breaking DMA.
To fix this properly, I need to move the buffer into the device's private data structure. However, doing so requires serialization to prevent concurrent reads from corrupting the shared buffer. Since moving to with_info provides that serialization, my plan for the v2 series is:
- Patch 1: Convert to hwmon_device_register_with_info (which natively serializes the driver).
- Patch 2: Fix the SPI DMA bug by introducing a shared tx_buf (now safely protected by the hwmon core).
I will drop the custom mutex entirely and send out v2 with this structure.
Thanks,
Tabrez