Skip to content

Commit

Permalink
hwmon: fix potential sensor registration fail if of_node is missing
Browse files Browse the repository at this point in the history
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.

Fixes: d560168 ("hwmon: (core) New hwmon registration API")
Signed-off-by: Phinex Hung <phinex@realtek.com>
Link: https://lore.kernel.org/r/20230321060224.3819-1-phinex@realtek.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
  • Loading branch information
Phinex Hung authored and Guenter Roeck committed Mar 21, 2023
1 parent 2b91c4a commit 2315332
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions drivers/hwmon/hwmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 2315332

Please sign in to comment.