Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Ivan Orlov and committed by
Greg Kroah-Hartman
8e991436 044a6115

+12 -12
+12 -12
drivers/usb/gadget/udc/core.c
··· 50 50 bool started; 51 51 }; 52 52 53 - static struct class *udc_class; 53 + static const struct class udc_class; 54 54 static LIST_HEAD(udc_list); 55 55 56 56 /* Protects udc_list, udc->driver, driver->is_bound, and related calls */ ··· 1312 1312 1313 1313 device_initialize(&udc->dev); 1314 1314 udc->dev.release = usb_udc_release; 1315 - udc->dev.class = udc_class; 1315 + udc->dev.class = &udc_class; 1316 1316 udc->dev.groups = usb_udc_attr_groups; 1317 1317 udc->dev.parent = gadget->dev.parent; 1318 1318 ret = dev_set_name(&udc->dev, "%s", ··· 1774 1774 return 0; 1775 1775 } 1776 1776 1777 + static const struct class udc_class = { 1778 + .name = "udc", 1779 + .dev_uevent = usb_udc_uevent, 1780 + }; 1781 + 1777 1782 static const struct bus_type gadget_bus_type = { 1778 1783 .name = "gadget", 1779 1784 .probe = gadget_bind_driver, ··· 1790 1785 { 1791 1786 int rc; 1792 1787 1793 - udc_class = class_create("udc"); 1794 - if (IS_ERR(udc_class)) { 1795 - pr_err("failed to create udc class --> %ld\n", 1796 - PTR_ERR(udc_class)); 1797 - return PTR_ERR(udc_class); 1798 - } 1799 - 1800 - udc_class->dev_uevent = usb_udc_uevent; 1788 + rc = class_register(&udc_class); 1789 + if (rc) 1790 + return rc; 1801 1791 1802 1792 rc = bus_register(&gadget_bus_type); 1803 1793 if (rc) 1804 - class_destroy(udc_class); 1794 + class_unregister(&udc_class); 1805 1795 return rc; 1806 1796 } 1807 1797 subsys_initcall(usb_udc_init); ··· 1804 1804 static void __exit usb_udc_exit(void) 1805 1805 { 1806 1806 bus_unregister(&gadget_bus_type); 1807 - class_destroy(udc_class); 1807 + class_unregister(&udc_class); 1808 1808 } 1809 1809 module_exit(usb_udc_exit); 1810 1810