Skip to content

hwmon: (applesmc) Convert to hwmon_device_register_with_info

Shih-Yuan Lee linux-hwmon lkml 6 versions – Applied

Status from this message: Applied.

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v6 Latest3 patches 3 repliesApplied
  2. v53 patches 0 repliesSuperseded
  3. v41 patch 0 repliesSuperseded
Earlier versions · 3
VersionPostedPatchesRepliesStatus
v31 patch0 repliesSuperseded
v21 patch0 repliesSuperseded
v11 patch4 repliesSuperseded

Changes in v6 from the cover letter

- Fix HWMON ABI violation for pwmX_enable by mapping manual mode to 1 and automatic mode to 2 (instead of 1 and 0), and rejecting invalid values.

Patches in v6 Applied

#Subject and filesSizeRepliesApplied
1/3hwmon: (applesmc) Cache fan positions during register initializationdrivers/hwmon/applesmc.c+12 -11 reply
2/3hwmon: (applesmc) Fix lockless cache validation data racedrivers/hwmon/applesmc.c+5 -21 reply
3/3hwmon: (applesmc) Convert to hwmon_device_register_with_infodrivers/hwmon/applesmc.c+321 -1491 reply

Reviews trailers per patch

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

Read the v6 thread

Cover letter [PATCH v6 0/3] hwmon: (applesmc) Convert to hwmon_device_register_with_info

Hi Guenter, Armin, and Henrik,

This is v6 of the patch series converting the applesmc driver from using the deprecated hwmon_device_register() function to the modern hwmon_device_register_with_info() API.

Changes in v6:
- Fix HWMON ABI violation for pwmX_enable by mapping manual mode to 1 and automatic mode to 2 (instead of 1 and 0), and rejecting invalid values.

Changes in v5:
- Split the refactoring into a 3-patch logical series:
- Patch 1: Cache fan positions during register initialization (preparatory).
- Patch 2: Fix a pre-existing concurrency bug in lockless cache validation by introducing proper memory barriers (smp_load_acquire and smp_store_release) with checkpatch-compliant comments.
- Patch 3: Convert the driver to the modern HWMON API.
- Address Sashiko AI's findings regarding the lifetime mismatch and teardown race condition:
- Revert the driver from using devm allocations and managed hwmon registration.
- Manually register with unmanaged hwmon_device_register_with_info() and manually free structures via applesmc_free_hwmon().
- Ensure unregistration order is safe: call hwmon_device_unregister() at the very beginning of applesmc_exit() to close the sysfs nodes prior to freeing the register structures and dynamic memory.

Changes in v4:
- Convert to devres-managed devm_hwmon_device_register_with_info() to fix a lifetime Use-After-Free mismatch when the driver is unbound via sysfs (releasing devres-managed attributes memory while keeping the hwmon sysfs files active).
- Declare hwmon_dev locally in applesmc_init() and remove it from the global static variables, and clean up the redundant manual hwmon_device_unregister() call in applesmc_exit().

Changes in v3:
- Fix a recursive mutex deadlock in applesmc_hwmon_write() when writing to pwmX_enable by using applesmc_get_entry_by_key() to resolve the entry locklessly and then calling the underlying raw SMC read/write calls.
- Fix a fallback fan label truncation bug by pre-padding the generated fallback string with four spaces so that the "+ 4" pointer arithmetic offset yields the correct label "Fan %d".

Changes in v2:
- Abandon the minimal dummy registration approach in v1.
- Fully convert the driver to modern HWMON ABI standards by dynamically allocating temp and fan channels at initialization.
- Rename legacy non-standard attributes to comply with the standard HWMON ABI:
- fanX_output -> fanX_target (HWMON_F_TARGET)
- fanX_manual -> pwmX_enable (HWMON_PWM_ENABLE)
- Dynamically register the remaining non-standard fanX_safe attributes under HWMON class directory via extra_groups.
- Load and cache fan positions in smcreg.fan_positions to support returning labels by reference in .read_string.
- Clean up unused static attribute groups and show/store callback functions to avoid unused symbol compiler warnings.
- Verified compilation and successfully tested on real MacBook hardware.

We appreciate your review and comments on this refactoring.

Shih-Yuan Lee (3):
hwmon: (applesmc) Cache fan positions during register initialization
hwmon: (applesmc) Fix lockless cache validation data race
hwmon: (applesmc) Convert to hwmon_device_register_with_info

 drivers/hwmon/applesmc.c | 490 +++++++++++++++++++++++++++------------
 1 file changed, 338 insertions(+), 152 deletions(-)
Signature · 1 line
2.39.5