Message ID | 79bec8125df260bdae294345bd7773dc3dd9c434.1588345420.git.mirq-linux@rere.qmqm.pl (mailing list archive) |
---|---|
State | Not Applicable, archived |
Headers | show |
Series | power: supply: core: extend with new properties | expand |
Hi, On Fri, May 01, 2020 at 05:11:18PM +0200, Michał Mirosław wrote: > 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> > --- > v2: split from fix temperature labels > v3: remove power_supply_hwmon_read_string() parameter checks > as it is internal API (suggested by Guenter Roeck) > v4: remove unreachable() as it triggers compiler bugs > --- Thanks, queued. -- Sebastian > drivers/power/supply/power_supply_hwmon.c | 20 +++++++++++++++++++- > 1 file changed, 19 insertions(+), 1 deletion(-) > > diff --git a/drivers/power/supply/power_supply_hwmon.c b/drivers/power/supply/power_supply_hwmon.c > index af72e5693f65..f5d538485aaa 100644 > --- a/drivers/power/supply/power_supply_hwmon.c > +++ b/drivers/power/supply/power_supply_hwmon.c > @@ -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; > } > > -- > 2.20.1 >
diff --git a/drivers/power/supply/power_supply_hwmon.c b/drivers/power/supply/power_supply_hwmon.c index af72e5693f65..f5d538485aaa 100644 --- a/drivers/power/supply/power_supply_hwmon.c +++ b/drivers/power/supply/power_supply_hwmon.c @@ -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; }
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> --- v2: split from fix temperature labels v3: remove power_supply_hwmon_read_string() parameter checks as it is internal API (suggested by Guenter Roeck) v4: remove unreachable() as it triggers compiler bugs --- drivers/power/supply/power_supply_hwmon.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)