Skip to content

Commit 8e99143

Browse files
ivanorlov2206gregkh
authored andcommitted
USB: gadget: udc: core: make udc_class a static const structure
Now that the driver core allows for struct class to be in read-only memory, move the udc_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-8-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 044a611 commit 8e99143

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

drivers/usb/gadget/udc/core.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct usb_udc {
5050
bool started;
5151
};
5252

53-
static struct class *udc_class;
53+
static const struct class udc_class;
5454
static LIST_HEAD(udc_list);
5555

5656
/* Protects udc_list, udc->driver, driver->is_bound, and related calls */
@@ -1312,7 +1312,7 @@ int usb_add_gadget(struct usb_gadget *gadget)
13121312

13131313
device_initialize(&udc->dev);
13141314
udc->dev.release = usb_udc_release;
1315-
udc->dev.class = udc_class;
1315+
udc->dev.class = &udc_class;
13161316
udc->dev.groups = usb_udc_attr_groups;
13171317
udc->dev.parent = gadget->dev.parent;
13181318
ret = dev_set_name(&udc->dev, "%s",
@@ -1774,6 +1774,11 @@ static int usb_udc_uevent(const struct device *dev, struct kobj_uevent_env *env)
17741774
return 0;
17751775
}
17761776

1777+
static const struct class udc_class = {
1778+
.name = "udc",
1779+
.dev_uevent = usb_udc_uevent,
1780+
};
1781+
17771782
static const struct bus_type gadget_bus_type = {
17781783
.name = "gadget",
17791784
.probe = gadget_bind_driver,
@@ -1785,26 +1790,21 @@ static int __init usb_udc_init(void)
17851790
{
17861791
int rc;
17871792

1788-
udc_class = class_create("udc");
1789-
if (IS_ERR(udc_class)) {
1790-
pr_err("failed to create udc class --> %ld\n",
1791-
PTR_ERR(udc_class));
1792-
return PTR_ERR(udc_class);
1793-
}
1794-
1795-
udc_class->dev_uevent = usb_udc_uevent;
1793+
rc = class_register(&udc_class);
1794+
if (rc)
1795+
return rc;
17961796

17971797
rc = bus_register(&gadget_bus_type);
17981798
if (rc)
1799-
class_destroy(udc_class);
1799+
class_unregister(&udc_class);
18001800
return rc;
18011801
}
18021802
subsys_initcall(usb_udc_init);
18031803

18041804
static void __exit usb_udc_exit(void)
18051805
{
18061806
bus_unregister(&gadget_bus_type);
1807-
class_destroy(udc_class);
1807+
class_unregister(&udc_class);
18081808
}
18091809
module_exit(usb_udc_exit);
18101810

0 commit comments

Comments
 (0)