Skip to content

hwmon: chipcap2: various bug fixes

Javier Carrasco linux-hwmon lkml sashiko-reviews stable 3 versions – In review

Get series with b4
b4 am [email protected] change-id 20260820-chipcap2_locks-c01013a24a0c

Versions newest first

  1. v3 Latest11 patches 2 repliesIn review
  2. v24 patches 6 repliesApplied
  3. v11 patch 3 repliesSuperseded

Changes in v3 from the cover letter

- Use a dedicated mutex instead of the hwmon subsystem lock to serialize
the access to the alarm indicators, which no longer blocks the alarm handlers behind a sysfs read.
- New patch: do not discard the pending alarms on disable.
- New patch: synchronize the ready IRQ state.
- Register the data ready IRQ before registering the hwmon device (its handler does not use hwmon).
- Split the fixes into one patch per issue.
- Drop the patch to fix the channels in the humidity alarm
notifications, which is already applied.
- Link to v2: https://lore.kernel.org/r/[email protected]

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/11hwmon: chipcap2: fix command error diagnosticsdrivers/hwmon/chipcap2.c+4 -40 replies
2/11hwmon: chipcap2: fix off-by-one in command mode retry loopdrivers/hwmon/chipcap2.c+1 -11 reply
3/11hwmon: chipcap2: fix be16 handlingdrivers/hwmon/chipcap2.c+5 -50 replies
4/11hwmon: chipcap2: defer probe when IRQs are unavailabledrivers/hwmon/chipcap2.c+6 -00 replies
5/11hwmon: chipcap2: fix IRQ teardown orderingdrivers/hwmon/chipcap2.c+32 -200 replies
6/11hwmon: chipcap2: disable device after hwmon teardowndrivers/hwmon/chipcap2.c+9 -80 replies
7/11hwmon: chipcap2: enable IRQ processing when regulator is already enableddrivers/hwmon/chipcap2.c+3 -10 replies
8/11hwmon: chipcap2: balance regulator statedrivers/hwmon/chipcap2.c+13 -50 replies
9/11hwmon: chipcap2: do not discard pending alarms on disabledrivers/hwmon/chipcap2.c+7 -00 replies
10/11hwmon: chipcap2: serialize access to the alarm indicatorsdrivers/hwmon/chipcap2.c+37 -210 replies
11/11hwmon: chipcap2: synchronize ready IRQ statedrivers/hwmon/chipcap2.c+17 -50 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.

Read the v3 thread

Cover letter [PATCH v3 00/11] hwmon: chipcap2: various bug fixes

The original issue (race condition for the alarms) was found by Sashiko[1] when an unrelated patch affected chipcap2.c. The issue is real as the access to the variables is not protected by any locking mechanism although 2 different sources (threaded interrupts and sysfs) could modify them.

In further iterations Sashiko found new issues[2] that have been added to the series:

- Fix be16 data handling.
- Defer probe when the IRQs are not available yet.
- IRQ teardown ordering: split the current implementation to provide the available interrupts before registering the hwmon device, and register the IRQs after the hwmon device has been registered.
- Disable the device after the hwmon device has been unregistered.
- Enable IRQ processing when the regulator is already enabled.
- Balance regulator counter.
- Do not discard the pending alarms when the device is disabled.
- Reset the completion to account for counter > 1.
- IRQ serialization and synchronization.

The last item required a dedicated mutex because the hwmon_lock was not suitable to close the gaps where an interrupt might go unnoticed because there is some dependency between the data read and the interrupt generation, and also in the completion mechanism. I went through the different alternatives with a combination of local Sashiko and a second AI agent, and discarded some complex solutions to close gaps that are more theoretical than practical e.g. the interrupt was fired, but it did not reach the controller due to nested GPIO expanders. I added the

Assisted-by tags to those patches accordingly, although it seems that

this requirement will soon vanish.

Additionally, a harmless off-by-one in a for loop has been fixed to save ~80 ms after the last failed command retry, and the error reporting has been fixed to show the right issue. These two ones have not been tagged for stable as they are only meant to improve reaction time and logging inaccuracies after a command fails. The deferred probe does not have the stable tag as it is just a reaction if interrupts were provided but still not available. Of course, I can add the tags to all patches if required.

The fixes have been validated on real hardware with an Amphenol ChipCap 2 CC2D23S sensor.

[1] Link: https://lore.kernel.org/linux-hwmon/[email protected]/
[2] Link: https://lore.kernel.org/linux-hwmon/[email protected]/

To: Guenter Roeck <[email protected]>

Changes in v3:
- Use a dedicated mutex instead of the hwmon subsystem lock to serialize
the access to the alarm indicators, which no longer blocks the alarm handlers behind a sysfs read.
- New patch: do not discard the pending alarms on disable.
- New patch: synchronize the ready IRQ state.
- Register the data ready IRQ before registering the hwmon device (its handler does not use hwmon).
- Split the fixes into one patch per issue.
- Drop the patch to fix the channels in the humidity alarm
notifications, which is already applied.
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Add fixes to the new issues reported by Sashiko.
- Use hwmon subsystem lock.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Javier Carrasco (11):
hwmon: chipcap2: fix command error diagnostics
hwmon: chipcap2: fix off-by-one in command mode retry loop
hwmon: chipcap2: fix be16 handling
hwmon: chipcap2: defer probe when IRQs are unavailable
hwmon: chipcap2: fix IRQ teardown ordering
hwmon: chipcap2: disable device after hwmon teardown
hwmon: chipcap2: enable IRQ processing when regulator is already enabled
hwmon: chipcap2: balance regulator state
hwmon: chipcap2: do not discard pending alarms on disable
hwmon: chipcap2: serialize access to the alarm indicators
hwmon: chipcap2: synchronize ready IRQ state

 drivers/hwmon/chipcap2.c | 192 +++++++++++++++++++++++++++++++----------------
 1 file changed, 128 insertions(+), 64 deletions(-)

---
base-commit: 3857c2fe5449541e24afc5efdb0f81a8a8f9a3a0
change-id: 20260820-chipcap2_locks-c01013a24a0c

Best regards,

Signature · 1 line
Javier Carrasco <[email protected]>