From: Shih-Yuan Lee <fourdollars@debian.org>
To: Henrik Rydberg <rydberg@bitmath.org>, Guenter Roeck <linux@roeck-us.net>
Cc: Armin Wolf <W_Armin@gmx.de>,
linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org,
Shih-Yuan Lee <fourdollars@debian.org>
Subject: [PATCH v6 0/3] hwmon: (applesmc) Convert to hwmon_device_register_with_info
Date: Sat, 11 Jul 2026 17:33:20 +0800 [thread overview]
Message-ID: <20260711093323.14529-1-fourdollars@debian.org> (raw)
In-Reply-To: <20260710123236.10508-1-fourdollars@debian.org>
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(-)
--
2.39.5
next prev parent reply other threads:[~2026-07-11 9:33 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-10 12:32 [PATCH 0/1] hwmon: (applesmc) Convert to hwmon_device_register_with_info Shih-Yuan Lee
2026-07-10 12:32 ` [PATCH 1/1] " Shih-Yuan Lee
2026-07-10 12:47 ` sashiko-bot
2026-07-10 14:01 ` Guenter Roeck
2026-07-10 21:10 ` Armin Wolf
2026-07-10 22:28 ` Guenter Roeck
2026-07-11 2:51 ` Shih-Yuan Lee (FourDollars)
2026-07-11 3:36 ` [PATCH v2 0/1] " Shih-Yuan Lee
2026-07-11 3:37 ` [PATCH v2 1/1] " Shih-Yuan Lee
2026-07-11 3:47 ` sashiko-bot
2026-07-11 5:39 ` [PATCH v3 0/1] " Shih-Yuan Lee
2026-07-11 5:39 ` [PATCH v3 1/1] " Shih-Yuan Lee
2026-07-11 5:52 ` sashiko-bot
2026-07-11 6:06 ` [PATCH v4 0/1] " Shih-Yuan Lee
2026-07-11 6:06 ` [PATCH v4 1/1] " Shih-Yuan Lee
2026-07-11 6:17 ` sashiko-bot
2026-07-11 7:57 ` [PATCH v5 0/3] " Shih-Yuan Lee
2026-07-11 7:57 ` [PATCH v5 1/3] hwmon: (applesmc) Cache fan positions during register initialization Shih-Yuan Lee
2026-07-11 8:06 ` sashiko-bot
2026-07-11 7:57 ` [PATCH v5 2/3] hwmon: (applesmc) Fix lockless cache validation data race Shih-Yuan Lee
2026-07-11 8:10 ` sashiko-bot
2026-07-11 7:57 ` [PATCH v5 3/3] hwmon: (applesmc) Convert to hwmon_device_register_with_info Shih-Yuan Lee
2026-07-11 8:12 ` sashiko-bot
2026-07-11 9:33 ` Shih-Yuan Lee [this message]
2026-07-11 9:33 ` [PATCH v6 1/3] hwmon: (applesmc) Cache fan positions during register initialization Shih-Yuan Lee
2026-07-11 9:42 ` sashiko-bot
2026-07-11 9:33 ` [PATCH v6 2/3] hwmon: (applesmc) Fix lockless cache validation data race Shih-Yuan Lee
2026-07-11 9:43 ` sashiko-bot
2026-07-11 9:33 ` [PATCH v6 3/3] hwmon: (applesmc) Convert to hwmon_device_register_with_info Shih-Yuan Lee
2026-07-11 9:42 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260711093323.14529-1-fourdollars@debian.org \
--to=fourdollars@debian.org \
--cc=W_Armin@gmx.de \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=rydberg@bitmath.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.