]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-5.1/hwmon-pmbus-core-treat-parameters-as-paged-if-on-mul.patch
fixes for 5.1
[thirdparty/kernel/stable-queue.git] / queue-5.1 / hwmon-pmbus-core-treat-parameters-as-paged-if-on-mul.patch
1 From b9ce8102c6bbc9093f71b69f47a0097790d6456b Mon Sep 17 00:00:00 2001
2 From: Robert Hancock <hancock@sedsystems.ca>
3 Date: Wed, 5 Jun 2019 13:49:00 -0600
4 Subject: hwmon: (pmbus/core) Treat parameters as paged if on multiple pages
5
6 [ Upstream commit 4a60570dce658e3f8885bbcf852430b99f65aca5 ]
7
8 Some chips have attributes which exist on more than one page but the
9 attribute is not presently marked as paged. This causes the attributes
10 to be generated with the same label, which makes it impossible for
11 userspace to tell them apart.
12
13 Marking all such attributes as paged would result in the page suffix
14 being added regardless of whether they were present on more than one
15 page or not, which might break existing setups. Therefore, we add a
16 second check which treats the attribute as paged, even if not marked as
17 such, if it is present on multiple pages.
18
19 Fixes: b4ce237b7f7d ("hwmon: (pmbus) Introduce infrastructure to detect sensors and limit registers")
20 Signed-off-by: Robert Hancock <hancock@sedsystems.ca>
21 Signed-off-by: Guenter Roeck <linux@roeck-us.net>
22 Signed-off-by: Sasha Levin <sashal@kernel.org>
23 ---
24 drivers/hwmon/pmbus/pmbus_core.c | 34 ++++++++++++++++++++++++++++----
25 1 file changed, 30 insertions(+), 4 deletions(-)
26
27 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
28 index 2e2b5851139c..cd24b375df1e 100644
29 --- a/drivers/hwmon/pmbus/pmbus_core.c
30 +++ b/drivers/hwmon/pmbus/pmbus_core.c
31 @@ -1230,7 +1230,8 @@ static int pmbus_add_sensor_attrs_one(struct i2c_client *client,
32 const struct pmbus_driver_info *info,
33 const char *name,
34 int index, int page,
35 - const struct pmbus_sensor_attr *attr)
36 + const struct pmbus_sensor_attr *attr,
37 + bool paged)
38 {
39 struct pmbus_sensor *base;
40 bool upper = !!(attr->gbit & 0xff00); /* need to check STATUS_WORD */
41 @@ -1238,7 +1239,7 @@ static int pmbus_add_sensor_attrs_one(struct i2c_client *client,
42
43 if (attr->label) {
44 ret = pmbus_add_label(data, name, index, attr->label,
45 - attr->paged ? page + 1 : 0);
46 + paged ? page + 1 : 0);
47 if (ret)
48 return ret;
49 }
50 @@ -1271,6 +1272,30 @@ static int pmbus_add_sensor_attrs_one(struct i2c_client *client,
51 return 0;
52 }
53
54 +static bool pmbus_sensor_is_paged(const struct pmbus_driver_info *info,
55 + const struct pmbus_sensor_attr *attr)
56 +{
57 + int p;
58 +
59 + if (attr->paged)
60 + return true;
61 +
62 + /*
63 + * Some attributes may be present on more than one page despite
64 + * not being marked with the paged attribute. If that is the case,
65 + * then treat the sensor as being paged and add the page suffix to the
66 + * attribute name.
67 + * We don't just add the paged attribute to all such attributes, in
68 + * order to maintain the un-suffixed labels in the case where the
69 + * attribute is only on page 0.
70 + */
71 + for (p = 1; p < info->pages; p++) {
72 + if (info->func[p] & attr->func)
73 + return true;
74 + }
75 + return false;
76 +}
77 +
78 static int pmbus_add_sensor_attrs(struct i2c_client *client,
79 struct pmbus_data *data,
80 const char *name,
81 @@ -1284,14 +1309,15 @@ static int pmbus_add_sensor_attrs(struct i2c_client *client,
82 index = 1;
83 for (i = 0; i < nattrs; i++) {
84 int page, pages;
85 + bool paged = pmbus_sensor_is_paged(info, attrs);
86
87 - pages = attrs->paged ? info->pages : 1;
88 + pages = paged ? info->pages : 1;
89 for (page = 0; page < pages; page++) {
90 if (!(info->func[page] & attrs->func))
91 continue;
92 ret = pmbus_add_sensor_attrs_one(client, data, info,
93 name, index, page,
94 - attrs);
95 + attrs, paged);
96 if (ret)
97 return ret;
98 index++;
99 --
100 2.20.1
101