mirror of
https://github.com/torvalds/linux.git
synced 2024-11-10 22:21:40 +00:00
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>
This commit is contained in:
parent
34d401a191
commit
044a61158b
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user