summaryrefslogtreecommitdiff
path: root/drivers/usb/gadget/legacy/printer.c
diff options
context:
space:
mode:
authorAndrzej Pietrasiewicz <andrzej.p@samsung.com>2015-03-03 10:52:18 +0100
committerFelipe Balbi <balbi@ti.com>2015-03-10 15:33:37 -0500
commitd82cd82edb98d727c6a0804a6e271e3081559404 (patch)
tree21309463de8093e881a6236f2b46c5f34a538cda /drivers/usb/gadget/legacy/printer.c
parent5a84e6f608598dd691c0024eab50fffb96aca43b (diff)
usb: gadget: printer: add setup and cleanup functions
Factor out gprinter_setup() and gprinter_cleanup() so that it is easy to change the place they are called from. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com> Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/gadget/legacy/printer.c')
-rw-r--r--drivers/usb/gadget/legacy/printer.c46
1 files changed, 31 insertions, 15 deletions
diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c
index 42c46da6f59f..83cea9a5c75e 100644
--- a/drivers/usb/gadget/legacy/printer.c
+++ b/drivers/usb/gadget/legacy/printer.c
@@ -1298,6 +1298,34 @@ static int __init printer_do_config(struct usb_configuration *c)
}
+static int gprinter_setup(void)
+{
+ int status;
+
+ usb_gadget_class = class_create(THIS_MODULE, "usb_printer_gadget");
+ if (IS_ERR(usb_gadget_class)) {
+ status = PTR_ERR(usb_gadget_class);
+ pr_err("unable to create usb_gadget class %d\n", status);
+ return status;
+ }
+
+ status = alloc_chrdev_region(&g_printer_devno, 0, 1,
+ "USB printer gadget");
+ if (status) {
+ pr_err("alloc_chrdev_region %d\n", status);
+ class_destroy(usb_gadget_class);
+ }
+
+ return status;
+}
+
+/* must be called with struct printer_dev's lock_printer_io held */
+static void gprinter_cleanup(void)
+{
+ unregister_chrdev_region(g_printer_devno, 1);
+ class_destroy(usb_gadget_class);
+}
+
static int __init printer_bind(struct usb_composite_dev *cdev)
{
int ret;
@@ -1329,20 +1357,9 @@ init(void)
{
int status;
- usb_gadget_class = class_create(THIS_MODULE, "usb_printer_gadget");
- if (IS_ERR(usb_gadget_class)) {
- status = PTR_ERR(usb_gadget_class);
- pr_err("unable to create usb_gadget class %d\n", status);
- return status;
- }
-
- status = alloc_chrdev_region(&g_printer_devno, 0, 1,
- "USB printer gadget");
- if (status) {
- pr_err("alloc_chrdev_region %d\n", status);
- class_destroy(usb_gadget_class);
+ status = gprinter_setup();
+ if (status)
return status;
- }
status = usb_composite_probe(&printer_driver);
if (status) {
@@ -1360,8 +1377,7 @@ cleanup(void)
{
mutex_lock(&usb_printer_gadget.lock_printer_io);
usb_composite_unregister(&printer_driver);
- unregister_chrdev_region(g_printer_devno, 1);
- class_destroy(usb_gadget_class);
+ gprinter_cleanup();
mutex_unlock(&usb_printer_gadget.lock_printer_io);
}
module_exit(cleanup);