Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

phy: core: make phy_class constant

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 phy_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>
Link: https://lore.kernel.org/r/20240305-class_cleanup-phy-v1-1-106013a644dc@marliere.net
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Ricardo B. Marliere and committed by
Vinod Koul
db704bf6 5cee04a8

+15 -11
+15 -11
drivers/phy/phy-core.c
··· 20 20 #include <linux/pm_runtime.h> 21 21 #include <linux/regulator/consumer.h> 22 22 23 - static struct class *phy_class; 23 + static void phy_release(struct device *dev); 24 + static const struct class phy_class = { 25 + .name = "phy", 26 + .dev_release = phy_release, 27 + }; 28 + 24 29 static struct dentry *phy_debugfs_root; 25 30 static DEFINE_MUTEX(phy_provider_mutex); 26 31 static LIST_HEAD(phy_provider_list); ··· 758 753 struct phy *phy; 759 754 struct class_dev_iter iter; 760 755 761 - class_dev_iter_init(&iter, phy_class, NULL, NULL); 756 + class_dev_iter_init(&iter, &phy_class, NULL, NULL); 762 757 while ((dev = class_dev_iter_next(&iter))) { 763 758 phy = to_phy(dev); 764 759 if (args->np != phy->dev.of_node) ··· 1021 1016 device_initialize(&phy->dev); 1022 1017 mutex_init(&phy->mutex); 1023 1018 1024 - phy->dev.class = phy_class; 1019 + phy->dev.class = &phy_class; 1025 1020 phy->dev.parent = dev; 1026 1021 phy->dev.of_node = node ?: dev->of_node; 1027 1022 phy->id = id; ··· 1290 1285 1291 1286 static int __init phy_core_init(void) 1292 1287 { 1293 - phy_class = class_create("phy"); 1294 - if (IS_ERR(phy_class)) { 1295 - pr_err("failed to create phy class --> %ld\n", 1296 - PTR_ERR(phy_class)); 1297 - return PTR_ERR(phy_class); 1298 - } 1288 + int err; 1299 1289 1300 - phy_class->dev_release = phy_release; 1290 + err = class_register(&phy_class); 1291 + if (err) { 1292 + pr_err("failed to register phy class"); 1293 + return err; 1294 + } 1301 1295 1302 1296 phy_debugfs_root = debugfs_create_dir("phy", NULL); 1303 1297 ··· 1307 1303 static void __exit phy_core_exit(void) 1308 1304 { 1309 1305 debugfs_remove_recursive(phy_debugfs_root); 1310 - class_destroy(phy_class); 1306 + class_unregister(&phy_class); 1311 1307 } 1312 1308 module_exit(phy_core_exit);