[PATCH] devfreq: change devfreq_class to a const struct

Jori Koolstra posted 1 patch 1 month, 1 week ago
drivers/devfreq/devfreq.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
[PATCH] devfreq: change devfreq_class to a const struct
Posted by Jori Koolstra 1 month, 1 week ago
The class_create() call has been deprecated in favor of class_register()
as the driver core now allows for a struct class to be in read-only
memory. Change devfreq_class to be a const struct class and drop the
class_create() call. This is compile tested only.

Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Jori Koolstra <jkoolstra@xs4all.nl>
---
 drivers/devfreq/devfreq.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index c0a74091b904..f2298f8e3224 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -36,7 +36,13 @@
 #define IS_SUPPORTED_FLAG(f, name) ((f & DEVFREQ_GOV_FLAG_##name) ? true : false)
 #define IS_SUPPORTED_ATTR(f, name) ((f & DEVFREQ_GOV_ATTR_##name) ? true : false)
 
-static struct class *devfreq_class;
+static struct attribute *devfreq_attrs[];
+ATTRIBUTE_GROUPS(devfreq);
+
+static const struct class devfreq_class = {
+	.name		= "devfreq",
+	.dev_groups	= devfreq_groups
+};
 static struct dentry *devfreq_debugfs;
 
 /*
@@ -830,7 +836,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
 	mutex_init(&devfreq->lock);
 	mutex_lock(&devfreq->lock);
 	devfreq->dev.parent = dev;
-	devfreq->dev.class = devfreq_class;
+	devfreq->dev.class = &devfreq_class;
 	devfreq->dev.groups = profile->dev_groups;
 	devfreq->dev.release = devfreq_dev_release;
 	INIT_LIST_HEAD(&devfreq->node);
@@ -1807,7 +1813,6 @@ static struct attribute *devfreq_attrs[] = {
 	&dev_attr_trans_stat.attr,
 	NULL,
 };
-ATTRIBUTE_GROUPS(devfreq);
 
 static ssize_t polling_interval_show(struct device *dev,
 				     struct device_attribute *attr, char *buf)
@@ -2019,19 +2024,20 @@ DEFINE_SHOW_ATTRIBUTE(devfreq_summary);
 
 static int __init devfreq_init(void)
 {
-	devfreq_class = class_create("devfreq");
-	if (IS_ERR(devfreq_class)) {
+	int err;
+
+	err = class_register(&devfreq_class);
+	if (err) {
 		pr_err("%s: couldn't create class\n", __FILE__);
-		return PTR_ERR(devfreq_class);
+		return err;
 	}
 
 	devfreq_wq = create_freezable_workqueue("devfreq_wq");
 	if (!devfreq_wq) {
-		class_destroy(devfreq_class);
+		class_unregister(&devfreq_class);
 		pr_err("%s: couldn't create workqueue\n", __FILE__);
 		return -ENOMEM;
 	}
-	devfreq_class->dev_groups = devfreq_groups;
 
 	devfreq_debugfs = debugfs_create_dir("devfreq", NULL);
 	debugfs_create_file("devfreq_summary", 0444,

base-commit: d466c332e106fe666d1e2f5a24d08e308bebbfa1
-- 
2.53.0