Commit 070bef83 authored by Ricardo B. Marliere's avatar Ricardo B. Marliere Committed by Jakub Kicinski
Browse files

net: wwan: core: make wwan_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 wwan_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>
Acked-by: default avatarSergey Ryazanov <ryazanov.s.a@gmail.com>
Link: https://lore.kernel.org/r/20240302-class_cleanup-net-next-v1-5-8fa378595b93@marliere.net


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent d9567f21
Loading
Loading
Loading
Loading
+15 −15
Original line number Diff line number Diff line
@@ -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 @@ static struct wwan_device *wwan_create_dev(struct device *parent)

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);