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.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
commit
73a42f4174
@ -12,7 +12,9 @@
|
||||
|
||||
#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
|
||||
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)
|
||||
|
||||
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;
|
||||
}
|
||||
@ -415,7 +417,7 @@ int hnae_ae_register(struct hnae_ae_dev *hdev, struct module *owner)
|
||||
hdev->owner = owner;
|
||||
hdev->id = (int)atomic_inc_return(&id);
|
||||
hdev->cls_dev.parent = hdev->dev;
|
||||
hdev->cls_dev.class = hnae_class;
|
||||
hdev->cls_dev.class = &hnae_class;
|
||||
hdev->cls_dev.release = hnae_release;
|
||||
(void)dev_set_name(&hdev->cls_dev, "hnae%d", hdev->id);
|
||||
ret = device_register(&hdev->cls_dev);
|
||||
@ -448,13 +450,12 @@ EXPORT_SYMBOL(hnae_ae_unregister);
|
||||
|
||||
static int __init hnae_init(void)
|
||||
{
|
||||
hnae_class = class_create("hnae");
|
||||
return PTR_ERR_OR_ZERO(hnae_class);
|
||||
return class_register(&hnae_class);
|
||||
}
|
||||
|
||||
static void __exit hnae_exit(void)
|
||||
{
|
||||
class_destroy(hnae_class);
|
||||
class_unregister(&hnae_class);
|
||||
}
|
||||
|
||||
subsys_initcall(hnae_init);
|
||||
|
@ -295,7 +295,9 @@ static void ppp_setup(struct net_device *dev);
|
||||
|
||||
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 */
|
||||
static inline struct ppp_net *ppp_pernet(struct net *net)
|
||||
@ -1394,11 +1396,9 @@ static int __init ppp_init(void)
|
||||
goto out_net;
|
||||
}
|
||||
|
||||
ppp_class = class_create("ppp");
|
||||
if (IS_ERR(ppp_class)) {
|
||||
err = PTR_ERR(ppp_class);
|
||||
err = class_register(&ppp_class);
|
||||
if (err)
|
||||
goto out_chrdev;
|
||||
}
|
||||
|
||||
err = rtnl_link_register(&ppp_link_ops);
|
||||
if (err) {
|
||||
@ -1407,12 +1407,12 @@ static int __init ppp_init(void)
|
||||
}
|
||||
|
||||
/* 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;
|
||||
|
||||
out_class:
|
||||
class_destroy(ppp_class);
|
||||
class_unregister(&ppp_class);
|
||||
out_chrdev:
|
||||
unregister_chrdev(PPP_MAJOR, "ppp");
|
||||
out_net:
|
||||
@ -3549,8 +3549,8 @@ static void __exit ppp_cleanup(void)
|
||||
pr_err("PPP: removing module but units remain!\n");
|
||||
rtnl_link_unregister(&ppp_link_ops);
|
||||
unregister_chrdev(PPP_MAJOR, "ppp");
|
||||
device_destroy(ppp_class, MKDEV(PPP_MAJOR, 0));
|
||||
class_destroy(ppp_class);
|
||||
device_destroy(&ppp_class, MKDEV(PPP_MAJOR, 0));
|
||||
class_unregister(&ppp_class);
|
||||
unregister_pernet_device(&ppp_net_ops);
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,12 @@
|
||||
#include <linux/regulator/consumer.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 LIST_HEAD(framer_provider_list);
|
||||
static DEFINE_IDA(framer_ida);
|
||||
@ -627,7 +632,7 @@ struct framer *framer_create(struct device *dev, struct device_node *node,
|
||||
INIT_DELAYED_WORK(&framer->polling_work, framer_polling_work);
|
||||
BLOCKING_INIT_NOTIFIER_HEAD(&framer->notifier_list);
|
||||
|
||||
framer->dev.class = framer_class;
|
||||
framer->dev.class = &framer_class;
|
||||
framer->dev.parent = dev;
|
||||
framer->dev.of_node = node ? node : dev->of_node;
|
||||
framer->id = id;
|
||||
@ -741,7 +746,7 @@ struct framer *framer_provider_simple_of_xlate(struct device *dev,
|
||||
struct class_dev_iter iter;
|
||||
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))) {
|
||||
framer = dev_to_framer(dev);
|
||||
if (args->np != framer->dev.of_node)
|
||||
@ -870,14 +875,6 @@ static void framer_release(struct device *dev)
|
||||
|
||||
static int __init framer_core_init(void)
|
||||
{
|
||||
framer_class = class_create("framer");
|
||||
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;
|
||||
return class_register(&framer_class);
|
||||
}
|
||||
device_initcall(framer_core_init);
|
||||
|
@ -26,7 +26,9 @@
|
||||
static DEFINE_MUTEX(wwan_register_lock); /* WWAN device create|remove lock */
|
||||
static DEFINE_IDA(minors); /* minors for WWAN port chardevs */
|
||||
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 struct dentry *wwan_debugfs_dir;
|
||||
|
||||
@ -130,7 +132,7 @@ static struct wwan_device *wwan_dev_get_by_parent(struct device *parent)
|
||||
{
|
||||
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)
|
||||
return ERR_PTR(-ENODEV);
|
||||
|
||||
@ -147,7 +149,7 @@ static struct wwan_device *wwan_dev_get_by_name(const char *name)
|
||||
{
|
||||
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)
|
||||
return ERR_PTR(-ENODEV);
|
||||
|
||||
@ -183,7 +185,7 @@ static struct wwan_device *wwan_dev_get_by_debugfs(struct dentry *dir)
|
||||
{
|
||||
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)
|
||||
return ERR_PTR(-ENODEV);
|
||||
|
||||
@ -239,7 +241,7 @@ static struct wwan_device *wwan_create_dev(struct device *parent)
|
||||
}
|
||||
|
||||
wwandev->dev.parent = parent;
|
||||
wwandev->dev.class = wwan_class;
|
||||
wwandev->dev.class = &wwan_class;
|
||||
wwandev->dev.type = &wwan_dev_type;
|
||||
wwandev->id = id;
|
||||
dev_set_name(&wwandev->dev, "wwan%d", wwandev->id);
|
||||
@ -265,7 +267,7 @@ done_unlock:
|
||||
|
||||
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)
|
||||
@ -375,7 +377,7 @@ static struct wwan_port *wwan_port_get_by_minor(unsigned int minor)
|
||||
{
|
||||
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)
|
||||
return ERR_PTR(-ENODEV);
|
||||
|
||||
@ -405,7 +407,7 @@ static int __wwan_port_dev_assign_name(struct wwan_port *port, const char *fmt)
|
||||
return -ENOMEM;
|
||||
|
||||
/* 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))) {
|
||||
if (dev->parent != &wwandev->dev)
|
||||
continue;
|
||||
@ -477,7 +479,7 @@ struct wwan_port *wwan_create_port(struct device *parent,
|
||||
mutex_init(&port->data_lock);
|
||||
|
||||
port->dev.parent = &wwandev->dev;
|
||||
port->dev.class = wwan_class;
|
||||
port->dev.class = &wwan_class;
|
||||
port->dev.type = &wwan_port_dev_type;
|
||||
port->dev.devt = MKDEV(wwan_major, minor);
|
||||
dev_set_drvdata(&port->dev, drvdata);
|
||||
@ -1212,11 +1214,9 @@ static int __init wwan_init(void)
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
wwan_class = class_create("wwan");
|
||||
if (IS_ERR(wwan_class)) {
|
||||
err = PTR_ERR(wwan_class);
|
||||
err = class_register(&wwan_class);
|
||||
if (err)
|
||||
goto unregister;
|
||||
}
|
||||
|
||||
/* chrdev used for wwan ports */
|
||||
wwan_major = __register_chrdev(0, 0, WWAN_MAX_MINORS, "wwan_port",
|
||||
@ -1233,7 +1233,7 @@ static int __init wwan_init(void)
|
||||
return 0;
|
||||
|
||||
destroy:
|
||||
class_destroy(wwan_class);
|
||||
class_unregister(&wwan_class);
|
||||
unregister:
|
||||
rtnl_link_unregister(&wwan_rtnl_link_ops);
|
||||
return err;
|
||||
@ -1244,7 +1244,7 @@ static void __exit wwan_exit(void)
|
||||
debugfs_remove_recursive(wwan_debugfs_dir);
|
||||
__unregister_chrdev(wwan_major, 0, WWAN_MAX_MINORS, "wwan_port");
|
||||
rtnl_link_unregister(&wwan_rtnl_link_ops);
|
||||
class_destroy(wwan_class);
|
||||
class_unregister(&wwan_class);
|
||||
}
|
||||
|
||||
module_init(wwan_init);
|
||||
|
@ -25,7 +25,9 @@ static int wwan_hwsim_devsnum = 2;
|
||||
module_param_named(devices, wwan_hwsim_devsnum, int, 0444);
|
||||
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_devcreate;
|
||||
@ -277,7 +279,7 @@ static struct wwan_hwsim_dev *wwan_hwsim_dev_new(void)
|
||||
spin_unlock(&wwan_hwsim_devs_lock);
|
||||
|
||||
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);
|
||||
|
||||
spin_lock_init(&dev->ports_lock);
|
||||
@ -511,11 +513,9 @@ static int __init wwan_hwsim_init(void)
|
||||
if (!wwan_wq)
|
||||
return -ENOMEM;
|
||||
|
||||
wwan_hwsim_class = class_create("wwan_hwsim");
|
||||
if (IS_ERR(wwan_hwsim_class)) {
|
||||
err = PTR_ERR(wwan_hwsim_class);
|
||||
err = class_register(&wwan_hwsim_class);
|
||||
if (err)
|
||||
goto err_wq_destroy;
|
||||
}
|
||||
|
||||
wwan_hwsim_debugfs_topdir = debugfs_create_dir("wwan_hwsim", NULL);
|
||||
wwan_hwsim_debugfs_devcreate =
|
||||
@ -534,7 +534,7 @@ err_clean_devs:
|
||||
wwan_hwsim_free_devs();
|
||||
flush_workqueue(wwan_wq); /* Wait deletion works completion */
|
||||
debugfs_remove(wwan_hwsim_debugfs_topdir);
|
||||
class_destroy(wwan_hwsim_class);
|
||||
class_unregister(&wwan_hwsim_class);
|
||||
err_wq_destroy:
|
||||
destroy_workqueue(wwan_wq);
|
||||
|
||||
@ -547,7 +547,7 @@ static void __exit wwan_hwsim_exit(void)
|
||||
wwan_hwsim_free_devs();
|
||||
flush_workqueue(wwan_wq); /* Wait deletion works completion */
|
||||
debugfs_remove(wwan_hwsim_debugfs_topdir);
|
||||
class_destroy(wwan_hwsim_class);
|
||||
class_unregister(&wwan_hwsim_class);
|
||||
destroy_workqueue(wwan_wq);
|
||||
}
|
||||
|
||||
|
@ -196,7 +196,7 @@ struct nfc_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,
|
||||
u32 supported_protocols,
|
||||
|
@ -1015,7 +1015,7 @@ static void nfc_check_pres_timeout(struct timer_list *t)
|
||||
schedule_work(&dev->check_pres_work);
|
||||
}
|
||||
|
||||
struct class nfc_class = {
|
||||
const struct class nfc_class = {
|
||||
.name = "nfc",
|
||||
.dev_release = nfc_release,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user