mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-15 16:24:13 +08:00
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: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com> Link: https://lore.kernel.org/r/20230620094412.508580-10-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
e571e843f0
commit
2c10e7a049
@ -54,7 +54,10 @@
|
||||
#define DEFAULT_Q_LEN 10 /* same as legacy g_printer gadget */
|
||||
|
||||
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_MUTEX(printer_ida_lock); /* protects access do printer_ida */
|
||||
|
||||
@ -1120,7 +1123,7 @@ autoconf_fail:
|
||||
|
||||
/* Setup the sysfs files for the printer gadget. */
|
||||
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);
|
||||
if (IS_ERR(pdev)) {
|
||||
ERROR(dev, "Failed to create device: g_printer\n");
|
||||
@ -1143,7 +1146,7 @@ autoconf_fail:
|
||||
return 0;
|
||||
|
||||
fail_cdev_add:
|
||||
device_destroy(usb_gadget_class, devt);
|
||||
device_destroy(&usb_gadget_class, devt);
|
||||
|
||||
fail_rx_reqs:
|
||||
while (!list_empty(&dev->rx_reqs)) {
|
||||
@ -1410,7 +1413,7 @@ static void printer_func_unbind(struct usb_configuration *c,
|
||||
|
||||
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 */
|
||||
cdev_del(&dev->printer_cdev);
|
||||
@ -1512,19 +1515,14 @@ static int gprinter_setup(int count)
|
||||
int status;
|
||||
dev_t devt;
|
||||
|
||||
usb_gadget_class = class_create("usb_printer_gadget");
|
||||
if (IS_ERR(usb_gadget_class)) {
|
||||
status = PTR_ERR(usb_gadget_class);
|
||||
usb_gadget_class = NULL;
|
||||
pr_err("unable to create usb_gadget class %d\n", status);
|
||||
status = class_register(&usb_gadget_class);
|
||||
if (status)
|
||||
return status;
|
||||
}
|
||||
|
||||
status = alloc_chrdev_region(&devt, 0, count, "USB printer gadget");
|
||||
if (status) {
|
||||
pr_err("alloc_chrdev_region %d\n", status);
|
||||
class_destroy(usb_gadget_class);
|
||||
usb_gadget_class = NULL;
|
||||
class_unregister(&usb_gadget_class);
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -1540,6 +1538,5 @@ static void gprinter_cleanup(void)
|
||||
unregister_chrdev_region(MKDEV(major, 0), minors);
|
||||
major = minors = 0;
|
||||
}
|
||||
class_destroy(usb_gadget_class);
|
||||
usb_gadget_class = NULL;
|
||||
class_unregister(&usb_gadget_class);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user