Skip to content

Commit 322900a

Browse files
jwrdegoedesre
authored andcommitted
power: supply: sysfs: Move power_supply_show_enum_with_available() up
Move power_supply_show_enum_with_available() higher up in the power_supply_sysfs.c file. This is a preparation patch to avoid needing a forward declaration when replacing power_supply_show_usb_type() with it later on. This commit only moves the function, there are no changes to it. Signed-off-by: Hans de Goede <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sebastian Reichel <[email protected]>
1 parent a6456d4 commit 322900a

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

drivers/power/supply/power_supply_sysfs.c

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,37 @@ static enum power_supply_property dev_attr_psp(struct device_attribute *attr)
237237
return to_ps_attr(attr) - power_supply_attrs;
238238
}
239239

240+
static ssize_t power_supply_show_enum_with_available(
241+
struct device *dev, const char * const labels[], int label_count,
242+
unsigned int available_values, int value, char *buf)
243+
{
244+
bool match = false, available, active;
245+
ssize_t count = 0;
246+
int i;
247+
248+
for (i = 0; i < label_count; i++) {
249+
available = available_values & BIT(i);
250+
active = i == value;
251+
252+
if (available && active) {
253+
count += sysfs_emit_at(buf, count, "[%s] ", labels[i]);
254+
match = true;
255+
} else if (available) {
256+
count += sysfs_emit_at(buf, count, "%s ", labels[i]);
257+
}
258+
}
259+
260+
if (!match) {
261+
dev_warn(dev, "driver reporting unavailable enum value %d\n", value);
262+
return -EINVAL;
263+
}
264+
265+
if (count)
266+
buf[count - 1] = '\n';
267+
268+
return count;
269+
}
270+
240271
static ssize_t power_supply_show_usb_type(struct device *dev,
241272
const struct power_supply_desc *desc,
242273
union power_supply_propval *value,
@@ -518,37 +549,6 @@ int power_supply_uevent(const struct device *dev, struct kobj_uevent_env *env)
518549
return ret;
519550
}
520551

521-
static ssize_t power_supply_show_enum_with_available(
522-
struct device *dev, const char * const labels[], int label_count,
523-
unsigned int available_values, int value, char *buf)
524-
{
525-
bool match = false, available, active;
526-
ssize_t count = 0;
527-
int i;
528-
529-
for (i = 0; i < label_count; i++) {
530-
available = available_values & BIT(i);
531-
active = i == value;
532-
533-
if (available && active) {
534-
count += sysfs_emit_at(buf, count, "[%s] ", labels[i]);
535-
match = true;
536-
} else if (available) {
537-
count += sysfs_emit_at(buf, count, "%s ", labels[i]);
538-
}
539-
}
540-
541-
if (!match) {
542-
dev_warn(dev, "driver reporting unavailable enum value %d\n", value);
543-
return -EINVAL;
544-
}
545-
546-
if (count)
547-
buf[count - 1] = '\n';
548-
549-
return count;
550-
}
551-
552552
ssize_t power_supply_charge_behaviour_show(struct device *dev,
553553
unsigned int available_behaviours,
554554
enum power_supply_charge_behaviour current_behaviour,

0 commit comments

Comments
 (0)