Commit b6e3c115 authored by Ricardo B. Marliere's avatar Ricardo B. Marliere Committed by Jakub Kicinski

net: hns: make hnae_class constant

Since commit 43a7206b ("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 hnae_class structure to be declared at build time
placing it into read-only memory, instead of having to be dynamically
allocated at boot time.
Suggested-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarRicardo B. Marliere <ricardo@marliere.net>
Reviewed-by: default avatarSimon Horman <horms@kernel.org>
Link: https://lore.kernel.org/r/20240302-class_cleanup-net-next-v1-1-8fa378595b93@marliere.netSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent e8efd372
...@@ -12,7 +12,9 @@ ...@@ -12,7 +12,9 @@
#define cls_to_ae_dev(dev) container_of(dev, struct hnae_ae_dev, cls_dev) #define cls_to_ae_dev(dev) container_of(dev, struct hnae_ae_dev, cls_dev)
static struct class *hnae_class; static const struct class hnae_class = {
.name = "hnae",
};
static void static void
hnae_list_add(spinlock_t *lock, struct list_head *node, struct list_head *head) hnae_list_add(spinlock_t *lock, struct list_head *node, struct list_head *head)
...@@ -111,7 +113,7 @@ static struct hnae_ae_dev *find_ae(const struct fwnode_handle *fwnode) ...@@ -111,7 +113,7 @@ static struct hnae_ae_dev *find_ae(const struct fwnode_handle *fwnode)
WARN_ON(!fwnode); WARN_ON(!fwnode);
dev = class_find_device(hnae_class, NULL, fwnode, __ae_match); dev = class_find_device(&hnae_class, NULL, fwnode, __ae_match);
return dev ? cls_to_ae_dev(dev) : NULL; return dev ? cls_to_ae_dev(dev) : NULL;
} }
...@@ -415,7 +417,7 @@ int hnae_ae_register(struct hnae_ae_dev *hdev, struct module *owner) ...@@ -415,7 +417,7 @@ int hnae_ae_register(struct hnae_ae_dev *hdev, struct module *owner)
hdev->owner = owner; hdev->owner = owner;
hdev->id = (int)atomic_inc_return(&id); hdev->id = (int)atomic_inc_return(&id);
hdev->cls_dev.parent = hdev->dev; hdev->cls_dev.parent = hdev->dev;
hdev->cls_dev.class = hnae_class; hdev->cls_dev.class = &hnae_class;
hdev->cls_dev.release = hnae_release; hdev->cls_dev.release = hnae_release;
(void)dev_set_name(&hdev->cls_dev, "hnae%d", hdev->id); (void)dev_set_name(&hdev->cls_dev, "hnae%d", hdev->id);
ret = device_register(&hdev->cls_dev); ret = device_register(&hdev->cls_dev);
...@@ -448,13 +450,12 @@ EXPORT_SYMBOL(hnae_ae_unregister); ...@@ -448,13 +450,12 @@ EXPORT_SYMBOL(hnae_ae_unregister);
static int __init hnae_init(void) static int __init hnae_init(void)
{ {
hnae_class = class_create("hnae"); return class_register(&hnae_class);
return PTR_ERR_OR_ZERO(hnae_class);
} }
static void __exit hnae_exit(void) static void __exit hnae_exit(void)
{ {
class_destroy(hnae_class); class_unregister(&hnae_class);
} }
subsys_initcall(hnae_init); subsys_initcall(hnae_init);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment