Commit 73a42f41 authored by Jakub Kicinski's avatar Jakub Kicinski

Merge branch 'net-constify-struct-class-usage'

Ricardo B. Marliere says:

====================
net: constify struct class usage

This is a simple and straight forward cleanup series that aims to make the
class structures in net constant. This has been possible since 2023 [1].

[1]: https://lore.kernel.org/all/2023040248-customary-release-4aec@gregkh/
====================

Link: https://lore.kernel.org/r/20240302-class_cleanup-net-next-v1-0-8fa378595b93@marliere.netSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents e8efd372 e5560011
...@@ -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);
......
...@@ -295,7 +295,9 @@ static void ppp_setup(struct net_device *dev); ...@@ -295,7 +295,9 @@ static void ppp_setup(struct net_device *dev);
static const struct net_device_ops ppp_netdev_ops; static const struct net_device_ops ppp_netdev_ops;
static struct class *ppp_class; static const struct class ppp_class = {
.name = "ppp",
};
/* per net-namespace data */ /* per net-namespace data */
static inline struct ppp_net *ppp_pernet(struct net *net) static inline struct ppp_net *ppp_pernet(struct net *net)
...@@ -1394,11 +1396,9 @@ static int __init ppp_init(void) ...@@ -1394,11 +1396,9 @@ static int __init ppp_init(void)
goto out_net; goto out_net;
} }
ppp_class = class_create("ppp"); err = class_register(&ppp_class);
if (IS_ERR(ppp_class)) { if (err)
err = PTR_ERR(ppp_class);
goto out_chrdev; goto out_chrdev;
}
err = rtnl_link_register(&ppp_link_ops); err = rtnl_link_register(&ppp_link_ops);
if (err) { if (err) {
...@@ -1407,12 +1407,12 @@ static int __init ppp_init(void) ...@@ -1407,12 +1407,12 @@ static int __init ppp_init(void)
} }
/* not a big deal if we fail here :-) */ /* not a big deal if we fail here :-) */
device_create(ppp_class, NULL, MKDEV(PPP_MAJOR, 0), NULL, "ppp"); device_create(&ppp_class, NULL, MKDEV(PPP_MAJOR, 0), NULL, "ppp");
return 0; return 0;
out_class: out_class:
class_destroy(ppp_class); class_unregister(&ppp_class);
out_chrdev: out_chrdev:
unregister_chrdev(PPP_MAJOR, "ppp"); unregister_chrdev(PPP_MAJOR, "ppp");
out_net: out_net:
...@@ -3549,8 +3549,8 @@ static void __exit ppp_cleanup(void) ...@@ -3549,8 +3549,8 @@ static void __exit ppp_cleanup(void)
pr_err("PPP: removing module but units remain!\n"); pr_err("PPP: removing module but units remain!\n");
rtnl_link_unregister(&ppp_link_ops); rtnl_link_unregister(&ppp_link_ops);
unregister_chrdev(PPP_MAJOR, "ppp"); unregister_chrdev(PPP_MAJOR, "ppp");
device_destroy(ppp_class, MKDEV(PPP_MAJOR, 0)); device_destroy(&ppp_class, MKDEV(PPP_MAJOR, 0));
class_destroy(ppp_class); class_unregister(&ppp_class);
unregister_pernet_device(&ppp_net_ops); unregister_pernet_device(&ppp_net_ops);
} }
......
...@@ -18,7 +18,12 @@ ...@@ -18,7 +18,12 @@
#include <linux/regulator/consumer.h> #include <linux/regulator/consumer.h>
#include <linux/slab.h> #include <linux/slab.h>
static struct class *framer_class; static void framer_release(struct device *dev);
static const struct class framer_class = {
.name = "framer",
.dev_release = framer_release,
};
static DEFINE_MUTEX(framer_provider_mutex); static DEFINE_MUTEX(framer_provider_mutex);
static LIST_HEAD(framer_provider_list); static LIST_HEAD(framer_provider_list);
static DEFINE_IDA(framer_ida); static DEFINE_IDA(framer_ida);
...@@ -627,7 +632,7 @@ struct framer *framer_create(struct device *dev, struct device_node *node, ...@@ -627,7 +632,7 @@ struct framer *framer_create(struct device *dev, struct device_node *node,
INIT_DELAYED_WORK(&framer->polling_work, framer_polling_work); INIT_DELAYED_WORK(&framer->polling_work, framer_polling_work);
BLOCKING_INIT_NOTIFIER_HEAD(&framer->notifier_list); BLOCKING_INIT_NOTIFIER_HEAD(&framer->notifier_list);
framer->dev.class = framer_class; framer->dev.class = &framer_class;
framer->dev.parent = dev; framer->dev.parent = dev;
framer->dev.of_node = node ? node : dev->of_node; framer->dev.of_node = node ? node : dev->of_node;
framer->id = id; framer->id = id;
...@@ -741,7 +746,7 @@ struct framer *framer_provider_simple_of_xlate(struct device *dev, ...@@ -741,7 +746,7 @@ struct framer *framer_provider_simple_of_xlate(struct device *dev,
struct class_dev_iter iter; struct class_dev_iter iter;
struct framer *framer; struct framer *framer;
class_dev_iter_init(&iter, framer_class, NULL, NULL); class_dev_iter_init(&iter, &framer_class, NULL, NULL);
while ((dev = class_dev_iter_next(&iter))) { while ((dev = class_dev_iter_next(&iter))) {
framer = dev_to_framer(dev); framer = dev_to_framer(dev);
if (args->np != framer->dev.of_node) if (args->np != framer->dev.of_node)
...@@ -870,14 +875,6 @@ static void framer_release(struct device *dev) ...@@ -870,14 +875,6 @@ static void framer_release(struct device *dev)
static int __init framer_core_init(void) static int __init framer_core_init(void)
{ {
framer_class = class_create("framer"); return class_register(&framer_class);
if (IS_ERR(framer_class)) {
pr_err("failed to create framer class (%pe)\n", framer_class);
return PTR_ERR(framer_class);
}
framer_class->dev_release = framer_release;
return 0;
} }
device_initcall(framer_core_init); device_initcall(framer_core_init);
...@@ -26,7 +26,9 @@ ...@@ -26,7 +26,9 @@
static DEFINE_MUTEX(wwan_register_lock); /* WWAN device create|remove lock */ static DEFINE_MUTEX(wwan_register_lock); /* WWAN device create|remove lock */
static DEFINE_IDA(minors); /* minors for WWAN port chardevs */ static DEFINE_IDA(minors); /* minors for WWAN port chardevs */
static DEFINE_IDA(wwan_dev_ids); /* for unique WWAN device IDs */ static DEFINE_IDA(wwan_dev_ids); /* for unique WWAN device IDs */
static struct class *wwan_class; static const struct class wwan_class = {
.name = "wwan",
};
static int wwan_major; static int wwan_major;
static struct dentry *wwan_debugfs_dir; static struct dentry *wwan_debugfs_dir;
...@@ -130,7 +132,7 @@ static struct wwan_device *wwan_dev_get_by_parent(struct device *parent) ...@@ -130,7 +132,7 @@ static struct wwan_device *wwan_dev_get_by_parent(struct device *parent)
{ {
struct device *dev; struct device *dev;
dev = class_find_device(wwan_class, NULL, parent, wwan_dev_parent_match); dev = class_find_device(&wwan_class, NULL, parent, wwan_dev_parent_match);
if (!dev) if (!dev)
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
...@@ -147,7 +149,7 @@ static struct wwan_device *wwan_dev_get_by_name(const char *name) ...@@ -147,7 +149,7 @@ static struct wwan_device *wwan_dev_get_by_name(const char *name)
{ {
struct device *dev; struct device *dev;
dev = class_find_device(wwan_class, NULL, name, wwan_dev_name_match); dev = class_find_device(&wwan_class, NULL, name, wwan_dev_name_match);
if (!dev) if (!dev)
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
...@@ -183,7 +185,7 @@ static struct wwan_device *wwan_dev_get_by_debugfs(struct dentry *dir) ...@@ -183,7 +185,7 @@ static struct wwan_device *wwan_dev_get_by_debugfs(struct dentry *dir)
{ {
struct device *dev; struct device *dev;
dev = class_find_device(wwan_class, NULL, dir, wwan_dev_debugfs_match); dev = class_find_device(&wwan_class, NULL, dir, wwan_dev_debugfs_match);
if (!dev) if (!dev)
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
...@@ -239,7 +241,7 @@ static struct wwan_device *wwan_create_dev(struct device *parent) ...@@ -239,7 +241,7 @@ static struct wwan_device *wwan_create_dev(struct device *parent)
} }
wwandev->dev.parent = parent; wwandev->dev.parent = parent;
wwandev->dev.class = wwan_class; wwandev->dev.class = &wwan_class;
wwandev->dev.type = &wwan_dev_type; wwandev->dev.type = &wwan_dev_type;
wwandev->id = id; wwandev->id = id;
dev_set_name(&wwandev->dev, "wwan%d", wwandev->id); dev_set_name(&wwandev->dev, "wwan%d", wwandev->id);
...@@ -265,7 +267,7 @@ static struct wwan_device *wwan_create_dev(struct device *parent) ...@@ -265,7 +267,7 @@ static struct wwan_device *wwan_create_dev(struct device *parent)
static int is_wwan_child(struct device *dev, void *data) static int is_wwan_child(struct device *dev, void *data)
{ {
return dev->class == wwan_class; return dev->class == &wwan_class;
} }
static void wwan_remove_dev(struct wwan_device *wwandev) static void wwan_remove_dev(struct wwan_device *wwandev)
...@@ -375,7 +377,7 @@ static struct wwan_port *wwan_port_get_by_minor(unsigned int minor) ...@@ -375,7 +377,7 @@ static struct wwan_port *wwan_port_get_by_minor(unsigned int minor)
{ {
struct device *dev; struct device *dev;
dev = class_find_device(wwan_class, NULL, &minor, wwan_port_minor_match); dev = class_find_device(&wwan_class, NULL, &minor, wwan_port_minor_match);
if (!dev) if (!dev)
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
...@@ -405,7 +407,7 @@ static int __wwan_port_dev_assign_name(struct wwan_port *port, const char *fmt) ...@@ -405,7 +407,7 @@ static int __wwan_port_dev_assign_name(struct wwan_port *port, const char *fmt)
return -ENOMEM; return -ENOMEM;
/* Collect ids of same name format ports */ /* Collect ids of same name format ports */
class_dev_iter_init(&iter, wwan_class, NULL, &wwan_port_dev_type); class_dev_iter_init(&iter, &wwan_class, NULL, &wwan_port_dev_type);
while ((dev = class_dev_iter_next(&iter))) { while ((dev = class_dev_iter_next(&iter))) {
if (dev->parent != &wwandev->dev) if (dev->parent != &wwandev->dev)
continue; continue;
...@@ -477,7 +479,7 @@ struct wwan_port *wwan_create_port(struct device *parent, ...@@ -477,7 +479,7 @@ struct wwan_port *wwan_create_port(struct device *parent,
mutex_init(&port->data_lock); mutex_init(&port->data_lock);
port->dev.parent = &wwandev->dev; port->dev.parent = &wwandev->dev;
port->dev.class = wwan_class; port->dev.class = &wwan_class;
port->dev.type = &wwan_port_dev_type; port->dev.type = &wwan_port_dev_type;
port->dev.devt = MKDEV(wwan_major, minor); port->dev.devt = MKDEV(wwan_major, minor);
dev_set_drvdata(&port->dev, drvdata); dev_set_drvdata(&port->dev, drvdata);
...@@ -1212,11 +1214,9 @@ static int __init wwan_init(void) ...@@ -1212,11 +1214,9 @@ static int __init wwan_init(void)
if (err) if (err)
return err; return err;
wwan_class = class_create("wwan"); err = class_register(&wwan_class);
if (IS_ERR(wwan_class)) { if (err)
err = PTR_ERR(wwan_class);
goto unregister; goto unregister;
}
/* chrdev used for wwan ports */ /* chrdev used for wwan ports */
wwan_major = __register_chrdev(0, 0, WWAN_MAX_MINORS, "wwan_port", wwan_major = __register_chrdev(0, 0, WWAN_MAX_MINORS, "wwan_port",
...@@ -1233,7 +1233,7 @@ static int __init wwan_init(void) ...@@ -1233,7 +1233,7 @@ static int __init wwan_init(void)
return 0; return 0;
destroy: destroy:
class_destroy(wwan_class); class_unregister(&wwan_class);
unregister: unregister:
rtnl_link_unregister(&wwan_rtnl_link_ops); rtnl_link_unregister(&wwan_rtnl_link_ops);
return err; return err;
...@@ -1244,7 +1244,7 @@ static void __exit wwan_exit(void) ...@@ -1244,7 +1244,7 @@ static void __exit wwan_exit(void)
debugfs_remove_recursive(wwan_debugfs_dir); debugfs_remove_recursive(wwan_debugfs_dir);
__unregister_chrdev(wwan_major, 0, WWAN_MAX_MINORS, "wwan_port"); __unregister_chrdev(wwan_major, 0, WWAN_MAX_MINORS, "wwan_port");
rtnl_link_unregister(&wwan_rtnl_link_ops); rtnl_link_unregister(&wwan_rtnl_link_ops);
class_destroy(wwan_class); class_unregister(&wwan_class);
} }
module_init(wwan_init); module_init(wwan_init);
......
...@@ -25,7 +25,9 @@ static int wwan_hwsim_devsnum = 2; ...@@ -25,7 +25,9 @@ static int wwan_hwsim_devsnum = 2;
module_param_named(devices, wwan_hwsim_devsnum, int, 0444); module_param_named(devices, wwan_hwsim_devsnum, int, 0444);
MODULE_PARM_DESC(devices, "Number of simulated devices"); MODULE_PARM_DESC(devices, "Number of simulated devices");
static struct class *wwan_hwsim_class; static const struct class wwan_hwsim_class = {
.name = "wwan_hwsim",
};
static struct dentry *wwan_hwsim_debugfs_topdir; static struct dentry *wwan_hwsim_debugfs_topdir;
static struct dentry *wwan_hwsim_debugfs_devcreate; static struct dentry *wwan_hwsim_debugfs_devcreate;
...@@ -277,7 +279,7 @@ static struct wwan_hwsim_dev *wwan_hwsim_dev_new(void) ...@@ -277,7 +279,7 @@ static struct wwan_hwsim_dev *wwan_hwsim_dev_new(void)
spin_unlock(&wwan_hwsim_devs_lock); spin_unlock(&wwan_hwsim_devs_lock);
dev->dev.release = wwan_hwsim_dev_release; dev->dev.release = wwan_hwsim_dev_release;
dev->dev.class = wwan_hwsim_class; dev->dev.class = &wwan_hwsim_class;
dev_set_name(&dev->dev, "hwsim%u", dev->id); dev_set_name(&dev->dev, "hwsim%u", dev->id);
spin_lock_init(&dev->ports_lock); spin_lock_init(&dev->ports_lock);
...@@ -511,11 +513,9 @@ static int __init wwan_hwsim_init(void) ...@@ -511,11 +513,9 @@ static int __init wwan_hwsim_init(void)
if (!wwan_wq) if (!wwan_wq)
return -ENOMEM; return -ENOMEM;
wwan_hwsim_class = class_create("wwan_hwsim"); err = class_register(&wwan_hwsim_class);
if (IS_ERR(wwan_hwsim_class)) { if (err)
err = PTR_ERR(wwan_hwsim_class);
goto err_wq_destroy; goto err_wq_destroy;
}
wwan_hwsim_debugfs_topdir = debugfs_create_dir("wwan_hwsim", NULL); wwan_hwsim_debugfs_topdir = debugfs_create_dir("wwan_hwsim", NULL);
wwan_hwsim_debugfs_devcreate = wwan_hwsim_debugfs_devcreate =
...@@ -534,7 +534,7 @@ static int __init wwan_hwsim_init(void) ...@@ -534,7 +534,7 @@ static int __init wwan_hwsim_init(void)
wwan_hwsim_free_devs(); wwan_hwsim_free_devs();
flush_workqueue(wwan_wq); /* Wait deletion works completion */ flush_workqueue(wwan_wq); /* Wait deletion works completion */
debugfs_remove(wwan_hwsim_debugfs_topdir); debugfs_remove(wwan_hwsim_debugfs_topdir);
class_destroy(wwan_hwsim_class); class_unregister(&wwan_hwsim_class);
err_wq_destroy: err_wq_destroy:
destroy_workqueue(wwan_wq); destroy_workqueue(wwan_wq);
...@@ -547,7 +547,7 @@ static void __exit wwan_hwsim_exit(void) ...@@ -547,7 +547,7 @@ static void __exit wwan_hwsim_exit(void)
wwan_hwsim_free_devs(); wwan_hwsim_free_devs();
flush_workqueue(wwan_wq); /* Wait deletion works completion */ flush_workqueue(wwan_wq); /* Wait deletion works completion */
debugfs_remove(wwan_hwsim_debugfs_topdir); debugfs_remove(wwan_hwsim_debugfs_topdir);
class_destroy(wwan_hwsim_class); class_unregister(&wwan_hwsim_class);
destroy_workqueue(wwan_wq); destroy_workqueue(wwan_wq);
} }
......
...@@ -196,7 +196,7 @@ struct nfc_dev { ...@@ -196,7 +196,7 @@ struct nfc_dev {
}; };
#define to_nfc_dev(_dev) container_of(_dev, struct nfc_dev, dev) #define to_nfc_dev(_dev) container_of(_dev, struct nfc_dev, dev)
extern struct class nfc_class; extern const struct class nfc_class;
struct nfc_dev *nfc_allocate_device(const struct nfc_ops *ops, struct nfc_dev *nfc_allocate_device(const struct nfc_ops *ops,
u32 supported_protocols, u32 supported_protocols,
......
...@@ -1015,7 +1015,7 @@ static void nfc_check_pres_timeout(struct timer_list *t) ...@@ -1015,7 +1015,7 @@ static void nfc_check_pres_timeout(struct timer_list *t)
schedule_work(&dev->check_pres_work); schedule_work(&dev->check_pres_work);
} }
struct class nfc_class = { const struct class nfc_class = {
.name = "nfc", .name = "nfc",
.dev_release = nfc_release, .dev_release = nfc_release,
}; };
......
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