diff options
author | Ivan Orlov <ivan.orlov0322@gmail.com> | 2023-06-20 11:44:13 +0200 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2023-06-20 16:20:40 +0200 |
commit | 044a61158b9e00ee4b69bc4fa0f3e720b5dd669a (patch) | |
tree | 33cb33b40d0e01a8c8619ff9afb3275c5fc36e7b /drivers/usb | |
parent | 34d401a1910dde53356fa5ac03649085fd20e5e3 (diff) | |
download | linux-044a61158b9e00ee4b69bc4fa0f3e720b5dd669a.tar.gz linux-044a61158b9e00ee4b69bc4fa0f3e720b5dd669a.tar.bz2 linux-044a61158b9e00ee4b69bc4fa0f3e720b5dd669a.zip |
USB: roles: make role_class a static const structure
Now that the driver core allows for struct class to be in read-only
memory, move the role_class structure to be declared at build time
placing it into read-only memory, instead of having to be dynamically
allocated at load time.
Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
Link: https://lore.kernel.org/r/20230620094412.508580-7-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb')
-rw-r--r-- | drivers/usb/roles/class.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c index 0395bd5dbd3e..ae41578bd014 100644 --- a/drivers/usb/roles/class.c +++ b/drivers/usb/roles/class.c @@ -14,7 +14,9 @@ #include <linux/mutex.h> #include <linux/slab.h> -static struct class *role_class; +static const struct class role_class = { + .name = "usb_role", +}; struct usb_role_switch { struct device dev; @@ -95,7 +97,7 @@ static void *usb_role_switch_match(const struct fwnode_handle *fwnode, const cha if (id && !fwnode_property_present(fwnode, id)) return NULL; - dev = class_find_device_by_fwnode(role_class, fwnode); + dev = class_find_device_by_fwnode(&role_class, fwnode); return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER); } @@ -111,7 +113,7 @@ usb_role_switch_is_parent(struct fwnode_handle *fwnode) return NULL; } - dev = class_find_device_by_fwnode(role_class, parent); + dev = class_find_device_by_fwnode(&role_class, parent); fwnode_handle_put(parent); return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER); } @@ -191,7 +193,7 @@ usb_role_switch_find_by_fwnode(const struct fwnode_handle *fwnode) if (!fwnode) return NULL; - dev = class_find_device_by_fwnode(role_class, fwnode); + dev = class_find_device_by_fwnode(&role_class, fwnode); if (dev) WARN_ON(!try_module_get(dev->parent->driver->owner)); @@ -338,7 +340,7 @@ usb_role_switch_register(struct device *parent, sw->dev.parent = parent; sw->dev.fwnode = desc->fwnode; - sw->dev.class = role_class; + sw->dev.class = &role_class; sw->dev.type = &usb_role_dev_type; dev_set_drvdata(&sw->dev, desc->driver_data); dev_set_name(&sw->dev, "%s-role-switch", @@ -392,14 +394,13 @@ EXPORT_SYMBOL_GPL(usb_role_switch_get_drvdata); static int __init usb_roles_init(void) { - role_class = class_create("usb_role"); - return PTR_ERR_OR_ZERO(role_class); + return class_register(&role_class); } subsys_initcall(usb_roles_init); static void __exit usb_roles_exit(void) { - class_destroy(role_class); + class_unregister(&role_class); } module_exit(usb_roles_exit); |