aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/usb-skeleton.c
diff options
context:
space:
mode:
authorLuiz Fernando N. Capitulino <lcapitulino@mandriva.com.br>2006-08-14 21:44:29 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2006-09-27 14:58:54 -0400
commitc07045412f21c5bb344244e8ec45671529e411bd (patch)
tree2e4e988a86a112e73b8ad3de74d140809a75fa5c /drivers/usb/usb-skeleton.c
parentd5cbad4b8b37acfde3e63d31b92561b87288ad0f (diff)
usb-skeleton: small update
o CodingStyle fixes o Removes trailing spaces o Do not make not needed initialiation of automatic variables o Use usb_endpoint_* functions o If we get an error in the write URB callback print an error message instead of a debug one (Pretty unrelated changes, but spliting this up doesn't pay off as our main changes are just CodingStyle fixes). Signed-off-by: Luiz Fernando N. Capitulino <lcapitulino@mandriva.com.br> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/usb-skeleton.c')
-rw-r--r--drivers/usb/usb-skeleton.c50
1 files changed, 22 insertions, 28 deletions
diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c
index 3339373239ad..9b542a6ba978 100644
--- a/drivers/usb/usb-skeleton.c
+++ b/drivers/usb/usb-skeleton.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * USB Skeleton driver - 2.1 2 * USB Skeleton driver - 2.2
3 * 3 *
4 * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com) 4 * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com)
5 * 5 *
@@ -7,7 +7,7 @@
7 * modify it under the terms of the GNU General Public License as 7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2. 8 * published by the Free Software Foundation, version 2.
9 * 9 *
10 * This driver is based on the 2.6.3 version of drivers/usb/usb-skeleton.c 10 * This driver is based on the 2.6.3 version of drivers/usb/usb-skeleton.c
11 * but has been rewritten to be easier to read and use. 11 * but has been rewritten to be easier to read and use.
12 * 12 *
13 */ 13 */
@@ -32,22 +32,22 @@ static struct usb_device_id skel_table [] = {
32 { USB_DEVICE(USB_SKEL_VENDOR_ID, USB_SKEL_PRODUCT_ID) }, 32 { USB_DEVICE(USB_SKEL_VENDOR_ID, USB_SKEL_PRODUCT_ID) },
33 { } /* Terminating entry */ 33 { } /* Terminating entry */
34}; 34};
35MODULE_DEVICE_TABLE (usb, skel_table); 35MODULE_DEVICE_TABLE(usb, skel_table);
36 36
37 37
38/* Get a minor range for your devices from the usb maintainer */ 38/* Get a minor range for your devices from the usb maintainer */
39#define USB_SKEL_MINOR_BASE 192 39#define USB_SKEL_MINOR_BASE 192
40 40
41/* our private defines. if this grows any larger, use your own .h file */ 41/* our private defines. if this grows any larger, use your own .h file */
42#define MAX_TRANSFER ( PAGE_SIZE - 512 ) 42#define MAX_TRANSFER (PAGE_SIZE - 512)
43#define WRITES_IN_FLIGHT 8 43#define WRITES_IN_FLIGHT 8
44 44
45/* Structure to hold all of our device specific stuff */ 45/* Structure to hold all of our device specific stuff */
46struct usb_skel { 46struct usb_skel {
47 struct usb_device * udev; /* the usb device for this device */ 47 struct usb_device *dev; /* the usb device for this device */
48 struct usb_interface * interface; /* the interface for this device */ 48 struct usb_interface *interface; /* the interface for this device */
49 struct semaphore limit_sem; /* limiting the number of writes in progress */ 49 struct semaphore limit_sem; /* limiting the number of writes in progress */
50 unsigned char * bulk_in_buffer; /* the buffer to receive data */ 50 unsigned char *bulk_in_buffer; /* the buffer to receive data */
51 size_t bulk_in_size; /* the size of the receive buffer */ 51 size_t bulk_in_size; /* the size of the receive buffer */
52 __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */ 52 __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */
53 __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */ 53 __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */
@@ -59,12 +59,12 @@ struct usb_skel {
59static struct usb_driver skel_driver; 59static struct usb_driver skel_driver;
60 60
61static void skel_delete(struct kref *kref) 61static void skel_delete(struct kref *kref)
62{ 62{
63 struct usb_skel *dev = to_skel_dev(kref); 63 struct usb_skel *dev = to_skel_dev(kref);
64 64
65 usb_put_dev(dev->udev); 65 usb_put_dev(dev->udev);
66 kfree (dev->bulk_in_buffer); 66 kfree(dev->bulk_in_buffer);
67 kfree (dev); 67 kfree(dev);
68} 68}
69 69
70static int skel_open(struct inode *inode, struct file *file) 70static int skel_open(struct inode *inode, struct file *file)
@@ -116,7 +116,7 @@ static int skel_release(struct inode *inode, struct file *file)
116static ssize_t skel_read(struct file *file, char *buffer, size_t count, loff_t *ppos) 116static ssize_t skel_read(struct file *file, char *buffer, size_t count, loff_t *ppos)
117{ 117{
118 struct usb_skel *dev; 118 struct usb_skel *dev;
119 int retval = 0; 119 int retval;
120 int bytes_read; 120 int bytes_read;
121 121
122 dev = (struct usb_skel *)file->private_data; 122 dev = (struct usb_skel *)file->private_data;
@@ -154,16 +154,16 @@ static void skel_write_bulk_callback(struct urb *urb, struct pt_regs *regs)
154 dev = (struct usb_skel *)urb->context; 154 dev = (struct usb_skel *)urb->context;
155 155
156 /* sync/async unlink faults aren't errors */ 156 /* sync/async unlink faults aren't errors */
157 if (urb->status && 157 if (urb->status &&
158 !(urb->status == -ENOENT || 158 !(urb->status == -ENOENT ||
159 urb->status == -ECONNRESET || 159 urb->status == -ECONNRESET ||
160 urb->status == -ESHUTDOWN)) { 160 urb->status == -ESHUTDOWN)) {
161 dbg("%s - nonzero write bulk status received: %d", 161 err("%s - nonzero write bulk status received: %d",
162 __FUNCTION__, urb->status); 162 __FUNCTION__, urb->status);
163 } 163 }
164 164
165 /* free up our allocated buffer */ 165 /* free up our allocated buffer */
166 usb_buffer_free(urb->dev, urb->transfer_buffer_length, 166 usb_buffer_free(urb->dev, urb->transfer_buffer_length,
167 urb->transfer_buffer, urb->transfer_dma); 167 urb->transfer_buffer, urb->transfer_dma);
168 up(&dev->limit_sem); 168 up(&dev->limit_sem);
169} 169}
@@ -251,7 +251,7 @@ static const struct file_operations skel_fops = {
251 .release = skel_release, 251 .release = skel_release,
252}; 252};
253 253
254/* 254/*
255 * usb class driver info in order to get a minor number from the usb core, 255 * usb class driver info in order to get a minor number from the usb core,
256 * and to have the device registered with the driver core 256 * and to have the device registered with the driver core
257 */ 257 */
@@ -263,7 +263,7 @@ static struct usb_class_driver skel_class = {
263 263
264static int skel_probe(struct usb_interface *interface, const struct usb_device_id *id) 264static int skel_probe(struct usb_interface *interface, const struct usb_device_id *id)
265{ 265{
266 struct usb_skel *dev = NULL; 266 struct usb_skel *dev;
267 struct usb_host_interface *iface_desc; 267 struct usb_host_interface *iface_desc;
268 struct usb_endpoint_descriptor *endpoint; 268 struct usb_endpoint_descriptor *endpoint;
269 size_t buffer_size; 269 size_t buffer_size;
@@ -272,7 +272,7 @@ static int skel_probe(struct usb_interface *interface, const struct usb_device_i
272 272
273 /* allocate memory for our device state and initialize it */ 273 /* allocate memory for our device state and initialize it */
274 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 274 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
275 if (dev == NULL) { 275 if (!dev) {
276 err("Out of memory"); 276 err("Out of memory");
277 goto error; 277 goto error;
278 } 278 }
@@ -290,10 +290,7 @@ static int skel_probe(struct usb_interface *interface, const struct usb_device_i
290 endpoint = &iface_desc->endpoint[i].desc; 290 endpoint = &iface_desc->endpoint[i].desc;
291 291
292 if (!dev->bulk_in_endpointAddr && 292 if (!dev->bulk_in_endpointAddr &&
293 ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) 293 usb_endpoint_is_bulk_in(endpoint)) {
294 == USB_DIR_IN) &&
295 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
296 == USB_ENDPOINT_XFER_BULK)) {
297 /* we found a bulk in endpoint */ 294 /* we found a bulk in endpoint */
298 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 295 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
299 dev->bulk_in_size = buffer_size; 296 dev->bulk_in_size = buffer_size;
@@ -306,10 +303,7 @@ static int skel_probe(struct usb_interface *interface, const struct usb_device_i
306 } 303 }
307 304
308 if (!dev->bulk_out_endpointAddr && 305 if (!dev->bulk_out_endpointAddr &&
309 ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) 306 usb_endpoint_is_bulk_out(endpoint)) {
310 == USB_DIR_OUT) &&
311 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
312 == USB_ENDPOINT_XFER_BULK)) {
313 /* we found a bulk out endpoint */ 307 /* we found a bulk out endpoint */
314 dev->bulk_out_endpointAddr = endpoint->bEndpointAddress; 308 dev->bulk_out_endpointAddr = endpoint->bEndpointAddress;
315 } 309 }
@@ -393,7 +387,7 @@ static void __exit usb_skel_exit(void)
393 usb_deregister(&skel_driver); 387 usb_deregister(&skel_driver);
394} 388}
395 389
396module_init (usb_skel_init); 390module_init(usb_skel_init);
397module_exit (usb_skel_exit); 391module_exit(usb_skel_exit);
398 392
399MODULE_LICENSE("GPL"); 393MODULE_LICENSE("GPL");