1 // SPDX-License-Identifier: GPL-2.0+
3 * copyright (C) 1999/2000 by Henning Zabel <henning@uni-paderborn.de>
8 * USB-Kernel Driver for the Mustek MDC800 Digital Camera
9 * (c) 1999/2000 Henning Zabel <henning@uni-paderborn.de>
12 * The driver brings the USB functions of the MDC800 to Linux.
13 * To use the Camera you must support the USB Protocol of the camera
15 * The Driver uses a misc device Node. Create it with :
16 * mknod /dev/mustek c 180 32
18 * The driver supports only one camera.
20 * Fix: mdc800 used sleep_on and slept with io_lock held.
21 * Converted sleep_on to waitqueues with schedule_timeout and made io_lock
22 * a semaphore from a spinlock.
23 * by Oliver Neukum <oliver@neukum.name>
26 * Identify version on module load.
30 * Fixed potential SMP races with Spinlocks.
31 * Thanks to Oliver Neukum <oliver@neukum.name> who
32 * noticed the race conditions.
35 * Fixed: Setting urb->dev before submitting urb.
36 * by Greg KH <greg@kroah.com>
40 * bugfix : The mdc800->state field gets set to READY after the
41 * the disconnect function sets it to NOT_CONNECTED. This makes the
42 * driver running like the camera is connected and causes some
46 * MOD_INC and MOD_DEC are changed in usb_probe to prevent load/unload
47 * problems when compiled as Module.
50 * The mdc800 driver gets assigned the USB Minor 32-47. The Registration
51 * was updated to use these values.
54 * The Init und Exit Module Function are updated.
58 * Rewrite of the driver : The driver now uses URB's. The old stuff
62 * Rewrite of this driver: The Emulation of the rs232 protocoll
63 * has been removed from the driver. A special executeCommand function
64 * for this driver is included to gphoto.
65 * The driver supports two kind of communication to bulk endpoints.
66 * Either with the dev->bus->ops->bulk... or with callback function.
70 * first Version that gets a version number. Most of the needed
75 #include <linux/sched/signal.h>
76 #include <linux/signal.h>
77 #include <linux/spinlock.h>
78 #include <linux/errno.h>
79 #include <linux/random.h>
80 #include <linux/poll.h>
81 #include <linux/init.h>
82 #include <linux/slab.h>
83 #include <linux/module.h>
84 #include <linux/wait.h>
85 #include <linux/mutex.h>
87 #include <linux/usb.h>
93 #define DRIVER_VERSION "v0.7.5 (30/10/2000)"
94 #define DRIVER_AUTHOR "Henning Zabel <henning@uni-paderborn.de>"
95 #define DRIVER_DESC "USB Driver for Mustek MDC800 Digital Camera"
97 /* Vendor and Product Information */
98 #define MDC800_VENDOR_ID 0x055f
99 #define MDC800_PRODUCT_ID 0xa800
101 /* Timeouts (msec) */
102 #define TO_DOWNLOAD_GET_READY 1500
103 #define TO_DOWNLOAD_GET_BUSY 1500
104 #define TO_WRITE_GET_READY 1000
105 #define TO_DEFAULT_COMMAND 5000
106 #define TO_READ_FROM_IRQ TO_DEFAULT_COMMAND
107 #define TO_GET_READY TO_DEFAULT_COMMAND
109 /* Minor Number of the device (create with mknod /dev/mustek c 180 32) */
110 #define MDC800_DEVICE_MINOR_BASE 32
113 /**************************************************************************
115 ***************************************************************************/
119 NOT_CONNECTED
, READY
, WORKING
, DOWNLOAD
123 /* Data for the driver */
126 struct usb_device
* dev
; // Device Data
129 unsigned int endpoint
[4];
131 struct urb
* irq_urb
;
132 wait_queue_head_t irq_wait
;
134 char* irq_urb_buffer
;
136 int camera_busy
; // is camera busy ?
137 int camera_request_ready
; // Status to synchronize with irq
138 char camera_response
[8]; // last Bytes send after busy
140 struct urb
* write_urb
;
141 char* write_urb_buffer
;
142 wait_queue_head_t write_wait
;
146 struct urb
* download_urb
;
147 char* download_urb_buffer
;
148 wait_queue_head_t download_wait
;
150 int download_left
; // Bytes left to download ?
154 char out
[64]; // Answer Buffer
155 int out_ptr
; // Index to the first not readen byte
156 int out_count
; // Bytes in the buffer
158 int open
; // Camera device open ?
159 struct mutex io_lock
; // IO -lock
161 char in
[8]; // Command Input Buffer
164 int pic_index
; // Cache for the Imagesize (-1 for nothing cached )
170 /* Specification of the Endpoints */
171 static struct usb_endpoint_descriptor mdc800_ed
[4] =
175 .bDescriptorType
= 0,
176 .bEndpointAddress
= 0x01,
177 .bmAttributes
= 0x02,
178 .wMaxPacketSize
= cpu_to_le16(8),
185 .bDescriptorType
= 0,
186 .bEndpointAddress
= 0x82,
187 .bmAttributes
= 0x03,
188 .wMaxPacketSize
= cpu_to_le16(8),
195 .bDescriptorType
= 0,
196 .bEndpointAddress
= 0x03,
197 .bmAttributes
= 0x02,
198 .wMaxPacketSize
= cpu_to_le16(64),
205 .bDescriptorType
= 0,
206 .bEndpointAddress
= 0x84,
207 .bmAttributes
= 0x02,
208 .wMaxPacketSize
= cpu_to_le16(64),
215 /* The Variable used by the driver */
216 static struct mdc800_data
* mdc800
;
219 /***************************************************************************
220 The USB Part of the driver
221 ****************************************************************************/
223 static int mdc800_endpoint_equals (struct usb_endpoint_descriptor
*a
,struct usb_endpoint_descriptor
*b
)
226 ( a
->bEndpointAddress
== b
->bEndpointAddress
)
227 && ( a
->bmAttributes
== b
->bmAttributes
)
228 && ( a
->wMaxPacketSize
== b
->wMaxPacketSize
)
234 * Checks whether the camera responds busy
236 static int mdc800_isBusy (char* ch
)
241 if (ch
[i
] != (char)0x99)
250 * Checks whether the Camera is ready
252 static int mdc800_isReady (char *ch
)
257 if (ch
[i
] != (char)0xbb)
267 * USB IRQ Handler for InputLine
269 static void mdc800_usb_irq (struct urb
*urb
)
271 int data_received
=0, wake_up
;
272 unsigned char* b
=urb
->transfer_buffer
;
273 struct mdc800_data
* mdc800
=urb
->context
;
274 struct device
*dev
= &mdc800
->dev
->dev
;
275 int status
= urb
->status
;
278 if (mdc800_isBusy (b
))
280 if (!mdc800
->camera_busy
)
282 mdc800
->camera_busy
=1;
283 dev_dbg(dev
, "gets busy\n");
288 if (mdc800
->camera_busy
&& mdc800_isReady (b
))
290 mdc800
->camera_busy
=0;
291 dev_dbg(dev
, "gets ready\n");
294 if (!(mdc800_isBusy (b
) || mdc800_isReady (b
)))
296 /* Store Data in camera_answer field */
297 dev_dbg(dev
, "%i %i %i %i %i %i %i %i \n",b
[0],b
[1],b
[2],b
[3],b
[4],b
[5],b
[6],b
[7]);
299 memcpy (mdc800
->camera_response
,b
,8);
303 wake_up
= ( mdc800
->camera_request_ready
> 0 )
306 ((mdc800
->camera_request_ready
== 1) && (!mdc800
->camera_busy
))
308 ((mdc800
->camera_request_ready
== 2) && data_received
)
310 ((mdc800
->camera_request_ready
== 3) && (mdc800
->camera_busy
))
317 mdc800
->camera_request_ready
=0;
319 wake_up (&mdc800
->irq_wait
);
325 * Waits a while until the irq responds that camera is ready
327 * mode : 0: Wait for camera gets ready
328 * 1: Wait for receiving data
329 * 2: Wait for camera gets busy
333 static int mdc800_usb_waitForIRQ (int mode
, int msec
)
335 mdc800
->camera_request_ready
=1+mode
;
337 wait_event_timeout(mdc800
->irq_wait
, mdc800
->irq_woken
,
338 msecs_to_jiffies(msec
));
339 mdc800
->irq_woken
= 0;
341 if (mdc800
->camera_request_ready
>0)
343 mdc800
->camera_request_ready
=0;
344 dev_err(&mdc800
->dev
->dev
, "timeout waiting for camera.\n");
348 if (mdc800
->state
== NOT_CONNECTED
)
350 printk(KERN_WARNING
"mdc800: Camera gets disconnected "
351 "during waiting for irq.\n");
352 mdc800
->camera_request_ready
=0;
361 * The write_urb callback function
363 static void mdc800_usb_write_notify (struct urb
*urb
)
365 struct mdc800_data
* mdc800
=urb
->context
;
366 int status
= urb
->status
;
369 dev_err(&mdc800
->dev
->dev
,
370 "writing command fails (status=%i)\n", status
);
374 wake_up (&mdc800
->write_wait
);
379 * The download_urb callback function
381 static void mdc800_usb_download_notify (struct urb
*urb
)
383 struct mdc800_data
* mdc800
=urb
->context
;
384 int status
= urb
->status
;
387 /* Fill output buffer with these data */
388 memcpy (mdc800
->out
, urb
->transfer_buffer
, 64);
389 mdc800
->out_count
=64;
391 mdc800
->download_left
-=64;
392 if (mdc800
->download_left
== 0)
397 dev_err(&mdc800
->dev
->dev
,
398 "request bytes fails (status:%i)\n", status
);
400 mdc800
->downloaded
= 1;
401 wake_up (&mdc800
->download_wait
);
405 /***************************************************************************
406 Probing for the Camera
407 ***************************************************************************/
409 static struct usb_driver mdc800_usb_driver
;
410 static const struct file_operations mdc800_device_ops
;
411 static struct usb_class_driver mdc800_class
= {
413 .fops
= &mdc800_device_ops
,
414 .minor_base
= MDC800_DEVICE_MINOR_BASE
,
419 * Callback to search the Mustek MDC800 on the USB Bus
421 static int mdc800_usb_probe (struct usb_interface
*intf
,
422 const struct usb_device_id
*id
)
425 struct usb_host_interface
*intf_desc
;
426 struct usb_device
*dev
= interface_to_usbdev (intf
);
430 dev_dbg(&intf
->dev
, "(%s) called.\n", __func__
);
433 if (mdc800
->dev
!= NULL
)
435 dev_warn(&intf
->dev
, "only one Mustek MDC800 is supported.\n");
439 if (dev
->descriptor
.bNumConfigurations
!= 1)
442 "probe fails -> wrong Number of Configuration\n");
445 intf_desc
= intf
->cur_altsetting
;
448 ( intf_desc
->desc
.bInterfaceClass
!= 0xff )
449 || ( intf_desc
->desc
.bInterfaceSubClass
!= 0 )
450 || ( intf_desc
->desc
.bInterfaceProtocol
!= 0 )
451 || ( intf_desc
->desc
.bNumEndpoints
!= 4)
454 dev_err(&intf
->dev
, "probe fails -> wrong Interface\n");
458 /* Check the Endpoints */
461 mdc800
->endpoint
[i
]=-1;
464 if (mdc800_endpoint_equals (&intf_desc
->endpoint
[j
].desc
,&mdc800_ed
[i
]))
466 mdc800
->endpoint
[i
]=intf_desc
->endpoint
[j
].desc
.bEndpointAddress
;
469 irq_interval
=intf_desc
->endpoint
[j
].desc
.bInterval
;
473 if (mdc800
->endpoint
[i
] == -1)
475 dev_err(&intf
->dev
, "probe fails -> Wrong Endpoints.\n");
481 dev_info(&intf
->dev
, "Found Mustek MDC800 on USB.\n");
483 mutex_lock(&mdc800
->io_lock
);
485 retval
= usb_register_dev(intf
, &mdc800_class
);
487 dev_err(&intf
->dev
, "Not able to get a minor for this device.\n");
488 mutex_unlock(&mdc800
->io_lock
);
495 /* Setup URB Structs */
499 usb_rcvintpipe (mdc800
->dev
,mdc800
->endpoint
[1]),
500 mdc800
->irq_urb_buffer
,
510 usb_sndbulkpipe (mdc800
->dev
, mdc800
->endpoint
[0]),
511 mdc800
->write_urb_buffer
,
513 mdc800_usb_write_notify
,
518 mdc800
->download_urb
,
520 usb_rcvbulkpipe (mdc800
->dev
, mdc800
->endpoint
[3]),
521 mdc800
->download_urb_buffer
,
523 mdc800_usb_download_notify
,
529 mutex_unlock(&mdc800
->io_lock
);
531 usb_set_intfdata(intf
, mdc800
);
537 * Disconnect USB device (maybe the MDC800)
539 static void mdc800_usb_disconnect (struct usb_interface
*intf
)
541 struct mdc800_data
* mdc800
= usb_get_intfdata(intf
);
543 dev_dbg(&intf
->dev
, "(%s) called\n", __func__
);
546 if (mdc800
->state
== NOT_CONNECTED
)
549 usb_deregister_dev(intf
, &mdc800_class
);
551 /* must be under lock to make sure no URB
552 is submitted after usb_kill_urb() */
553 mutex_lock(&mdc800
->io_lock
);
554 mdc800
->state
=NOT_CONNECTED
;
556 usb_kill_urb(mdc800
->irq_urb
);
557 usb_kill_urb(mdc800
->write_urb
);
558 usb_kill_urb(mdc800
->download_urb
);
559 mutex_unlock(&mdc800
->io_lock
);
562 usb_set_intfdata(intf
, NULL
);
564 dev_info(&intf
->dev
, "Mustek MDC800 disconnected from USB.\n");
568 /***************************************************************************
569 The Misc device Part (file_operations)
570 ****************************************************************************/
573 * This Function calc the Answersize for a command.
575 static int mdc800_getAnswerSize (char command
)
577 switch ((unsigned char) command
)
592 return mdc800
->pic_len
;
604 * Init the device: (1) alloc mem (2) Increase MOD Count ..
606 static int mdc800_device_open (struct inode
* inode
, struct file
*file
)
611 mutex_lock(&mdc800
->io_lock
);
613 if (mdc800
->state
== NOT_CONNECTED
)
629 mdc800
->download_left
=0;
631 mdc800
->camera_busy
=0;
632 mdc800
->camera_request_ready
=0;
635 mdc800
->irq_urb
->dev
= mdc800
->dev
;
636 retval
= usb_submit_urb (mdc800
->irq_urb
, GFP_KERNEL
);
638 dev_err(&mdc800
->dev
->dev
,
639 "request USB irq fails (submit_retval=%i).\n", retval
);
645 dev_dbg(&mdc800
->dev
->dev
, "Mustek MDC800 device opened.\n");
648 mutex_unlock(&mdc800
->io_lock
);
654 * Close the Camera and release Memory
656 static int mdc800_device_release (struct inode
* inode
, struct file
*file
)
660 mutex_lock(&mdc800
->io_lock
);
661 if (mdc800
->open
&& (mdc800
->state
!= NOT_CONNECTED
))
663 usb_kill_urb(mdc800
->irq_urb
);
664 usb_kill_urb(mdc800
->write_urb
);
665 usb_kill_urb(mdc800
->download_urb
);
673 mutex_unlock(&mdc800
->io_lock
);
679 * The Device read callback Function
681 static ssize_t
mdc800_device_read (struct file
*file
, char __user
*buf
, size_t len
, loff_t
*pos
)
683 size_t left
=len
, sts
=len
; /* single transfer size */
684 char __user
*ptr
= buf
;
687 mutex_lock(&mdc800
->io_lock
);
688 if (mdc800
->state
== NOT_CONNECTED
)
690 mutex_unlock(&mdc800
->io_lock
);
693 if (mdc800
->state
== WORKING
)
695 printk(KERN_WARNING
"mdc800: Illegal State \"working\""
696 "reached during read ?!\n");
697 mutex_unlock(&mdc800
->io_lock
);
702 mutex_unlock(&mdc800
->io_lock
);
708 if (signal_pending (current
))
710 mutex_unlock(&mdc800
->io_lock
);
714 sts
=left
> (mdc800
->out_count
-mdc800
->out_ptr
)?mdc800
->out_count
-mdc800
->out_ptr
:left
;
718 /* Too less Data in buffer */
719 if (mdc800
->state
== DOWNLOAD
)
724 /* Download -> Request new bytes */
725 mdc800
->download_urb
->dev
= mdc800
->dev
;
726 retval
= usb_submit_urb (mdc800
->download_urb
, GFP_KERNEL
);
728 dev_err(&mdc800
->dev
->dev
,
729 "Can't submit download urb "
730 "(retval=%i)\n", retval
);
731 mutex_unlock(&mdc800
->io_lock
);
734 wait_event_timeout(mdc800
->download_wait
,
736 msecs_to_jiffies(TO_DOWNLOAD_GET_READY
));
737 mdc800
->downloaded
= 0;
738 if (mdc800
->download_urb
->status
!= 0)
740 dev_err(&mdc800
->dev
->dev
,
741 "request download-bytes fails "
743 mdc800
->download_urb
->status
);
744 mutex_unlock(&mdc800
->io_lock
);
750 /* No more bytes -> that's an error*/
751 mutex_unlock(&mdc800
->io_lock
);
758 if (copy_to_user(ptr
, &mdc800
->out
[mdc800
->out_ptr
],
760 mutex_unlock(&mdc800
->io_lock
);
765 mdc800
->out_ptr
+=sts
;
769 mutex_unlock(&mdc800
->io_lock
);
775 * The Device write callback Function
776 * If a 8Byte Command is received, it will be send to the camera.
777 * After this the driver initiates the request for the answer or
778 * just waits until the camera becomes ready.
780 static ssize_t
mdc800_device_write (struct file
*file
, const char __user
*buf
, size_t len
, loff_t
*pos
)
785 mutex_lock(&mdc800
->io_lock
);
786 if (mdc800
->state
!= READY
)
788 mutex_unlock(&mdc800
->io_lock
);
793 mutex_unlock(&mdc800
->io_lock
);
800 if (signal_pending (current
))
802 mutex_unlock(&mdc800
->io_lock
);
806 if(get_user(c
, buf
+i
))
808 mutex_unlock(&mdc800
->io_lock
);
812 /* check for command start */
818 mdc800
->download_left
=0;
821 /* save command byte */
822 if (mdc800
->in_count
< 8)
824 mdc800
->in
[mdc800
->in_count
] = c
;
829 mutex_unlock(&mdc800
->io_lock
);
833 /* Command Buffer full ? -> send it to camera */
834 if (mdc800
->in_count
== 8)
838 if (mdc800_usb_waitForIRQ (0,TO_GET_READY
))
840 dev_err(&mdc800
->dev
->dev
,
841 "Camera didn't get ready.\n");
842 mutex_unlock(&mdc800
->io_lock
);
846 answersize
=mdc800_getAnswerSize (mdc800
->in
[1]);
848 mdc800
->state
=WORKING
;
849 memcpy (mdc800
->write_urb
->transfer_buffer
, mdc800
->in
,8);
850 mdc800
->write_urb
->dev
= mdc800
->dev
;
851 retval
= usb_submit_urb (mdc800
->write_urb
, GFP_KERNEL
);
853 dev_err(&mdc800
->dev
->dev
,
854 "submitting write urb fails "
855 "(retval=%i)\n", retval
);
856 mutex_unlock(&mdc800
->io_lock
);
859 wait_event_timeout(mdc800
->write_wait
, mdc800
->written
,
860 msecs_to_jiffies(TO_WRITE_GET_READY
));
862 if (mdc800
->state
== WORKING
)
864 usb_kill_urb(mdc800
->write_urb
);
865 mutex_unlock(&mdc800
->io_lock
);
869 switch ((unsigned char) mdc800
->in
[1])
871 case 0x05: /* Download Image */
872 case 0x3e: /* Take shot in Fine Mode (WCam Mode) */
873 if (mdc800
->pic_len
< 0)
875 dev_err(&mdc800
->dev
->dev
,
879 mutex_unlock(&mdc800
->io_lock
);
885 case 0x09: /* Download Thumbnail */
886 mdc800
->download_left
=answersize
+64;
887 mdc800
->state
=DOWNLOAD
;
888 mdc800_usb_waitForIRQ (0,TO_DOWNLOAD_GET_BUSY
);
896 if (mdc800_usb_waitForIRQ (1,TO_READ_FROM_IRQ
))
898 dev_err(&mdc800
->dev
->dev
, "requesting answer from irq fails\n");
899 mutex_unlock(&mdc800
->io_lock
);
903 /* Write dummy data, (this is ugly but part of the USB Protocol */
904 /* if you use endpoint 1 as bulk and not as irq) */
905 memcpy (mdc800
->out
, mdc800
->camera_response
,8);
907 /* This is the interpreted answer */
908 memcpy (&mdc800
->out
[8], mdc800
->camera_response
,8);
911 mdc800
->out_count
=16;
913 /* Cache the Imagesize, if command was getImageSize */
914 if (mdc800
->in
[1] == (char) 0x07)
916 mdc800
->pic_len
=(int) 65536*(unsigned char) mdc800
->camera_response
[0]+256*(unsigned char) mdc800
->camera_response
[1]+(unsigned char) mdc800
->camera_response
[2];
918 dev_dbg(&mdc800
->dev
->dev
, "cached imagesize = %i\n", mdc800
->pic_len
);
924 if (mdc800_usb_waitForIRQ (0,TO_DEFAULT_COMMAND
))
926 dev_err(&mdc800
->dev
->dev
, "Command Timeout.\n");
927 mutex_unlock(&mdc800
->io_lock
);
937 mutex_unlock(&mdc800
->io_lock
);
942 /***************************************************************************
943 Init and Cleanup this driver (Structs and types)
944 ****************************************************************************/
946 /* File Operations of this drivers */
947 static const struct file_operations mdc800_device_ops
=
949 .owner
= THIS_MODULE
,
950 .read
= mdc800_device_read
,
951 .write
= mdc800_device_write
,
952 .open
= mdc800_device_open
,
953 .release
= mdc800_device_release
,
954 .llseek
= noop_llseek
,
959 static const struct usb_device_id mdc800_table
[] = {
960 { USB_DEVICE(MDC800_VENDOR_ID
, MDC800_PRODUCT_ID
) },
961 { } /* Terminating entry */
964 MODULE_DEVICE_TABLE (usb
, mdc800_table
);
966 * USB Driver Struct for this device
968 static struct usb_driver mdc800_usb_driver
=
971 .probe
= mdc800_usb_probe
,
972 .disconnect
= mdc800_usb_disconnect
,
973 .id_table
= mdc800_table
978 /************************************************************************
979 Init and Cleanup this driver (Main Functions)
980 *************************************************************************/
982 static int __init
usb_mdc800_init (void)
984 int retval
= -ENODEV
;
985 /* Allocate Memory */
986 mdc800
=kzalloc (sizeof (struct mdc800_data
), GFP_KERNEL
);
988 goto cleanup_on_fail
;
991 mdc800
->state
=NOT_CONNECTED
;
992 mutex_init (&mdc800
->io_lock
);
994 init_waitqueue_head (&mdc800
->irq_wait
);
995 init_waitqueue_head (&mdc800
->write_wait
);
996 init_waitqueue_head (&mdc800
->download_wait
);
998 mdc800
->irq_woken
= 0;
999 mdc800
->downloaded
= 0;
1000 mdc800
->written
= 0;
1002 mdc800
->irq_urb_buffer
=kmalloc (8, GFP_KERNEL
);
1003 if (!mdc800
->irq_urb_buffer
)
1004 goto cleanup_on_fail
;
1005 mdc800
->write_urb_buffer
=kmalloc (8, GFP_KERNEL
);
1006 if (!mdc800
->write_urb_buffer
)
1007 goto cleanup_on_fail
;
1008 mdc800
->download_urb_buffer
=kmalloc (64, GFP_KERNEL
);
1009 if (!mdc800
->download_urb_buffer
)
1010 goto cleanup_on_fail
;
1012 mdc800
->irq_urb
=usb_alloc_urb (0, GFP_KERNEL
);
1013 if (!mdc800
->irq_urb
)
1014 goto cleanup_on_fail
;
1015 mdc800
->download_urb
=usb_alloc_urb (0, GFP_KERNEL
);
1016 if (!mdc800
->download_urb
)
1017 goto cleanup_on_fail
;
1018 mdc800
->write_urb
=usb_alloc_urb (0, GFP_KERNEL
);
1019 if (!mdc800
->write_urb
)
1020 goto cleanup_on_fail
;
1022 /* Register the driver */
1023 retval
= usb_register(&mdc800_usb_driver
);
1025 goto cleanup_on_fail
;
1027 printk(KERN_INFO KBUILD_MODNAME
": " DRIVER_VERSION
":"
1032 /* Clean driver up, when something fails */
1038 printk(KERN_ERR
"mdc800: can't alloc memory!\n");
1040 kfree(mdc800
->download_urb_buffer
);
1041 kfree(mdc800
->write_urb_buffer
);
1042 kfree(mdc800
->irq_urb_buffer
);
1044 usb_free_urb(mdc800
->write_urb
);
1045 usb_free_urb(mdc800
->download_urb
);
1046 usb_free_urb(mdc800
->irq_urb
);
1055 static void __exit
usb_mdc800_cleanup (void)
1057 usb_deregister (&mdc800_usb_driver
);
1059 usb_free_urb (mdc800
->irq_urb
);
1060 usb_free_urb (mdc800
->download_urb
);
1061 usb_free_urb (mdc800
->write_urb
);
1063 kfree (mdc800
->irq_urb_buffer
);
1064 kfree (mdc800
->write_urb_buffer
);
1065 kfree (mdc800
->download_urb_buffer
);
1071 module_init (usb_mdc800_init
);
1072 module_exit (usb_mdc800_cleanup
);
1074 MODULE_AUTHOR( DRIVER_AUTHOR
);
1075 MODULE_DESCRIPTION( DRIVER_DESC
);
1076 MODULE_LICENSE("GPL");