Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] USB Storage: code cleanups for onetouch.c

As sugested by Alan Stern here are a few code cleanups for onetouch.c:

-Check number of endpoints before directly referencing intf->endpoint[2]
-Use defined constants instead of magic numbers
-Revmove the non-ascii characters from copyright notice
-Make registration and deregistration messages more similar

Signed-off-by: Nick Sillik <n.sillik@temple.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Nick Sillik and committed by
Greg Kroah-Hartman
d6450e19 02568396

+18 -13
+18 -13
drivers/usb/storage/onetouch.c
··· 5 5 * Copyright (c) 2005 Nick Sillik <n.sillik@temple.edu> 6 6 * 7 7 * Initial work by: 8 - * Copyright (c) 2003 Erik Thyrén <erth7411@student.uu.se> 8 + * Copyright (c) 2003 Erik Thyren <erth7411@student.uu.se> 9 9 * 10 10 * Based on usbmouse.c (Vojtech Pavlik) and xpad.c (Marko Friedemann) 11 11 * ··· 35 35 #include <linux/slab.h> 36 36 #include <linux/module.h> 37 37 #include <linux/usb.h> 38 + #include <linux/usb_ch9.h> 39 + #include <linux/usb_input.h> 38 40 #include "usb.h" 39 41 #include "onetouch.h" 40 42 #include "debug.h" ··· 118 116 119 117 interface = ss->pusb_intf->cur_altsetting; 120 118 121 - endpoint = &interface->endpoint[2].desc; 122 - if(!(endpoint->bEndpointAddress & 0x80)) 119 + if (interface->desc.bNumEndpoints != 3) 123 120 return -ENODEV; 124 - if((endpoint->bmAttributes & 3) != 3) 121 + 122 + endpoint = &interface->endpoint[2].desc; 123 + if(!(endpoint->bEndpointAddress & USB_DIR_IN)) 124 + return -ENODEV; 125 + if((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) 126 + != USB_ENDPOINT_XFER_INT) 125 127 return -ENODEV; 126 128 127 129 pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress); ··· 134 128 if (!(onetouch = kcalloc(1, sizeof(struct usb_onetouch), GFP_KERNEL))) 135 129 return -ENOMEM; 136 130 137 - onetouch->data = usb_buffer_alloc(udev, ONETOUCH_PKT_LEN, SLAB_ATOMIC, &onetouch->data_dma); 131 + onetouch->data = usb_buffer_alloc(udev, ONETOUCH_PKT_LEN, 132 + SLAB_ATOMIC, &onetouch->data_dma); 138 133 if (!onetouch->data){ 139 134 kfree(onetouch); 140 135 return -ENOMEM; ··· 144 137 onetouch->irq = usb_alloc_urb(0, GFP_KERNEL); 145 138 if (!onetouch->irq){ 146 139 kfree(onetouch); 147 - usb_buffer_free(udev, ONETOUCH_PKT_LEN, onetouch->data, onetouch->data_dma); 140 + usb_buffer_free(udev, ONETOUCH_PKT_LEN, 141 + onetouch->data, onetouch->data_dma); 148 142 return -ENODEV; 149 143 } 150 144 ··· 160 152 onetouch->dev.open = usb_onetouch_open; 161 153 onetouch->dev.close = usb_onetouch_close; 162 154 163 - usb_make_path(udev, path, 64); 155 + usb_make_path(udev, path, sizeof(path)); 164 156 sprintf(onetouch->phys, "%s/input0", path); 165 157 166 158 onetouch->dev.name = onetouch->name; 167 159 onetouch->dev.phys = onetouch->phys; 168 160 169 - onetouch->dev.id.bustype = BUS_USB; 170 - onetouch->dev.id.vendor = le16_to_cpu(udev->descriptor.idVendor); 171 - onetouch->dev.id.product = le16_to_cpu(udev->descriptor.idProduct); 172 - onetouch->dev.id.version = le16_to_cpu(udev->descriptor.bcdDevice); 161 + usb_to_input_id(udev, &onetouch->dev.id); 173 162 174 163 onetouch->dev.dev = &udev->dev; 175 164 ··· 204 199 usb_free_urb(onetouch->irq); 205 200 usb_buffer_free(onetouch->udev, ONETOUCH_PKT_LEN, 206 201 onetouch->data, onetouch->data_dma); 207 - printk(KERN_INFO "Maxtor Onetouch %04x:%04x Deregistered\n", 208 - onetouch->dev.id.vendor, onetouch->dev.id.product); 202 + printk(KERN_INFO "usb-input: deregistering %s\n", 203 + onetouch->dev.name); 209 204 } 210 205 }