From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: "Ricardo B. Marliere" <ricardo@marliere.net>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Linus Walleij <linus.walleij@linaro.org>,
Sebastian Reichel <sebastian.reichel@collabora.com>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.6.y 2/7] power: supply: core: make power_supply_class constant
Date: Tue, 10 Nov 2026 12:21:08 -0500 [thread overview]
Message-ID: <20261110172014.2622013-2-sashal@kernel.org> (raw)
In-Reply-To: <20261110172014.2622013-1-sashal@kernel.org>
From: "Ricardo B. Marliere" <ricardo@marliere.net>
[ Upstream commit 71c2cc5cbf686c2397f43cbcb51a31589bdcee7b ]
Since commit 43a7206b0963 ("driver core: class: make class_register() take
a const *"), the driver core allows for struct class to be in read-only
memory, so move the power_supply_class structure to be declared at build
time placing it into read-only memory, instead of having to be dynamically
allocated at boot time.
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ricardo B. Marliere <ricardo@marliere.net>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20240301-class_cleanup-power-v1-1-97e0b7bf9c94@marliere.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/ab8500_btemp.c | 2 +-
drivers/power/supply/ab8500_chargalg.c | 2 +-
drivers/power/supply/ab8500_charger.c | 2 +-
drivers/power/supply/ab8500_fg.c | 2 +-
drivers/power/supply/apm_power.c | 2 +-
drivers/power/supply/power_supply_core.c | 39 +++++++++++++-----------
include/linux/power_supply.h | 2 +-
7 files changed, 27 insertions(+), 24 deletions(-)
diff --git a/drivers/power/supply/ab8500_btemp.c b/drivers/power/supply/ab8500_btemp.c
index ce36d6ca34226..3ea01301da9ff 100644
--- a/drivers/power/supply/ab8500_btemp.c
+++ b/drivers/power/supply/ab8500_btemp.c
@@ -617,7 +617,7 @@ static int ab8500_btemp_get_ext_psy_data(struct device *dev, void *data)
*/
static void ab8500_btemp_external_power_changed(struct power_supply *psy)
{
- class_for_each_device(power_supply_class, NULL, psy,
+ class_for_each_device(&power_supply_class, NULL, psy,
ab8500_btemp_get_ext_psy_data);
}
diff --git a/drivers/power/supply/ab8500_chargalg.c b/drivers/power/supply/ab8500_chargalg.c
index 2205ea0834a61..faff6f7f38054 100644
--- a/drivers/power/supply/ab8500_chargalg.c
+++ b/drivers/power/supply/ab8500_chargalg.c
@@ -1231,7 +1231,7 @@ static void ab8500_chargalg_algorithm(struct ab8500_chargalg *di)
int ret;
/* Collect data from all power_supply class devices */
- class_for_each_device(power_supply_class, NULL,
+ class_for_each_device(&power_supply_class, NULL,
di->chargalg_psy, ab8500_chargalg_get_ext_psy_data);
ab8500_chargalg_end_of_charge(di);
diff --git a/drivers/power/supply/ab8500_charger.c b/drivers/power/supply/ab8500_charger.c
index c6d513953b042..39eeeb10b5b04 100644
--- a/drivers/power/supply/ab8500_charger.c
+++ b/drivers/power/supply/ab8500_charger.c
@@ -1949,7 +1949,7 @@ static void ab8500_charger_check_vbat_work(struct work_struct *work)
struct ab8500_charger *di = container_of(work,
struct ab8500_charger, check_vbat_work.work);
- class_for_each_device(power_supply_class, NULL,
+ class_for_each_device(&power_supply_class, NULL,
&di->usb_chg, ab8500_charger_get_ext_psy_data);
/* First run old_vbat is 0. */
diff --git a/drivers/power/supply/ab8500_fg.c b/drivers/power/supply/ab8500_fg.c
index b8b96e3225b27..178394a7b289a 100644
--- a/drivers/power/supply/ab8500_fg.c
+++ b/drivers/power/supply/ab8500_fg.c
@@ -2408,7 +2408,7 @@ static int ab8500_fg_init_hw_registers(struct ab8500_fg *di)
*/
static void ab8500_fg_external_power_changed(struct power_supply *psy)
{
- class_for_each_device(power_supply_class, NULL, psy,
+ class_for_each_device(&power_supply_class, NULL, psy,
ab8500_fg_get_ext_psy_data);
}
diff --git a/drivers/power/supply/apm_power.c b/drivers/power/supply/apm_power.c
index 50b9636945599..0bde81dd22e6c 100644
--- a/drivers/power/supply/apm_power.c
+++ b/drivers/power/supply/apm_power.c
@@ -79,7 +79,7 @@ static void find_main_battery(void)
main_battery = NULL;
bp.main = main_battery;
- error = class_for_each_device(power_supply_class, NULL, &bp,
+ error = class_for_each_device(&power_supply_class, NULL, &bp,
__find_main_battery);
if (error) {
main_battery = bp.main;
diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index 4f350db05efa0..43f72ca0cbe4f 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -26,7 +26,10 @@
#include "samsung-sdi-battery.h"
/* exported for the APM Power driver, APM emulation */
-struct class *power_supply_class;
+const struct class power_supply_class = {
+ .name = "power_supply",
+ .dev_uevent = power_supply_uevent,
+};
EXPORT_SYMBOL_GPL(power_supply_class);
BLOCKING_NOTIFIER_HEAD(power_supply_notifier);
@@ -94,7 +97,7 @@ static void power_supply_changed_work(struct work_struct *work)
if (likely(psy->changed)) {
psy->changed = false;
spin_unlock_irqrestore(&psy->changed_lock, flags);
- class_for_each_device(power_supply_class, NULL, psy,
+ class_for_each_device(&power_supply_class, NULL, psy,
__power_supply_changed_work);
power_supply_update_leds(psy);
blocking_notifier_call_chain(&power_supply_notifier,
@@ -188,7 +191,7 @@ static int power_supply_populate_supplied_from(struct power_supply *psy)
{
int error;
- error = class_for_each_device(power_supply_class, NULL, psy,
+ error = class_for_each_device(&power_supply_class, NULL, psy,
__power_supply_populate_supplied_from);
dev_dbg(&psy->dev, "%s %d\n", __func__, error);
@@ -223,8 +226,8 @@ static int power_supply_find_supply_from_node(struct device_node *supply_node)
* We return 0 if class_for_each_device() returned 1, -EPROBE_DEFER if
* it returned 0, or error as returned by it.
*/
- error = class_for_each_device(power_supply_class, NULL, supply_node,
- __power_supply_find_supply_from_node);
+ error = class_for_each_device(&power_supply_class, NULL, supply_node,
+ __power_supply_find_supply_from_node);
return error ? (error == 1 ? 0 : error) : -EPROBE_DEFER;
}
@@ -325,7 +328,7 @@ int power_supply_am_i_supplied(struct power_supply *psy)
struct psy_am_i_supplied_data data = { psy, 0 };
int error;
- error = class_for_each_device(power_supply_class, NULL, &data,
+ error = class_for_each_device(&power_supply_class, NULL, &data,
__power_supply_am_i_supplied);
dev_dbg(&psy->dev, "%s count %u err %d\n", __func__, data.count, error);
@@ -361,7 +364,7 @@ int power_supply_is_system_supplied(void)
int error;
unsigned int count = 0;
- error = class_for_each_device(power_supply_class, NULL, &count,
+ error = class_for_each_device(&power_supply_class, NULL, &count,
__power_supply_is_system_supplied);
/*
@@ -408,7 +411,7 @@ int power_supply_get_property_from_supplier(struct power_supply *psy,
* This function is not intended for use with a supply with multiple
* suppliers, we simply pick the first supply to report the psp.
*/
- ret = class_for_each_device(power_supply_class, NULL, &data,
+ ret = class_for_each_device(&power_supply_class, NULL, &data,
__power_supply_get_supplier_property);
if (ret < 0)
return ret;
@@ -454,8 +457,8 @@ static int power_supply_match_device_by_name(struct device *dev, const void *dat
struct power_supply *power_supply_get_by_name(const char *name)
{
struct power_supply *psy = NULL;
- struct device *dev = class_find_device(power_supply_class, NULL, name,
- power_supply_match_device_by_name);
+ struct device *dev = class_find_device(&power_supply_class, NULL, name,
+ power_supply_match_device_by_name);
if (dev) {
psy = dev_get_drvdata(dev);
@@ -509,8 +512,8 @@ struct power_supply *power_supply_get_by_phandle(struct device_node *np,
if (!power_supply_np)
return ERR_PTR(-ENODEV);
- dev = class_find_device(power_supply_class, NULL, power_supply_np,
- power_supply_match_device_node);
+ dev = class_find_device(&power_supply_class, NULL, power_supply_np,
+ power_supply_match_device_node);
of_node_put(power_supply_np);
@@ -1362,7 +1365,7 @@ __power_supply_register(struct device *parent,
device_initialize(dev);
- dev->class = power_supply_class;
+ dev->class = &power_supply_class;
dev->type = &power_supply_dev_type;
dev->parent = parent;
dev->release = power_supply_dev_release;
@@ -1609,12 +1612,12 @@ EXPORT_SYMBOL_GPL(power_supply_get_drvdata);
static int __init power_supply_class_init(void)
{
- power_supply_class = class_create("power_supply");
+ int err;
- if (IS_ERR(power_supply_class))
- return PTR_ERR(power_supply_class);
+ err = class_register(&power_supply_class);
+ if (err)
+ return err;
- power_supply_class->dev_uevent = power_supply_uevent;
power_supply_init_attrs(&power_supply_dev_type);
return 0;
@@ -1622,7 +1625,7 @@ static int __init power_supply_class_init(void)
static void __exit power_supply_class_exit(void)
{
- class_destroy(power_supply_class);
+ class_unregister(&power_supply_class);
}
subsys_initcall(power_supply_class_init);
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index aa20bf8c3366d..87cd0fefc1dc2 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -896,7 +896,7 @@ extern int power_supply_powers(struct power_supply *psy, struct device *dev);
extern void *power_supply_get_drvdata(struct power_supply *psy);
/* For APM emulation, think legacy userspace. */
-extern struct class *power_supply_class;
+extern const struct class power_supply_class;
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 ` Sasha Levin [this message]
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 ` [PATCH 6.6.y 4/7] power: supply: core: introduce power_supply_for_each_psy() Sasha Levin
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-2-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linus.walleij@linaro.org \
--cc=ricardo@marliere.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