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

[PATCH] drivers/usb/input: convert to dynamic input_dev allocation

Input: convert drivers/iusb/input to dynamic input_dev allocation

This is required for input_dev sysfs integration

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Dmitry Torokhov and committed by
Greg Kroah-Hartman
c5b7c7c3 3c42f0c3

+988 -1029
+39 -37
drivers/usb/input/acecad.c
··· 53 53 char name[128]; 54 54 char phys[64]; 55 55 struct usb_device *usbdev; 56 - struct input_dev dev; 56 + struct input_dev *input; 57 57 struct urb *irq; 58 58 59 59 signed char *data; ··· 64 64 { 65 65 struct usb_acecad *acecad = urb->context; 66 66 unsigned char *data = acecad->data; 67 - struct input_dev *dev = &acecad->dev; 67 + struct input_dev *dev = acecad->input; 68 68 int prox, status; 69 69 70 70 switch (urb->status) { ··· 135 135 struct usb_host_interface *interface = intf->cur_altsetting; 136 136 struct usb_endpoint_descriptor *endpoint; 137 137 struct usb_acecad *acecad; 138 + struct input_dev *input_dev; 138 139 int pipe, maxp; 139 - char path[64]; 140 140 141 141 if (interface->desc.bNumEndpoints != 1) 142 142 return -ENODEV; ··· 153 153 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe)); 154 154 155 155 acecad = kzalloc(sizeof(struct usb_acecad), GFP_KERNEL); 156 - if (!acecad) 157 - return -ENOMEM; 156 + input_dev = input_allocate_device(); 157 + if (!acecad || !input_dev) 158 + goto fail1; 158 159 159 160 acecad->data = usb_buffer_alloc(dev, 8, SLAB_KERNEL, &acecad->data_dma); 160 161 if (!acecad->data) ··· 164 163 acecad->irq = usb_alloc_urb(0, GFP_KERNEL); 165 164 if (!acecad->irq) 166 165 goto fail2; 166 + 167 + acecad->usbdev = dev; 168 + acecad->input = input_dev; 167 169 168 170 if (dev->manufacturer) 169 171 strlcpy(acecad->name, dev->manufacturer, sizeof(acecad->name)); ··· 177 173 strlcat(acecad->name, dev->product, sizeof(acecad->name)); 178 174 } 179 175 180 - usb_make_path(dev, path, sizeof(path)); 181 - snprintf(acecad->phys, sizeof(acecad->phys), "%s/input0", path); 176 + usb_make_path(dev, acecad->phys, sizeof(acecad->phys)); 177 + strlcat(acecad->phys, "/input0", sizeof(acecad->phys)); 182 178 183 - acecad->usbdev = dev; 179 + input_dev->name = acecad->name; 180 + input_dev->phys = acecad->phys; 181 + usb_to_input_id(dev, &input_dev->id); 182 + input_dev->cdev.dev = &intf->dev; 183 + input_dev->private = acecad; 184 184 185 - acecad->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 186 - acecad->dev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE); 187 - acecad->dev.keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE); 188 - acecad->dev.keybit[LONG(BTN_DIGI)] = BIT(BTN_TOOL_PEN) |BIT(BTN_TOUCH) | BIT(BTN_STYLUS) | BIT(BTN_STYLUS2); 185 + input_dev->open = usb_acecad_open; 186 + input_dev->close = usb_acecad_close; 187 + 188 + input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 189 + input_dev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE); 190 + input_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE); 191 + input_dev->keybit[LONG(BTN_DIGI)] = BIT(BTN_TOOL_PEN) |BIT(BTN_TOUCH) | BIT(BTN_STYLUS) | BIT(BTN_STYLUS2); 189 192 190 193 switch (id->driver_info) { 191 194 case 0: 192 - acecad->dev.absmax[ABS_X] = 5000; 193 - acecad->dev.absmax[ABS_Y] = 3750; 194 - acecad->dev.absmax[ABS_PRESSURE] = 512; 195 + input_dev->absmax[ABS_X] = 5000; 196 + input_dev->absmax[ABS_Y] = 3750; 197 + input_dev->absmax[ABS_PRESSURE] = 512; 195 198 if (!strlen(acecad->name)) 196 199 snprintf(acecad->name, sizeof(acecad->name), 197 200 "USB Acecad Flair Tablet %04x:%04x", 198 - dev->descriptor.idVendor, dev->descriptor.idProduct); 201 + le16_to_cpu(dev->descriptor.idVendor), 202 + le16_to_cpu(dev->descriptor.idProduct)); 199 203 break; 200 204 case 1: 201 - acecad->dev.absmax[ABS_X] = 3000; 202 - acecad->dev.absmax[ABS_Y] = 2250; 203 - acecad->dev.absmax[ABS_PRESSURE] = 1024; 205 + input_dev->absmax[ABS_X] = 3000; 206 + input_dev->absmax[ABS_Y] = 2250; 207 + input_dev->absmax[ABS_PRESSURE] = 1024; 204 208 if (!strlen(acecad->name)) 205 209 snprintf(acecad->name, sizeof(acecad->name), 206 210 "USB Acecad 302 Tablet %04x:%04x", 207 - dev->descriptor.idVendor, dev->descriptor.idProduct); 211 + le16_to_cpu(dev->descriptor.idVendor), 212 + le16_to_cpu(dev->descriptor.idProduct)); 208 213 break; 209 214 } 210 215 211 - acecad->dev.absfuzz[ABS_X] = 4; 212 - acecad->dev.absfuzz[ABS_Y] = 4; 213 - 214 - acecad->dev.private = acecad; 215 - acecad->dev.open = usb_acecad_open; 216 - acecad->dev.close = usb_acecad_close; 217 - 218 - acecad->dev.name = acecad->name; 219 - acecad->dev.phys = acecad->phys; 220 - usb_to_input_id(dev, &acecad->dev.id); 221 - acecad->dev.dev = &intf->dev; 216 + input_dev->absfuzz[ABS_X] = 4; 217 + input_dev->absfuzz[ABS_Y] = 4; 222 218 223 219 usb_fill_int_urb(acecad->irq, dev, pipe, 224 220 acecad->data, maxp > 8 ? 8 : maxp, ··· 226 222 acecad->irq->transfer_dma = acecad->data_dma; 227 223 acecad->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 228 224 229 - input_register_device(&acecad->dev); 230 - 231 - printk(KERN_INFO "input: %s with packet size %d on %s\n", 232 - acecad->name, maxp, path); 225 + input_register_device(acecad->input); 233 226 234 227 usb_set_intfdata(intf, acecad); 235 228 236 229 return 0; 237 230 238 231 fail2: usb_buffer_free(dev, 8, acecad->data, acecad->data_dma); 239 - fail1: kfree(acecad); 232 + fail1: input_free_device(input_dev); 233 + kfree(acecad); 240 234 return -ENOMEM; 241 235 } 242 236 ··· 245 243 usb_set_intfdata(intf, NULL); 246 244 if (acecad) { 247 245 usb_kill_urb(acecad->irq); 248 - input_unregister_device(&acecad->dev); 246 + input_unregister_device(acecad->input); 249 247 usb_free_urb(acecad->irq); 250 248 usb_buffer_free(interface_to_usbdev(intf), 10, acecad->data, acecad->data_dma); 251 249 kfree(acecad);
+93 -116
drivers/usb/input/aiptek.c
··· 317 317 }; 318 318 319 319 struct aiptek { 320 - struct input_dev inputdev; /* input device struct */ 320 + struct input_dev *inputdev; /* input device struct */ 321 321 struct usb_device *usbdev; /* usb device struct */ 322 322 struct urb *urb; /* urb for incoming reports */ 323 323 dma_addr_t data_dma; /* our dma stuffage */ ··· 402 402 { 403 403 struct aiptek *aiptek = urb->context; 404 404 unsigned char *data = aiptek->data; 405 - struct input_dev *inputdev = &aiptek->inputdev; 405 + struct input_dev *inputdev = aiptek->inputdev; 406 406 int jitterable = 0; 407 407 int retval, macro, x, y, z, left, right, middle, p, dv, tip, bs, pck; 408 408 ··· 955 955 /* Query getXextension */ 956 956 if ((ret = aiptek_query(aiptek, 0x01, 0x00)) < 0) 957 957 return ret; 958 - aiptek->inputdev.absmin[ABS_X] = 0; 959 - aiptek->inputdev.absmax[ABS_X] = ret - 1; 958 + aiptek->inputdev->absmin[ABS_X] = 0; 959 + aiptek->inputdev->absmax[ABS_X] = ret - 1; 960 960 961 961 /* Query getYextension */ 962 962 if ((ret = aiptek_query(aiptek, 0x01, 0x01)) < 0) 963 963 return ret; 964 - aiptek->inputdev.absmin[ABS_Y] = 0; 965 - aiptek->inputdev.absmax[ABS_Y] = ret - 1; 964 + aiptek->inputdev->absmin[ABS_Y] = 0; 965 + aiptek->inputdev->absmax[ABS_Y] = ret - 1; 966 966 967 967 /* Query getPressureLevels */ 968 968 if ((ret = aiptek_query(aiptek, 0x08, 0x00)) < 0) 969 969 return ret; 970 - aiptek->inputdev.absmin[ABS_PRESSURE] = 0; 971 - aiptek->inputdev.absmax[ABS_PRESSURE] = ret - 1; 970 + aiptek->inputdev->absmin[ABS_PRESSURE] = 0; 971 + aiptek->inputdev->absmax[ABS_PRESSURE] = ret - 1; 972 972 973 973 /* Depending on whether we are in absolute or relative mode, we will 974 974 * do a switchToTablet(absolute) or switchToMouse(relative) command. ··· 1025 1025 return 0; 1026 1026 1027 1027 return snprintf(buf, PAGE_SIZE, "%dx%d\n", 1028 - aiptek->inputdev.absmax[ABS_X] + 1, 1029 - aiptek->inputdev.absmax[ABS_Y] + 1); 1028 + aiptek->inputdev->absmax[ABS_X] + 1, 1029 + aiptek->inputdev->absmax[ABS_Y] + 1); 1030 1030 } 1031 1031 1032 1032 /* These structs define the sysfs files, param #1 is the name of the ··· 1048 1048 return 0; 1049 1049 1050 1050 return snprintf(buf, PAGE_SIZE, "0x%04x\n", 1051 - aiptek->inputdev.id.product); 1051 + aiptek->inputdev->id.product); 1052 1052 } 1053 1053 1054 1054 static DEVICE_ATTR(product_id, S_IRUGO, show_tabletProductId, NULL); ··· 1063 1063 if (aiptek == NULL) 1064 1064 return 0; 1065 1065 1066 - return snprintf(buf, PAGE_SIZE, "0x%04x\n", aiptek->inputdev.id.vendor); 1066 + return snprintf(buf, PAGE_SIZE, "0x%04x\n", aiptek->inputdev->id.vendor); 1067 1067 } 1068 1068 1069 1069 static DEVICE_ATTR(vendor_id, S_IRUGO, show_tabletVendorId, NULL); ··· 1977 1977 struct input_dev *inputdev; 1978 1978 struct input_handle *inputhandle; 1979 1979 struct list_head *node, *next; 1980 - char path[64 + 1]; 1981 1980 int i; 1982 1981 int speeds[] = { 0, 1983 1982 AIPTEK_PROGRAMMABLE_DELAY_50, ··· 1995 1996 */ 1996 1997 speeds[0] = programmableDelay; 1997 1998 1998 - if ((aiptek = kmalloc(sizeof(struct aiptek), GFP_KERNEL)) == NULL) 1999 - return -ENOMEM; 2000 - memset(aiptek, 0, sizeof(struct aiptek)); 1999 + aiptek = kzalloc(sizeof(struct aiptek), GFP_KERNEL); 2000 + inputdev = input_allocate_device(); 2001 + if (!aiptek || !inputdev) 2002 + goto fail1; 2001 2003 2002 2004 aiptek->data = usb_buffer_alloc(usbdev, AIPTEK_PACKET_LENGTH, 2003 2005 SLAB_ATOMIC, &aiptek->data_dma); 2004 - if (aiptek->data == NULL) { 2005 - kfree(aiptek); 2006 - return -ENOMEM; 2007 - } 2006 + if (!aiptek->data) 2007 + goto fail1; 2008 2008 2009 2009 aiptek->urb = usb_alloc_urb(0, GFP_KERNEL); 2010 - if (aiptek->urb == NULL) { 2011 - usb_buffer_free(usbdev, AIPTEK_PACKET_LENGTH, aiptek->data, 2012 - aiptek->data_dma); 2013 - kfree(aiptek); 2014 - return -ENOMEM; 2015 - } 2010 + if (!aiptek->urb) 2011 + goto fail2; 2012 + 2013 + aiptek->inputdev = inputdev; 2014 + aiptek->usbdev = usbdev; 2015 + aiptek->ifnum = intf->altsetting[0].desc.bInterfaceNumber; 2016 + aiptek->inDelay = 0; 2017 + aiptek->endDelay = 0; 2018 + aiptek->previousJitterable = 0; 2016 2019 2017 2020 /* Set up the curSettings struct. Said struct contains the current 2018 2021 * programmable parameters. The newSetting struct contains changes ··· 2037 2036 2038 2037 /* Both structs should have equivalent settings 2039 2038 */ 2040 - memcpy(&aiptek->newSetting, &aiptek->curSetting, 2041 - sizeof(struct aiptek_settings)); 2039 + aiptek->newSetting = aiptek->curSetting; 2040 + 2041 + /* Determine the usb devices' physical path. 2042 + * Asketh not why we always pretend we're using "../input0", 2043 + * but I suspect this will have to be refactored one 2044 + * day if a single USB device can be a keyboard & a mouse 2045 + * & a tablet, and the inputX number actually will tell 2046 + * us something... 2047 + */ 2048 + usb_make_path(usbdev, aiptek->features.usbPath, 2049 + sizeof(aiptek->features.usbPath)); 2050 + strlcat(aiptek->features.usbPath, "/input0", 2051 + sizeof(aiptek->features.usbPath)); 2052 + 2053 + /* Set up client data, pointers to open and close routines 2054 + * for the input device. 2055 + */ 2056 + inputdev->name = "Aiptek"; 2057 + inputdev->phys = aiptek->features.usbPath; 2058 + usb_to_input_id(usbdev, &inputdev->id); 2059 + inputdev->cdev.dev = &intf->dev; 2060 + inputdev->private = aiptek; 2061 + inputdev->open = aiptek_open; 2062 + inputdev->close = aiptek_close; 2042 2063 2043 2064 /* Now program the capacities of the tablet, in terms of being 2044 2065 * an input device. 2045 2066 */ 2046 - aiptek->inputdev.evbit[0] |= BIT(EV_KEY) 2067 + inputdev->evbit[0] |= BIT(EV_KEY) 2047 2068 | BIT(EV_ABS) 2048 2069 | BIT(EV_REL) 2049 2070 | BIT(EV_MSC); 2050 2071 2051 - aiptek->inputdev.absbit[0] |= 2052 - (BIT(ABS_X) | 2053 - BIT(ABS_Y) | 2054 - BIT(ABS_PRESSURE) | 2055 - BIT(ABS_TILT_X) | 2056 - BIT(ABS_TILT_Y) | BIT(ABS_WHEEL) | BIT(ABS_MISC)); 2072 + inputdev->absbit[0] |= BIT(ABS_MISC); 2057 2073 2058 - aiptek->inputdev.relbit[0] |= 2074 + inputdev->relbit[0] |= 2059 2075 (BIT(REL_X) | BIT(REL_Y) | BIT(REL_WHEEL) | BIT(REL_MISC)); 2060 2076 2061 - aiptek->inputdev.keybit[LONG(BTN_LEFT)] |= 2077 + inputdev->keybit[LONG(BTN_LEFT)] |= 2062 2078 (BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE)); 2063 2079 2064 - aiptek->inputdev.keybit[LONG(BTN_DIGI)] |= 2080 + inputdev->keybit[LONG(BTN_DIGI)] |= 2065 2081 (BIT(BTN_TOOL_PEN) | 2066 2082 BIT(BTN_TOOL_RUBBER) | 2067 2083 BIT(BTN_TOOL_PENCIL) | ··· 2088 2070 BIT(BTN_TOOL_LENS) | 2089 2071 BIT(BTN_TOUCH) | BIT(BTN_STYLUS) | BIT(BTN_STYLUS2)); 2090 2072 2091 - aiptek->inputdev.mscbit[0] = BIT(MSC_SERIAL); 2073 + inputdev->mscbit[0] = BIT(MSC_SERIAL); 2092 2074 2093 2075 /* Programming the tablet macro keys needs to be done with a for loop 2094 2076 * as the keycodes are discontiguous. 2095 2077 */ 2096 2078 for (i = 0; i < sizeof(macroKeyEvents) / sizeof(macroKeyEvents[0]); ++i) 2097 - set_bit(macroKeyEvents[i], aiptek->inputdev.keybit); 2079 + set_bit(macroKeyEvents[i], inputdev->keybit); 2098 2080 2099 - /* Set up client data, pointers to open and close routines 2100 - * for the input device. 2101 - */ 2102 - aiptek->inputdev.private = aiptek; 2103 - aiptek->inputdev.open = aiptek_open; 2104 - aiptek->inputdev.close = aiptek_close; 2105 - 2106 - /* Determine the usb devices' physical path. 2107 - * Asketh not why we always pretend we're using "../input0", 2108 - * but I suspect this will have to be refactored one 2109 - * day if a single USB device can be a keyboard & a mouse 2110 - * & a tablet, and the inputX number actually will tell 2111 - * us something... 2112 - */ 2113 - if (usb_make_path(usbdev, path, 64) > 0) 2114 - sprintf(aiptek->features.usbPath, "%s/input0", path); 2115 - 2116 - /* Program the input device coordinate capacities. We do not yet 2081 + /* 2082 + * Program the input device coordinate capacities. We do not yet 2117 2083 * know what maximum X, Y, and Z values are, so we're putting fake 2118 2084 * values in. Later, we'll ask the tablet to put in the correct 2119 2085 * values. 2120 2086 */ 2121 - aiptek->inputdev.absmin[ABS_X] = 0; 2122 - aiptek->inputdev.absmax[ABS_X] = 2999; 2123 - aiptek->inputdev.absmin[ABS_Y] = 0; 2124 - aiptek->inputdev.absmax[ABS_Y] = 2249; 2125 - aiptek->inputdev.absmin[ABS_PRESSURE] = 0; 2126 - aiptek->inputdev.absmax[ABS_PRESSURE] = 511; 2127 - aiptek->inputdev.absmin[ABS_TILT_X] = AIPTEK_TILT_MIN; 2128 - aiptek->inputdev.absmax[ABS_TILT_X] = AIPTEK_TILT_MAX; 2129 - aiptek->inputdev.absmin[ABS_TILT_Y] = AIPTEK_TILT_MIN; 2130 - aiptek->inputdev.absmax[ABS_TILT_Y] = AIPTEK_TILT_MAX; 2131 - aiptek->inputdev.absmin[ABS_WHEEL] = AIPTEK_WHEEL_MIN; 2132 - aiptek->inputdev.absmax[ABS_WHEEL] = AIPTEK_WHEEL_MAX - 1; 2133 - aiptek->inputdev.absfuzz[ABS_X] = 0; 2134 - aiptek->inputdev.absfuzz[ABS_Y] = 0; 2135 - aiptek->inputdev.absfuzz[ABS_PRESSURE] = 0; 2136 - aiptek->inputdev.absfuzz[ABS_TILT_X] = 0; 2137 - aiptek->inputdev.absfuzz[ABS_TILT_Y] = 0; 2138 - aiptek->inputdev.absfuzz[ABS_WHEEL] = 0; 2139 - aiptek->inputdev.absflat[ABS_X] = 0; 2140 - aiptek->inputdev.absflat[ABS_Y] = 0; 2141 - aiptek->inputdev.absflat[ABS_PRESSURE] = 0; 2142 - aiptek->inputdev.absflat[ABS_TILT_X] = 0; 2143 - aiptek->inputdev.absflat[ABS_TILT_Y] = 0; 2144 - aiptek->inputdev.absflat[ABS_WHEEL] = 0; 2145 - aiptek->inputdev.name = "Aiptek"; 2146 - aiptek->inputdev.phys = aiptek->features.usbPath; 2147 - usb_to_input_id(usbdev, &aiptek->inputdev.id); 2148 - aiptek->inputdev.dev = &intf->dev; 2149 - 2150 - aiptek->usbdev = usbdev; 2151 - aiptek->ifnum = intf->altsetting[0].desc.bInterfaceNumber; 2152 - aiptek->inDelay = 0; 2153 - aiptek->endDelay = 0; 2154 - aiptek->previousJitterable = 0; 2087 + input_set_abs_params(inputdev, ABS_X, 0, 2999, 0, 0); 2088 + input_set_abs_params(inputdev, ABS_X, 0, 2249, 0, 0); 2089 + input_set_abs_params(inputdev, ABS_PRESSURE, 0, 511, 0, 0); 2090 + input_set_abs_params(inputdev, ABS_TILT_X, AIPTEK_TILT_MIN, AIPTEK_TILT_MAX, 0, 0); 2091 + input_set_abs_params(inputdev, ABS_TILT_Y, AIPTEK_TILT_MIN, AIPTEK_TILT_MAX, 0, 0); 2092 + input_set_abs_params(inputdev, ABS_WHEEL, AIPTEK_WHEEL_MIN, AIPTEK_WHEEL_MAX - 1, 0, 0); 2155 2093 2156 2094 endpoint = &intf->altsetting[0].endpoint[0].desc; 2157 2095 ··· 2124 2150 aiptek->urb->transfer_dma = aiptek->data_dma; 2125 2151 aiptek->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 2126 2152 2127 - /* Register the tablet as an Input Device 2128 - */ 2129 - input_register_device(&aiptek->inputdev); 2130 - 2131 - /* We now will look for the evdev device which is mapped to 2132 - * the tablet. The partial name is kept in the link list of 2133 - * input_handles associated with this input device. 2134 - * What identifies an evdev input_handler is that it begins 2135 - * with 'event', continues with a digit, and that in turn 2136 - * is mapped to /{devfs}/input/eventN. 2137 - */ 2138 - inputdev = &aiptek->inputdev; 2139 - list_for_each_safe(node, next, &inputdev->h_list) { 2140 - inputhandle = to_handle(node); 2141 - if (strncmp(inputhandle->name, "event", 5) == 0) { 2142 - strcpy(aiptek->features.inputPath, inputhandle->name); 2143 - break; 2144 - } 2145 - } 2146 - 2147 - info("input: Aiptek on %s (%s)\n", path, aiptek->features.inputPath); 2148 - 2149 2153 /* Program the tablet. This sets the tablet up in the mode 2150 2154 * specified in newSetting, and also queries the tablet's 2151 2155 * physical capacities. ··· 2138 2186 for (i = 0; i < sizeof(speeds) / sizeof(speeds[0]); ++i) { 2139 2187 aiptek->curSetting.programmableDelay = speeds[i]; 2140 2188 (void)aiptek_program_tablet(aiptek); 2141 - if (aiptek->inputdev.absmax[ABS_X] > 0) { 2189 + if (aiptek->inputdev->absmax[ABS_X] > 0) { 2142 2190 info("input: Aiptek using %d ms programming speed\n", 2143 2191 aiptek->curSetting.programmableDelay); 2192 + break; 2193 + } 2194 + } 2195 + 2196 + /* Register the tablet as an Input Device 2197 + */ 2198 + input_register_device(aiptek->inputdev); 2199 + 2200 + /* We now will look for the evdev device which is mapped to 2201 + * the tablet. The partial name is kept in the link list of 2202 + * input_handles associated with this input device. 2203 + * What identifies an evdev input_handler is that it begins 2204 + * with 'event', continues with a digit, and that in turn 2205 + * is mapped to /{devfs}/input/eventN. 2206 + */ 2207 + list_for_each_safe(node, next, &inputdev->h_list) { 2208 + inputhandle = to_handle(node); 2209 + if (strncmp(inputhandle->name, "event", 5) == 0) { 2210 + strcpy(aiptek->features.inputPath, inputhandle->name); 2144 2211 break; 2145 2212 } 2146 2213 } ··· 2178 2207 info("aiptek: error loading 'evdev' module"); 2179 2208 2180 2209 return 0; 2210 + 2211 + fail2: usb_buffer_free(usbdev, AIPTEK_PACKET_LENGTH, aiptek->data, 2212 + aiptek->data_dma); 2213 + fail1: input_free_device(inputdev); 2214 + kfree(aiptek); 2215 + return -ENOMEM; 2181 2216 } 2182 2217 2183 2218 /* Forward declaration */ ··· 2211 2234 /* Free & unhook everything from the system. 2212 2235 */ 2213 2236 usb_kill_urb(aiptek->urb); 2214 - input_unregister_device(&aiptek->inputdev); 2237 + input_unregister_device(aiptek->inputdev); 2215 2238 aiptek_delete_files(&intf->dev); 2216 2239 usb_free_urb(aiptek->urb); 2217 2240 usb_buffer_free(interface_to_usbdev(intf),
+68 -62
drivers/usb/input/appletouch.c
··· 39 39 #define APPLE_VENDOR_ID 0x05AC 40 40 41 41 #define ATP_DEVICE(prod) \ 42 - .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \ 42 + .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \ 43 43 USB_DEVICE_ID_MATCH_INT_CLASS | \ 44 44 USB_DEVICE_ID_MATCH_INT_PROTOCOL, \ 45 45 .idVendor = APPLE_VENDOR_ID, \ ··· 78 78 * We try to keep the touchpad aspect ratio while still doing only simple 79 79 * arithmetics. 80 80 * The factors below give coordinates like: 81 - * 0 <= x < 960 on 12" and 15" Powerbooks 82 - * 0 <= x < 1600 on 17" Powerbooks 83 - * 0 <= y < 646 81 + * 0 <= x < 960 on 12" and 15" Powerbooks 82 + * 0 <= x < 1600 on 17" Powerbooks 83 + * 0 <= y < 646 84 84 */ 85 85 #define ATP_XFACT 64 86 86 #define ATP_YFACT 43 ··· 93 93 94 94 /* Structure to hold all of our device specific stuff */ 95 95 struct atp { 96 + char phys[64]; 96 97 struct usb_device * udev; /* usb device */ 97 98 struct urb * urb; /* usb request block */ 98 99 signed char * data; /* transferred data */ 99 100 int open; /* non-zero if opened */ 100 - struct input_dev input; /* input dev */ 101 + struct input_dev *input; /* input dev */ 101 102 int valid; /* are the sensors valid ? */ 102 103 int x_old; /* last reported x/y, */ 103 104 int y_old; /* used for smoothing */ ··· 115 114 int i; \ 116 115 printk("appletouch: %s %lld", msg, (long long)jiffies); \ 117 116 for (i = 0; i < ATP_XSENSORS + ATP_YSENSORS; i++) \ 118 - printk(" %02x", tab[i]); \ 119 - printk("\n"); \ 117 + printk(" %02x", tab[i]); \ 118 + printk("\n"); \ 120 119 } 121 120 122 - #define dprintk(format, a...) \ 121 + #define dprintk(format, a...) \ 123 122 do { \ 124 123 if (debug) printk(format, ##a); \ 125 124 } while (0) ··· 220 219 for (i = 16; i < ATP_XSENSORS; i++) 221 220 if (dev->xy_cur[i]) { 222 221 printk("appletouch: 17\" model detected.\n"); 223 - input_set_abs_params(&dev->input, ABS_X, 0, 224 - (ATP_XSENSORS - 1) * 222 + input_set_abs_params(dev->input, ABS_X, 0, 223 + (ATP_XSENSORS - 1) * 225 224 ATP_XFACT - 1, 226 225 ATP_FUZZ, 0); 227 226 break; ··· 261 260 "Xz: %3d Yz: %3d\n", 262 261 x, y, x_z, y_z); 263 262 264 - input_report_key(&dev->input, BTN_TOUCH, 1); 265 - input_report_abs(&dev->input, ABS_X, x); 266 - input_report_abs(&dev->input, ABS_Y, y); 267 - input_report_abs(&dev->input, ABS_PRESSURE, 263 + input_report_key(dev->input, BTN_TOUCH, 1); 264 + input_report_abs(dev->input, ABS_X, x); 265 + input_report_abs(dev->input, ABS_Y, y); 266 + input_report_abs(dev->input, ABS_PRESSURE, 268 267 min(ATP_PRESSURE, x_z + y_z)); 269 - atp_report_fingers(&dev->input, max(x_f, y_f)); 268 + atp_report_fingers(dev->input, max(x_f, y_f)); 270 269 } 271 270 dev->x_old = x; 272 271 dev->y_old = y; ··· 274 273 else if (!x && !y) { 275 274 276 275 dev->x_old = dev->y_old = -1; 277 - input_report_key(&dev->input, BTN_TOUCH, 0); 278 - input_report_abs(&dev->input, ABS_PRESSURE, 0); 279 - atp_report_fingers(&dev->input, 0); 276 + input_report_key(dev->input, BTN_TOUCH, 0); 277 + input_report_abs(dev->input, ABS_PRESSURE, 0); 278 + atp_report_fingers(dev->input, 0); 280 279 281 280 /* reset the accumulator on release */ 282 281 memset(dev->xy_acc, 0, sizeof(dev->xy_acc)); 283 282 } 284 283 285 - input_report_key(&dev->input, BTN_LEFT, !!dev->data[80]); 284 + input_report_key(dev->input, BTN_LEFT, !!dev->data[80]); 286 285 287 - input_sync(&dev->input); 286 + input_sync(dev->input); 288 287 289 288 exit: 290 289 retval = usb_submit_urb(dev->urb, GFP_ATOMIC); ··· 315 314 316 315 static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id) 317 316 { 318 - struct atp *dev = NULL; 317 + struct atp *dev; 318 + struct input_dev *input_dev; 319 + struct usb_device *udev = interface_to_usbdev(iface); 319 320 struct usb_host_interface *iface_desc; 320 321 struct usb_endpoint_descriptor *endpoint; 321 322 int int_in_endpointAddr = 0; 322 323 int i, retval = -ENOMEM; 323 324 324 - /* allocate memory for our device state and initialize it */ 325 - dev = kmalloc(sizeof(struct atp), GFP_KERNEL); 326 - if (dev == NULL) { 327 - err("Out of memory"); 328 - goto err_kmalloc; 329 - } 330 - memset(dev, 0, sizeof(struct atp)); 331 - 332 - dev->udev = interface_to_usbdev(iface); 333 325 334 326 /* set up the endpoint information */ 335 327 /* use only the first interrupt-in endpoint */ ··· 339 345 } 340 346 } 341 347 if (!int_in_endpointAddr) { 342 - retval = -EIO; 343 348 err("Could not find int-in endpoint"); 344 - goto err_endpoint; 349 + return -EIO; 345 350 } 346 351 347 - /* save our data pointer in this interface device */ 348 - usb_set_intfdata(iface, dev); 352 + /* allocate memory for our device state and initialize it */ 353 + dev = kzalloc(sizeof(struct atp), GFP_KERNEL); 354 + input_dev = input_allocate_device(); 355 + if (!dev || !input_dev) { 356 + err("Out of memory"); 357 + goto err_free_devs; 358 + } 359 + 360 + dev->udev = udev; 361 + dev->input = input_dev; 349 362 350 363 dev->urb = usb_alloc_urb(0, GFP_KERNEL); 351 364 if (!dev->urb) { 352 365 retval = -ENOMEM; 353 - goto err_usballoc; 366 + goto err_free_devs; 354 367 } 368 + 355 369 dev->data = usb_buffer_alloc(dev->udev, ATP_DATASIZE, GFP_KERNEL, 356 370 &dev->urb->transfer_dma); 357 371 if (!dev->data) { 358 372 retval = -ENOMEM; 359 - goto err_usbbufalloc; 373 + goto err_free_urb; 360 374 } 361 - usb_fill_int_urb(dev->urb, dev->udev, 362 - usb_rcvintpipe(dev->udev, int_in_endpointAddr), 375 + 376 + usb_fill_int_urb(dev->urb, udev, 377 + usb_rcvintpipe(udev, int_in_endpointAddr), 363 378 dev->data, ATP_DATASIZE, atp_complete, dev, 1); 364 379 365 - init_input_dev(&dev->input); 366 - dev->input.name = "appletouch"; 367 - dev->input.dev = &iface->dev; 368 - dev->input.private = dev; 369 - dev->input.open = atp_open; 370 - dev->input.close = atp_close; 380 + usb_make_path(udev, dev->phys, sizeof(dev->phys)); 381 + strlcat(dev->phys, "/input0", sizeof(dev->phys)); 371 382 372 - usb_to_input_id(dev->udev, &dev->input.id); 383 + input_dev->name = "appletouch"; 384 + input_dev->phys = dev->phys; 385 + usb_to_input_id(dev->udev, &input_dev->id); 386 + input_dev->cdev.dev = &iface->dev; 373 387 374 - set_bit(EV_ABS, dev->input.evbit); 388 + input_dev->private = dev; 389 + input_dev->open = atp_open; 390 + input_dev->close = atp_close; 391 + 392 + set_bit(EV_ABS, input_dev->evbit); 375 393 376 394 /* 377 395 * 12" and 15" Powerbooks only have 16 x sensors, 378 396 * 17" models are detected later. 379 397 */ 380 - input_set_abs_params(&dev->input, ABS_X, 0, 398 + input_set_abs_params(input_dev, ABS_X, 0, 381 399 (16 - 1) * ATP_XFACT - 1, ATP_FUZZ, 0); 382 - input_set_abs_params(&dev->input, ABS_Y, 0, 400 + input_set_abs_params(input_dev, ABS_Y, 0, 383 401 (ATP_YSENSORS - 1) * ATP_YFACT - 1, ATP_FUZZ, 0); 384 - input_set_abs_params(&dev->input, ABS_PRESSURE, 0, ATP_PRESSURE, 0, 0); 402 + input_set_abs_params(input_dev, ABS_PRESSURE, 0, ATP_PRESSURE, 0, 0); 385 403 386 - set_bit(EV_KEY, dev->input.evbit); 387 - set_bit(BTN_TOUCH, dev->input.keybit); 388 - set_bit(BTN_TOOL_FINGER, dev->input.keybit); 389 - set_bit(BTN_TOOL_DOUBLETAP, dev->input.keybit); 390 - set_bit(BTN_TOOL_TRIPLETAP, dev->input.keybit); 391 - set_bit(BTN_LEFT, dev->input.keybit); 404 + set_bit(EV_KEY, input_dev->evbit); 405 + set_bit(BTN_TOUCH, input_dev->keybit); 406 + set_bit(BTN_TOOL_FINGER, input_dev->keybit); 407 + set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit); 408 + set_bit(BTN_TOOL_TRIPLETAP, input_dev->keybit); 409 + set_bit(BTN_LEFT, input_dev->keybit); 392 410 393 - input_register_device(&dev->input); 411 + input_register_device(dev->input); 394 412 395 - printk(KERN_INFO "input: appletouch connected\n"); 413 + /* save our data pointer in this interface device */ 414 + usb_set_intfdata(iface, dev); 396 415 397 416 return 0; 398 417 399 - err_usbbufalloc: 418 + err_free_urb: 400 419 usb_free_urb(dev->urb); 401 - err_usballoc: 420 + err_free_devs: 402 421 usb_set_intfdata(iface, NULL); 403 - err_endpoint: 404 422 kfree(dev); 405 - err_kmalloc: 423 + input_free_device(input_dev); 406 424 return retval; 407 425 } 408 426 ··· 425 419 usb_set_intfdata(iface, NULL); 426 420 if (dev) { 427 421 usb_kill_urb(dev->urb); 428 - input_unregister_device(&dev->input); 422 + input_unregister_device(dev->input); 429 423 usb_free_urb(dev->urb); 430 424 usb_buffer_free(dev->udev, ATP_DATASIZE, 431 425 dev->data, dev->urb->transfer_dma);
+90 -85
drivers/usb/input/ati_remote.c
··· 112 112 113 113 #define NAME_BUFSIZE 80 /* size of product name, path buffers */ 114 114 #define DATA_BUFSIZE 63 /* size of URB data buffers */ 115 - #define ATI_INPUTNUM 1 /* Which input device to register as */ 116 115 117 116 static unsigned long channel_mask; 118 117 module_param(channel_mask, ulong, 0444); ··· 161 162 static DECLARE_MUTEX(disconnect_sem); 162 163 163 164 struct ati_remote { 164 - struct input_dev idev; 165 + struct input_dev *idev; 165 166 struct usb_device *udev; 166 167 struct usb_interface *interface; 167 168 ··· 197 198 #define KIND_ACCEL 7 /* Directional keypad - left, right, up, down.*/ 198 199 199 200 /* Translation table from hardware messages to input events. */ 200 - static struct 201 - { 201 + static struct { 202 202 short kind; 203 203 unsigned char data1, data2; 204 204 int type; 205 205 unsigned int code; 206 206 int value; 207 - } ati_remote_tbl[] = 208 - { 207 + } ati_remote_tbl[] = { 209 208 /* Directional control pad axes */ 210 209 {KIND_ACCEL, 0x35, 0x70, EV_REL, REL_X, -1}, /* left */ 211 210 {KIND_ACCEL, 0x36, 0x71, EV_REL, REL_X, 1}, /* right */ ··· 283 286 284 287 /* Local function prototypes */ 285 288 static void ati_remote_dump (unsigned char *data, unsigned int actual_length); 286 - static void ati_remote_delete (struct ati_remote *dev); 287 289 static int ati_remote_open (struct input_dev *inputdev); 288 290 static void ati_remote_close (struct input_dev *inputdev); 289 291 static int ati_remote_sendpacket (struct ati_remote *ati_remote, u16 cmd, unsigned char *data); ··· 424 428 { 425 429 struct ati_remote *ati_remote = urb->context; 426 430 unsigned char *data= ati_remote->inbuf; 427 - struct input_dev *dev = &ati_remote->idev; 431 + struct input_dev *dev = ati_remote->idev; 428 432 int index, acc; 429 433 int remote_num; 430 434 ··· 583 587 } 584 588 585 589 /* 586 - * ati_remote_delete 590 + * ati_remote_alloc_buffers 587 591 */ 588 - static void ati_remote_delete(struct ati_remote *ati_remote) 592 + static int ati_remote_alloc_buffers(struct usb_device *udev, 593 + struct ati_remote *ati_remote) 594 + { 595 + ati_remote->inbuf = usb_buffer_alloc(udev, DATA_BUFSIZE, SLAB_ATOMIC, 596 + &ati_remote->inbuf_dma); 597 + if (!ati_remote->inbuf) 598 + return -1; 599 + 600 + ati_remote->outbuf = usb_buffer_alloc(udev, DATA_BUFSIZE, SLAB_ATOMIC, 601 + &ati_remote->outbuf_dma); 602 + if (!ati_remote->outbuf) 603 + return -1; 604 + 605 + ati_remote->irq_urb = usb_alloc_urb(0, GFP_KERNEL); 606 + if (!ati_remote->irq_urb) 607 + return -1; 608 + 609 + ati_remote->out_urb = usb_alloc_urb(0, GFP_KERNEL); 610 + if (!ati_remote->out_urb) 611 + return -1; 612 + 613 + return 0; 614 + } 615 + 616 + /* 617 + * ati_remote_free_buffers 618 + */ 619 + static void ati_remote_free_buffers(struct ati_remote *ati_remote) 589 620 { 590 621 if (ati_remote->irq_urb) 591 - usb_kill_urb(ati_remote->irq_urb); 622 + usb_free_urb(ati_remote->irq_urb); 592 623 593 624 if (ati_remote->out_urb) 594 - usb_kill_urb(ati_remote->out_urb); 595 - 596 - input_unregister_device(&ati_remote->idev); 625 + usb_free_urb(ati_remote->out_urb); 597 626 598 627 if (ati_remote->inbuf) 599 628 usb_buffer_free(ati_remote->udev, DATA_BUFSIZE, ··· 626 605 627 606 if (ati_remote->outbuf) 628 607 usb_buffer_free(ati_remote->udev, DATA_BUFSIZE, 629 - ati_remote->outbuf, ati_remote->outbuf_dma); 630 - 631 - if (ati_remote->irq_urb) 632 - usb_free_urb(ati_remote->irq_urb); 633 - 634 - if (ati_remote->out_urb) 635 - usb_free_urb(ati_remote->out_urb); 636 - 637 - kfree(ati_remote); 608 + ati_remote->inbuf, ati_remote->outbuf_dma); 638 609 } 639 610 640 611 static void ati_remote_input_init(struct ati_remote *ati_remote) 641 612 { 642 - struct input_dev *idev = &(ati_remote->idev); 613 + struct input_dev *idev = ati_remote->idev; 643 614 int i; 644 615 645 616 idev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL); ··· 650 637 idev->phys = ati_remote->phys; 651 638 652 639 usb_to_input_id(ati_remote->udev, &idev->id); 653 - idev->dev = &ati_remote->udev->dev; 640 + idev->cdev.dev = &ati_remote->udev->dev; 654 641 } 655 642 656 643 static int ati_remote_initialize(struct ati_remote *ati_remote) ··· 687 674 (ati_remote_sendpacket(ati_remote, 0x8007, init2))) { 688 675 dev_err(&ati_remote->interface->dev, 689 676 "Initializing ati_remote hardware failed.\n"); 690 - return 1; 677 + return -EIO; 691 678 } 692 679 693 680 return 0; ··· 699 686 static int ati_remote_probe(struct usb_interface *interface, const struct usb_device_id *id) 700 687 { 701 688 struct usb_device *udev = interface_to_usbdev(interface); 702 - struct ati_remote *ati_remote = NULL; 703 - struct usb_host_interface *iface_host; 704 - int retval = -ENOMEM; 705 - char path[64]; 689 + struct usb_host_interface *iface_host = interface->cur_altsetting; 690 + struct usb_endpoint_descriptor *endpoint_in, *endpoint_out; 691 + struct ati_remote *ati_remote; 692 + struct input_dev *input_dev; 693 + int err = -ENOMEM; 706 694 707 - /* Allocate and clear an ati_remote struct */ 708 - if (!(ati_remote = kmalloc(sizeof (struct ati_remote), GFP_KERNEL))) 709 - return -ENOMEM; 710 - memset(ati_remote, 0x00, sizeof (struct ati_remote)); 711 - 712 - iface_host = interface->cur_altsetting; 713 695 if (iface_host->desc.bNumEndpoints != 2) { 714 696 err("%s: Unexpected desc.bNumEndpoints\n", __FUNCTION__); 715 - retval = -ENODEV; 716 - goto error; 697 + return -ENODEV; 717 698 } 718 699 719 - ati_remote->endpoint_in = &(iface_host->endpoint[0].desc); 720 - ati_remote->endpoint_out = &(iface_host->endpoint[1].desc); 721 - ati_remote->udev = udev; 722 - ati_remote->interface = interface; 700 + endpoint_in = &iface_host->endpoint[0].desc; 701 + endpoint_out = &iface_host->endpoint[1].desc; 723 702 724 - if (!(ati_remote->endpoint_in->bEndpointAddress & 0x80)) { 703 + if (!(endpoint_in->bEndpointAddress & USB_DIR_IN)) { 725 704 err("%s: Unexpected endpoint_in->bEndpointAddress\n", __FUNCTION__); 726 - retval = -ENODEV; 727 - goto error; 705 + return -ENODEV; 728 706 } 729 - if ((ati_remote->endpoint_in->bmAttributes & 3) != 3) { 707 + if ((endpoint_in->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_INT) { 730 708 err("%s: Unexpected endpoint_in->bmAttributes\n", __FUNCTION__); 731 - retval = -ENODEV; 732 - goto error; 709 + return -ENODEV; 733 710 } 734 - if (le16_to_cpu(ati_remote->endpoint_in->wMaxPacketSize) == 0) { 711 + if (le16_to_cpu(endpoint_in->wMaxPacketSize) == 0) { 735 712 err("%s: endpoint_in message size==0? \n", __FUNCTION__); 736 - retval = -ENODEV; 737 - goto error; 713 + return -ENODEV; 738 714 } 715 + 716 + ati_remote = kzalloc(sizeof (struct ati_remote), GFP_KERNEL); 717 + input_dev = input_allocate_device(); 718 + if (!ati_remote || !input_dev) 719 + goto fail1; 739 720 740 721 /* Allocate URB buffers, URBs */ 741 - ati_remote->inbuf = usb_buffer_alloc(udev, DATA_BUFSIZE, SLAB_ATOMIC, 742 - &ati_remote->inbuf_dma); 743 - if (!ati_remote->inbuf) 744 - goto error; 722 + if (ati_remote_alloc_buffers(udev, ati_remote)) 723 + goto fail2; 745 724 746 - ati_remote->outbuf = usb_buffer_alloc(udev, DATA_BUFSIZE, SLAB_ATOMIC, 747 - &ati_remote->outbuf_dma); 748 - if (!ati_remote->outbuf) 749 - goto error; 725 + ati_remote->endpoint_in = endpoint_in; 726 + ati_remote->endpoint_out = endpoint_out; 727 + ati_remote->udev = udev; 728 + ati_remote->idev = input_dev; 729 + ati_remote->interface = interface; 750 730 751 - ati_remote->irq_urb = usb_alloc_urb(0, GFP_KERNEL); 752 - if (!ati_remote->irq_urb) 753 - goto error; 731 + usb_make_path(udev, ati_remote->phys, sizeof(ati_remote->phys)); 732 + strlcpy(ati_remote->phys, "/input0", sizeof(ati_remote->phys)); 754 733 755 - ati_remote->out_urb = usb_alloc_urb(0, GFP_KERNEL); 756 - if (!ati_remote->out_urb) 757 - goto error; 758 - 759 - usb_make_path(udev, path, NAME_BUFSIZE); 760 - sprintf(ati_remote->phys, "%s/input%d", path, ATI_INPUTNUM); 761 734 if (udev->manufacturer) 762 - strcat(ati_remote->name, udev->manufacturer); 735 + strlcpy(ati_remote->name, udev->manufacturer, sizeof(ati_remote->name)); 763 736 764 737 if (udev->product) 765 - sprintf(ati_remote->name, "%s %s", ati_remote->name, udev->product); 738 + snprintf(ati_remote->name, sizeof(ati_remote->name), 739 + "%s %s", ati_remote->name, udev->product); 766 740 767 741 if (!strlen(ati_remote->name)) 768 - sprintf(ati_remote->name, DRIVER_DESC "(%04x,%04x)", 742 + snprintf(ati_remote->name, sizeof(ati_remote->name), 743 + DRIVER_DESC "(%04x,%04x)", 769 744 le16_to_cpu(ati_remote->udev->descriptor.idVendor), 770 745 le16_to_cpu(ati_remote->udev->descriptor.idProduct)); 771 746 747 + ati_remote_input_init(ati_remote); 748 + 772 749 /* Device Hardware Initialization - fills in ati_remote->idev from udev. */ 773 - retval = ati_remote_initialize(ati_remote); 774 - if (retval) 775 - goto error; 750 + err = ati_remote_initialize(ati_remote); 751 + if (err) 752 + goto fail3; 776 753 777 754 /* Set up and register input device */ 778 - ati_remote_input_init(ati_remote); 779 - input_register_device(&ati_remote->idev); 780 - 781 - dev_info(&ati_remote->interface->dev, "Input registered: %s on %s\n", 782 - ati_remote->name, path); 755 + input_register_device(ati_remote->idev); 783 756 784 757 usb_set_intfdata(interface, ati_remote); 758 + return 0; 785 759 786 - error: 787 - if (retval) 788 - ati_remote_delete(ati_remote); 789 - 790 - return retval; 760 + fail3: usb_kill_urb(ati_remote->irq_urb); 761 + usb_kill_urb(ati_remote->out_urb); 762 + fail2: ati_remote_free_buffers(ati_remote); 763 + fail1: input_free_device(input_dev); 764 + kfree(ati_remote); 765 + return err; 791 766 } 792 767 793 768 /* ··· 792 791 return; 793 792 } 794 793 795 - ati_remote_delete(ati_remote); 794 + usb_kill_urb(ati_remote->irq_urb); 795 + usb_kill_urb(ati_remote->out_urb); 796 + input_unregister_device(ati_remote->idev); 797 + ati_remote_free_buffers(ati_remote); 798 + kfree(ati_remote); 796 799 } 797 800 798 801 /*
+26 -23
drivers/usb/input/hid-core.c
··· 1619 1619 struct hid_descriptor *hdesc; 1620 1620 struct hid_device *hid; 1621 1621 unsigned quirks = 0, rsize = 0; 1622 - char *buf, *rdesc; 1623 - int n, insize = 0; 1622 + char *rdesc; 1623 + int n, len, insize = 0; 1624 1624 1625 1625 for (n = 0; hid_blacklist[n].idVendor; n++) 1626 1626 if ((hid_blacklist[n].idVendor == le16_to_cpu(dev->descriptor.idVendor)) && ··· 1630 1630 if (quirks & HID_QUIRK_IGNORE) 1631 1631 return NULL; 1632 1632 1633 - if (usb_get_extra_descriptor(interface, HID_DT_HID, &hdesc) && ((!interface->desc.bNumEndpoints) || 1634 - usb_get_extra_descriptor(&interface->endpoint[0], HID_DT_HID, &hdesc))) { 1635 - dbg("class descriptor not present\n"); 1636 - return NULL; 1633 + if (usb_get_extra_descriptor(interface, HID_DT_HID, &hdesc) && 1634 + (!interface->desc.bNumEndpoints || 1635 + usb_get_extra_descriptor(&interface->endpoint[0], HID_DT_HID, &hdesc))) { 1636 + dbg("class descriptor not present\n"); 1637 + return NULL; 1637 1638 } 1638 1639 1639 1640 for (n = 0; n < hdesc->bNumDescriptors; n++) ··· 1750 1749 1751 1750 hid->name[0] = 0; 1752 1751 1753 - if (!(buf = kmalloc(64, GFP_KERNEL))) 1754 - goto fail; 1752 + if (dev->manufacturer) 1753 + strlcpy(hid->name, dev->manufacturer, sizeof(hid->name)); 1755 1754 1756 - if (dev->manufacturer) { 1757 - strcat(hid->name, dev->manufacturer); 1758 - if (dev->product) 1759 - snprintf(hid->name, 64, "%s %s", hid->name, dev->product); 1760 - } else if (dev->product) { 1761 - snprintf(hid->name, 128, "%s", dev->product); 1762 - } else 1763 - snprintf(hid->name, 128, "%04x:%04x", 1764 - le16_to_cpu(dev->descriptor.idVendor), 1765 - le16_to_cpu(dev->descriptor.idProduct)); 1755 + if (dev->product) { 1756 + if (dev->manufacturer) 1757 + strlcat(hid->name, " ", sizeof(hid->name)); 1758 + strlcat(hid->name, dev->product, sizeof(hid->name)); 1759 + } 1766 1760 1767 - usb_make_path(dev, buf, 64); 1768 - snprintf(hid->phys, 64, "%s/input%d", buf, 1769 - intf->altsetting[0].desc.bInterfaceNumber); 1761 + if (!strlen(hid->name)) 1762 + snprintf(hid->name, sizeof(hid->name), "HID %04x:%04x", 1763 + le16_to_cpu(dev->descriptor.idVendor), 1764 + le16_to_cpu(dev->descriptor.idProduct)); 1765 + 1766 + usb_make_path(dev, hid->phys, sizeof(hid->phys)); 1767 + strlcat(hid->phys, "/input", sizeof(hid->phys)); 1768 + len = strlen(hid->phys); 1769 + if (len < sizeof(hid->phys) - 1) 1770 + snprintf(hid->phys + len, sizeof(hid->phys) - len, 1771 + "%d", intf->altsetting[0].desc.bInterfaceNumber); 1770 1772 1771 1773 if (usb_string(dev, dev->descriptor.iSerialNumber, hid->uniq, 64) <= 0) 1772 1774 hid->uniq[0] = 0; 1773 1775 1774 - kfree(buf); 1775 - 1776 1776 hid->urbctrl = usb_alloc_urb(0, GFP_KERNEL); 1777 1777 if (!hid->urbctrl) 1778 1778 goto fail; 1779 + 1779 1780 usb_fill_control_urb(hid->urbctrl, dev, 0, (void *) hid->cr, 1780 1781 hid->ctrlbuf, 1, hid_ctrl, hid); 1781 1782 hid->urbctrl->setup_dma = hid->cr_dma;
+29 -29
drivers/usb/input/hid-input.c
··· 76 76 static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_field *field, 77 77 struct hid_usage *usage) 78 78 { 79 - struct input_dev *input = &hidinput->input; 80 - struct hid_device *device = hidinput->input.private; 79 + struct input_dev *input = hidinput->input; 80 + struct hid_device *device = input->private; 81 81 int max = 0, code; 82 82 unsigned long *bit = NULL; 83 83 ··· 461 461 462 462 if (!field->hidinput) 463 463 return; 464 - input = &field->hidinput->input; 464 + 465 + input = field->hidinput->input; 465 466 466 467 input_regs(input, regs); 467 468 ··· 534 533 535 534 void hidinput_report_event(struct hid_device *hid, struct hid_report *report) 536 535 { 537 - struct list_head *lh; 538 536 struct hid_input *hidinput; 539 537 540 - list_for_each (lh, &hid->inputs) { 541 - hidinput = list_entry(lh, struct hid_input, list); 542 - input_sync(&hidinput->input); 543 - } 538 + list_for_each_entry(hidinput, &hid->inputs, list) 539 + input_sync(hidinput->input); 544 540 } 545 541 546 542 static int hidinput_find_field(struct hid_device *hid, unsigned int type, unsigned int code, struct hid_field **field) ··· 602 604 struct usb_device *dev = hid->dev; 603 605 struct hid_report *report; 604 606 struct hid_input *hidinput = NULL; 607 + struct input_dev *input_dev; 605 608 int i, j, k; 606 609 607 610 INIT_LIST_HEAD(&hid->inputs); ··· 623 624 continue; 624 625 625 626 if (!hidinput) { 626 - hidinput = kmalloc(sizeof(*hidinput), GFP_KERNEL); 627 - if (!hidinput) { 627 + hidinput = kzalloc(sizeof(*hidinput), GFP_KERNEL); 628 + input_dev = input_allocate_device(); 629 + if (!hidinput || !input_dev) { 630 + kfree(hidinput); 631 + input_free_device(input_dev); 628 632 err("Out of memory during hid input probe"); 629 633 return -1; 630 634 } 631 - memset(hidinput, 0, sizeof(*hidinput)); 632 635 636 + input_dev->private = hid; 637 + input_dev->event = hidinput_input_event; 638 + input_dev->open = hidinput_open; 639 + input_dev->close = hidinput_close; 640 + 641 + input_dev->name = hid->name; 642 + input_dev->phys = hid->phys; 643 + input_dev->uniq = hid->uniq; 644 + usb_to_input_id(dev, &input_dev->id); 645 + input_dev->cdev.dev = &hid->intf->dev; 646 + 647 + hidinput->input = input_dev; 633 648 list_add_tail(&hidinput->list, &hid->inputs); 634 - 635 - hidinput->input.private = hid; 636 - hidinput->input.event = hidinput_input_event; 637 - hidinput->input.open = hidinput_open; 638 - hidinput->input.close = hidinput_close; 639 - 640 - hidinput->input.name = hid->name; 641 - hidinput->input.phys = hid->phys; 642 - hidinput->input.uniq = hid->uniq; 643 - usb_to_input_id(dev, &hidinput->input.id); 644 - hidinput->input.dev = &hid->intf->dev; 645 649 } 646 650 647 651 for (i = 0; i < report->maxfield; i++) ··· 659 657 * UGCI) cram a lot of unrelated inputs into the 660 658 * same interface. */ 661 659 hidinput->report = report; 662 - input_register_device(&hidinput->input); 660 + input_register_device(hidinput->input); 663 661 hidinput = NULL; 664 662 } 665 663 } ··· 669 667 * only useful in this case, and not for multi-input quirks. */ 670 668 if (hidinput) { 671 669 hid_ff_init(hid); 672 - input_register_device(&hidinput->input); 670 + input_register_device(hidinput->input); 673 671 } 674 672 675 673 return 0; ··· 677 675 678 676 void hidinput_disconnect(struct hid_device *hid) 679 677 { 680 - struct list_head *lh, *next; 681 - struct hid_input *hidinput; 678 + struct hid_input *hidinput, *next; 682 679 683 - list_for_each_safe(lh, next, &hid->inputs) { 684 - hidinput = list_entry(lh, struct hid_input, list); 685 - input_unregister_device(&hidinput->input); 680 + list_for_each_entry_safe(hidinput, next, &hid->inputs, list) { 686 681 list_del(&hidinput->list); 682 + input_unregister_device(hidinput->input); 687 683 kfree(hidinput); 688 684 } 689 685 }
+7 -10
drivers/usb/input/hid-lgff.c
··· 255 255 u16 idVendor = le16_to_cpu(hid->dev->descriptor.idVendor); 256 256 u16 idProduct = le16_to_cpu(hid->dev->descriptor.idProduct); 257 257 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); 258 + struct input_dev *input_dev = hidinput->input; 258 259 259 260 while (dev->idVendor && (idVendor != dev->idVendor || idProduct != dev->idProduct)) 260 261 dev++; 261 262 262 - ff = dev->ff; 263 + for (ff = dev->ff; *ff >= 0; ff++) 264 + set_bit(*ff, input_dev->ffbit); 263 265 264 - while (*ff >= 0) { 265 - set_bit(*ff, hidinput->input.ffbit); 266 - ++ff; 267 - } 266 + input_dev->upload_effect = hid_lgff_upload_effect; 267 + input_dev->flush = hid_lgff_flush; 268 268 269 - hidinput->input.upload_effect = hid_lgff_upload_effect; 270 - hidinput->input.flush = hid_lgff_flush; 271 - 272 - set_bit(EV_FF, hidinput->input.evbit); 273 - hidinput->input.ff_effects_max = LGFF_EFFECTS; 269 + set_bit(EV_FF, input_dev->evbit); 270 + input_dev->ff_effects_max = LGFF_EFFECTS; 274 271 } 275 272 276 273 static void hid_lgff_exit(struct hid_device* hid)
+6 -5
drivers/usb/input/hid-tmff.c
··· 111 111 struct tmff_device *private; 112 112 struct list_head *pos; 113 113 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); 114 + struct input_dev *input_dev = hidinput->input; 114 115 115 116 private = kmalloc(sizeof(struct tmff_device), GFP_KERNEL); 116 117 if (!private) ··· 156 155 private->report = report; 157 156 private->rumble = field; 158 157 159 - set_bit(FF_RUMBLE, hidinput->input.ffbit); 158 + set_bit(FF_RUMBLE, input_dev->ffbit); 160 159 break; 161 160 162 161 default: ··· 165 164 } 166 165 167 166 /* Fallthrough to here only when a valid usage is found */ 168 - hidinput->input.upload_effect = hid_tmff_upload_effect; 169 - hidinput->input.flush = hid_tmff_flush; 167 + input_dev->upload_effect = hid_tmff_upload_effect; 168 + input_dev->flush = hid_tmff_flush; 170 169 171 - set_bit(EV_FF, hidinput->input.evbit); 172 - hidinput->input.ff_effects_max = TMFF_EFFECTS; 170 + set_bit(EV_FF, input_dev->evbit); 171 + input_dev->ff_effects_max = TMFF_EFFECTS; 173 172 } 174 173 } 175 174
+1 -1
drivers/usb/input/hid.h
··· 371 371 struct hid_input { 372 372 struct list_head list; 373 373 struct hid_report *report; 374 - struct input_dev input; 374 + struct input_dev *input; 375 375 }; 376 376 377 377 struct hid_device { /* device report descriptor */
+42 -28
drivers/usb/input/itmtouch.c
··· 73 73 74 74 struct itmtouch_dev { 75 75 struct usb_device *usbdev; /* usb device */ 76 - struct input_dev inputdev; /* input device */ 76 + struct input_dev *inputdev; /* input device */ 77 77 struct urb *readurb; /* urb */ 78 78 char rbuf[ITM_BUFSIZE]; /* data */ 79 79 int users; ··· 88 88 89 89 static void itmtouch_irq(struct urb *urb, struct pt_regs *regs) 90 90 { 91 - struct itmtouch_dev * itmtouch = urb->context; 91 + struct itmtouch_dev *itmtouch = urb->context; 92 92 unsigned char *data = urb->transfer_buffer; 93 - struct input_dev *dev = &itmtouch->inputdev; 93 + struct input_dev *dev = itmtouch->inputdev; 94 94 int retval; 95 95 96 96 switch (urb->status) { ··· 156 156 static int itmtouch_probe(struct usb_interface *intf, const struct usb_device_id *id) 157 157 { 158 158 struct itmtouch_dev *itmtouch; 159 + struct input_dev *input_dev; 159 160 struct usb_host_interface *interface; 160 161 struct usb_endpoint_descriptor *endpoint; 161 162 struct usb_device *udev = interface_to_usbdev(intf); 162 163 unsigned int pipe; 163 164 unsigned int maxp; 164 - char path[PATH_SIZE]; 165 165 166 166 interface = intf->cur_altsetting; 167 167 endpoint = &interface->endpoint[0].desc; 168 168 169 - if (!(itmtouch = kzalloc(sizeof(struct itmtouch_dev), GFP_KERNEL))) { 169 + itmtouch = kzalloc(sizeof(struct itmtouch_dev), GFP_KERNEL); 170 + input_dev = input_allocate_device(); 171 + if (!itmtouch || !input_dev) { 170 172 err("%s - Out of memory.", __FUNCTION__); 171 - return -ENOMEM; 173 + goto fail; 172 174 } 173 175 174 176 itmtouch->usbdev = udev; 177 + itmtouch->inputdev = input_dev; 175 178 176 - itmtouch->inputdev.private = itmtouch; 177 - itmtouch->inputdev.open = itmtouch_open; 178 - itmtouch->inputdev.close = itmtouch_close; 179 + if (udev->manufacturer) 180 + strlcpy(itmtouch->name, udev->manufacturer, sizeof(itmtouch->name)); 179 181 180 - usb_make_path(udev, path, PATH_SIZE); 181 - 182 - itmtouch->inputdev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 183 - itmtouch->inputdev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE); 184 - itmtouch->inputdev.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); 185 - 186 - itmtouch->inputdev.name = itmtouch->name; 187 - itmtouch->inputdev.phys = itmtouch->phys; 188 - usb_to_input_id(udev, &itmtouch->inputdev.id); 189 - itmtouch->inputdev.dev = &intf->dev; 182 + if (udev->product) { 183 + if (udev->manufacturer) 184 + strlcat(itmtouch->name, " ", sizeof(itmtouch->name)); 185 + strlcat(itmtouch->name, udev->product, sizeof(itmtouch->name)); 186 + } 190 187 191 188 if (!strlen(itmtouch->name)) 192 189 sprintf(itmtouch->name, "USB ITM touchscreen"); 190 + 191 + usb_make_path(udev, itmtouch->phys, sizeof(itmtouch->phys)); 192 + strlcpy(itmtouch->phys, "/input0", sizeof(itmtouch->phys)); 193 + 194 + input_dev->name = itmtouch->name; 195 + input_dev->phys = itmtouch->phys; 196 + usb_to_input_id(udev, &input_dev->id); 197 + input_dev->cdev.dev = &intf->dev; 198 + input_dev->private = itmtouch; 199 + 200 + input_dev->open = itmtouch_open; 201 + input_dev->close = itmtouch_close; 202 + 203 + input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 204 + input_dev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE); 205 + input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); 193 206 194 207 /* device limits */ 195 208 /* as specified by the ITM datasheet, X and Y are 12bit, 196 209 * Z (pressure) is 8 bit. However, the fields are defined up 197 210 * to 14 bits for future possible expansion. 198 211 */ 199 - input_set_abs_params(&itmtouch->inputdev, ABS_X, 0, 0x0FFF, 2, 0); 200 - input_set_abs_params(&itmtouch->inputdev, ABS_Y, 0, 0x0FFF, 2, 0); 201 - input_set_abs_params(&itmtouch->inputdev, ABS_PRESSURE, 0, 0xFF, 2, 0); 212 + input_set_abs_params(input_dev, ABS_X, 0, 0x0FFF, 2, 0); 213 + input_set_abs_params(input_dev, ABS_Y, 0, 0x0FFF, 2, 0); 214 + input_set_abs_params(input_dev, ABS_PRESSURE, 0, 0xFF, 2, 0); 202 215 203 216 /* initialise the URB so we can read from the transport stream */ 204 217 pipe = usb_rcvintpipe(itmtouch->usbdev, endpoint->bEndpointAddress); ··· 221 208 maxp = ITM_BUFSIZE; 222 209 223 210 itmtouch->readurb = usb_alloc_urb(0, GFP_KERNEL); 224 - 225 211 if (!itmtouch->readurb) { 226 212 dbg("%s - usb_alloc_urb failed: itmtouch->readurb", __FUNCTION__); 227 - kfree(itmtouch); 228 - return -ENOMEM; 213 + goto fail; 229 214 } 230 215 231 216 usb_fill_int_urb(itmtouch->readurb, itmtouch->usbdev, pipe, itmtouch->rbuf, 232 217 maxp, itmtouch_irq, itmtouch, endpoint->bInterval); 233 218 234 - input_register_device(&itmtouch->inputdev); 219 + input_register_device(itmtouch->inputdev); 235 220 236 - printk(KERN_INFO "itmtouch: %s registered on %s\n", itmtouch->name, path); 237 221 usb_set_intfdata(intf, itmtouch); 238 222 239 223 return 0; 224 + 225 + fail: input_free_device(input_dev); 226 + kfree(itmtouch); 227 + return -ENOMEM; 240 228 } 241 229 242 230 static void itmtouch_disconnect(struct usb_interface *intf) ··· 247 233 usb_set_intfdata(intf, NULL); 248 234 249 235 if (itmtouch) { 250 - input_unregister_device(&itmtouch->inputdev); 236 + input_unregister_device(itmtouch->inputdev); 251 237 usb_kill_urb(itmtouch->readurb); 252 238 usb_free_urb(itmtouch->readurb); 253 239 kfree(itmtouch);
+40 -48
drivers/usb/input/kbtab.c
··· 34 34 struct kbtab { 35 35 signed char *data; 36 36 dma_addr_t data_dma; 37 - struct input_dev dev; 37 + struct input_dev *dev; 38 38 struct usb_device *usbdev; 39 39 struct urb *irq; 40 40 int x, y; ··· 48 48 { 49 49 struct kbtab *kbtab = urb->context; 50 50 unsigned char *data = kbtab->data; 51 - struct input_dev *dev = &kbtab->dev; 51 + struct input_dev *dev = kbtab->dev; 52 52 int retval; 53 53 54 54 switch (urb->status) { ··· 124 124 struct usb_device *dev = interface_to_usbdev(intf); 125 125 struct usb_endpoint_descriptor *endpoint; 126 126 struct kbtab *kbtab; 127 - char path[64]; 127 + struct input_dev *input_dev; 128 128 129 - if (!(kbtab = kmalloc(sizeof(struct kbtab), GFP_KERNEL))) 130 - return -ENOMEM; 131 - memset(kbtab, 0, sizeof(struct kbtab)); 129 + kbtab = kzalloc(sizeof(struct kbtab), GFP_KERNEL); 130 + input_dev = input_allocate_device(); 131 + if (!kbtab || !input_dev) 132 + goto fail1; 132 133 133 134 kbtab->data = usb_buffer_alloc(dev, 8, GFP_KERNEL, &kbtab->data_dma); 134 - if (!kbtab->data) { 135 - kfree(kbtab); 136 - return -ENOMEM; 137 - } 135 + if (!kbtab->data) 136 + goto fail1; 138 137 139 138 kbtab->irq = usb_alloc_urb(0, GFP_KERNEL); 140 - if (!kbtab->irq) { 141 - usb_buffer_free(dev, 10, kbtab->data, kbtab->data_dma); 142 - kfree(kbtab); 143 - return -ENOMEM; 144 - } 139 + if (!kbtab->irq) 140 + goto fail2; 145 141 146 - kbtab->dev.evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_MSC); 147 - kbtab->dev.absbit[0] |= BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE); 148 - 149 - kbtab->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE); 150 - 151 - kbtab->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_PEN) | BIT(BTN_TOUCH); 152 - 153 - kbtab->dev.mscbit[0] |= BIT(MSC_SERIAL); 154 - 155 - kbtab->dev.absmax[ABS_X] = 0x2000; 156 - kbtab->dev.absmax[ABS_Y] = 0x1750; 157 - kbtab->dev.absmax[ABS_PRESSURE] = 0xff; 158 - 159 - kbtab->dev.absfuzz[ABS_X] = 4; 160 - kbtab->dev.absfuzz[ABS_Y] = 4; 161 - 162 - kbtab->dev.private = kbtab; 163 - kbtab->dev.open = kbtab_open; 164 - kbtab->dev.close = kbtab_close; 165 - 166 - usb_make_path(dev, path, 64); 167 - sprintf(kbtab->phys, "%s/input0", path); 168 - 169 - kbtab->dev.name = "KB Gear Tablet"; 170 - kbtab->dev.phys = kbtab->phys; 171 - usb_to_input_id(dev, &kbtab->dev.id); 172 - kbtab->dev.dev = &intf->dev; 173 142 kbtab->usbdev = dev; 143 + kbtab->dev = input_dev; 144 + 145 + usb_make_path(dev, kbtab->phys, sizeof(kbtab->phys)); 146 + strlcat(kbtab->phys, "/input0", sizeof(kbtab->phys)); 147 + 148 + input_dev->name = "KB Gear Tablet"; 149 + input_dev->phys = kbtab->phys; 150 + usb_to_input_id(dev, &input_dev->id); 151 + input_dev->cdev.dev = &intf->dev; 152 + input_dev->private = kbtab; 153 + 154 + input_dev->open = kbtab_open; 155 + input_dev->close = kbtab_close; 156 + 157 + input_dev->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_MSC); 158 + input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE); 159 + input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_PEN) | BIT(BTN_TOUCH); 160 + input_dev->mscbit[0] |= BIT(MSC_SERIAL); 161 + input_set_abs_params(input_dev, ABS_X, 0, 0x2000, 4, 0); 162 + input_set_abs_params(input_dev, ABS_X, 0, 0x1750, 4, 0); 163 + input_set_abs_params(input_dev, ABS_PRESSURE, 0, 0xff, 0, 0); 174 164 175 165 endpoint = &intf->cur_altsetting->endpoint[0].desc; 176 166 ··· 171 181 kbtab->irq->transfer_dma = kbtab->data_dma; 172 182 kbtab->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 173 183 174 - input_register_device(&kbtab->dev); 175 - 176 - printk(KERN_INFO "input: KB Gear Tablet on %s\n", path); 184 + input_register_device(kbtab->dev); 177 185 178 186 usb_set_intfdata(intf, kbtab); 179 - 180 187 return 0; 188 + 189 + fail2: usb_buffer_free(dev, 10, kbtab->data, kbtab->data_dma); 190 + fail1: input_free_device(input_dev); 191 + kfree(kbtab); 192 + return -ENOMEM; 181 193 } 182 194 183 195 static void kbtab_disconnect(struct usb_interface *intf) 184 196 { 185 - struct kbtab *kbtab = usb_get_intfdata (intf); 197 + struct kbtab *kbtab = usb_get_intfdata(intf); 186 198 187 199 usb_set_intfdata(intf, NULL); 188 200 if (kbtab) { 189 201 usb_kill_urb(kbtab->irq); 190 - input_unregister_device(&kbtab->dev); 202 + input_unregister_device(kbtab->dev); 191 203 usb_free_urb(kbtab->irq); 192 204 usb_buffer_free(interface_to_usbdev(intf), 10, kbtab->data, kbtab->data_dma); 193 205 kfree(kbtab);
+89 -125
drivers/usb/input/keyspan_remote.c
··· 20 20 #include <linux/moduleparam.h> 21 21 #include <linux/input.h> 22 22 #include <linux/usb.h> 23 + #include <linux/usb_input.h> 23 24 24 25 #define DRIVER_VERSION "v0.1" 25 26 #define DRIVER_AUTHOR "Michael Downey <downey@zymeta.com>" ··· 76 75 char name[128]; 77 76 char phys[64]; 78 77 struct usb_device* udev; 79 - struct input_dev input; 78 + struct input_dev *input; 80 79 struct usb_interface* interface; 81 80 struct usb_endpoint_descriptor* in_endpoint; 82 81 struct urb* irq_urb; ··· 137 136 */ 138 137 static void keyspan_print(struct usb_keyspan* dev) /*unsigned char* data)*/ 139 138 { 140 - char codes[4*RECV_SIZE]; 139 + char codes[4 * RECV_SIZE]; 141 140 int i; 142 141 143 - for (i = 0; i < RECV_SIZE; i++) { 144 - snprintf(codes+i*3, 4, "%02x ", dev->in_buffer[i]); 145 - } 142 + for (i = 0; i < RECV_SIZE; i++) 143 + snprintf(codes + i * 3, 4, "%02x ", dev->in_buffer[i]); 146 144 147 145 dev_info(&dev->udev->dev, "%s\n", codes); 148 146 } ··· 153 153 static int keyspan_load_tester(struct usb_keyspan* dev, int bits_needed) 154 154 { 155 155 if (dev->data.bits_left >= bits_needed) 156 - return(0); 156 + return 0; 157 157 158 158 /* 159 159 * Somehow we've missed the last message. The message will be repeated ··· 162 162 if (dev->data.pos >= dev->data.len) { 163 163 dev_dbg(&dev->udev, "%s - Error ran out of data. pos: %d, len: %d\n", 164 164 __FUNCTION__, dev->data.pos, dev->data.len); 165 - return(-1); 165 + return -1; 166 166 } 167 167 168 168 /* Load as much as we can into the tester. */ ··· 172 172 dev->data.bits_left += 8; 173 173 } 174 174 175 - return(0); 175 + return 0; 176 176 } 177 177 178 178 /* ··· 311 311 __FUNCTION__, message.system, message.button, message.toggle); 312 312 313 313 if (message.toggle != remote->toggle) { 314 - input_regs(&remote->input, regs); 315 - input_report_key(&remote->input, keyspan_key_table[message.button], 1); 316 - input_report_key(&remote->input, keyspan_key_table[message.button], 0); 317 - input_sync(&remote->input); 314 + input_regs(remote->input, regs); 315 + input_report_key(remote->input, keyspan_key_table[message.button], 1); 316 + input_report_key(remote->input, keyspan_key_table[message.button], 0); 317 + input_sync(remote->input); 318 318 remote->toggle = message.toggle; 319 319 } 320 320 ··· 397 397 { 398 398 struct usb_keyspan *remote = dev->private; 399 399 400 - if (remote->open++) 401 - return 0; 402 - 403 400 remote->irq_urb->dev = remote->udev; 404 - if (usb_submit_urb(remote->irq_urb, GFP_KERNEL)) { 405 - remote->open--; 401 + if (usb_submit_urb(remote->irq_urb, GFP_KERNEL)) 406 402 return -EIO; 407 - } 408 403 409 404 return 0; 410 405 } ··· 408 413 { 409 414 struct usb_keyspan *remote = dev->private; 410 415 411 - if (!--remote->open) 412 - usb_kill_urb(remote->irq_urb); 416 + usb_kill_urb(remote->irq_urb); 417 + } 418 + 419 + static struct usb_endpoint_descriptor *keyspan_get_in_endpoint(struct usb_host_interface *iface) 420 + { 421 + 422 + struct usb_endpoint_descriptor *endpoint; 423 + int i; 424 + 425 + for (i = 0; i < iface->desc.bNumEndpoints; ++i) { 426 + endpoint = &iface->endpoint[i].desc; 427 + 428 + if ((endpoint->bEndpointAddress & USB_DIR_IN) && 429 + ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)) { 430 + /* we found our interrupt in endpoint */ 431 + return endpoint; 432 + } 433 + } 434 + 435 + return NULL; 413 436 } 414 437 415 438 /* ··· 435 422 */ 436 423 static int keyspan_probe(struct usb_interface *interface, const struct usb_device_id *id) 437 424 { 438 - int i; 439 - int retval = -ENOMEM; 440 - char path[64]; 441 - char *buf; 442 - struct usb_keyspan *remote = NULL; 443 - struct usb_host_interface *iface_desc; 425 + struct usb_device *udev = interface_to_usbdev(interface); 444 426 struct usb_endpoint_descriptor *endpoint; 445 - struct usb_device *udev = usb_get_dev(interface_to_usbdev(interface)); 427 + struct usb_keyspan *remote; 428 + struct input_dev *input_dev; 429 + int i, retval; 446 430 447 - /* allocate memory for our device state and initialize it */ 448 - remote = kmalloc(sizeof(*remote), GFP_KERNEL); 449 - if (remote == NULL) { 450 - err("Out of memory\n"); 451 - goto error; 431 + endpoint = keyspan_get_in_endpoint(interface->cur_altsetting); 432 + if (!endpoint) 433 + return -ENODEV; 434 + 435 + remote = kzalloc(sizeof(*remote), GFP_KERNEL); 436 + input_dev = input_allocate_device(); 437 + if (!remote || !input_dev) { 438 + retval = -ENOMEM; 439 + goto fail1; 452 440 } 453 - memset(remote, 0x00, sizeof(*remote)); 454 441 455 442 remote->udev = udev; 443 + remote->input = input_dev; 456 444 remote->interface = interface; 445 + remote->in_endpoint = endpoint; 457 446 remote->toggle = -1; /* Set to -1 so we will always not match the toggle from the first remote message. */ 458 447 459 - /* set up the endpoint information */ 460 - /* use only the first in interrupt endpoint */ 461 - iface_desc = interface->cur_altsetting; 462 - for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { 463 - endpoint = &iface_desc->endpoint[i].desc; 464 - 465 - if (!remote->in_endpoint && 466 - (endpoint->bEndpointAddress & USB_DIR_IN) && 467 - ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)) { 468 - /* we found our interrupt in endpoint */ 469 - remote->in_endpoint = endpoint; 470 - 471 - remote->in_buffer = usb_buffer_alloc(remote->udev, RECV_SIZE, SLAB_ATOMIC, &remote->in_dma); 472 - if (!remote->in_buffer) { 473 - retval = -ENOMEM; 474 - goto error; 475 - } 476 - } 477 - } 478 - 479 - if (!remote->in_endpoint) { 480 - err("Could not find interrupt input endpoint.\n"); 481 - retval = -ENODEV; 482 - goto error; 448 + remote->in_buffer = usb_buffer_alloc(udev, RECV_SIZE, SLAB_ATOMIC, &remote->in_dma); 449 + if (!remote->in_buffer) { 450 + retval = -ENOMEM; 451 + goto fail1; 483 452 } 484 453 485 454 remote->irq_urb = usb_alloc_urb(0, GFP_KERNEL); 486 455 if (!remote->irq_urb) { 487 - err("Failed to allocate urb.\n"); 488 456 retval = -ENOMEM; 489 - goto error; 457 + goto fail2; 490 458 } 491 459 492 - retval = keyspan_setup(remote->udev); 460 + retval = keyspan_setup(udev); 493 461 if (retval) { 494 - err("Failed to setup device.\n"); 495 462 retval = -ENODEV; 496 - goto error; 463 + goto fail3; 497 464 } 498 465 499 - /* 500 - * Setup the input system with the bits we are going to be reporting 501 - */ 502 - remote->input.evbit[0] = BIT(EV_KEY); /* We will only report KEY events. */ 503 - for (i = 0; i < 32; ++i) { 504 - if (keyspan_key_table[i] != KEY_RESERVED) { 505 - set_bit(keyspan_key_table[i], remote->input.keybit); 506 - } 466 + if (udev->manufacturer) 467 + strlcpy(remote->name, udev->manufacturer, sizeof(remote->name)); 468 + 469 + if (udev->product) { 470 + if (udev->manufacturer) 471 + strlcat(remote->name, " ", sizeof(remote->name)); 472 + strlcat(remote->name, udev->product, sizeof(remote->name)); 507 473 } 508 - 509 - remote->input.private = remote; 510 - remote->input.open = keyspan_open; 511 - remote->input.close = keyspan_close; 512 - 513 - usb_make_path(remote->udev, path, 64); 514 - sprintf(remote->phys, "%s/input0", path); 515 - 516 - remote->input.name = remote->name; 517 - remote->input.phys = remote->phys; 518 - remote->input.id.bustype = BUS_USB; 519 - remote->input.id.vendor = le16_to_cpu(remote->udev->descriptor.idVendor); 520 - remote->input.id.product = le16_to_cpu(remote->udev->descriptor.idProduct); 521 - remote->input.id.version = le16_to_cpu(remote->udev->descriptor.bcdDevice); 522 - 523 - if (!(buf = kmalloc(63, GFP_KERNEL))) { 524 - usb_buffer_free(remote->udev, RECV_SIZE, remote->in_buffer, remote->in_dma); 525 - kfree(remote); 526 - return -ENOMEM; 527 - } 528 - 529 - if (remote->udev->descriptor.iManufacturer && 530 - usb_string(remote->udev, remote->udev->descriptor.iManufacturer, buf, 63) > 0) 531 - strcat(remote->name, buf); 532 - 533 - if (remote->udev->descriptor.iProduct && 534 - usb_string(remote->udev, remote->udev->descriptor.iProduct, buf, 63) > 0) 535 - sprintf(remote->name, "%s %s", remote->name, buf); 536 474 537 475 if (!strlen(remote->name)) 538 - sprintf(remote->name, "USB Keyspan Remote %04x:%04x", 539 - remote->input.id.vendor, remote->input.id.product); 476 + snprintf(remote->name, sizeof(remote->name), 477 + "USB Keyspan Remote %04x:%04x", 478 + le16_to_cpu(udev->descriptor.idVendor), 479 + le16_to_cpu(udev->descriptor.idProduct)); 540 480 541 - kfree(buf); 481 + usb_make_path(udev, remote->phys, sizeof(remote->phys)); 482 + strlcat(remote->phys, "/input0", sizeof(remote->phys)); 483 + 484 + input_dev->name = remote->name; 485 + input_dev->phys = remote->phys; 486 + usb_to_input_id(udev, &input_dev->id); 487 + input_dev->cdev.dev = &interface->dev; 488 + 489 + input_dev->evbit[0] = BIT(EV_KEY); /* We will only report KEY events. */ 490 + for (i = 0; i < ARRAY_SIZE(keyspan_key_table); i++) 491 + if (keyspan_key_table[i] != KEY_RESERVED) 492 + set_bit(keyspan_key_table[i], input_dev->keybit); 493 + 494 + input_dev->private = remote; 495 + input_dev->open = keyspan_open; 496 + input_dev->close = keyspan_close; 542 497 543 498 /* 544 499 * Initialize the URB to access the device. The urb gets sent to the device in keyspan_open() ··· 519 538 remote->irq_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 520 539 521 540 /* we can register the device now, as it is ready */ 522 - input_register_device(&remote->input); 541 + input_register_device(remote->input); 523 542 524 543 /* save our data pointer in this interface device */ 525 544 usb_set_intfdata(interface, remote); 526 545 527 - /* let the user know what node this device is now attached to */ 528 - info("connected: %s on %s", remote->name, path); 529 546 return 0; 530 547 531 - error: 532 - /* 533 - * In case of error we need to clean up any allocated buffers 534 - */ 535 - if (remote->irq_urb) 536 - usb_free_urb(remote->irq_urb); 537 - 538 - if (remote->in_buffer) 539 - usb_buffer_free(remote->udev, RECV_SIZE, remote->in_buffer, remote->in_dma); 540 - 541 - if (remote) 542 - kfree(remote); 548 + fail3: usb_free_urb(remote->irq_urb); 549 + fail2: usb_buffer_free(udev, RECV_SIZE, remote->in_buffer, remote->in_dma); 550 + fail1: kfree(remote); 551 + input_free_device(input_dev); 543 552 544 553 return retval; 545 554 } ··· 541 570 { 542 571 struct usb_keyspan *remote; 543 572 544 - /* prevent keyspan_open() from racing keyspan_disconnect() */ 545 - lock_kernel(); 546 - 547 573 remote = usb_get_intfdata(interface); 548 574 usb_set_intfdata(interface, NULL); 549 575 550 576 if (remote) { /* We have a valid driver structure so clean up everything we allocated. */ 551 - input_unregister_device(&remote->input); 577 + input_unregister_device(remote->input); 552 578 usb_kill_urb(remote->irq_urb); 553 579 usb_free_urb(remote->irq_urb); 554 - usb_buffer_free(interface_to_usbdev(interface), RECV_SIZE, remote->in_buffer, remote->in_dma); 580 + usb_buffer_free(remote->udev, RECV_SIZE, remote->in_buffer, remote->in_dma); 555 581 kfree(remote); 556 582 } 557 - 558 - unlock_kernel(); 559 - 560 - info("USB Keyspan now disconnected"); 561 583 } 562 584 563 585 /*
+55 -56
drivers/usb/input/mtouchusb.c
··· 98 98 dma_addr_t data_dma; 99 99 struct urb *irq; 100 100 struct usb_device *udev; 101 - struct input_dev input; 101 + struct input_dev *input; 102 102 char name[128]; 103 103 char phys[64]; 104 104 }; ··· 135 135 goto exit; 136 136 } 137 137 138 - input_regs(&mtouch->input, regs); 139 - input_report_key(&mtouch->input, BTN_TOUCH, 138 + input_regs(mtouch->input, regs); 139 + input_report_key(mtouch->input, BTN_TOUCH, 140 140 MTOUCHUSB_GET_TOUCHED(mtouch->data)); 141 - input_report_abs(&mtouch->input, ABS_X, MTOUCHUSB_GET_XC(mtouch->data)); 142 - input_report_abs(&mtouch->input, ABS_Y, 141 + input_report_abs(mtouch->input, ABS_X, MTOUCHUSB_GET_XC(mtouch->data)); 142 + input_report_abs(mtouch->input, ABS_Y, 143 143 (raw_coordinates ? MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC) 144 144 - MTOUCHUSB_GET_YC(mtouch->data)); 145 - input_sync(&mtouch->input); 145 + input_sync(mtouch->input); 146 146 147 147 exit: 148 148 retval = usb_submit_urb(urb, GFP_ATOMIC); ··· 195 195 static int mtouchusb_probe(struct usb_interface *intf, const struct usb_device_id *id) 196 196 { 197 197 struct mtouch_usb *mtouch; 198 + struct input_dev *input_dev; 198 199 struct usb_host_interface *interface; 199 200 struct usb_endpoint_descriptor *endpoint; 200 201 struct usb_device *udev = interface_to_usbdev(intf); 201 - char path[64]; 202 202 int nRet; 203 203 204 204 dbg("%s - called", __FUNCTION__); ··· 209 209 dbg("%s - setting endpoint", __FUNCTION__); 210 210 endpoint = &interface->endpoint[0].desc; 211 211 212 - if (!(mtouch = kmalloc(sizeof(struct mtouch_usb), GFP_KERNEL))) { 212 + mtouch = kzalloc(sizeof(struct mtouch_usb), GFP_KERNEL); 213 + input_dev = input_allocate_device(); 214 + if (!mtouch || !input_dev) { 213 215 err("%s - Out of memory.", __FUNCTION__); 214 - return -ENOMEM; 216 + goto fail1; 215 217 } 216 - 217 - memset(mtouch, 0, sizeof(struct mtouch_usb)); 218 - mtouch->udev = udev; 219 218 220 219 dbg("%s - allocating buffers", __FUNCTION__); 221 - if (mtouchusb_alloc_buffers(udev, mtouch)) { 222 - mtouchusb_free_buffers(udev, mtouch); 223 - kfree(mtouch); 224 - return -ENOMEM; 225 - } 220 + if (mtouchusb_alloc_buffers(udev, mtouch)) 221 + goto fail2; 226 222 227 - mtouch->input.private = mtouch; 228 - mtouch->input.open = mtouchusb_open; 229 - mtouch->input.close = mtouchusb_close; 230 - 231 - usb_make_path(udev, path, 64); 232 - sprintf(mtouch->phys, "%s/input0", path); 233 - 234 - mtouch->input.name = mtouch->name; 235 - mtouch->input.phys = mtouch->phys; 236 - usb_to_input_id(udev, &mtouch->input.id); 237 - mtouch->input.dev = &intf->dev; 238 - 239 - mtouch->input.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 240 - mtouch->input.absbit[0] = BIT(ABS_X) | BIT(ABS_Y); 241 - mtouch->input.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); 242 - 243 - /* Used to Scale Compensated Data and Flip Y */ 244 - mtouch->input.absmin[ABS_X] = MTOUCHUSB_MIN_XC; 245 - mtouch->input.absmax[ABS_X] = raw_coordinates ? 246 - MTOUCHUSB_MAX_RAW_XC : MTOUCHUSB_MAX_CALIB_XC; 247 - mtouch->input.absfuzz[ABS_X] = MTOUCHUSB_XC_FUZZ; 248 - mtouch->input.absflat[ABS_X] = MTOUCHUSB_XC_FLAT; 249 - mtouch->input.absmin[ABS_Y] = MTOUCHUSB_MIN_YC; 250 - mtouch->input.absmax[ABS_Y] = raw_coordinates ? 251 - MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC; 252 - mtouch->input.absfuzz[ABS_Y] = MTOUCHUSB_YC_FUZZ; 253 - mtouch->input.absflat[ABS_Y] = MTOUCHUSB_YC_FLAT; 223 + mtouch->udev = udev; 224 + mtouch->input = input_dev; 254 225 255 226 if (udev->manufacturer) 256 - strcat(mtouch->name, udev->manufacturer); 257 - if (udev->product) 258 - sprintf(mtouch->name, "%s %s", mtouch->name, udev->product); 227 + strlcpy(mtouch->name, udev->manufacturer, sizeof(mtouch->name)); 228 + 229 + if (udev->product) { 230 + if (udev->manufacturer) 231 + strlcat(mtouch->name, " ", sizeof(mtouch->name)); 232 + strlcat(mtouch->name, udev->product, sizeof(mtouch->name)); 233 + } 259 234 260 235 if (!strlen(mtouch->name)) 261 - sprintf(mtouch->name, "USB Touchscreen %04x:%04x", 262 - mtouch->input.id.vendor, mtouch->input.id.product); 236 + snprintf(mtouch->name, sizeof(mtouch->name), 237 + "USB Touchscreen %04x:%04x", 238 + le16_to_cpu(udev->descriptor.idVendor), 239 + le16_to_cpu(udev->descriptor.idProduct)); 240 + 241 + usb_make_path(udev, mtouch->phys, sizeof(mtouch->phys)); 242 + strlcpy(mtouch->phys, "/input0", sizeof(mtouch->phys)); 243 + 244 + input_dev->name = mtouch->name; 245 + input_dev->phys = mtouch->phys; 246 + usb_to_input_id(udev, &input_dev->id); 247 + input_dev->cdev.dev = &intf->dev; 248 + input_dev->private = mtouch; 249 + 250 + input_dev->open = mtouchusb_open; 251 + input_dev->close = mtouchusb_close; 252 + 253 + input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 254 + input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); 255 + input_set_abs_params(input_dev, ABS_X, MTOUCHUSB_MIN_XC, 256 + raw_coordinates ? MTOUCHUSB_MAX_RAW_XC : MTOUCHUSB_MAX_CALIB_XC, 257 + MTOUCHUSB_XC_FUZZ, MTOUCHUSB_XC_FLAT); 258 + input_set_abs_params(input_dev, ABS_Y, MTOUCHUSB_MIN_YC, 259 + raw_coordinates ? MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC, 260 + MTOUCHUSB_YC_FUZZ, MTOUCHUSB_YC_FLAT); 263 261 264 262 nRet = usb_control_msg(mtouch->udev, usb_rcvctrlpipe(udev, 0), 265 263 MTOUCHUSB_RESET, ··· 270 272 mtouch->irq = usb_alloc_urb(0, GFP_KERNEL); 271 273 if (!mtouch->irq) { 272 274 dbg("%s - usb_alloc_urb failed: mtouch->irq", __FUNCTION__); 273 - mtouchusb_free_buffers(udev, mtouch); 274 - kfree(mtouch); 275 - return -ENOMEM; 275 + goto fail2; 276 276 } 277 277 278 278 dbg("%s - usb_fill_int_urb", __FUNCTION__); ··· 280 284 mtouchusb_irq, mtouch, endpoint->bInterval); 281 285 282 286 dbg("%s - input_register_device", __FUNCTION__); 283 - input_register_device(&mtouch->input); 287 + input_register_device(mtouch->input); 284 288 285 289 nRet = usb_control_msg(mtouch->udev, usb_rcvctrlpipe(udev, 0), 286 290 MTOUCHUSB_ASYNC_REPORT, ··· 289 293 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d", 290 294 __FUNCTION__, nRet); 291 295 292 - printk(KERN_INFO "input: %s on %s\n", mtouch->name, path); 293 296 usb_set_intfdata(intf, mtouch); 294 - 295 297 return 0; 298 + 299 + fail2: mtouchusb_free_buffers(udev, mtouch); 300 + fail1: input_free_device(input_dev); 301 + kfree(mtouch); 302 + return -ENOMEM; 296 303 } 297 304 298 305 static void mtouchusb_disconnect(struct usb_interface *intf) ··· 307 308 if (mtouch) { 308 309 dbg("%s - mtouch is initialized, cleaning up", __FUNCTION__); 309 310 usb_kill_urb(mtouch->irq); 310 - input_unregister_device(&mtouch->input); 311 + input_unregister_device(mtouch->input); 311 312 usb_free_urb(mtouch->irq); 312 313 mtouchusb_free_buffers(interface_to_usbdev(intf), mtouch); 313 314 kfree(mtouch);
+7 -5
drivers/usb/input/pid.c
··· 262 262 { 263 263 struct hid_ff_pid *private; 264 264 struct hid_input *hidinput = list_entry(&hid->inputs, struct hid_input, list); 265 + struct input_dev *input_dev = hidinput->input; 265 266 266 267 private = hid->ff_private = kzalloc(sizeof(struct hid_ff_pid), GFP_KERNEL); 267 268 if (!private) ··· 282 281 usb_fill_control_urb(private->urbffout, hid->dev, 0, 283 282 (void *)&private->ffcr, private->ctrl_buffer, 8, 284 283 hid_pid_ctrl_out, hid); 285 - hidinput->input.upload_effect = hid_pid_upload_effect; 286 - hidinput->input.flush = hid_pid_flush; 287 - hidinput->input.ff_effects_max = 8; // A random default 288 - set_bit(EV_FF, hidinput->input.evbit); 289 - set_bit(EV_FF_STATUS, hidinput->input.evbit); 284 + 285 + input_dev->upload_effect = hid_pid_upload_effect; 286 + input_dev->flush = hid_pid_flush; 287 + input_dev->ff_effects_max = 8; // A random default 288 + set_bit(EV_FF, input_dev->evbit); 289 + set_bit(EV_FF_STATUS, input_dev->evbit); 290 290 291 291 spin_lock_init(&private->lock); 292 292
+70 -66
drivers/usb/input/powermate.c
··· 68 68 struct usb_ctrlrequest *configcr; 69 69 dma_addr_t configcr_dma; 70 70 struct usb_device *udev; 71 - struct input_dev input; 71 + struct input_dev *input; 72 72 spinlock_t lock; 73 73 int static_brightness; 74 74 int pulse_speed; ··· 106 106 } 107 107 108 108 /* handle updates to device state */ 109 - input_regs(&pm->input, regs); 110 - input_report_key(&pm->input, BTN_0, pm->data[0] & 0x01); 111 - input_report_rel(&pm->input, REL_DIAL, pm->data[1]); 112 - input_sync(&pm->input); 109 + input_regs(pm->input, regs); 110 + input_report_key(pm->input, BTN_0, pm->data[0] & 0x01); 111 + input_report_rel(pm->input, REL_DIAL, pm->data[1]); 112 + input_sync(pm->input); 113 113 114 114 exit: 115 115 retval = usb_submit_urb (urb, GFP_ATOMIC); ··· 153 153 154 154 Only values of 'arg' quite close to 255 are particularly useful/spectacular. 155 155 */ 156 - if (pm->pulse_speed < 255){ 156 + if (pm->pulse_speed < 255) { 157 157 op = 0; // divide 158 158 arg = 255 - pm->pulse_speed; 159 - } else if (pm->pulse_speed > 255){ 159 + } else if (pm->pulse_speed > 255) { 160 160 op = 2; // multiply 161 161 arg = pm->pulse_speed - 255; 162 162 } else { ··· 166 166 pm->configcr->wValue = cpu_to_le16( (pm->pulse_table << 8) | SET_PULSE_MODE ); 167 167 pm->configcr->wIndex = cpu_to_le16( (arg << 8) | op ); 168 168 pm->requires_update &= ~UPDATE_PULSE_MODE; 169 - }else if (pm->requires_update & UPDATE_STATIC_BRIGHTNESS){ 169 + } else if (pm->requires_update & UPDATE_STATIC_BRIGHTNESS) { 170 170 pm->configcr->wValue = cpu_to_le16( SET_STATIC_BRIGHTNESS ); 171 171 pm->configcr->wIndex = cpu_to_le16( pm->static_brightness ); 172 172 pm->requires_update &= ~UPDATE_STATIC_BRIGHTNESS; 173 - }else{ 173 + } else { 174 174 printk(KERN_ERR "powermate: unknown update required"); 175 175 pm->requires_update = 0; /* fudge the bug */ 176 176 return; ··· 228 228 spin_lock_irqsave(&pm->lock, flags); 229 229 230 230 /* mark state updates which are required */ 231 - if (static_brightness != pm->static_brightness){ 231 + if (static_brightness != pm->static_brightness) { 232 232 pm->static_brightness = static_brightness; 233 233 pm->requires_update |= UPDATE_STATIC_BRIGHTNESS; 234 234 } 235 - if (pulse_asleep != pm->pulse_asleep){ 235 + if (pulse_asleep != pm->pulse_asleep) { 236 236 pm->pulse_asleep = pulse_asleep; 237 237 pm->requires_update |= (UPDATE_PULSE_ASLEEP | UPDATE_STATIC_BRIGHTNESS); 238 238 } 239 - if (pulse_awake != pm->pulse_awake){ 239 + if (pulse_awake != pm->pulse_awake) { 240 240 pm->pulse_awake = pulse_awake; 241 241 pm->requires_update |= (UPDATE_PULSE_AWAKE | UPDATE_STATIC_BRIGHTNESS); 242 242 } 243 - if (pulse_speed != pm->pulse_speed || pulse_table != pm->pulse_table){ 243 + if (pulse_speed != pm->pulse_speed || pulse_table != pm->pulse_table) { 244 244 pm->pulse_speed = pulse_speed; 245 245 pm->pulse_table = pulse_table; 246 246 pm->requires_update |= UPDATE_PULSE_MODE; ··· 283 283 SLAB_ATOMIC, &pm->data_dma); 284 284 if (!pm->data) 285 285 return -1; 286 + 286 287 pm->configcr = usb_buffer_alloc(udev, sizeof(*(pm->configcr)), 287 288 SLAB_ATOMIC, &pm->configcr_dma); 288 289 if (!pm->configcr) ··· 309 308 struct usb_host_interface *interface; 310 309 struct usb_endpoint_descriptor *endpoint; 311 310 struct powermate_device *pm; 311 + struct input_dev *input_dev; 312 312 int pipe, maxp; 313 - char path[64]; 313 + int err = -ENOMEM; 314 314 315 315 interface = intf->cur_altsetting; 316 316 endpoint = &interface->endpoint[0].desc; ··· 325 323 0, interface->desc.bInterfaceNumber, NULL, 0, 326 324 USB_CTRL_SET_TIMEOUT); 327 325 328 - if (!(pm = kmalloc(sizeof(struct powermate_device), GFP_KERNEL))) 329 - return -ENOMEM; 326 + pm = kzalloc(sizeof(struct powermate_device), GFP_KERNEL); 327 + input_dev = input_allocate_device(); 328 + if (!pm || !input_dev) 329 + goto fail1; 330 330 331 - memset(pm, 0, sizeof(struct powermate_device)); 332 - pm->udev = udev; 333 - 334 - if (powermate_alloc_buffers(udev, pm)) { 335 - powermate_free_buffers(udev, pm); 336 - kfree(pm); 337 - return -ENOMEM; 338 - } 331 + if (powermate_alloc_buffers(udev, pm)) 332 + goto fail2; 339 333 340 334 pm->irq = usb_alloc_urb(0, GFP_KERNEL); 341 - if (!pm->irq) { 342 - powermate_free_buffers(udev, pm); 343 - kfree(pm); 344 - return -ENOMEM; 345 - } 335 + if (!pm->irq) 336 + goto fail2; 346 337 347 338 pm->config = usb_alloc_urb(0, GFP_KERNEL); 348 - if (!pm->config) { 349 - usb_free_urb(pm->irq); 350 - powermate_free_buffers(udev, pm); 351 - kfree(pm); 352 - return -ENOMEM; 353 - } 339 + if (!pm->config) 340 + goto fail3; 341 + 342 + pm->udev = udev; 343 + pm->input = input_dev; 344 + 345 + usb_make_path(udev, pm->phys, sizeof(pm->phys)); 346 + strlcpy(pm->phys, "/input0", sizeof(pm->phys)); 354 347 355 348 spin_lock_init(&pm->lock); 356 - init_input_dev(&pm->input); 349 + 350 + switch (le16_to_cpu(udev->descriptor.idProduct)) { 351 + case POWERMATE_PRODUCT_NEW: 352 + input_dev->name = pm_name_powermate; 353 + break; 354 + case POWERMATE_PRODUCT_OLD: 355 + input_dev->name = pm_name_soundknob; 356 + break; 357 + default: 358 + input_dev->name = pm_name_soundknob; 359 + printk(KERN_WARNING "powermate: unknown product id %04x\n", 360 + le16_to_cpu(udev->descriptor.idProduct)); 361 + } 362 + 363 + input_dev->phys = pm->phys; 364 + usb_to_input_id(udev, &input_dev->id); 365 + input_dev->cdev.dev = &intf->dev; 366 + input_dev->private = pm; 367 + 368 + input_dev->event = powermate_input_event; 369 + 370 + input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL) | BIT(EV_MSC); 371 + input_dev->keybit[LONG(BTN_0)] = BIT(BTN_0); 372 + input_dev->relbit[LONG(REL_DIAL)] = BIT(REL_DIAL); 373 + input_dev->mscbit[LONG(MSC_PULSELED)] = BIT(MSC_PULSELED); 357 374 358 375 /* get a handle to the interrupt data pipe */ 359 376 pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress); 360 377 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe)); 361 378 362 - if(maxp < POWERMATE_PAYLOAD_SIZE_MIN || maxp > POWERMATE_PAYLOAD_SIZE_MAX){ 363 - printk("powermate: Expected payload of %d--%d bytes, found %d bytes!\n", 379 + if (maxp < POWERMATE_PAYLOAD_SIZE_MIN || maxp > POWERMATE_PAYLOAD_SIZE_MAX) { 380 + printk(KERN_WARNING "powermate: Expected payload of %d--%d bytes, found %d bytes!\n", 364 381 POWERMATE_PAYLOAD_SIZE_MIN, POWERMATE_PAYLOAD_SIZE_MAX, maxp); 365 382 maxp = POWERMATE_PAYLOAD_SIZE_MAX; 366 383 } ··· 392 371 393 372 /* register our interrupt URB with the USB system */ 394 373 if (usb_submit_urb(pm->irq, GFP_KERNEL)) { 395 - powermate_free_buffers(udev, pm); 396 - kfree(pm); 397 - return -EIO; /* failure */ 374 + err = -EIO; 375 + goto fail4; 398 376 } 399 377 400 - switch (le16_to_cpu(udev->descriptor.idProduct)) { 401 - case POWERMATE_PRODUCT_NEW: pm->input.name = pm_name_powermate; break; 402 - case POWERMATE_PRODUCT_OLD: pm->input.name = pm_name_soundknob; break; 403 - default: 404 - pm->input.name = pm_name_soundknob; 405 - printk(KERN_WARNING "powermate: unknown product id %04x\n", 406 - le16_to_cpu(udev->descriptor.idProduct)); 407 - } 408 - 409 - pm->input.private = pm; 410 - pm->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REL) | BIT(EV_MSC); 411 - pm->input.keybit[LONG(BTN_0)] = BIT(BTN_0); 412 - pm->input.relbit[LONG(REL_DIAL)] = BIT(REL_DIAL); 413 - pm->input.mscbit[LONG(MSC_PULSELED)] = BIT(MSC_PULSELED); 414 - usb_to_input_id(udev, &pm->input.id); 415 - pm->input.event = powermate_input_event; 416 - pm->input.dev = &intf->dev; 417 - pm->input.phys = pm->phys; 418 - 419 - input_register_device(&pm->input); 420 - 421 - usb_make_path(udev, path, 64); 422 - snprintf(pm->phys, 64, "%s/input0", path); 423 - printk(KERN_INFO "input: %s on %s\n", pm->input.name, pm->input.phys); 378 + input_register_device(pm->input); 424 379 425 380 /* force an update of everything */ 426 381 pm->requires_update = UPDATE_PULSE_ASLEEP | UPDATE_PULSE_AWAKE | UPDATE_PULSE_MODE | UPDATE_STATIC_BRIGHTNESS; ··· 404 407 405 408 usb_set_intfdata(intf, pm); 406 409 return 0; 410 + 411 + fail4: usb_free_urb(pm->config); 412 + fail3: usb_free_urb(pm->irq); 413 + fail2: powermate_free_buffers(udev, pm); 414 + fail1: input_free_device(input_dev); 415 + kfree(pm); 416 + return err; 407 417 } 408 418 409 419 /* Called when a USB device we've accepted ownership of is removed */ ··· 422 418 if (pm) { 423 419 pm->requires_update = 0; 424 420 usb_kill_urb(pm->irq); 425 - input_unregister_device(&pm->input); 421 + input_unregister_device(pm->input); 426 422 usb_free_urb(pm->irq); 427 423 usb_free_urb(pm->config); 428 424 powermate_free_buffers(interface_to_usbdev(intf), pm);
+55 -61
drivers/usb/input/touchkitusb.c
··· 68 68 dma_addr_t data_dma; 69 69 struct urb *irq; 70 70 struct usb_device *udev; 71 - struct input_dev input; 71 + struct input_dev *input; 72 72 char name[128]; 73 73 char phys[64]; 74 74 }; ··· 115 115 y = TOUCHKIT_GET_Y(touchkit->data); 116 116 } 117 117 118 - input_regs(&touchkit->input, regs); 119 - input_report_key(&touchkit->input, BTN_TOUCH, 118 + input_regs(touchkit->input, regs); 119 + input_report_key(touchkit->input, BTN_TOUCH, 120 120 TOUCHKIT_GET_TOUCHED(touchkit->data)); 121 - input_report_abs(&touchkit->input, ABS_X, x); 122 - input_report_abs(&touchkit->input, ABS_Y, y); 123 - input_sync(&touchkit->input); 121 + input_report_abs(touchkit->input, ABS_X, x); 122 + input_report_abs(touchkit->input, ABS_Y, y); 123 + input_sync(touchkit->input); 124 124 125 125 exit: 126 126 retval = usb_submit_urb(urb, GFP_ATOMIC); ··· 171 171 static int touchkit_probe(struct usb_interface *intf, 172 172 const struct usb_device_id *id) 173 173 { 174 - int ret; 175 174 struct touchkit_usb *touchkit; 175 + struct input_dev *input_dev; 176 176 struct usb_host_interface *interface; 177 177 struct usb_endpoint_descriptor *endpoint; 178 178 struct usb_device *udev = interface_to_usbdev(intf); 179 - char path[64]; 180 179 181 180 interface = intf->cur_altsetting; 182 181 endpoint = &interface->endpoint[0].desc; 183 182 184 - touchkit = kmalloc(sizeof(struct touchkit_usb), GFP_KERNEL); 185 - if (!touchkit) 186 - return -ENOMEM; 187 - 188 - memset(touchkit, 0, sizeof(struct touchkit_usb)); 189 - touchkit->udev = udev; 190 - 191 - if (touchkit_alloc_buffers(udev, touchkit)) { 192 - ret = -ENOMEM; 183 + touchkit = kzalloc(sizeof(struct touchkit_usb), GFP_KERNEL); 184 + input_dev = input_allocate_device(); 185 + if (!touchkit || !input_dev) 193 186 goto out_free; 194 - } 195 187 196 - touchkit->input.private = touchkit; 197 - touchkit->input.open = touchkit_open; 198 - touchkit->input.close = touchkit_close; 199 - 200 - usb_make_path(udev, path, 64); 201 - sprintf(touchkit->phys, "%s/input0", path); 202 - 203 - touchkit->input.name = touchkit->name; 204 - touchkit->input.phys = touchkit->phys; 205 - usb_to_input_id(udev, &touchkit->input.id); 206 - touchkit->input.dev = &intf->dev; 207 - 208 - touchkit->input.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 209 - touchkit->input.absbit[0] = BIT(ABS_X) | BIT(ABS_Y); 210 - touchkit->input.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); 211 - 212 - /* Used to Scale Compensated Data */ 213 - touchkit->input.absmin[ABS_X] = TOUCHKIT_MIN_XC; 214 - touchkit->input.absmax[ABS_X] = TOUCHKIT_MAX_XC; 215 - touchkit->input.absfuzz[ABS_X] = TOUCHKIT_XC_FUZZ; 216 - touchkit->input.absflat[ABS_X] = TOUCHKIT_XC_FLAT; 217 - touchkit->input.absmin[ABS_Y] = TOUCHKIT_MIN_YC; 218 - touchkit->input.absmax[ABS_Y] = TOUCHKIT_MAX_YC; 219 - touchkit->input.absfuzz[ABS_Y] = TOUCHKIT_YC_FUZZ; 220 - touchkit->input.absflat[ABS_Y] = TOUCHKIT_YC_FLAT; 221 - 222 - if (udev->manufacturer) 223 - strcat(touchkit->name, udev->manufacturer); 224 - if (udev->product) 225 - sprintf(touchkit->name, "%s %s", touchkit->name, udev->product); 226 - 227 - if (!strlen(touchkit->name)) 228 - sprintf(touchkit->name, "USB Touchscreen %04x:%04x", 229 - touchkit->input.id.vendor, touchkit->input.id.product); 188 + if (touchkit_alloc_buffers(udev, touchkit)) 189 + goto out_free; 230 190 231 191 touchkit->irq = usb_alloc_urb(0, GFP_KERNEL); 232 192 if (!touchkit->irq) { 233 193 dbg("%s - usb_alloc_urb failed: touchkit->irq", __FUNCTION__); 234 - ret = -ENOMEM; 235 194 goto out_free_buffers; 236 195 } 237 196 197 + touchkit->udev = udev; 198 + touchkit->input = input_dev; 199 + 200 + if (udev->manufacturer) 201 + strlcpy(touchkit->name, udev->manufacturer, sizeof(touchkit->name)); 202 + 203 + if (udev->product) { 204 + if (udev->manufacturer) 205 + strlcat(touchkit->name, " ", sizeof(touchkit->name)); 206 + strlcat(touchkit->name, udev->product, sizeof(touchkit->name)); 207 + } 208 + 209 + if (!strlen(touchkit->name)) 210 + snprintf(touchkit->name, sizeof(touchkit->name), 211 + "USB Touchscreen %04x:%04x", 212 + le16_to_cpu(udev->descriptor.idVendor), 213 + le16_to_cpu(udev->descriptor.idProduct)); 214 + 215 + usb_make_path(udev, touchkit->phys, sizeof(touchkit->phys)); 216 + strlcpy(touchkit->phys, "/input0", sizeof(touchkit->phys)); 217 + 218 + input_dev->name = touchkit->name; 219 + input_dev->phys = touchkit->phys; 220 + usb_to_input_id(udev, &input_dev->id); 221 + input_dev->cdev.dev = &intf->dev; 222 + input_dev->private = touchkit; 223 + input_dev->open = touchkit_open; 224 + input_dev->close = touchkit_close; 225 + 226 + input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 227 + input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); 228 + input_set_abs_params(input_dev, ABS_X, TOUCHKIT_MIN_XC, TOUCHKIT_MAX_XC, 229 + TOUCHKIT_XC_FUZZ, TOUCHKIT_XC_FLAT); 230 + input_set_abs_params(input_dev, ABS_Y, TOUCHKIT_MIN_YC, TOUCHKIT_MAX_YC, 231 + TOUCHKIT_YC_FUZZ, TOUCHKIT_YC_FLAT); 232 + 238 233 usb_fill_int_urb(touchkit->irq, touchkit->udev, 239 - usb_rcvintpipe(touchkit->udev, 0x81), 240 - touchkit->data, TOUCHKIT_REPORT_DATA_SIZE, 241 - touchkit_irq, touchkit, endpoint->bInterval); 234 + usb_rcvintpipe(touchkit->udev, 0x81), 235 + touchkit->data, TOUCHKIT_REPORT_DATA_SIZE, 236 + touchkit_irq, touchkit, endpoint->bInterval); 242 237 243 - input_register_device(&touchkit->input); 238 + input_register_device(touchkit->input); 244 239 245 - printk(KERN_INFO "input: %s on %s\n", touchkit->name, path); 246 240 usb_set_intfdata(intf, touchkit); 247 - 248 241 return 0; 249 242 250 243 out_free_buffers: 251 244 touchkit_free_buffers(udev, touchkit); 252 245 out_free: 246 + input_free_device(input_dev); 253 247 kfree(touchkit); 254 - return ret; 248 + return -ENOMEM; 255 249 } 256 250 257 251 static void touchkit_disconnect(struct usb_interface *intf) ··· 259 265 260 266 dbg("%s - touchkit is initialized, cleaning up", __FUNCTION__); 261 267 usb_set_intfdata(intf, NULL); 262 - input_unregister_device(&touchkit->input); 263 268 usb_kill_urb(touchkit->irq); 269 + input_unregister_device(touchkit->input); 264 270 usb_free_urb(touchkit->irq); 265 271 touchkit_free_buffers(interface_to_usbdev(intf), touchkit); 266 272 kfree(touchkit);
+56 -49
drivers/usb/input/usbkbd.c
··· 66 66 }; 67 67 68 68 struct usb_kbd { 69 - struct input_dev dev; 69 + struct input_dev *dev; 70 70 struct usb_device *usbdev; 71 71 unsigned char old[8]; 72 72 struct urb *irq, *led; ··· 99 99 goto resubmit; 100 100 } 101 101 102 - input_regs(&kbd->dev, regs); 102 + input_regs(kbd->dev, regs); 103 103 104 104 for (i = 0; i < 8; i++) 105 - input_report_key(&kbd->dev, usb_kbd_keycode[i + 224], (kbd->new[0] >> i) & 1); 105 + input_report_key(kbd->dev, usb_kbd_keycode[i + 224], (kbd->new[0] >> i) & 1); 106 106 107 107 for (i = 2; i < 8; i++) { 108 108 109 109 if (kbd->old[i] > 3 && memscan(kbd->new + 2, kbd->old[i], 6) == kbd->new + 8) { 110 110 if (usb_kbd_keycode[kbd->old[i]]) 111 - input_report_key(&kbd->dev, usb_kbd_keycode[kbd->old[i]], 0); 111 + input_report_key(kbd->dev, usb_kbd_keycode[kbd->old[i]], 0); 112 112 else 113 113 info("Unknown key (scancode %#x) released.", kbd->old[i]); 114 114 } 115 115 116 116 if (kbd->new[i] > 3 && memscan(kbd->old + 2, kbd->new[i], 6) == kbd->old + 8) { 117 117 if (usb_kbd_keycode[kbd->new[i]]) 118 - input_report_key(&kbd->dev, usb_kbd_keycode[kbd->new[i]], 1); 118 + input_report_key(kbd->dev, usb_kbd_keycode[kbd->new[i]], 1); 119 119 else 120 120 info("Unknown key (scancode %#x) pressed.", kbd->new[i]); 121 121 } 122 122 } 123 123 124 - input_sync(&kbd->dev); 124 + input_sync(kbd->dev); 125 125 126 126 memcpy(kbd->old, kbd->new, 8); 127 127 ··· 227 227 static int usb_kbd_probe(struct usb_interface *iface, 228 228 const struct usb_device_id *id) 229 229 { 230 - struct usb_device * dev = interface_to_usbdev(iface); 230 + struct usb_device *dev = interface_to_usbdev(iface); 231 231 struct usb_host_interface *interface; 232 232 struct usb_endpoint_descriptor *endpoint; 233 233 struct usb_kbd *kbd; 234 + struct input_dev *input_dev; 234 235 int i, pipe, maxp; 235 - char path[64]; 236 236 237 237 interface = iface->cur_altsetting; 238 238 ··· 240 240 return -ENODEV; 241 241 242 242 endpoint = &interface->endpoint[0].desc; 243 - if (!(endpoint->bEndpointAddress & 0x80)) 243 + if (!(endpoint->bEndpointAddress & USB_DIR_IN)) 244 244 return -ENODEV; 245 - if ((endpoint->bmAttributes & 3) != 3) 245 + if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_INT) 246 246 return -ENODEV; 247 247 248 248 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress); 249 249 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe)); 250 250 251 - if (!(kbd = kmalloc(sizeof(struct usb_kbd), GFP_KERNEL))) 252 - return -ENOMEM; 253 - memset(kbd, 0, sizeof(struct usb_kbd)); 251 + kbd = kzalloc(sizeof(struct usb_kbd), GFP_KERNEL); 252 + input_dev = input_allocate_device(); 253 + if (!kbd || !input_dev) 254 + goto fail1; 254 255 255 - if (usb_kbd_alloc_mem(dev, kbd)) { 256 - usb_kbd_free_mem(dev, kbd); 257 - kfree(kbd); 258 - return -ENOMEM; 259 - } 256 + if (usb_kbd_alloc_mem(dev, kbd)) 257 + goto fail2; 260 258 261 259 kbd->usbdev = dev; 260 + kbd->dev = input_dev; 262 261 263 - kbd->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_LED) | BIT(EV_REP); 264 - kbd->dev.ledbit[0] = BIT(LED_NUML) | BIT(LED_CAPSL) | BIT(LED_SCROLLL) | BIT(LED_COMPOSE) | BIT(LED_KANA); 262 + if (dev->manufacturer) 263 + strlcpy(kbd->name, dev->manufacturer, sizeof(kbd->name)); 264 + 265 + if (dev->product) { 266 + if (dev->manufacturer) 267 + strlcat(kbd->name, " ", sizeof(kbd->name)); 268 + strlcat(kbd->name, dev->product, sizeof(kbd->name)); 269 + } 270 + 271 + if (!strlen(kbd->name)) 272 + snprintf(kbd->name, sizeof(kbd->name), 273 + "USB HIDBP Keyboard %04x:%04x", 274 + le16_to_cpu(dev->descriptor.idVendor), 275 + le16_to_cpu(dev->descriptor.idProduct)); 276 + 277 + usb_make_path(dev, kbd->phys, sizeof(kbd->phys)); 278 + strlcpy(kbd->phys, "/input0", sizeof(kbd->phys)); 279 + 280 + input_dev->name = kbd->name; 281 + input_dev->phys = kbd->phys; 282 + usb_to_input_id(dev, &input_dev->id); 283 + input_dev->cdev.dev = &iface->dev; 284 + input_dev->private = kbd; 285 + 286 + input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_LED) | BIT(EV_REP); 287 + input_dev->ledbit[0] = BIT(LED_NUML) | BIT(LED_CAPSL) | BIT(LED_SCROLLL) | BIT(LED_COMPOSE) | BIT(LED_KANA); 265 288 266 289 for (i = 0; i < 255; i++) 267 - set_bit(usb_kbd_keycode[i], kbd->dev.keybit); 268 - clear_bit(0, kbd->dev.keybit); 290 + set_bit(usb_kbd_keycode[i], input_dev->keybit); 291 + clear_bit(0, input_dev->keybit); 269 292 270 - kbd->dev.private = kbd; 271 - kbd->dev.event = usb_kbd_event; 272 - kbd->dev.open = usb_kbd_open; 273 - kbd->dev.close = usb_kbd_close; 293 + input_dev->event = usb_kbd_event; 294 + input_dev->open = usb_kbd_open; 295 + input_dev->close = usb_kbd_close; 274 296 275 297 usb_fill_int_urb(kbd->irq, dev, pipe, 276 298 kbd->new, (maxp > 8 ? 8 : maxp), ··· 306 284 kbd->cr->wIndex = cpu_to_le16(interface->desc.bInterfaceNumber); 307 285 kbd->cr->wLength = cpu_to_le16(1); 308 286 309 - usb_make_path(dev, path, 64); 310 - sprintf(kbd->phys, "%s/input0", path); 311 - 312 - kbd->dev.name = kbd->name; 313 - kbd->dev.phys = kbd->phys; 314 - usb_to_input_id(dev, &kbd->dev.id); 315 - kbd->dev.dev = &iface->dev; 316 - 317 - if (dev->manufacturer) 318 - strcat(kbd->name, dev->manufacturer); 319 - if (dev->product) 320 - sprintf(kbd->name, "%s %s", kbd->name, dev->product); 321 - 322 - if (!strlen(kbd->name)) 323 - sprintf(kbd->name, "USB HIDBP Keyboard %04x:%04x", 324 - kbd->dev.id.vendor, kbd->dev.id.product); 325 - 326 287 usb_fill_control_urb(kbd->led, dev, usb_sndctrlpipe(dev, 0), 327 288 (void *) kbd->cr, kbd->leds, 1, 328 289 usb_kbd_led, kbd); 329 290 kbd->led->setup_dma = kbd->cr_dma; 330 291 kbd->led->transfer_dma = kbd->leds_dma; 331 - kbd->led->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP 332 - | URB_NO_SETUP_DMA_MAP); 292 + kbd->led->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP); 333 293 334 - input_register_device(&kbd->dev); 335 - 336 - printk(KERN_INFO "input: %s on %s\n", kbd->name, path); 294 + input_register_device(kbd->dev); 337 295 338 296 usb_set_intfdata(iface, kbd); 339 297 return 0; 298 + 299 + fail2: usb_kbd_free_mem(dev, kbd); 300 + fail1: input_free_device(input_dev); 301 + kfree(kbd); 302 + return -ENOMEM; 340 303 } 341 304 342 305 static void usb_kbd_disconnect(struct usb_interface *intf) ··· 331 324 usb_set_intfdata(intf, NULL); 332 325 if (kbd) { 333 326 usb_kill_urb(kbd->irq); 334 - input_unregister_device(&kbd->dev); 327 + input_unregister_device(kbd->dev); 335 328 usb_kbd_free_mem(interface_to_usbdev(intf), kbd); 336 329 kfree(kbd); 337 330 }
+52 -45
drivers/usb/input/usbmouse.c
··· 50 50 char name[128]; 51 51 char phys[64]; 52 52 struct usb_device *usbdev; 53 - struct input_dev dev; 53 + struct input_dev *dev; 54 54 struct urb *irq; 55 55 56 56 signed char *data; ··· 61 61 { 62 62 struct usb_mouse *mouse = urb->context; 63 63 signed char *data = mouse->data; 64 - struct input_dev *dev = &mouse->dev; 64 + struct input_dev *dev = mouse->dev; 65 65 int status; 66 66 67 67 switch (urb->status) { ··· 115 115 usb_kill_urb(mouse->irq); 116 116 } 117 117 118 - static int usb_mouse_probe(struct usb_interface * intf, const struct usb_device_id * id) 118 + static int usb_mouse_probe(struct usb_interface *intf, const struct usb_device_id *id) 119 119 { 120 - struct usb_device * dev = interface_to_usbdev(intf); 120 + struct usb_device *dev = interface_to_usbdev(intf); 121 121 struct usb_host_interface *interface; 122 122 struct usb_endpoint_descriptor *endpoint; 123 123 struct usb_mouse *mouse; 124 + struct input_dev *input_dev; 124 125 int pipe, maxp; 125 - char path[64]; 126 126 127 127 interface = intf->cur_altsetting; 128 128 ··· 130 130 return -ENODEV; 131 131 132 132 endpoint = &interface->endpoint[0].desc; 133 - if (!(endpoint->bEndpointAddress & 0x80)) 133 + if (!(endpoint->bEndpointAddress & USB_DIR_IN)) 134 134 return -ENODEV; 135 - if ((endpoint->bmAttributes & 3) != 3) 135 + if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_INT) 136 136 return -ENODEV; 137 137 138 138 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress); 139 139 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe)); 140 140 141 - if (!(mouse = kmalloc(sizeof(struct usb_mouse), GFP_KERNEL))) 142 - return -ENOMEM; 143 - memset(mouse, 0, sizeof(struct usb_mouse)); 141 + mouse = kzalloc(sizeof(struct usb_mouse), GFP_KERNEL); 142 + input_dev = input_allocate_device(); 143 + if (!mouse || !input_dev) 144 + goto fail1; 144 145 145 146 mouse->data = usb_buffer_alloc(dev, 8, SLAB_ATOMIC, &mouse->data_dma); 146 - if (!mouse->data) { 147 - kfree(mouse); 148 - return -ENOMEM; 149 - } 147 + if (!mouse->data) 148 + goto fail1; 150 149 151 150 mouse->irq = usb_alloc_urb(0, GFP_KERNEL); 152 - if (!mouse->irq) { 153 - usb_buffer_free(dev, 8, mouse->data, mouse->data_dma); 154 - kfree(mouse); 155 - return -ENODEV; 156 - } 151 + if (!mouse->irq) 152 + goto fail2; 157 153 158 154 mouse->usbdev = dev; 159 - 160 - mouse->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL); 161 - mouse->dev.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE); 162 - mouse->dev.relbit[0] = BIT(REL_X) | BIT(REL_Y); 163 - mouse->dev.keybit[LONG(BTN_MOUSE)] |= BIT(BTN_SIDE) | BIT(BTN_EXTRA); 164 - mouse->dev.relbit[0] |= BIT(REL_WHEEL); 165 - 166 - mouse->dev.private = mouse; 167 - mouse->dev.open = usb_mouse_open; 168 - mouse->dev.close = usb_mouse_close; 169 - 170 - usb_make_path(dev, path, 64); 171 - sprintf(mouse->phys, "%s/input0", path); 172 - 173 - mouse->dev.name = mouse->name; 174 - mouse->dev.phys = mouse->phys; 175 - usb_to_input_id(dev, &mouse->dev.id); 176 - mouse->dev.dev = &intf->dev; 155 + mouse->dev = input_dev; 177 156 178 157 if (dev->manufacturer) 179 - strcat(mouse->name, dev->manufacturer); 180 - if (dev->product) 181 - sprintf(mouse->name, "%s %s", mouse->name, dev->product); 158 + strlcpy(mouse->name, dev->manufacturer, sizeof(mouse->name)); 159 + 160 + if (dev->product) { 161 + if (dev->manufacturer) 162 + strlcat(mouse->name, " ", sizeof(mouse->name)); 163 + strlcat(mouse->name, dev->product, sizeof(mouse->name)); 164 + } 182 165 183 166 if (!strlen(mouse->name)) 184 - sprintf(mouse->name, "USB HIDBP Mouse %04x:%04x", 185 - mouse->dev.id.vendor, mouse->dev.id.product); 167 + snprintf(mouse->name, sizeof(mouse->name), 168 + "USB HIDBP Mouse %04x:%04x", 169 + le16_to_cpu(dev->descriptor.idVendor), 170 + le16_to_cpu(dev->descriptor.idProduct)); 171 + 172 + usb_make_path(dev, mouse->phys, sizeof(mouse->phys)); 173 + strlcat(mouse->phys, "/input0", sizeof(mouse->phys)); 174 + 175 + input_dev->name = mouse->name; 176 + input_dev->phys = mouse->phys; 177 + usb_to_input_id(dev, &input_dev->id); 178 + input_dev->cdev.dev = &intf->dev; 179 + 180 + input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL); 181 + input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE); 182 + input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y); 183 + input_dev->keybit[LONG(BTN_MOUSE)] |= BIT(BTN_SIDE) | BIT(BTN_EXTRA); 184 + input_dev->relbit[0] |= BIT(REL_WHEEL); 185 + 186 + input_dev->private = mouse; 187 + input_dev->open = usb_mouse_open; 188 + input_dev->close = usb_mouse_close; 186 189 187 190 usb_fill_int_urb(mouse->irq, dev, pipe, mouse->data, 188 191 (maxp > 8 ? 8 : maxp), ··· 193 190 mouse->irq->transfer_dma = mouse->data_dma; 194 191 mouse->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 195 192 196 - input_register_device(&mouse->dev); 197 - printk(KERN_INFO "input: %s on %s\n", mouse->name, path); 193 + input_register_device(mouse->dev); 198 194 199 195 usb_set_intfdata(intf, mouse); 200 196 return 0; 197 + 198 + fail2: usb_buffer_free(dev, 8, mouse->data, mouse->data_dma); 199 + fail1: input_free_device(input_dev); 200 + kfree(mouse); 201 + return -ENOMEM; 201 202 } 202 203 203 204 static void usb_mouse_disconnect(struct usb_interface *intf) ··· 211 204 usb_set_intfdata(intf, NULL); 212 205 if (mouse) { 213 206 usb_kill_urb(mouse->irq); 214 - input_unregister_device(&mouse->dev); 207 + input_unregister_device(mouse->dev); 215 208 usb_free_urb(mouse->irq); 216 209 usb_buffer_free(interface_to_usbdev(intf), 8, mouse->data, mouse->data_dma); 217 210 kfree(mouse);
+66 -76
drivers/usb/input/wacom.c
··· 111 111 struct wacom { 112 112 signed char *data; 113 113 dma_addr_t data_dma; 114 - struct input_dev dev; 114 + struct input_dev *dev; 115 115 struct usb_device *usbdev; 116 116 struct urb *irq; 117 117 struct wacom_features *features; ··· 135 135 { 136 136 struct wacom *wacom = urb->context; 137 137 unsigned char *data = wacom->data; 138 - struct input_dev *dev = &wacom->dev; 138 + struct input_dev *dev = wacom->dev; 139 139 int prox, pressure; 140 140 int retval; 141 141 ··· 225 225 { 226 226 struct wacom *wacom = urb->context; 227 227 unsigned char *data = wacom->data; 228 - struct input_dev *dev = &wacom->dev; 228 + struct input_dev *dev = wacom->dev; 229 229 int retval; 230 230 231 231 switch (urb->status) { ··· 275 275 { 276 276 struct wacom *wacom = urb->context; 277 277 unsigned char *data = wacom->data; 278 - struct input_dev *dev = &wacom->dev; 278 + struct input_dev *dev = wacom->dev; 279 279 int retval; 280 280 281 281 switch (urb->status) { ··· 318 318 { 319 319 struct wacom *wacom = urb->context; 320 320 unsigned char *data = wacom->data; 321 - struct input_dev *dev = &wacom->dev; 321 + struct input_dev *dev = wacom->dev; 322 322 int x, y; 323 323 int retval; 324 324 ··· 397 397 { 398 398 struct wacom *wacom = urb->context; 399 399 unsigned char *data = wacom->data; 400 - struct input_dev *dev = &wacom->dev; 400 + struct input_dev *dev = wacom->dev; 401 401 int idx; 402 402 403 403 /* tool number */ ··· 479 479 { 480 480 struct wacom *wacom = urb->context; 481 481 unsigned char *data = wacom->data; 482 - struct input_dev *dev = &wacom->dev; 482 + struct input_dev *dev = wacom->dev; 483 483 unsigned int t; 484 484 485 485 /* general pen packet */ ··· 509 509 { 510 510 struct wacom *wacom = urb->context; 511 511 unsigned char *data = wacom->data; 512 - struct input_dev *dev = &wacom->dev; 512 + struct input_dev *dev = wacom->dev; 513 513 unsigned int t; 514 514 int idx; 515 515 int retval; ··· 738 738 { 739 739 struct usb_device *dev = interface_to_usbdev(intf); 740 740 struct usb_endpoint_descriptor *endpoint; 741 - char rep_data[2] = {0x02, 0x02}; 742 741 struct wacom *wacom; 743 - char path[64]; 742 + struct input_dev *input_dev; 743 + char rep_data[2] = {0x02, 0x02}; 744 744 745 - if (!(wacom = kmalloc(sizeof(struct wacom), GFP_KERNEL))) 746 - return -ENOMEM; 747 - memset(wacom, 0, sizeof(struct wacom)); 745 + wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL); 746 + input_dev = input_allocate_device(); 747 + if (!wacom || !input_dev) 748 + goto fail1; 748 749 749 750 wacom->data = usb_buffer_alloc(dev, 10, GFP_KERNEL, &wacom->data_dma); 750 - if (!wacom->data) { 751 - kfree(wacom); 752 - return -ENOMEM; 753 - } 751 + if (!wacom->data) 752 + goto fail1; 754 753 755 754 wacom->irq = usb_alloc_urb(0, GFP_KERNEL); 756 - if (!wacom->irq) { 757 - usb_buffer_free(dev, 10, wacom->data, wacom->data_dma); 758 - kfree(wacom); 759 - return -ENOMEM; 760 - } 755 + if (!wacom->irq) 756 + goto fail2; 757 + 758 + wacom->usbdev = dev; 759 + wacom->dev = input_dev; 760 + usb_make_path(dev, wacom->phys, sizeof(wacom->phys)); 761 + strlcat(wacom->phys, "/input0", sizeof(wacom->phys)); 761 762 762 763 wacom->features = wacom_features + (id - wacom_ids); 764 + if (wacom->features->pktlen > 10) 765 + BUG(); 763 766 764 - wacom->dev.evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS); 765 - wacom->dev.absbit[0] |= BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE); 766 - wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_PEN) | BIT(BTN_TOUCH) | BIT(BTN_STYLUS); 767 + input_dev->name = wacom->features->name; 768 + usb_to_input_id(dev, &input_dev->id); 769 + 770 + input_dev->cdev.dev = &intf->dev; 771 + input_dev->private = wacom; 772 + input_dev->open = wacom_open; 773 + input_dev->close = wacom_close; 774 + 775 + input_dev->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS); 776 + input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_PEN) | BIT(BTN_TOUCH) | BIT(BTN_STYLUS); 777 + input_set_abs_params(input_dev, ABS_X, 0, wacom->features->y_max, 4, 0); 778 + input_set_abs_params(input_dev, ABS_Y, 0, wacom->features->y_max, 4, 0); 779 + input_set_abs_params(input_dev, ABS_PRESSURE, 0, wacom->features->pressure_max, 0, 0); 767 780 768 781 switch (wacom->features->type) { 769 782 case GRAPHIRE: 770 - wacom->dev.evbit[0] |= BIT(EV_REL); 771 - wacom->dev.relbit[0] |= BIT(REL_WHEEL); 772 - wacom->dev.absbit[0] |= BIT(ABS_DISTANCE); 773 - wacom->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE); 774 - wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_STYLUS2); 783 + input_dev->evbit[0] |= BIT(EV_REL); 784 + input_dev->relbit[0] |= BIT(REL_WHEEL); 785 + input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE); 786 + input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_STYLUS2); 787 + input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom->features->distance_max, 0, 0); 775 788 break; 776 789 777 790 case INTUOS3: 778 791 case CINTIQ: 779 - wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER); 780 - wacom->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_0) | BIT(BTN_1) | BIT(BTN_2) | BIT(BTN_3) | BIT(BTN_4) | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7); 781 - wacom->dev.absbit[0] |= BIT(ABS_RX) | BIT(ABS_RY); 792 + input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER); 793 + input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_0) | BIT(BTN_1) | BIT(BTN_2) | BIT(BTN_3) | BIT(BTN_4) | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7); 794 + input_set_abs_params(input_dev, ABS_RX, 0, 4097, 0, 0); 795 + input_set_abs_params(input_dev, ABS_RY, 0, 4097, 0, 0); 782 796 /* fall through */ 783 797 784 798 case INTUOS: 785 - wacom->dev.evbit[0] |= BIT(EV_MSC) | BIT(EV_REL); 786 - wacom->dev.mscbit[0] |= BIT(MSC_SERIAL); 787 - wacom->dev.relbit[0] |= BIT(REL_WHEEL); 788 - wacom->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE) | BIT(BTN_SIDE) | BIT(BTN_EXTRA); 789 - wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_TOOL_BRUSH) 799 + input_dev->evbit[0] |= BIT(EV_MSC) | BIT(EV_REL); 800 + input_dev->mscbit[0] |= BIT(MSC_SERIAL); 801 + input_dev->relbit[0] |= BIT(REL_WHEEL); 802 + input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE) | BIT(BTN_SIDE) | BIT(BTN_EXTRA); 803 + input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_TOOL_BRUSH) 790 804 | BIT(BTN_TOOL_PENCIL) | BIT(BTN_TOOL_AIRBRUSH) | BIT(BTN_TOOL_LENS) | BIT(BTN_STYLUS2); 791 - wacom->dev.absbit[0] |= BIT(ABS_DISTANCE) | BIT(ABS_WHEEL) | BIT(ABS_TILT_X) | BIT(ABS_TILT_Y) | BIT(ABS_RZ) | BIT(ABS_THROTTLE); 805 + input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom->features->distance_max, 0, 0); 806 + input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0); 807 + input_set_abs_params(input_dev, ABS_TILT_X, 0, 127, 0, 0); 808 + input_set_abs_params(input_dev, ABS_TILT_Y, 0, 127, 0, 0); 809 + input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0); 810 + input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0); 792 811 break; 793 812 794 813 case PL: 795 - wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_STYLUS2) | BIT(BTN_TOOL_RUBBER); 814 + input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_STYLUS2) | BIT(BTN_TOOL_RUBBER); 796 815 break; 797 816 } 798 - 799 - wacom->dev.absmax[ABS_X] = wacom->features->x_max; 800 - wacom->dev.absmax[ABS_Y] = wacom->features->y_max; 801 - wacom->dev.absmax[ABS_PRESSURE] = wacom->features->pressure_max; 802 - wacom->dev.absmax[ABS_DISTANCE] = wacom->features->distance_max; 803 - wacom->dev.absmax[ABS_TILT_X] = 127; 804 - wacom->dev.absmax[ABS_TILT_Y] = 127; 805 - wacom->dev.absmax[ABS_WHEEL] = 1023; 806 - 807 - wacom->dev.absmax[ABS_RX] = 4097; 808 - wacom->dev.absmax[ABS_RY] = 4097; 809 - wacom->dev.absmin[ABS_RZ] = -900; 810 - wacom->dev.absmax[ABS_RZ] = 899; 811 - wacom->dev.absmin[ABS_THROTTLE] = -1023; 812 - wacom->dev.absmax[ABS_THROTTLE] = 1023; 813 - 814 - wacom->dev.absfuzz[ABS_X] = 4; 815 - wacom->dev.absfuzz[ABS_Y] = 4; 816 - 817 - wacom->dev.private = wacom; 818 - wacom->dev.open = wacom_open; 819 - wacom->dev.close = wacom_close; 820 - 821 - usb_make_path(dev, path, 64); 822 - sprintf(wacom->phys, "%s/input0", path); 823 - 824 - wacom->dev.name = wacom->features->name; 825 - wacom->dev.phys = wacom->phys; 826 - usb_to_input_id(dev, &wacom->dev.id); 827 - wacom->dev.dev = &intf->dev; 828 - wacom->usbdev = dev; 829 817 830 818 endpoint = &intf->cur_altsetting->endpoint[0].desc; 831 819 ··· 827 839 wacom->irq->transfer_dma = wacom->data_dma; 828 840 wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 829 841 830 - input_register_device(&wacom->dev); 842 + input_register_device(wacom->dev); 831 843 832 844 /* ask the tablet to report tablet data */ 833 845 usb_set_report(intf, 3, 2, rep_data, 2); 834 846 /* repeat once (not sure why the first call often fails) */ 835 847 usb_set_report(intf, 3, 2, rep_data, 2); 836 848 837 - printk(KERN_INFO "input: %s on %s\n", wacom->features->name, path); 838 - 839 849 usb_set_intfdata(intf, wacom); 840 - 841 850 return 0; 851 + 852 + fail2: usb_buffer_free(dev, 10, wacom->data, wacom->data_dma); 853 + fail1: input_free_device(input_dev); 854 + kfree(wacom); 855 + return -ENOMEM; 842 856 } 843 857 844 858 static void wacom_disconnect(struct usb_interface *intf) ··· 850 860 usb_set_intfdata(intf, NULL); 851 861 if (wacom) { 852 862 usb_kill_urb(wacom->irq); 853 - input_unregister_device(&wacom->dev); 863 + input_unregister_device(wacom->dev); 854 864 usb_free_urb(wacom->irq); 855 865 usb_buffer_free(interface_to_usbdev(intf), 10, wacom->data, wacom->data_dma); 856 866 kfree(wacom);
+62 -71
drivers/usb/input/xpad.c
··· 103 103 MODULE_DEVICE_TABLE (usb, xpad_table); 104 104 105 105 struct usb_xpad { 106 - struct input_dev dev; /* input device interface */ 106 + struct input_dev *dev; /* input device interface */ 107 107 struct usb_device *udev; /* usb device */ 108 108 109 109 struct urb *irq_in; /* urb for interrupt in report */ ··· 125 125 126 126 static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data, struct pt_regs *regs) 127 127 { 128 - struct input_dev *dev = &xpad->dev; 128 + struct input_dev *dev = xpad->dev; 129 129 130 130 input_regs(dev, regs); 131 131 ··· 214 214 static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id) 215 215 { 216 216 struct usb_device *udev = interface_to_usbdev (intf); 217 - struct usb_xpad *xpad = NULL; 217 + struct usb_xpad *xpad; 218 + struct input_dev *input_dev; 218 219 struct usb_endpoint_descriptor *ep_irq_in; 219 - char path[64]; 220 220 int i; 221 221 222 222 for (i = 0; xpad_device[i].idVendor; i++) { ··· 225 225 break; 226 226 } 227 227 228 - if ((xpad = kmalloc (sizeof(struct usb_xpad), GFP_KERNEL)) == NULL) { 229 - err("cannot allocate memory for new pad"); 230 - return -ENOMEM; 231 - } 232 - memset(xpad, 0, sizeof(struct usb_xpad)); 228 + xpad = kzalloc(sizeof(struct usb_xpad), GFP_KERNEL); 229 + input_dev = input_allocate_device(); 230 + if (!xpad || !input_dev) 231 + goto fail1; 233 232 234 233 xpad->idata = usb_buffer_alloc(udev, XPAD_PKT_LEN, 235 234 SLAB_ATOMIC, &xpad->idata_dma); 236 - if (!xpad->idata) { 237 - kfree(xpad); 238 - return -ENOMEM; 239 - } 235 + if (!xpad->idata) 236 + goto fail1; 240 237 241 238 xpad->irq_in = usb_alloc_urb(0, GFP_KERNEL); 242 - if (!xpad->irq_in) { 243 - err("cannot allocate memory for new pad irq urb"); 244 - usb_buffer_free(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma); 245 - kfree(xpad); 246 - return -ENOMEM; 247 - } 239 + if (!xpad->irq_in) 240 + goto fail2; 241 + 242 + xpad->udev = udev; 243 + xpad->dev = input_dev; 244 + usb_make_path(udev, xpad->phys, sizeof(xpad->phys)); 245 + strlcat(xpad->phys, "/input0", sizeof(xpad->phys)); 246 + 247 + input_dev->name = xpad_device[i].name; 248 + input_dev->phys = xpad->phys; 249 + usb_to_input_id(udev, &input_dev->id); 250 + input_dev->cdev.dev = &intf->dev; 251 + input_dev->private = xpad; 252 + input_dev->open = xpad_open; 253 + input_dev->close = xpad_close; 254 + 255 + input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 256 + 257 + for (i = 0; xpad_btn[i] >= 0; i++) 258 + set_bit(xpad_btn[i], input_dev->keybit); 259 + 260 + for (i = 0; xpad_abs[i] >= 0; i++) { 261 + 262 + signed short t = xpad_abs[i]; 263 + 264 + set_bit(t, input_dev->absbit); 265 + 266 + switch (t) { 267 + case ABS_X: 268 + case ABS_Y: 269 + case ABS_RX: 270 + case ABS_RY: /* the two sticks */ 271 + input_set_abs_params(input_dev, t, -32768, 32767, 16, 128); 272 + break; 273 + case ABS_Z: 274 + case ABS_RZ: /* the triggers */ 275 + input_set_abs_params(input_dev, t, 0, 255, 0, 0); 276 + break; 277 + case ABS_HAT0X: 278 + case ABS_HAT0Y: /* the d-pad */ 279 + input_set_abs_params(input_dev, t, -1, 1, 0, 0); 280 + break; 281 + } 282 + } 248 283 249 284 ep_irq_in = &intf->cur_altsetting->endpoint[0].desc; 250 - 251 285 usb_fill_int_urb(xpad->irq_in, udev, 252 286 usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress), 253 287 xpad->idata, XPAD_PKT_LEN, xpad_irq_in, ··· 289 255 xpad->irq_in->transfer_dma = xpad->idata_dma; 290 256 xpad->irq_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 291 257 292 - xpad->udev = udev; 293 - 294 - usb_to_input_id(udev, &xpad->dev.id); 295 - xpad->dev.dev = &intf->dev; 296 - xpad->dev.private = xpad; 297 - xpad->dev.name = xpad_device[i].name; 298 - xpad->dev.phys = xpad->phys; 299 - xpad->dev.open = xpad_open; 300 - xpad->dev.close = xpad_close; 301 - 302 - usb_make_path(udev, path, 64); 303 - snprintf(xpad->phys, 64, "%s/input0", path); 304 - 305 - xpad->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 306 - 307 - for (i = 0; xpad_btn[i] >= 0; i++) 308 - set_bit(xpad_btn[i], xpad->dev.keybit); 309 - 310 - for (i = 0; xpad_abs[i] >= 0; i++) { 311 - 312 - signed short t = xpad_abs[i]; 313 - 314 - set_bit(t, xpad->dev.absbit); 315 - 316 - switch (t) { 317 - case ABS_X: 318 - case ABS_Y: 319 - case ABS_RX: 320 - case ABS_RY: /* the two sticks */ 321 - xpad->dev.absmax[t] = 32767; 322 - xpad->dev.absmin[t] = -32768; 323 - xpad->dev.absflat[t] = 128; 324 - xpad->dev.absfuzz[t] = 16; 325 - break; 326 - case ABS_Z: 327 - case ABS_RZ: /* the triggers */ 328 - xpad->dev.absmax[t] = 255; 329 - xpad->dev.absmin[t] = 0; 330 - break; 331 - case ABS_HAT0X: 332 - case ABS_HAT0Y: /* the d-pad */ 333 - xpad->dev.absmax[t] = 1; 334 - xpad->dev.absmin[t] = -1; 335 - break; 336 - } 337 - } 338 - 339 - input_register_device(&xpad->dev); 340 - 341 - printk(KERN_INFO "input: %s on %s", xpad->dev.name, path); 258 + input_register_device(xpad->dev); 342 259 343 260 usb_set_intfdata(intf, xpad); 344 261 return 0; 262 + 263 + fail2: usb_buffer_free(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma); 264 + fail1: input_free_device(input_dev); 265 + kfree(xpad); 266 + return -ENOMEM; 267 + 345 268 } 346 269 347 270 static void xpad_disconnect(struct usb_interface *intf) ··· 308 317 usb_set_intfdata(intf, NULL); 309 318 if (xpad) { 310 319 usb_kill_urb(xpad->irq_in); 311 - input_unregister_device(&xpad->dev); 320 + input_unregister_device(xpad->dev); 312 321 usb_free_urb(xpad->irq_in); 313 322 usb_buffer_free(interface_to_usbdev(intf), XPAD_PKT_LEN, xpad->idata, xpad->idata_dma); 314 323 kfree(xpad);
+35 -31
drivers/usb/input/yealink.c
··· 54 54 #include <linux/module.h> 55 55 #include <linux/rwsem.h> 56 56 #include <linux/usb.h> 57 + #include <linux/usb_input.h> 57 58 58 59 #include "map_to_7segment.h" 59 60 #include "yealink.h" ··· 102 101 }; 103 102 104 103 struct yealink_dev { 105 - struct input_dev idev; /* input device */ 104 + struct input_dev *idev; /* input device */ 106 105 struct usb_device *udev; /* usb device */ 107 106 108 107 /* irq input channel */ 109 108 struct yld_ctl_packet *irq_data; 110 - dma_addr_t irq_dma; 109 + dma_addr_t irq_dma; 111 110 struct urb *urb_irq; 112 111 113 112 /* control output channel */ ··· 238 237 */ 239 238 static void report_key(struct yealink_dev *yld, int key, struct pt_regs *regs) 240 239 { 241 - struct input_dev *idev = &yld->idev; 240 + struct input_dev *idev = yld->idev; 242 241 243 242 input_regs(idev, regs); 244 243 if (yld->key_code >= 0) { ··· 810 809 } 811 810 if (yld->urb_ctl) 812 811 usb_free_urb(yld->urb_ctl); 813 - if (yld->idev.dev) 814 - input_unregister_device(&yld->idev); 812 + if (yld->idev) { 813 + if (err) 814 + input_free_device(yld->idev); 815 + else 816 + input_unregister_device(yld->idev); 817 + } 815 818 if (yld->ctl_req) 816 819 usb_buffer_free(yld->udev, sizeof(*(yld->ctl_req)), 817 820 yld->ctl_req, yld->ctl_req_dma); ··· 862 857 struct usb_host_interface *interface; 863 858 struct usb_endpoint_descriptor *endpoint; 864 859 struct yealink_dev *yld; 865 - char path[64]; 860 + struct input_dev *input_dev; 866 861 int ret, pipe, i; 867 862 868 863 i = usb_match(udev); ··· 871 866 872 867 interface = intf->cur_altsetting; 873 868 endpoint = &interface->endpoint[0].desc; 874 - if (!(endpoint->bEndpointAddress & 0x80)) 869 + if (!(endpoint->bEndpointAddress & USB_DIR_IN)) 875 870 return -EIO; 876 - if ((endpoint->bmAttributes & 3) != 3) 871 + if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_INT) 877 872 return -EIO; 878 873 879 - if ((yld = kmalloc(sizeof(struct yealink_dev), GFP_KERNEL)) == NULL) 874 + yld = kzalloc(sizeof(struct yealink_dev), GFP_KERNEL); 875 + if (!yld) 880 876 return -ENOMEM; 881 877 882 - memset(yld, 0, sizeof(*yld)); 883 878 yld->udev = udev; 879 + 880 + yld->idev = input_dev = input_allocate_device(); 881 + if (!input_dev) 882 + return usb_cleanup(yld, -ENOMEM); 884 883 885 884 /* allocate usb buffers */ 886 885 yld->irq_data = usb_buffer_alloc(udev, USB_PKT_LEN, ··· 944 935 yld->urb_ctl->dev = udev; 945 936 946 937 /* find out the physical bus location */ 947 - if (usb_make_path(udev, path, sizeof(path)) > 0) 948 - snprintf(yld->phys, sizeof(yld->phys)-1, "%s/input0", path); 938 + usb_make_path(udev, yld->phys, sizeof(yld->phys)); 939 + strlcat(yld->phys, "/input0", sizeof(yld->phys)); 949 940 950 941 /* register settings for the input device */ 951 - init_input_dev(&yld->idev); 952 - yld->idev.private = yld; 953 - yld->idev.id.bustype = BUS_USB; 954 - yld->idev.id.vendor = le16_to_cpu(udev->descriptor.idVendor); 955 - yld->idev.id.product = le16_to_cpu(udev->descriptor.idProduct); 956 - yld->idev.id.version = le16_to_cpu(udev->descriptor.bcdDevice); 957 - yld->idev.dev = &intf->dev; 958 - yld->idev.name = yld_device[i].name; 959 - yld->idev.phys = yld->phys; 960 - /* yld->idev.event = input_ev; TODO */ 961 - yld->idev.open = input_open; 962 - yld->idev.close = input_close; 942 + input_dev->name = yld_device[i].name; 943 + input_dev->phys = yld->phys; 944 + usb_to_input_id(udev, &input_dev->id); 945 + input_dev->cdev.dev = &intf->dev; 946 + 947 + input_dev->private = yld; 948 + input_dev->open = input_open; 949 + input_dev->close = input_close; 950 + /* input_dev->event = input_ev; TODO */ 963 951 964 952 /* register available key events */ 965 - yld->idev.evbit[0] = BIT(EV_KEY); 953 + input_dev->evbit[0] = BIT(EV_KEY); 966 954 for (i = 0; i < 256; i++) { 967 955 int k = map_p1k_to_key(i); 968 956 if (k >= 0) { 969 - set_bit(k & 0xff, yld->idev.keybit); 957 + set_bit(k & 0xff, input_dev->keybit); 970 958 if (k >> 8) 971 - set_bit(k >> 8, yld->idev.keybit); 959 + set_bit(k >> 8, input_dev->keybit); 972 960 } 973 961 } 974 962 975 - printk(KERN_INFO "input: %s on %s\n", yld->idev.name, path); 976 - 977 - input_register_device(&yld->idev); 963 + input_register_device(yld->idev); 978 964 979 965 usb_set_intfdata(intf, yld); 980 966 981 967 /* clear visible elements */ 982 - for (i=0; i<ARRAY_SIZE(lcdMap); i++) 968 + for (i = 0; i < ARRAY_SIZE(lcdMap); i++) 983 969 setChar(yld, i, ' '); 984 970 985 971 /* display driver version on LCD line 3 */