[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240220-device_cleanup-power-v1-1-e2b9e0cea072@marliere.net>
Date: Tue, 20 Feb 2024 15:40:06 -0300
From: "Ricardo B. Marliere" <ricardo@...liere.net>
To: Sebastian Reichel <sre@...nel.org>
Cc: linux-pm@...r.kernel.org, linux-kernel@...r.kernel.org,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"Ricardo B. Marliere" <ricardo@...liere.net>
Subject: [PATCH] power: supply: sysfs: constify the struct device_type
usage
Since commit aed65af1cc2f ("drivers: make device_type const"), the driver
core can properly handle constant struct device_type. Move the
power_supply_dev_type variable to be a constant structure as well, placing
it into read-only memory which can not be modified at runtime.
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Signed-off-by: Ricardo B. Marliere <ricardo@...liere.net>
---
drivers/power/supply/power_supply.h | 4 ++--
drivers/power/supply/power_supply_core.c | 2 +-
drivers/power/supply/power_supply_sysfs.c | 9 ++++++---
3 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/drivers/power/supply/power_supply.h b/drivers/power/supply/power_supply.h
index 645eee4d6b6a..d547dbe5676f 100644
--- a/drivers/power/supply/power_supply.h
+++ b/drivers/power/supply/power_supply.h
@@ -15,12 +15,12 @@ struct power_supply;
#ifdef CONFIG_SYSFS
-extern void power_supply_init_attrs(struct device_type *dev_type);
+extern void power_supply_init_attrs(const struct device_type *dev_type);
extern int power_supply_uevent(const struct device *dev, struct kobj_uevent_env *env);
#else
-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
+static inline void power_supply_init_attrs(const struct device_type *dev_type) {}
#define power_supply_uevent NULL
#endif /* CONFIG_SYSFS */
diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index ecef35ac3b7e..fda21cf4111c 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -31,7 +31,7 @@ EXPORT_SYMBOL_GPL(power_supply_class);
static BLOCKING_NOTIFIER_HEAD(power_supply_notifier);
-static struct device_type power_supply_dev_type;
+static const struct device_type power_supply_dev_type;
#define POWER_SUPPLY_DEFERRED_REGISTER_TIME msecs_to_jiffies(10)
diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c
index 977611e16373..ed365ca54c90 100644
--- a/drivers/power/supply/power_supply_sysfs.c
+++ b/drivers/power/supply/power_supply_sysfs.c
@@ -399,12 +399,15 @@ static const struct attribute_group *power_supply_attr_groups[] = {
NULL,
};
-void power_supply_init_attrs(struct device_type *dev_type)
+static const struct device_type power_supply_dev_type = {
+ .name = "power_supply",
+ .groups = power_supply_attr_groups,
+};
+
+void power_supply_init_attrs(const struct device_type *dev_type)
{
int i;
- dev_type->groups = power_supply_attr_groups;
-
for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++) {
struct device_attribute *attr;
---
base-commit: a9b254892ce1a447b06c5019cbf0e9caeb48c138
change-id: 20240220-device_cleanup-power-037594022cb1
Best regards,
--
Ricardo B. Marliere <ricardo@...liere.net>
Powered by blists - more mailing lists