From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: "Thomas Weißschuh" <linux@weissschuh.net>,
"Sebastian Reichel" <sebastian.reichel@collabora.com>,
"Sasha Levin" <sashal@kernel.org>
Subject: [PATCH 6.12.y 1/4] power: supply: core: introduce power_supply_for_each_psy()
Date: Tue, 10 Nov 2026 11:50:26 -0500 [thread overview]
Message-ID: <20261110164953.2511682-1-sashal@kernel.org> (raw)
In-Reply-To: <20261107051904-failed-6.12-6bd80f22c764@kernel.org>
From: Thomas Weißschuh <linux@weissschuh.net>
[ Upstream commit 9029409d1a250da19f1086ab1113752411c5163d ]
All existing callers of power_supply_for_each_device() want to iterate
over 'struct power_supply', not 'struct device'.
The power_supply_for_each_device() forces each caller to duplicate the
logic to go from one to the other.
Introduce power_supply_for_each_psy() to simplify the callers.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/r/20241210-power-supply-dev_to_psy-v2-2-9d8c9d24cfe4@weissschuh.net
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Stable-dep-of: 6bd80f22c764 ("power: supply: core: Honor supplied-from with CONFIG_OF=y")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/power/supply/power_supply_core.c | 24 ++++++++++++++++++++++++
include/linux/power_supply.h | 1 +
2 files changed, 25 insertions(+)
diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index edc7b3bd9b5c8..34aca2c76cc5d 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -122,6 +122,30 @@ int power_supply_for_each_device(void *data, int (*fn)(struct device *dev, void
}
EXPORT_SYMBOL_GPL(power_supply_for_each_device);
+struct psy_for_each_psy_cb_data {
+ int (*fn)(struct power_supply *psy, void *data);
+ void *data;
+};
+
+static int psy_for_each_psy_cb(struct device *dev, void *data)
+{
+ struct psy_for_each_psy_cb_data *cb_data = data;
+ struct power_supply *psy = dev_get_drvdata(dev);
+
+ return cb_data->fn(psy, cb_data->data);
+}
+
+int power_supply_for_each_psy(void *data, int (*fn)(struct power_supply *psy, void *data))
+{
+ struct psy_for_each_psy_cb_data cb_data = {
+ .fn = fn,
+ .data = data,
+ };
+
+ return power_supply_for_each_device(&cb_data, psy_for_each_psy_cb);
+}
+EXPORT_SYMBOL_GPL(power_supply_for_each_psy);
+
void power_supply_changed(struct power_supply *psy)
{
unsigned long flags;
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index b03991a29a65e..565a40172cc30 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -890,6 +890,7 @@ extern int power_supply_powers(struct power_supply *psy, struct device *dev);
extern void *power_supply_get_drvdata(struct power_supply *psy);
extern int power_supply_for_each_device(void *data, int (*fn)(struct device *dev, void *data));
+extern int power_supply_for_each_psy(void *data, int (*fn)(struct power_supply *psy, void *data));
static inline bool power_supply_is_amp_property(enum power_supply_property psp)
{
--
2.53.0
next prev parent reply other threads:[~2026-11-10 16:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-07 10:19 FAILED: patch "[PATCH] power: supply: core: Honor supplied-from with CONFIG_OF=y" failed to apply to 6.12-stable tree Sasha Levin
2026-11-10 16:50 ` Sasha Levin [this message]
2026-11-10 16:50 ` [PATCH 6.12.y 2/4] power: supply: core: use power_supply_for_each_psy() Sasha Levin
2026-11-10 16:50 ` [PATCH 6.12.y 3/4] power: supply: core: get rid of of_node Sasha Levin
2026-11-10 16:50 ` [PATCH 6.12.y 4/4] power: supply: core: Honor supplied-from with CONFIG_OF=y Sasha Levin
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=20261110164953.2511682-1-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=linux@weissschuh.net \
--cc=sebastian.reichel@collabora.com \
--cc=stable@vger.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