From: sashiko-bot@kernel.org
To: "Shih-Yuan Lee" <fourdollars@debian.org>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v4 1/1] hwmon: (applesmc) Convert to hwmon_device_register_with_info
Date: Sat, 11 Jul 2026 06:17:08 +0000 [thread overview]
Message-ID: <20260711061708.ACD321F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260711060634.5794-2-fourdollars@debian.org>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Migrating to `devm_hwmon_device_register_with_info()` inverts the teardown order, causing a NULL pointer dereference race condition on module exit.
- [Medium] Using `devm` allocations in `module_init` incorrectly ties the hwmon device lifecycle to the driver bind/unbind lifecycle rather than the module lifecycle.
--
--- Patch [1]: [PATCH v4 1/1] hwmon: (applesmc) Convert to hwmon_device_register_with_info ---
commit 64b6fb798f7a912d4278236bbe004e5659b03109
Author: Shih-Yuan Lee <fourdollars@debian.org>
hwmon: (applesmc) Convert to hwmon_device_register_with_info
Convert the driver to use the modern hwmon_device_register_with_info()
API. This migration moves the registration of standard sensor attributes
to the HWMON core.
> diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
> index 90a14a7f2c4c0..a93b1f91a35dd 100644
> --- a/drivers/hwmon/applesmc.c
> +++ b/drivers/hwmon/applesmc.c
[ ... ]
> @@ -1343,17 +1434,97 @@ static int __init applesmc_init(void)
> if (ret)
> goto out_smcreg;
>
> - ret = applesmc_create_nodes(fan_group, smcreg.fan_count);
> - if (ret)
> + /* allocate hwmon channel configs */
> + temp_config = devm_kcalloc(&pdev->dev, smcreg.index_count + 1,
> + sizeof(*temp_config), GFP_KERNEL);
[Severity: Medium]
Does using devm_ allocations in a module initialization function cause issues
if the driver is unbound via sysfs?
Since this driver performs its setup in applesmc_init() rather than a standard
probe() function, the devm_ allocations are tied to the device-driver binding.
If an admin unbinds the driver via sysfs, devres_release_all() will free the
devm_kcalloc memory and the devm_hwmon device, but will leave non-devm managed
resources like the input device active. Additionally, without a probe()
function, rebinding won't recreate the hwmon device, leaving the driver broken
until a full module reload.
[ ... ]
> @@ -1398,12 +1566,9 @@ static int __init applesmc_init(void)
>
> static void __exit applesmc_exit(void)
> {
> - hwmon_device_unregister(hwmon_dev);
[Severity: High]
Can this lead to a NULL pointer dereference during module exit?
By replacing the manual hwmon_device_unregister() with a devm managed hwmon
device, the sysfs teardown order is delayed until platform_device_unregister()
is called at the very end of this function.
> applesmc_release_key_backlight();
> applesmc_release_light_sensor();
> applesmc_release_accelerometer();
> - applesmc_destroy_nodes(temp_group);
> - applesmc_destroy_nodes(fan_group);
> applesmc_destroy_nodes(info_group);
> applesmc_destroy_smcreg();
> platform_device_unregister(pdev);
However, applesmc_destroy_smcreg() is called right before the platform device
is unregistered, which frees and nullifies smcreg.index and smcreg.cache. This
creates a window where the hwmon sysfs files are still active and accessible,
but their backing structures are gone.
If a concurrent read to a sysfs file occurs during this window, it could
call into the new hwmon read callbacks and dereference the null pointer:
applesmc_hwmon_read() {
...
case hwmon_temp:
if (attr == hwmon_temp_input) {
const char *key = smcreg.index[channel];
s16 value;
...
}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260711060634.5794-2-fourdollars@debian.org?part=1
next prev parent reply other threads:[~2026-07-11 6:17 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 [this message]
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 ` [PATCH v6 0/3] " Shih-Yuan Lee
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=20260711061708.ACD321F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=fourdollars@debian.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox