Loading drivers/usb/misc/usblcd.c +71 −56 Original line number Original line Diff line number Diff line Loading @@ -18,7 +18,7 @@ #include <linux/slab.h> #include <linux/slab.h> #include <linux/errno.h> #include <linux/errno.h> #include <linux/mutex.h> #include <linux/mutex.h> #include <asm/uaccess.h> #include <linux/uaccess.h> #include <linux/usb.h> #include <linux/usb.h> #define DRIVER_VERSION "USBLCD Driver Version 1.05" #define DRIVER_VERSION "USBLCD Driver Version 1.05" Loading @@ -41,15 +41,22 @@ static DEFINE_MUTEX(open_disc_mutex); struct usb_lcd { struct usb_lcd { struct usb_device *udev; /* init: probe_lcd */ struct usb_device *udev; /* init: probe_lcd */ struct usb_interface * interface; /* the interface for this device */ struct usb_interface *interface; /* the interface for unsigned char * bulk_in_buffer; /* the buffer to receive data */ this device */ size_t bulk_in_size; /* the size of the receive buffer */ unsigned char *bulk_in_buffer; /* the buffer to receive __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */ data */ __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */ size_t bulk_in_size; /* the size of the receive buffer */ __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */ __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */ struct kref kref; struct kref kref; struct semaphore limit_sem; /* to stop writes at full throttle from struct semaphore limit_sem; /* to stop writes at * using up all RAM */ full throttle from struct usb_anchor submitted; /* URBs to wait for before suspend */ using up all RAM */ struct usb_anchor submitted; /* URBs to wait for before suspend */ }; }; #define to_lcd_dev(d) container_of(d, struct usb_lcd, kref) #define to_lcd_dev(d) container_of(d, struct usb_lcd, kref) Loading Loading @@ -126,7 +133,8 @@ static int lcd_release(struct inode *inode, struct file *file) return 0; return 0; } } static ssize_t lcd_read(struct file *file, char __user * buffer, size_t count, loff_t *ppos) static ssize_t lcd_read(struct file *file, char __user * buffer, size_t count, loff_t *ppos) { { struct usb_lcd *dev; struct usb_lcd *dev; int retval = 0; int retval = 0; Loading @@ -136,7 +144,8 @@ static ssize_t lcd_read(struct file *file, char __user * buffer, size_t count, l /* do a blocking bulk read to get data from the device */ /* do a blocking bulk read to get data from the device */ retval = usb_bulk_msg(dev->udev, retval = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, dev->bulk_in_endpointAddr), usb_rcvbulkpipe(dev->udev, dev->bulk_in_endpointAddr), dev->bulk_in_buffer, dev->bulk_in_buffer, min(dev->bulk_in_size, count), min(dev->bulk_in_size, count), &bytes_read, 10000); &bytes_read, 10000); Loading Loading @@ -210,7 +219,8 @@ static void lcd_write_bulk_callback(struct urb *urb) up(&dev->limit_sem); up(&dev->limit_sem); } } static ssize_t lcd_write(struct file *file, const char __user * user_buffer, size_t count, loff_t *ppos) static ssize_t lcd_write(struct file *file, const char __user * user_buffer, size_t count, loff_t *ppos) { { struct usb_lcd *dev; struct usb_lcd *dev; int retval = 0, r; int retval = 0, r; Loading @@ -234,7 +244,8 @@ static ssize_t lcd_write(struct file *file, const char __user * user_buffer, siz goto err_no_buf; goto err_no_buf; } } buf = usb_alloc_coherent(dev->udev, count, GFP_KERNEL, &urb->transfer_dma); buf = usb_alloc_coherent(dev->udev, count, GFP_KERNEL, &urb->transfer_dma); if (!buf) { if (!buf) { retval = -ENOMEM; retval = -ENOMEM; goto error; goto error; Loading @@ -247,7 +258,8 @@ static ssize_t lcd_write(struct file *file, const char __user * user_buffer, siz /* initialize the urb properly */ /* initialize the urb properly */ usb_fill_bulk_urb(urb, dev->udev, usb_fill_bulk_urb(urb, dev->udev, usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr), usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr), buf, count, lcd_write_bulk_callback, dev); buf, count, lcd_write_bulk_callback, dev); urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; Loading @@ -256,11 +268,13 @@ static ssize_t lcd_write(struct file *file, const char __user * user_buffer, siz /* send the data out the bulk port */ /* send the data out the bulk port */ retval = usb_submit_urb(urb, GFP_KERNEL); retval = usb_submit_urb(urb, GFP_KERNEL); if (retval) { if (retval) { err("USBLCD: %s - failed submitting write urb, error %d", __func__, retval); err("USBLCD: %s - failed submitting write urb, error %d", __func__, retval); goto error_unanchor; goto error_unanchor; } } /* release our reference to this urb, the USB core will eventually free it entirely */ /* release our reference to this urb, the USB core will eventually free it entirely */ usb_free_urb(urb); usb_free_urb(urb); exit: exit: Loading Loading @@ -295,7 +309,8 @@ static struct usb_class_driver lcd_class = { .minor_base = USBLCD_MINOR, .minor_base = USBLCD_MINOR, }; }; static int lcd_probe(struct usb_interface *interface, const struct usb_device_id *id) static int lcd_probe(struct usb_interface *interface, const struct usb_device_id *id) { { struct usb_lcd *dev = NULL; struct usb_lcd *dev = NULL; struct usb_host_interface *iface_desc; struct usb_host_interface *iface_desc; Loading Loading
drivers/usb/misc/usblcd.c +71 −56 Original line number Original line Diff line number Diff line Loading @@ -18,7 +18,7 @@ #include <linux/slab.h> #include <linux/slab.h> #include <linux/errno.h> #include <linux/errno.h> #include <linux/mutex.h> #include <linux/mutex.h> #include <asm/uaccess.h> #include <linux/uaccess.h> #include <linux/usb.h> #include <linux/usb.h> #define DRIVER_VERSION "USBLCD Driver Version 1.05" #define DRIVER_VERSION "USBLCD Driver Version 1.05" Loading @@ -41,15 +41,22 @@ static DEFINE_MUTEX(open_disc_mutex); struct usb_lcd { struct usb_lcd { struct usb_device *udev; /* init: probe_lcd */ struct usb_device *udev; /* init: probe_lcd */ struct usb_interface * interface; /* the interface for this device */ struct usb_interface *interface; /* the interface for unsigned char * bulk_in_buffer; /* the buffer to receive data */ this device */ size_t bulk_in_size; /* the size of the receive buffer */ unsigned char *bulk_in_buffer; /* the buffer to receive __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */ data */ __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */ size_t bulk_in_size; /* the size of the receive buffer */ __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */ __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */ struct kref kref; struct kref kref; struct semaphore limit_sem; /* to stop writes at full throttle from struct semaphore limit_sem; /* to stop writes at * using up all RAM */ full throttle from struct usb_anchor submitted; /* URBs to wait for before suspend */ using up all RAM */ struct usb_anchor submitted; /* URBs to wait for before suspend */ }; }; #define to_lcd_dev(d) container_of(d, struct usb_lcd, kref) #define to_lcd_dev(d) container_of(d, struct usb_lcd, kref) Loading Loading @@ -126,7 +133,8 @@ static int lcd_release(struct inode *inode, struct file *file) return 0; return 0; } } static ssize_t lcd_read(struct file *file, char __user * buffer, size_t count, loff_t *ppos) static ssize_t lcd_read(struct file *file, char __user * buffer, size_t count, loff_t *ppos) { { struct usb_lcd *dev; struct usb_lcd *dev; int retval = 0; int retval = 0; Loading @@ -136,7 +144,8 @@ static ssize_t lcd_read(struct file *file, char __user * buffer, size_t count, l /* do a blocking bulk read to get data from the device */ /* do a blocking bulk read to get data from the device */ retval = usb_bulk_msg(dev->udev, retval = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, dev->bulk_in_endpointAddr), usb_rcvbulkpipe(dev->udev, dev->bulk_in_endpointAddr), dev->bulk_in_buffer, dev->bulk_in_buffer, min(dev->bulk_in_size, count), min(dev->bulk_in_size, count), &bytes_read, 10000); &bytes_read, 10000); Loading Loading @@ -210,7 +219,8 @@ static void lcd_write_bulk_callback(struct urb *urb) up(&dev->limit_sem); up(&dev->limit_sem); } } static ssize_t lcd_write(struct file *file, const char __user * user_buffer, size_t count, loff_t *ppos) static ssize_t lcd_write(struct file *file, const char __user * user_buffer, size_t count, loff_t *ppos) { { struct usb_lcd *dev; struct usb_lcd *dev; int retval = 0, r; int retval = 0, r; Loading @@ -234,7 +244,8 @@ static ssize_t lcd_write(struct file *file, const char __user * user_buffer, siz goto err_no_buf; goto err_no_buf; } } buf = usb_alloc_coherent(dev->udev, count, GFP_KERNEL, &urb->transfer_dma); buf = usb_alloc_coherent(dev->udev, count, GFP_KERNEL, &urb->transfer_dma); if (!buf) { if (!buf) { retval = -ENOMEM; retval = -ENOMEM; goto error; goto error; Loading @@ -247,7 +258,8 @@ static ssize_t lcd_write(struct file *file, const char __user * user_buffer, siz /* initialize the urb properly */ /* initialize the urb properly */ usb_fill_bulk_urb(urb, dev->udev, usb_fill_bulk_urb(urb, dev->udev, usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr), usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr), buf, count, lcd_write_bulk_callback, dev); buf, count, lcd_write_bulk_callback, dev); urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; Loading @@ -256,11 +268,13 @@ static ssize_t lcd_write(struct file *file, const char __user * user_buffer, siz /* send the data out the bulk port */ /* send the data out the bulk port */ retval = usb_submit_urb(urb, GFP_KERNEL); retval = usb_submit_urb(urb, GFP_KERNEL); if (retval) { if (retval) { err("USBLCD: %s - failed submitting write urb, error %d", __func__, retval); err("USBLCD: %s - failed submitting write urb, error %d", __func__, retval); goto error_unanchor; goto error_unanchor; } } /* release our reference to this urb, the USB core will eventually free it entirely */ /* release our reference to this urb, the USB core will eventually free it entirely */ usb_free_urb(urb); usb_free_urb(urb); exit: exit: Loading Loading @@ -295,7 +309,8 @@ static struct usb_class_driver lcd_class = { .minor_base = USBLCD_MINOR, .minor_base = USBLCD_MINOR, }; }; static int lcd_probe(struct usb_interface *interface, const struct usb_device_id *id) static int lcd_probe(struct usb_interface *interface, const struct usb_device_id *id) { { struct usb_lcd *dev = NULL; struct usb_lcd *dev = NULL; struct usb_host_interface *iface_desc; struct usb_host_interface *iface_desc; Loading