Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: Jared Mauch <jared@puck.nether.net>
To: Armin Wolf <W_Armin@gmx.de>
Cc: Jared Mauch <jared@puck.nether.net>,
	rydberg@bitmath.org, linux-hwmon@vger.kernel.org
Subject: Re: Patch: applesmc.c - update handling
Date: Wed, 19 Nov 2025 21:03:30 -0500	[thread overview]
Message-ID: <aR528iQGceJtE0nN@puck.nether.net> (raw)
In-Reply-To: <c5151e1f-cdf9-4d58-b00b-433f877b2ab3@gmx.de>

[-- Attachment #1: Type: text/plain, Size: 277 bytes --]

	oops, wrong attachment.

On Thu, Nov 20, 2025 at 12:54:24AM +0100, Armin Wolf wrote:
> Am 20.11.25 um 00:46 schrieb Jared Mauch:
> 
> > Updates code from hwmon_device_register to hwmon_device_register_with_info
> > 
> > Signed-off-by: Jared Mauch <jared@puck.nether.net>
> > 

[-- Attachment #2: hwmon.diff --]
[-- Type: text/plain, Size: 2460 bytes --]

diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
index fc6d6a9053ce..10d1bfc6bf7b 100644
--- a/drivers/hwmon/applesmc.c
+++ b/drivers/hwmon/applesmc.c
@@ -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();

  reply	other threads:[~2025-11-20  2:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-19 23:46 Patch: applesmc.c - update handling Jared Mauch
2025-11-19 23:54 ` Armin Wolf
2025-11-20  2:03   ` Jared Mauch [this message]
2025-11-20  2:39     ` Armin Wolf
2025-11-20  2:39 ` Guenter Roeck

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=aR528iQGceJtE0nN@puck.nether.net \
    --to=jared@puck.nether.net \
    --cc=W_Armin@gmx.de \
    --cc=linux-hwmon@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox