]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.14.130/hwmon-core-add-thermal-sensors-only-if-dev-of_node-i.patch
Linux 4.14.130
[thirdparty/kernel/stable-queue.git] / releases / 4.14.130 / hwmon-core-add-thermal-sensors-only-if-dev-of_node-i.patch
1 From 576aaa4f0ce243185c856a2ca7b7d25632dbc1fb Mon Sep 17 00:00:00 2001
2 From: Eduardo Valentin <eduval@amazon.com>
3 Date: Wed, 29 May 2019 19:56:04 -0700
4 Subject: hwmon: (core) add thermal sensors only if dev->of_node is present
5
6 [ Upstream commit c41dd48e21fae3e55b3670ccf2eb562fc1f6a67d ]
7
8 Drivers may register to hwmon and request for also registering
9 with the thermal subsystem (HWMON_C_REGISTER_TZ). However,
10 some of these driver, e.g. marvell phy, may be probed from
11 Device Tree or being dynamically allocated, and in the later
12 case, it will not have a dev->of_node entry.
13
14 Registering with hwmon without the dev->of_node may result in
15 different outcomes depending on the device tree, which may
16 be a bit misleading. If the device tree blob has no 'thermal-zones'
17 node, the *hwmon_device_register*() family functions are going
18 to gracefully succeed, because of-thermal,
19 *thermal_zone_of_sensor_register() return -ENODEV in this case,
20 and the hwmon error path handles this error code as success to
21 cover for the case where CONFIG_THERMAL_OF is not set.
22 However, if the device tree blob has the 'thermal-zones'
23 entry, the *hwmon_device_register*() will always fail on callers
24 with no dev->of_node, propagating -EINVAL.
25
26 If dev->of_node is not present, calling of-thermal does not
27 make sense. For this reason, this patch checks first if the
28 device has a of_node before going over the process of registering
29 with the thermal subsystem of-thermal interface. And in this case,
30 when a caller of *hwmon_device_register*() with HWMON_C_REGISTER_TZ
31 and no dev->of_node will still register with hwmon, but not with
32 the thermal subsystem. If all the hwmon part bits are in place,
33 the registration will succeed.
34
35 Fixes: d560168b5d0f ("hwmon: (core) New hwmon registration API")
36 Cc: Jean Delvare <jdelvare@suse.com>
37 Cc: Guenter Roeck <linux@roeck-us.net>
38 Cc: linux-hwmon@vger.kernel.org
39 Cc: linux-kernel@vger.kernel.org
40 Signed-off-by: Eduardo Valentin <eduval@amazon.com>
41 Signed-off-by: Guenter Roeck <linux@roeck-us.net>
42 Signed-off-by: Sasha Levin <sashal@kernel.org>
43 ---
44 drivers/hwmon/hwmon.c | 2 +-
45 1 file changed, 1 insertion(+), 1 deletion(-)
46
47 diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
48 index c9790e2c3440..7b53065e9882 100644
49 --- a/drivers/hwmon/hwmon.c
50 +++ b/drivers/hwmon/hwmon.c
51 @@ -608,7 +608,7 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
52 if (err)
53 goto free_hwmon;
54
55 - if (dev && chip && chip->ops->read &&
56 + if (dev && dev->of_node && chip && chip->ops->read &&
57 chip->info[0]->type == hwmon_chip &&
58 (chip->info[0]->config[0] & HWMON_C_REGISTER_TZ)) {
59 const struct hwmon_channel_info **info = chip->info;
60 --
61 2.20.1
62