Commit 2c10e7a0 authored by Ivan Orlov's avatar Ivan Orlov Committed by Greg Kroah-Hartman

USB: gadget: f_printer: make usb_gadget_class a static const structure

Now that the driver core allows for struct class to be in read-only
memory, move the usb_gadget_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: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarIvan Orlov <ivan.orlov0322@gmail.com>
Link: https://lore.kernel.org/r/20230620094412.508580-10-gregkh@linuxfoundation.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent e571e843
...@@ -54,7 +54,10 @@ ...@@ -54,7 +54,10 @@
#define DEFAULT_Q_LEN 10 /* same as legacy g_printer gadget */ #define DEFAULT_Q_LEN 10 /* same as legacy g_printer gadget */
static int major, minors; static int major, minors;
static struct class *usb_gadget_class; static const struct class usb_gadget_class = {
.name = "usb_printer_gadget",
};
static DEFINE_IDA(printer_ida); static DEFINE_IDA(printer_ida);
static DEFINE_MUTEX(printer_ida_lock); /* protects access do printer_ida */ static DEFINE_MUTEX(printer_ida_lock); /* protects access do printer_ida */
...@@ -1120,7 +1123,7 @@ static int printer_func_bind(struct usb_configuration *c, ...@@ -1120,7 +1123,7 @@ static int printer_func_bind(struct usb_configuration *c,
/* Setup the sysfs files for the printer gadget. */ /* Setup the sysfs files for the printer gadget. */
devt = MKDEV(major, dev->minor); devt = MKDEV(major, dev->minor);
pdev = device_create(usb_gadget_class, NULL, devt, pdev = device_create(&usb_gadget_class, NULL, devt,
NULL, "g_printer%d", dev->minor); NULL, "g_printer%d", dev->minor);
if (IS_ERR(pdev)) { if (IS_ERR(pdev)) {
ERROR(dev, "Failed to create device: g_printer\n"); ERROR(dev, "Failed to create device: g_printer\n");
...@@ -1143,7 +1146,7 @@ static int printer_func_bind(struct usb_configuration *c, ...@@ -1143,7 +1146,7 @@ static int printer_func_bind(struct usb_configuration *c,
return 0; return 0;
fail_cdev_add: fail_cdev_add:
device_destroy(usb_gadget_class, devt); device_destroy(&usb_gadget_class, devt);
fail_rx_reqs: fail_rx_reqs:
while (!list_empty(&dev->rx_reqs)) { while (!list_empty(&dev->rx_reqs)) {
...@@ -1410,7 +1413,7 @@ static void printer_func_unbind(struct usb_configuration *c, ...@@ -1410,7 +1413,7 @@ static void printer_func_unbind(struct usb_configuration *c,
dev = func_to_printer(f); dev = func_to_printer(f);
device_destroy(usb_gadget_class, MKDEV(major, dev->minor)); device_destroy(&usb_gadget_class, MKDEV(major, dev->minor));
/* Remove Character Device */ /* Remove Character Device */
cdev_del(&dev->printer_cdev); cdev_del(&dev->printer_cdev);
...@@ -1512,19 +1515,14 @@ static int gprinter_setup(int count) ...@@ -1512,19 +1515,14 @@ static int gprinter_setup(int count)
int status; int status;
dev_t devt; dev_t devt;
usb_gadget_class = class_create("usb_printer_gadget"); status = class_register(&usb_gadget_class);
if (IS_ERR(usb_gadget_class)) { if (status)
status = PTR_ERR(usb_gadget_class);
usb_gadget_class = NULL;
pr_err("unable to create usb_gadget class %d\n", status);
return status; return status;
}
status = alloc_chrdev_region(&devt, 0, count, "USB printer gadget"); status = alloc_chrdev_region(&devt, 0, count, "USB printer gadget");
if (status) { if (status) {
pr_err("alloc_chrdev_region %d\n", status); pr_err("alloc_chrdev_region %d\n", status);
class_destroy(usb_gadget_class); class_unregister(&usb_gadget_class);
usb_gadget_class = NULL;
return status; return status;
} }
...@@ -1540,6 +1538,5 @@ static void gprinter_cleanup(void) ...@@ -1540,6 +1538,5 @@ static void gprinter_cleanup(void)
unregister_chrdev_region(MKDEV(major, 0), minors); unregister_chrdev_region(MKDEV(major, 0), minors);
major = minors = 0; major = minors = 0;
} }
class_destroy(usb_gadget_class); class_unregister(&usb_gadget_class);
usb_gadget_class = NULL;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment