[PATCH 1/1] hwmon: (applesmc) Convert to hwmon_device_register_with_info

From: Shih-Yuan Lee

Date: Fri Jul 10 2026 - 08:36:51 EST


The legacy hwmon_device_register() function is deprecated and triggers a
warning in dmesg during driver initialization:

[ 24.706091] applesmc: key=620 fan=0 temp=37 index=36 acc=0 lux=2 kbd=0
[ 24.706270] applesmc applesmc.768: hwmon_device_register() is deprecated. Please convert the driver to use hwmon_device_register_with_info().

To silence this warning, convert the driver to use the modern
hwmon_device_register_with_info() API.

Because the driver creates all its sysfs attributes dynamically on the platform
device, we define a minimal struct hwmon_chip_info with a single temperature
channel and implement a visibility callback that returns 0 (hidden) for it.
This satisfies the new API requirements while keeping all existing sysfs paths
and attributes completely unchanged, ensuring backwards compatibility.

Signed-off-by: Shih-Yuan Lee <fourdollars@xxxxxxxxxx>
---
drivers/hwmon/applesmc.c | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
index 90a14a7f2c4c..2b10bef24d8d 100644
--- a/drivers/hwmon/applesmc.c
+++ b/drivers/hwmon/applesmc.c
@@ -1307,6 +1307,26 @@ static const struct dmi_system_id applesmc_whitelist[] __initconst = {
};
MODULE_DEVICE_TABLE(dmi, applesmc_whitelist);

+static umode_t applesmc_is_visible(const void *data, enum hwmon_sensor_types type,
+ u32 attr, int channel)
+{
+ return 0;
+}
+
+static const struct hwmon_ops applesmc_hwmon_ops = {
+ .is_visible = applesmc_is_visible,
+};
+
+static const struct hwmon_channel_info * const applesmc_info[] = {
+ HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT),
+ NULL
+};
+
+static const struct hwmon_chip_info applesmc_chip_info = {
+ .ops = &applesmc_hwmon_ops,
+ .info = applesmc_info,
+};
+
static int __init applesmc_init(void)
{
int ret;
@@ -1363,7 +1383,8 @@ static int __init applesmc_init(void)
if (ret)
goto out_light_sysfs;

- hwmon_dev = hwmon_device_register(&pdev->dev);
+ hwmon_dev = hwmon_device_register_with_info(&pdev->dev, "applesmc", NULL,
+ &applesmc_chip_info, NULL);
if (IS_ERR(hwmon_dev)) {
ret = PTR_ERR(hwmon_dev);
goto out_light_ledclass;
--
2.39.5