Skip to contentSkip to conversation

Patch: applesmc.c - update handling

PATCH NAK Jared Mauch 3 participants 5 messages Nov 19, 2025 – Nov 20, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Updates code from hwmon_device_register to hwmon_device_register_with_info

drivers/hwmon/applesmc.c +1 -1
index fc6d6a9053ce..984dfbf40233 100644
@@ -1362,7 +1362,7 @@ 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, NULL, NULL);
 	if (IS_ERR(hwmon_dev)) {
 		ret = PTR_ERR(hwmon_dev);
 		goto out_light_ledclass;
drivers/hwmon/applesmc.c +1 -1
index fc6d6a9053ce..984dfbf40233 100644
@@ -1362,7 +1362,7 @@ 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, NULL, NULL);
 	if (IS_ERR(hwmon_dev)) {
 		ret = PTR_ERR(hwmon_dev);
 		goto out_light_ledclass;
#1 lore raw

Am 20.11.25 um 00:46 schrieb Jared Mauch:

Quoted 9 lines

Updates code from hwmon_device_register to hwmon_device_register_with_info

drivers/hwmon/applesmc.c +0 -0
index fc6d6a9053ce..984dfbf40233 100644

drivers/hwmon/applesmc.c static int __init applesmc_init(void) · line 1365

Quoted 5 lines
drivers/hwmon/applesmc.c +1 -1
@@ -1362,7 +1362,7 @@ 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, NULL, NULL);

That is not how you migrate a driver from hwmon_device_register() to hwmon_device_register_with_info(). You are expected to also move the sysfs-centric attribute handling to struct hwmon_chip_info.

Thanks,
Armin Wolf

Quoted 5 lines
drivers/hwmon/applesmc.c +0 -0
  	if (IS_ERR(hwmon_dev)) {
  		ret = PTR_ERR(hwmon_dev);
  		goto out_light_ledclass;
#2 lore raw

oops, wrong attachment.

Quoted 6 lines · Armin Wolf

Am 20.11.25 um 00:46 schrieb Jared Mauch:

Quoted 4 lines

Updates code from hwmon_device_register to hwmon_device_register_with_info

drivers/hwmon/applesmc.c +16 -12
index fc6d6a9053ce..10d1bfc6bf7b 100644
@@ -1123,7 +1123,7 @@ static void applesmc_destroy_nodes(struct applesmc_node_group *groups)
 
 	for (grp = groups; grp->nodes; grp++) {
 		for (node = grp->nodes; node->sda.dev_attr.attr.name; node++)
-			sysfs_remove_file(&pdev->dev.kobj,
+			sysfs_remove_file(&hwmon_dev->kobj,
 					  &node->sda.dev_attr.attr);
 		kfree(grp->nodes);
 		grp->nodes = NULL;
@@ -1157,7 +1157,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
 			sysfs_attr_init(attr);
 			attr->name = node->name;
 			attr->mode = 0444 | (grp->store ? 0200 : 0);
-			ret = sysfs_create_file(&pdev->dev.kobj, attr);
+			ret = sysfs_create_file(&hwmon_dev->kobj, attr);
 			if (ret) {
 				attr->name = NULL;
 				goto out;
@@ -1338,9 +1338,16 @@ static int __init applesmc_init(void)
 	if (ret)
 		goto out_device;
 
+	/* Register hwmon device early so we can create sysfs files on it */
+	hwmon_dev = hwmon_device_register_with_info(&pdev->dev, "applesmc", NULL, NULL, NULL);
+	if (IS_ERR(hwmon_dev)) {
+		ret = PTR_ERR(hwmon_dev);
+		goto out_smcreg;
+	}
+
 	ret = applesmc_create_nodes(info_group, 1);
 	if (ret)
-		goto out_smcreg;
+		goto out_hwmon;
 
 	ret = applesmc_create_nodes(fan_group, smcreg.fan_count);
 	if (ret)
@@ -1362,17 +1369,10 @@ static int __init applesmc_init(void)
 	if (ret)
 		goto out_light_sysfs;
 
-	hwmon_dev = hwmon_device_register(&pdev->dev);
-	if (IS_ERR(hwmon_dev)) {
-		ret = PTR_ERR(hwmon_dev);
-		goto out_light_ledclass;
-	}
-
 	return 0;
 
-out_light_ledclass:
-	applesmc_release_key_backlight();
 out_light_sysfs:
+	applesmc_release_key_backlight();
 	applesmc_release_light_sensor();
 out_accelerometer:
 	applesmc_release_accelerometer();
@@ -1382,6 +1382,9 @@ static int __init applesmc_init(void)
 	applesmc_destroy_nodes(fan_group);
 out_info:
 	applesmc_destroy_nodes(info_group);
+out_hwmon:
+	if (!IS_ERR_OR_NULL(hwmon_dev))
+		hwmon_device_unregister(hwmon_dev);
 out_smcreg:
 	applesmc_destroy_smcreg();
 out_device:
@@ -1397,7 +1400,8 @@ static int __init applesmc_init(void)
 
 static void __exit applesmc_exit(void)
 {
-	hwmon_device_unregister(hwmon_dev);
+	if (!IS_ERR_OR_NULL(hwmon_dev))
+		hwmon_device_unregister(hwmon_dev);
 	applesmc_release_key_backlight();
 	applesmc_release_light_sensor();
 	applesmc_release_accelerometer();
#3 lore raw

Am 20.11.25 um 03:03 schrieb Jared Mauch:

Quoted 1 line

oops, wrong attachment.

- Please do not top post
- Please resend your patch if you make significant changes to it
- Please do not send patches as attachments (use git send-email for example)
- The attached patch still does not use struct hwmon_chip_info

Thanks,
Armin Wolf

Quoted 7 lines · Armin Wolf
Quoted 6 lines

Am 20.11.25 um 00:46 schrieb Jared Mauch:

Quoted 4 lines

Updates code from hwmon_device_register to hwmon_device_register_with_info

maintainer NAK
#4 lore raw
In reply to Jared Mauch
Quoted 4 lines · Jared Mauch

Updates code from hwmon_device_register to hwmon_device_register_with_info

NACK

Quoted 15 lines
drivers/hwmon/applesmc.c +1 -1
index fc6d6a9053ce..984dfbf40233 100644
@@ -1362,7 +1362,7 @@ 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, NULL, NULL);
  	if (IS_ERR(hwmon_dev)) {
  		ret = PTR_ERR(hwmon_dev);
  		goto out_light_ledclass;