Skip to content

Commit 2315332

Browse files
phinexhunggroeck
authored andcommitted
hwmon: fix potential sensor registration fail if of_node is missing
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Guenter Roeck <[email protected]>
1 parent 2b91c4a commit 2315332

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

drivers/hwmon/hwmon.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,7 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
757757
struct hwmon_device *hwdev;
758758
const char *label;
759759
struct device *hdev;
760+
struct device *tdev = dev;
760761
int i, err, id;
761762

762763
/* Complain about invalid characters in hwmon name attribute */
@@ -826,7 +827,9 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
826827
hwdev->name = name;
827828
hdev->class = &hwmon_class;
828829
hdev->parent = dev;
829-
hdev->of_node = dev ? dev->of_node : NULL;
830+
while (tdev && !tdev->of_node)
831+
tdev = tdev->parent;
832+
hdev->of_node = tdev ? tdev->of_node : NULL;
830833
hwdev->chip = chip;
831834
dev_set_drvdata(hdev, drvdata);
832835
dev_set_name(hdev, HWMON_ID_FORMAT, id);
@@ -838,7 +841,7 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
838841

839842
INIT_LIST_HEAD(&hwdev->tzdata);
840843

841-
if (dev && dev->of_node && chip && chip->ops->read &&
844+
if (hdev->of_node && chip && chip->ops->read &&
842845
chip->info[0]->type == hwmon_chip &&
843846
(chip->info[0]->config[0] & HWMON_C_REGISTER_TZ)) {
844847
err = hwmon_thermal_register_sensors(hdev);

0 commit comments

Comments
 (0)