From: Hans de Goede <hdegoede@redhat.com>
To: "Sebastian Reichel" <sre@kernel.org>,
"Thomas Weißschuh" <linux@weissschuh.net>,
"MyungJoo Ham" <myungjoo.ham@samsung.com>,
"Chanwoo Choi" <cw00.choi@samsung.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Heikki Krogerus" <heikki.krogerus@linux.intel.com>,
"Vinod Koul" <vkoul@kernel.org>,
"Kishon Vijay Abraham I" <kishon@kernel.org>
Cc: Hans de Goede <hdegoede@redhat.com>,
Enric Balletbo Serra <enric.balletbo@collabora.com>,
Andrey Smirnov <andrew.smirnov@gmail.com>,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-usb@vger.kernel.org, linux-phy@lists.infradead.org
Subject: [PATCH 5/6] power: supply: sysfs: Move power_supply_show_enum_with_available() up
Date: Sat, 31 Aug 2024 16:20:38 +0200 [thread overview]
Message-ID: <20240831142039.28830-6-hdegoede@redhat.com> (raw)
In-Reply-To: <20240831142039.28830-1-hdegoede@redhat.com>
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 <hdegoede@redhat.com>
---
drivers/power/supply/power_supply_sysfs.c | 62 +++++++++++------------
1 file changed, 31 insertions(+), 31 deletions(-)
diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c
index 9f21b0b54caf..c98a6de59d3b 100644
--- a/drivers/power/supply/power_supply_sysfs.c
+++ b/drivers/power/supply/power_supply_sysfs.c
@@ -237,6 +237,37 @@ static enum power_supply_property dev_attr_psp(struct device_attribute *attr)
return to_ps_attr(attr) - power_supply_attrs;
}
+static ssize_t power_supply_show_enum_with_available(
+ struct device *dev, const char * const labels[], int label_count,
+ unsigned int available_values, int value, char *buf)
+{
+ bool match = false, available, active;
+ ssize_t count = 0;
+ int i;
+
+ for (i = 0; i < label_count; i++) {
+ available = available_values & BIT(i);
+ active = i == value;
+
+ if (available && active) {
+ count += sysfs_emit_at(buf, count, "[%s] ", labels[i]);
+ match = true;
+ } else if (available) {
+ count += sysfs_emit_at(buf, count, "%s ", labels[i]);
+ }
+ }
+
+ if (!match) {
+ dev_warn(dev, "driver reporting unavailable enum value %d\n", value);
+ return -EINVAL;
+ }
+
+ if (count)
+ buf[count - 1] = '\n';
+
+ return count;
+}
+
static ssize_t power_supply_show_usb_type(struct device *dev,
const struct power_supply_desc *desc,
union power_supply_propval *value,
@@ -518,37 +549,6 @@ int power_supply_uevent(const struct device *dev, struct kobj_uevent_env *env)
return ret;
}
-static ssize_t power_supply_show_enum_with_available(
- struct device *dev, const char * const labels[], int label_count,
- unsigned int available_values, int value, char *buf)
-{
- bool match = false, available, active;
- ssize_t count = 0;
- int i;
-
- for (i = 0; i < label_count; i++) {
- available = available_values & BIT(i);
- active = i == value;
-
- if (available && active) {
- count += sysfs_emit_at(buf, count, "[%s] ", labels[i]);
- match = true;
- } else if (available) {
- count += sysfs_emit_at(buf, count, "%s ", labels[i]);
- }
- }
-
- if (!match) {
- dev_warn(dev, "driver reporting unavailable enum value %d\n", value);
- return -EINVAL;
- }
-
- if (count)
- buf[count - 1] = '\n';
-
- return count;
-}
-
ssize_t power_supply_charge_behaviour_show(struct device *dev,
unsigned int available_behaviours,
enum power_supply_charge_behaviour current_behaviour,
--
2.46.0
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
next prev parent reply other threads:[~2024-08-31 14:21 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-31 14:20 [PATCH 0/6] power: supply: Change usb_types from an array into a bitmask Hans de Goede
2024-08-31 14:20 ` [PATCH 1/6] power: supply: "usb_type" property may be written to Hans de Goede
2024-09-03 7:04 ` Greg Kroah-Hartman
2024-08-31 14:20 ` [PATCH 2/6] power: supply: ucs1002: Adjust ucs1002_set_usb_type() to accept string values Hans de Goede
2024-08-31 14:20 ` [PATCH 3/6] power: supply: rt9467-charger: Remove "usb_type" property write support Hans de Goede
2024-08-31 14:20 ` [PATCH 4/6] power: supply: sysfs: Add power_supply_show_enum_with_available() helper Hans de Goede
2024-08-31 14:20 ` Hans de Goede [this message]
2024-08-31 14:20 ` [PATCH 6/6] power: supply: Change usb_types from an array into a bitmask Hans de Goede
2024-09-03 7:04 ` Greg Kroah-Hartman
2024-09-03 8:27 ` Hans de Goede
2024-09-03 8:32 ` Greg Kroah-Hartman
2024-09-03 21:57 ` [PATCH 0/6] " Sebastian Reichel
2024-09-03 22:04 ` Sebastian Reichel
2024-09-04 9:26 ` Hans de Goede
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240831142039.28830-6-hdegoede@redhat.com \
--to=hdegoede@redhat.com \
--cc=andrew.smirnov@gmail.com \
--cc=cw00.choi@samsung.com \
--cc=enric.balletbo@collabora.com \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=kishon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=myungjoo.ham@samsung.com \
--cc=sre@kernel.org \
--cc=vkoul@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox