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.6.y 4/7] power: supply: core: introduce power_supply_for_each_psy()
Date: Tue, 10 Nov 2026 12:21:10 -0500 [thread overview]
Message-ID: <20261110172014.2622013-4-sashal@kernel.org> (raw)
In-Reply-To: <20261110172014.2622013-1-sashal@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 df5e21ec01638..260de00996bc1 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -119,6 +119,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 b08e00368f9de..4b231468c3f1d 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -896,6 +896,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 17:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-07 10:31 FAILED: patch "[PATCH] power: supply: core: Honor supplied-from with CONFIG_OF=y" failed to apply to 6.6-stable tree Sasha Levin
2026-11-10 17:21 ` [PATCH 6.6.y 1/7] power: supply: core: remove opencoded string_lower() Sasha Levin
2026-11-10 17:21 ` [PATCH 6.6.y 2/7] power: supply: core: make power_supply_class constant Sasha Levin
2026-11-10 17:21 ` [PATCH 6.6.y 3/7] power: supply: core: add power_supply_for_each_device() Sasha Levin
2026-11-10 17:21 ` Sasha Levin [this message]
2026-11-10 17:21 ` [PATCH 6.6.y 5/7] power: supply: core: use power_supply_for_each_psy() Sasha Levin
2026-11-10 17:21 ` [PATCH 6.6.y 6/7] power: supply: core: get rid of of_node Sasha Levin
2026-11-10 17:21 ` [PATCH 6.6.y 7/7] 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=20261110172014.2622013-4-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.