mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Phinex Hung <phinex@realtek.com>
To: unlisted-recipients:; (no To-header on input)
Cc: <phinex@realtek.com>, Jean Delvare <jdelvare@suse.com>,
	Guenter Roeck <linux@roeck-us.net>, <linux-hwmon@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH v2] hwmon: fix potential sensor registration fail if of_node is missing
Date: Tue, 21 Mar 2023 14:02:23 +0800	[thread overview]
Message-ID: <20230321060224.3819-1-phinex@realtek.com> (raw)
In-Reply-To: <20230315121606.GA71707@threadripper>

It is not sufficient to check of_node in current device.
In some cases, this would cause the sensor registration to fail.

This patch looks for device's ancestors to find a valid of_node if any.

Signed-off-by: Phinex Hung <phinex@realtek.com>
---

v2: assign of_node from its ancestor to support sensor registration

---
 drivers/hwmon/hwmon.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 33edb5c02f7d..d193ed3cb35e 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -757,6 +757,7 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
 	struct hwmon_device *hwdev;
 	const char *label;
 	struct device *hdev;
+	struct device *tdev = dev;
 	int i, err, id;
 
 	/* Complain about invalid characters in hwmon name attribute */
@@ -826,7 +827,9 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
 	hwdev->name = name;
 	hdev->class = &hwmon_class;
 	hdev->parent = dev;
-	hdev->of_node = dev ? dev->of_node : NULL;
+	while (tdev && !tdev->of_node)
+		tdev = tdev->parent;
+	hdev->of_node = tdev ? tdev->of_node : NULL;
 	hwdev->chip = chip;
 	dev_set_drvdata(hdev, drvdata);
 	dev_set_name(hdev, HWMON_ID_FORMAT, id);
@@ -838,7 +841,7 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
 
 	INIT_LIST_HEAD(&hwdev->tzdata);
 
-	if (dev && dev->of_node && chip && chip->ops->read &&
+	if (hdev->of_node && chip && chip->ops->read &&
 	    chip->info[0]->type == hwmon_chip &&
 	    (chip->info[0]->config[0] & HWMON_C_REGISTER_TZ)) {
 		err = hwmon_thermal_register_sensors(hdev);
-- 
2.17.1


      parent reply	other threads:[~2023-03-21  6:03 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-15 12:16 [PATCH v1] hwmon: drivetemp: support to be a platform driver for thermal_of phinex
2023-03-15 13:11 ` Krzysztof Kozlowski
2023-03-15 14:02   ` Phinex Hung
2023-03-15 14:06     ` Krzysztof Kozlowski
2023-03-15 14:16 ` Guenter Roeck
2023-03-15 15:06 ` kernel test robot
2023-03-15 15:36 ` Guenter Roeck
2023-03-16  2:21   ` Phinex Hung
2023-03-16  3:02     ` Guenter Roeck
2023-03-16  3:29       ` Phinex Hung
2023-03-16  5:07         ` Guenter Roeck
2023-03-16  7:35           ` Phinex Hung
2023-03-16  7:48             ` Phinex Hung
2023-03-16 13:22               ` Guenter Roeck
2023-03-16 14:17                 ` Phinex Hung
2023-03-16 18:17                   ` Guenter Roeck
2023-03-17  2:25                     ` Phinex Hung
2023-03-15 21:15 ` kernel test robot
2023-03-15 22:28 ` kernel test robot
2023-03-21  6:02 ` Phinex Hung [this message]

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=20230321060224.3819-1-phinex@realtek.com \
    --to=phinex@realtek.com \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    /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

all inboxes | Powered by JetHome®