]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
power: supply: core: tabularize HWMON temperature labels
authorMichał Mirosław <mirq-linux@rere.qmqm.pl>
Fri, 1 May 2020 15:11:18 +0000 (17:11 +0200)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Fri, 1 May 2020 16:58:42 +0000 (18:58 +0200)
Rework power_supply_hwmon_read_string() to check it's parameters.
This allows to extend it later with labels for other types of
measurements.

Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/power_supply_hwmon.c

index af72e5693f65888e33ce75e0202b0f0feba9b748..f5d538485aaad9667cdfe4ff57af475492a2cc41 100644 (file)
@@ -13,6 +13,11 @@ struct power_supply_hwmon {
        unsigned long *props;
 };
 
+static const char *const ps_temp_label[] = {
+       "temp",
+       "ambient temp",
+};
+
 static int power_supply_hwmon_in_to_property(u32 attr)
 {
        switch (attr) {
@@ -180,7 +185,20 @@ static int power_supply_hwmon_read_string(struct device *dev,
                                          u32 attr, int channel,
                                          const char **str)
 {
-       *str = channel ? "temp ambient" : "temp";
+       switch (type) {
+       case hwmon_temp:
+               *str = ps_temp_label[channel];
+               break;
+       default:
+               /* unreachable, but see:
+                * gcc bug #51513 [1] and clang bug #978 [2]
+                *
+                * [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51513
+                * [2] https://github.com/ClangBuiltLinux/linux/issues/978
+                */
+               break;
+       }
+
        return 0;
 }