Skip to content

Commit db704bf

Browse files
rbmarlierevinodkoul
authored andcommitted
phy: core: make phy_class constant
Since commit 43a7206 ("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 <[email protected]> Suggested-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: "Ricardo B. Marliere" <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 5cee04a commit db704bf

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

drivers/phy/phy-core.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020
#include <linux/pm_runtime.h>
2121
#include <linux/regulator/consumer.h>
2222

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+
2429
static struct dentry *phy_debugfs_root;
2530
static DEFINE_MUTEX(phy_provider_mutex);
2631
static LIST_HEAD(phy_provider_list);
@@ -753,7 +758,7 @@ struct phy *of_phy_simple_xlate(struct device *dev,
753758
struct phy *phy;
754759
struct class_dev_iter iter;
755760

756-
class_dev_iter_init(&iter, phy_class, NULL, NULL);
761+
class_dev_iter_init(&iter, &phy_class, NULL, NULL);
757762
while ((dev = class_dev_iter_next(&iter))) {
758763
phy = to_phy(dev);
759764
if (args->np != phy->dev.of_node)
@@ -1016,7 +1021,7 @@ struct phy *phy_create(struct device *dev, struct device_node *node,
10161021
device_initialize(&phy->dev);
10171022
mutex_init(&phy->mutex);
10181023

1019-
phy->dev.class = phy_class;
1024+
phy->dev.class = &phy_class;
10201025
phy->dev.parent = dev;
10211026
phy->dev.of_node = node ?: dev->of_node;
10221027
phy->id = id;
@@ -1285,14 +1290,13 @@ static void phy_release(struct device *dev)
12851290

12861291
static int __init phy_core_init(void)
12871292
{
1288-
phy_class = class_create("phy");
1289-
if (IS_ERR(phy_class)) {
1290-
pr_err("failed to create phy class --> %ld\n",
1291-
PTR_ERR(phy_class));
1292-
return PTR_ERR(phy_class);
1293-
}
1293+
int err;
12941294

1295-
phy_class->dev_release = phy_release;
1295+
err = class_register(&phy_class);
1296+
if (err) {
1297+
pr_err("failed to register phy class");
1298+
return err;
1299+
}
12961300

12971301
phy_debugfs_root = debugfs_create_dir("phy", NULL);
12981302

@@ -1303,6 +1307,6 @@ device_initcall(phy_core_init);
13031307
static void __exit phy_core_exit(void)
13041308
{
13051309
debugfs_remove_recursive(phy_debugfs_root);
1306-
class_destroy(phy_class);
1310+
class_unregister(&phy_class);
13071311
}
13081312
module_exit(phy_core_exit);

0 commit comments

Comments
 (0)