Skip to content

Commit 521d75b

Browse files
t-8chsre
authored andcommitted
power: supply: core: ease special formatting implementations
By moving the conditional into the default-branch of the switch new additions to the switch won't have to bypass the conditional. This makes it easier to implement those special cases like the upcoming change to the formatting of "charge_behaviour". Suggested-by: Hans de Goede <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Signed-off-by: Thomas Weißschuh <[email protected]> Link: https://lore.kernel.org/r/20240303-power_supply-charge_behaviour_prop-v2-2-8ebb0a7c2409@weissschuh.net Signed-off-by: Sebastian Reichel <[email protected]>
1 parent cd38a0a commit 521d75b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

drivers/power/supply/power_supply_sysfs.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,6 @@ static ssize_t power_supply_show_property(struct device *dev,
298298
}
299299
}
300300

301-
if (ps_attr->text_values_len > 0 &&
302-
value.intval < ps_attr->text_values_len && value.intval >= 0) {
303-
return sysfs_emit(buf, "%s\n", ps_attr->text_values[value.intval]);
304-
}
305-
306301
switch (psp) {
307302
case POWER_SUPPLY_PROP_USB_TYPE:
308303
ret = power_supply_show_usb_type(dev, psy->desc,
@@ -312,7 +307,12 @@ static ssize_t power_supply_show_property(struct device *dev,
312307
ret = sysfs_emit(buf, "%s\n", value.strval);
313308
break;
314309
default:
315-
ret = sysfs_emit(buf, "%d\n", value.intval);
310+
if (ps_attr->text_values_len > 0 &&
311+
value.intval < ps_attr->text_values_len && value.intval >= 0) {
312+
ret = sysfs_emit(buf, "%s\n", ps_attr->text_values[value.intval]);
313+
} else {
314+
ret = sysfs_emit(buf, "%d\n", value.intval);
315+
}
316316
}
317317

318318
return ret;

0 commit comments

Comments
 (0)