Commit 507a3ea7 authored by Zack Parsons's avatar Zack Parsons Committed by Greg Kroah-Hartman

usb: misc: usblcd: fixed coding style issues

Fixed multiple coding style issues
Signed-off-by: default avatarZack Parsons <k3bacon@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent ea835863
...@@ -18,7 +18,7 @@ ...@@ -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"
...@@ -34,22 +34,29 @@ static const struct usb_device_id id_table[] = { ...@@ -34,22 +34,29 @@ static const struct usb_device_id id_table[] = {
{ .idVendor = 0x10D2, .match_flags = USB_DEVICE_ID_MATCH_VENDOR, }, { .idVendor = 0x10D2, .match_flags = USB_DEVICE_ID_MATCH_VENDOR, },
{ }, { },
}; };
MODULE_DEVICE_TABLE (usb, id_table); MODULE_DEVICE_TABLE(usb, id_table);
static DEFINE_MUTEX(open_disc_mutex); 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)
...@@ -63,8 +70,8 @@ static void lcd_delete(struct kref *kref) ...@@ -63,8 +70,8 @@ static void lcd_delete(struct kref *kref)
struct usb_lcd *dev = to_lcd_dev(kref); struct usb_lcd *dev = to_lcd_dev(kref);
usb_put_dev(dev->udev); usb_put_dev(dev->udev);
kfree (dev->bulk_in_buffer); kfree(dev->bulk_in_buffer);
kfree (dev); kfree(dev);
} }
...@@ -80,7 +87,7 @@ static int lcd_open(struct inode *inode, struct file *file) ...@@ -80,7 +87,7 @@ static int lcd_open(struct inode *inode, struct file *file)
interface = usb_find_interface(&lcd_driver, subminor); interface = usb_find_interface(&lcd_driver, subminor);
if (!interface) { if (!interface) {
mutex_unlock(&lcd_mutex); mutex_unlock(&lcd_mutex);
err ("USBLCD: %s - error, can't find device for minor %d", err("USBLCD: %s - error, can't find device for minor %d",
__func__, subminor); __func__, subminor);
return -ENODEV; return -ENODEV;
} }
...@@ -126,7 +133,8 @@ static int lcd_release(struct inode *inode, struct file *file) ...@@ -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;
...@@ -135,8 +143,9 @@ static ssize_t lcd_read(struct file *file, char __user * buffer, size_t count, l ...@@ -135,8 +143,9 @@ static ssize_t lcd_read(struct file *file, char __user * buffer, size_t count, l
dev = file->private_data; dev = file->private_data;
/* 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);
...@@ -161,23 +170,23 @@ static long lcd_ioctl(struct file *file, unsigned int cmd, unsigned long arg) ...@@ -161,23 +170,23 @@ static long lcd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
dev = file->private_data; dev = file->private_data;
if (dev == NULL) if (dev == NULL)
return -ENODEV; return -ENODEV;
switch (cmd) { switch (cmd) {
case IOCTL_GET_HARD_VERSION: case IOCTL_GET_HARD_VERSION:
mutex_lock(&lcd_mutex); mutex_lock(&lcd_mutex);
bcdDevice = le16_to_cpu((dev->udev)->descriptor.bcdDevice); bcdDevice = le16_to_cpu((dev->udev)->descriptor.bcdDevice);
sprintf(buf,"%1d%1d.%1d%1d", sprintf(buf, "%1d%1d.%1d%1d",
(bcdDevice & 0xF000)>>12, (bcdDevice & 0xF000)>>12,
(bcdDevice & 0xF00)>>8, (bcdDevice & 0xF00)>>8,
(bcdDevice & 0xF0)>>4, (bcdDevice & 0xF0)>>4,
(bcdDevice & 0xF)); (bcdDevice & 0xF));
mutex_unlock(&lcd_mutex); mutex_unlock(&lcd_mutex);
if (copy_to_user((void __user *)arg,buf,strlen(buf))!=0) if (copy_to_user((void __user *)arg, buf, strlen(buf)) != 0)
return -EFAULT; return -EFAULT;
break; break;
case IOCTL_GET_DRV_VERSION: case IOCTL_GET_DRV_VERSION:
sprintf(buf,DRIVER_VERSION); sprintf(buf, DRIVER_VERSION);
if (copy_to_user((void __user *)arg,buf,strlen(buf))!=0) if (copy_to_user((void __user *)arg, buf, strlen(buf)) != 0)
return -EFAULT; return -EFAULT;
break; break;
default: default:
...@@ -199,7 +208,7 @@ static void lcd_write_bulk_callback(struct urb *urb) ...@@ -199,7 +208,7 @@ static void lcd_write_bulk_callback(struct urb *urb)
if (status && if (status &&
!(status == -ENOENT || !(status == -ENOENT ||
status == -ECONNRESET || status == -ECONNRESET ||
status == -ESHUTDOWN)) { status == -ESHUTDOWN)) {
dbg("USBLCD: %s - nonzero write bulk status received: %d", dbg("USBLCD: %s - nonzero write bulk status received: %d",
__func__, status); __func__, status);
} }
...@@ -210,15 +219,16 @@ static void lcd_write_bulk_callback(struct urb *urb) ...@@ -210,15 +219,16 @@ 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;
struct urb *urb = NULL; struct urb *urb = NULL;
char *buf = NULL; char *buf = NULL;
dev = file->private_data; dev = file->private_data;
/* verify that we actually have some data to write */ /* verify that we actually have some data to write */
if (count == 0) if (count == 0)
goto exit; goto exit;
...@@ -233,34 +243,38 @@ static ssize_t lcd_write(struct file *file, const char __user * user_buffer, siz ...@@ -233,34 +243,38 @@ static ssize_t lcd_write(struct file *file, const char __user * user_buffer, siz
retval = -ENOMEM; retval = -ENOMEM;
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;
} }
if (copy_from_user(buf, user_buffer, count)) { if (copy_from_user(buf, user_buffer, count)) {
retval = -EFAULT; retval = -EFAULT;
goto error; goto error;
} }
/* 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;
usb_anchor_urb(urb, &dev->submitted); usb_anchor_urb(urb, &dev->submitted);
/* 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:
...@@ -276,13 +290,13 @@ static ssize_t lcd_write(struct file *file, const char __user * user_buffer, siz ...@@ -276,13 +290,13 @@ static ssize_t lcd_write(struct file *file, const char __user * user_buffer, siz
} }
static const struct file_operations lcd_fops = { static const struct file_operations lcd_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.read = lcd_read, .read = lcd_read,
.write = lcd_write, .write = lcd_write,
.open = lcd_open, .open = lcd_open,
.unlocked_ioctl = lcd_ioctl, .unlocked_ioctl = lcd_ioctl,
.release = lcd_release, .release = lcd_release,
.llseek = noop_llseek, .llseek = noop_llseek,
}; };
/* /*
...@@ -290,12 +304,13 @@ static const struct file_operations lcd_fops = { ...@@ -290,12 +304,13 @@ static const struct file_operations lcd_fops = {
* and to have the device registered with the driver core * and to have the device registered with the driver core
*/ */
static struct usb_class_driver lcd_class = { static struct usb_class_driver lcd_class = {
.name = "lcd%d", .name = "lcd%d",
.fops = &lcd_fops, .fops = &lcd_fops,
.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;
...@@ -322,7 +337,7 @@ static int lcd_probe(struct usb_interface *interface, const struct usb_device_id ...@@ -322,7 +337,7 @@ static int lcd_probe(struct usb_interface *interface, const struct usb_device_id
retval = -ENODEV; retval = -ENODEV;
goto error; goto error;
} }
/* set up the endpoint information */ /* set up the endpoint information */
/* use only the first bulk-in and bulk-out endpoints */ /* use only the first bulk-in and bulk-out endpoints */
iface_desc = interface->cur_altsetting; iface_desc = interface->cur_altsetting;
...@@ -369,7 +384,7 @@ static int lcd_probe(struct usb_interface *interface, const struct usb_device_id ...@@ -369,7 +384,7 @@ static int lcd_probe(struct usb_interface *interface, const struct usb_device_id
dev_info(&interface->dev, "USBLCD Version %1d%1d.%1d%1d found " dev_info(&interface->dev, "USBLCD Version %1d%1d.%1d%1d found "
"at address %d\n", (i & 0xF000)>>12, (i & 0xF00)>>8, "at address %d\n", (i & 0xF000)>>12, (i & 0xF00)>>8,
(i & 0xF0)>>4,(i & 0xF), dev->udev->devnum); (i & 0xF0)>>4, (i & 0xF), dev->udev->devnum);
/* let the user know what node this device is now attached to */ /* let the user know what node this device is now attached to */
dev_info(&interface->dev, "USB LCD device now attached to USBLCD-%d\n", dev_info(&interface->dev, "USB LCD device now attached to USBLCD-%d\n",
...@@ -401,7 +416,7 @@ static int lcd_suspend(struct usb_interface *intf, pm_message_t message) ...@@ -401,7 +416,7 @@ static int lcd_suspend(struct usb_interface *intf, pm_message_t message)
return 0; return 0;
} }
static int lcd_resume (struct usb_interface *intf) static int lcd_resume(struct usb_interface *intf)
{ {
return 0; return 0;
} }
...@@ -409,16 +424,16 @@ static int lcd_resume (struct usb_interface *intf) ...@@ -409,16 +424,16 @@ static int lcd_resume (struct usb_interface *intf)
static void lcd_disconnect(struct usb_interface *interface) static void lcd_disconnect(struct usb_interface *interface)
{ {
struct usb_lcd *dev; struct usb_lcd *dev;
int minor = interface->minor; int minor = interface->minor;
mutex_lock(&open_disc_mutex); mutex_lock(&open_disc_mutex);
dev = usb_get_intfdata(interface); dev = usb_get_intfdata(interface);
usb_set_intfdata(interface, NULL); usb_set_intfdata(interface, NULL);
mutex_unlock(&open_disc_mutex); mutex_unlock(&open_disc_mutex);
/* give back our minor */ /* give back our minor */
usb_deregister_dev(interface, &lcd_class); usb_deregister_dev(interface, &lcd_class);
/* decrement our usage count */ /* decrement our usage count */
kref_put(&dev->kref, lcd_delete); kref_put(&dev->kref, lcd_delete);
...@@ -438,7 +453,7 @@ static struct usb_driver lcd_driver = { ...@@ -438,7 +453,7 @@ static struct usb_driver lcd_driver = {
static int __init usb_lcd_init(void) static int __init usb_lcd_init(void)
{ {
int result; int result;
result = usb_register(&lcd_driver); result = usb_register(&lcd_driver);
if (result) if (result)
err("usb_register failed. Error number %d", result); err("usb_register failed. Error number %d", result);
......
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