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

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'usb-3.7-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb

Pull USB fixes from Greg Kroah-Hartman:
"Here are a bunch of USB fixes for the 3.7-rc tree.

There's a lot of small USB serial driver fixes, and one larger one
(the mos7840 driver changes are mostly just moving code around to fix
problems.) Thanks to Johan Hovold for finding the problems and fixing
them all up.

Other than those, there is the usual new device ids, xhci bugfixes,
and gadget driver fixes, nothing out of the ordinary.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>"

* tag 'usb-3.7-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (49 commits)
xhci: trivial: Remove assigned but unused ep_ctx.
xhci: trivial: Remove assigned but unused slot_ctx.
xhci: Fix missing break in xhci_evaluate_context_result.
xhci: Fix potential NULL ptr deref in command cancellation.
ehci: Add yet-another Lucid nohandoff pci quirk
ehci: fix Lucid nohandoff pci quirk to be more generic with BIOS versions
USB: mos7840: fix port_probe flow
USB: mos7840: fix port-data memory leak
USB: mos7840: remove invalid disconnect handling
USB: mos7840: remove NULL-urb submission
USB: qcserial: fix interface-data memory leak in error path
USB: option: fix interface-data memory leak in error path
USB: ipw: fix interface-data memory leak in error path
USB: mos7840: fix port-device leak in error path
USB: mos7840: fix urb leak at release
USB: sierra: fix port-data memory leak
USB: sierra: fix memory leak in probe error path
USB: sierra: fix memory leak in attach error path
USB: usb-wwan: fix multiple memory leaks in error paths
USB: keyspan: fix NULL-pointer dereferences and memory leaks
...

+820 -869
+5 -2
drivers/usb/core/hub.c
··· 739 739 int limit = 100; 740 740 741 741 spin_lock_irqsave (&hub->tt.lock, flags); 742 - while (--limit && !list_empty (&hub->tt.clear_list)) { 742 + while (!list_empty(&hub->tt.clear_list)) { 743 743 struct list_head *next; 744 744 struct usb_tt_clear *clear; 745 745 struct usb_device *hdev = hub->hdev; 746 746 const struct hc_driver *drv; 747 747 int status; 748 + 749 + if (!hub->quiescing && --limit < 0) 750 + break; 748 751 749 752 next = hub->tt.clear_list.next; 750 753 clear = list_entry (next, struct usb_tt_clear, clear_list); ··· 1213 1210 if (hub->has_indicators) 1214 1211 cancel_delayed_work_sync(&hub->leds); 1215 1212 if (hub->tt.hub) 1216 - cancel_work_sync(&hub->tt.clear_work); 1213 + flush_work(&hub->tt.clear_work); 1217 1214 } 1218 1215 1219 1216 /* caller has locked the hub device */
+3 -1
drivers/usb/gadget/net2272.c
··· 2069 2069 #if defined(PLX_PCI_RDK2) 2070 2070 /* see if PCI int for us by checking irqstat */ 2071 2071 intcsr = readl(dev->rdk2.fpga_base_addr + RDK2_IRQSTAT); 2072 - if (!intcsr & (1 << NET2272_PCI_IRQ)) 2072 + if (!intcsr & (1 << NET2272_PCI_IRQ)) { 2073 + spin_unlock(&dev->lock); 2073 2074 return IRQ_NONE; 2075 + } 2074 2076 /* check dma interrupts */ 2075 2077 #endif 2076 2078 /* Platform/devcice interrupt handler */
+8 -1
drivers/usb/host/pci-quirks.c
··· 545 545 /* Pegatron Lucid (Ordissimo AIRIS) */ 546 546 .matches = { 547 547 DMI_MATCH(DMI_BOARD_NAME, "M11JB"), 548 - DMI_MATCH(DMI_BIOS_VERSION, "Lucid-GE-133"), 548 + DMI_MATCH(DMI_BIOS_VERSION, "Lucid-"), 549 + }, 550 + }, 551 + { 552 + /* Pegatron Lucid (Ordissimo) */ 553 + .matches = { 554 + DMI_MATCH(DMI_BOARD_NAME, "Ordissimo"), 555 + DMI_MATCH(DMI_BIOS_VERSION, "Lucid-"), 549 556 }, 550 557 }, 551 558 { }
-2
drivers/usb/host/xhci-dbg.c
··· 544 544 int i; 545 545 /* Fields are 32 bits wide, DMA addresses are in bytes */ 546 546 int field_size = 32 / 8; 547 - struct xhci_slot_ctx *slot_ctx; 548 547 dma_addr_t dma = ctx->dma; 549 548 int csz = HCC_64BYTE_CONTEXT(xhci->hcc_params); 550 549 ··· 569 570 dbg_rsvd64(xhci, (u64 *)ctrl_ctx, dma); 570 571 } 571 572 572 - slot_ctx = xhci_get_slot_ctx(xhci, ctx); 573 573 xhci_dbg_slot_ctx(xhci, ctx); 574 574 xhci_dbg_ep_ctx(xhci, ctx, last_ep); 575 575 }
+6 -3
drivers/usb/host/xhci-hub.c
··· 151 151 if (portsc & PORT_DEV_REMOVE) 152 152 port_removable |= 1 << (i + 1); 153 153 } 154 - memset(&desc->u.ss.DeviceRemovable, 155 - (__force __u16) cpu_to_le16(port_removable), 156 - sizeof(__u16)); 154 + 155 + desc->u.ss.DeviceRemovable = cpu_to_le16(port_removable); 157 156 } 158 157 159 158 static void xhci_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci, ··· 808 809 temp = xhci_readl(xhci, port_array[wIndex]); 809 810 xhci_dbg(xhci, "set port power, actual port %d status = 0x%x\n", wIndex, temp); 810 811 812 + spin_unlock_irqrestore(&xhci->lock, flags); 811 813 temp = usb_acpi_power_manageable(hcd->self.root_hub, 812 814 wIndex); 813 815 if (temp) 814 816 usb_acpi_set_power_state(hcd->self.root_hub, 815 817 wIndex, true); 818 + spin_lock_irqsave(&xhci->lock, flags); 816 819 break; 817 820 case USB_PORT_FEAT_RESET: 818 821 temp = (temp | PORT_RESET); ··· 918 917 xhci_writel(xhci, temp & ~PORT_POWER, 919 918 port_array[wIndex]); 920 919 920 + spin_unlock_irqrestore(&xhci->lock, flags); 921 921 temp = usb_acpi_power_manageable(hcd->self.root_hub, 922 922 wIndex); 923 923 if (temp) 924 924 usb_acpi_set_power_state(hcd->self.root_hub, 925 925 wIndex, false); 926 + spin_lock_irqsave(&xhci->lock, flags); 926 927 break; 927 928 default: 928 929 goto error;
+11
drivers/usb/host/xhci-ring.c
··· 1228 1228 cur_seg = find_trb_seg(xhci->cmd_ring->first_seg, 1229 1229 xhci->cmd_ring->dequeue, &cycle_state); 1230 1230 1231 + if (!cur_seg) { 1232 + xhci_warn(xhci, "Command ring mismatch, dequeue = %p %llx (dma)\n", 1233 + xhci->cmd_ring->dequeue, 1234 + (unsigned long long) 1235 + xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, 1236 + xhci->cmd_ring->dequeue)); 1237 + xhci_debug_ring(xhci, xhci->cmd_ring); 1238 + xhci_dbg_ring_ptrs(xhci, xhci->cmd_ring); 1239 + return; 1240 + } 1241 + 1231 1242 /* find the command trb matched by cd from command ring */ 1232 1243 for (cmd_trb = xhci->cmd_ring->dequeue; 1233 1244 cmd_trb != xhci->cmd_ring->enqueue;
+4 -4
drivers/usb/host/xhci.c
··· 1627 1627 struct xhci_hcd *xhci; 1628 1628 struct xhci_container_ctx *in_ctx, *out_ctx; 1629 1629 unsigned int ep_index; 1630 - struct xhci_ep_ctx *ep_ctx; 1631 1630 struct xhci_slot_ctx *slot_ctx; 1632 1631 struct xhci_input_control_ctx *ctrl_ctx; 1633 1632 u32 added_ctxs; ··· 1662 1663 out_ctx = virt_dev->out_ctx; 1663 1664 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx); 1664 1665 ep_index = xhci_get_endpoint_index(&ep->desc); 1665 - ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index); 1666 1666 1667 1667 /* If this endpoint is already in use, and the upper layers are trying 1668 1668 * to add it again without dropping it, reject the addition. ··· 1815 1817 case COMP_EBADSLT: 1816 1818 dev_warn(&udev->dev, "WARN: slot not enabled for" 1817 1819 "evaluate context command.\n"); 1820 + ret = -EINVAL; 1821 + break; 1818 1822 case COMP_CTX_STATE: 1819 1823 dev_warn(&udev->dev, "WARN: invalid context state for " 1820 1824 "evaluate context command.\n"); ··· 4021 4021 static unsigned long long xhci_service_interval_to_ns( 4022 4022 struct usb_endpoint_descriptor *desc) 4023 4023 { 4024 - return (1 << (desc->bInterval - 1)) * 125 * 1000; 4024 + return (1ULL << (desc->bInterval - 1)) * 125 * 1000; 4025 4025 } 4026 4026 4027 4027 static u16 xhci_get_timeout_no_hub_lpm(struct usb_device *udev, ··· 4142 4142 (xhci_service_interval_to_ns(desc) > timeout_ns)) 4143 4143 timeout_ns = xhci_service_interval_to_ns(desc); 4144 4144 4145 - u2_del_ns = udev->bos->ss_cap->bU2DevExitLat * 1000; 4145 + u2_del_ns = le16_to_cpu(udev->bos->ss_cap->bU2DevExitLat) * 1000ULL; 4146 4146 if (u2_del_ns > timeout_ns) 4147 4147 timeout_ns = u2_del_ns; 4148 4148
+1
drivers/usb/misc/ezusb.c
··· 158 158 } 159 159 EXPORT_SYMBOL_GPL(ezusb_fx2_ihex_firmware_download); 160 160 161 + MODULE_LICENSE("GPL");
+4 -4
drivers/usb/musb/musb_dsps.c
··· 458 458 struct platform_device *musb; 459 459 struct resource *res; 460 460 struct resource resources[2]; 461 - char res_name[10]; 461 + char res_name[11]; 462 462 int ret, musbid; 463 463 464 464 /* get memory resource */ 465 - sprintf(res_name, "musb%d", id); 465 + snprintf(res_name, sizeof(res_name), "musb%d", id); 466 466 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, res_name); 467 467 if (!res) { 468 468 dev_err(dev, "%s get mem resource failed\n", res_name); ··· 473 473 resources[0] = *res; 474 474 475 475 /* get irq resource */ 476 - sprintf(res_name, "musb%d-irq", id); 476 + snprintf(res_name, sizeof(res_name), "musb%d-irq", id); 477 477 res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, res_name); 478 478 if (!res) { 479 479 dev_err(dev, "%s get irq resource failed\n", res_name); ··· 530 530 531 531 of_property_read_u32(np, "num-eps", (u32 *)&config->num_eps); 532 532 of_property_read_u32(np, "ram-bits", (u32 *)&config->ram_bits); 533 - sprintf(res_name, "port%d-mode", id); 533 + snprintf(res_name, sizeof(res_name), "port%d-mode", id); 534 534 of_property_read_u32(np, res_name, (u32 *)&pdata->mode); 535 535 of_property_read_u32(np, "power", (u32 *)&pdata->power); 536 536 config->multipoint = of_property_read_bool(np, "multipoint");
+1
drivers/usb/renesas_usbhs/fifo.c
··· 795 795 dev_dbg(dev, " %s %d (%d/ %d)\n", 796 796 fifo->name, usbhs_pipe_number(pipe), pkt->length, pkt->zero); 797 797 798 + usbhs_pipe_enable(pipe); 798 799 usbhsf_dma_start(pipe, fifo); 799 800 dma_async_issue_pending(chan); 800 801 }
+5
drivers/usb/renesas_usbhs/mod_host.c
··· 334 334 struct device *dev = usbhs_priv_to_dev(priv); 335 335 unsigned long flags; 336 336 337 + if (unlikely(!uep)) { 338 + dev_err(dev, "no uep\n"); 339 + return; 340 + } 341 + 337 342 /******************** spin lock ********************/ 338 343 usbhs_lock(priv, flags); 339 344
+16 -7
drivers/usb/serial/ch341.c
··· 242 242 return r; 243 243 } 244 244 245 - /* allocate private data */ 246 - static int ch341_attach(struct usb_serial *serial) 245 + static int ch341_port_probe(struct usb_serial_port *port) 247 246 { 248 247 struct ch341_private *priv; 249 248 int r; 250 249 251 - /* private data */ 252 250 priv = kzalloc(sizeof(struct ch341_private), GFP_KERNEL); 253 251 if (!priv) 254 252 return -ENOMEM; ··· 256 258 priv->baud_rate = DEFAULT_BAUD_RATE; 257 259 priv->line_control = CH341_BIT_RTS | CH341_BIT_DTR; 258 260 259 - r = ch341_configure(serial->dev, priv); 261 + r = ch341_configure(port->serial->dev, priv); 260 262 if (r < 0) 261 263 goto error; 262 264 263 - usb_set_serial_port_data(serial->port[0], priv); 265 + usb_set_serial_port_data(port, priv); 264 266 return 0; 265 267 266 268 error: kfree(priv); 267 269 return r; 270 + } 271 + 272 + static int ch341_port_remove(struct usb_serial_port *port) 273 + { 274 + struct ch341_private *priv; 275 + 276 + priv = usb_get_serial_port_data(port); 277 + kfree(priv); 278 + 279 + return 0; 268 280 } 269 281 270 282 static int ch341_carrier_raised(struct usb_serial_port *port) ··· 312 304 static int ch341_open(struct tty_struct *tty, struct usb_serial_port *port) 313 305 { 314 306 struct usb_serial *serial = port->serial; 315 - struct ch341_private *priv = usb_get_serial_port_data(serial->port[0]); 307 + struct ch341_private *priv = usb_get_serial_port_data(port); 316 308 int r; 317 309 318 310 priv->baud_rate = DEFAULT_BAUD_RATE; ··· 616 608 .tiocmget = ch341_tiocmget, 617 609 .tiocmset = ch341_tiocmset, 618 610 .read_int_callback = ch341_read_int_callback, 619 - .attach = ch341_attach, 611 + .port_probe = ch341_port_probe, 612 + .port_remove = ch341_port_remove, 620 613 .reset_resume = ch341_reset_resume, 621 614 }; 622 615
+67 -50
drivers/usb/serial/digi_acceleport.c
··· 244 244 static int digi_startup(struct usb_serial *serial); 245 245 static void digi_disconnect(struct usb_serial *serial); 246 246 static void digi_release(struct usb_serial *serial); 247 + static int digi_port_probe(struct usb_serial_port *port); 248 + static int digi_port_remove(struct usb_serial_port *port); 247 249 static void digi_read_bulk_callback(struct urb *urb); 248 250 static int digi_read_inb_callback(struct urb *urb); 249 251 static int digi_read_oob_callback(struct urb *urb); ··· 296 294 .attach = digi_startup, 297 295 .disconnect = digi_disconnect, 298 296 .release = digi_release, 297 + .port_probe = digi_port_probe, 298 + .port_remove = digi_port_remove, 299 299 }; 300 300 301 301 static struct usb_serial_driver digi_acceleport_4_device = { ··· 324 320 .attach = digi_startup, 325 321 .disconnect = digi_disconnect, 326 322 .release = digi_release, 323 + .port_probe = digi_port_probe, 324 + .port_remove = digi_port_remove, 327 325 }; 328 326 329 327 static struct usb_serial_driver * const serial_drivers[] = { ··· 1246 1240 return ret; 1247 1241 } 1248 1242 1243 + static int digi_port_init(struct usb_serial_port *port, unsigned port_num) 1244 + { 1245 + struct digi_port *priv; 1246 + 1247 + priv = kzalloc(sizeof(*priv), GFP_KERNEL); 1248 + if (!priv) 1249 + return -ENOMEM; 1250 + 1251 + spin_lock_init(&priv->dp_port_lock); 1252 + priv->dp_port_num = port_num; 1253 + init_waitqueue_head(&priv->dp_modem_change_wait); 1254 + init_waitqueue_head(&priv->dp_transmit_idle_wait); 1255 + init_waitqueue_head(&priv->dp_flush_wait); 1256 + init_waitqueue_head(&priv->dp_close_wait); 1257 + INIT_WORK(&priv->dp_wakeup_work, digi_wakeup_write_lock); 1258 + priv->dp_port = port; 1259 + 1260 + init_waitqueue_head(&port->write_wait); 1261 + 1262 + usb_set_serial_port_data(port, priv); 1263 + 1264 + return 0; 1265 + } 1249 1266 1250 1267 static int digi_startup(struct usb_serial *serial) 1251 1268 { 1252 - 1253 - int i; 1254 - struct digi_port *priv; 1255 1269 struct digi_serial *serial_priv; 1270 + int ret; 1256 1271 1257 - /* allocate the private data structures for all ports */ 1258 - /* number of regular ports + 1 for the out-of-band port */ 1259 - for (i = 0; i < serial->type->num_ports + 1; i++) { 1260 - /* allocate port private structure */ 1261 - priv = kmalloc(sizeof(struct digi_port), GFP_KERNEL); 1262 - if (priv == NULL) { 1263 - while (--i >= 0) 1264 - kfree(usb_get_serial_port_data(serial->port[i])); 1265 - return 1; /* error */ 1266 - } 1272 + serial_priv = kzalloc(sizeof(*serial_priv), GFP_KERNEL); 1273 + if (!serial_priv) 1274 + return -ENOMEM; 1267 1275 1268 - /* initialize port private structure */ 1269 - spin_lock_init(&priv->dp_port_lock); 1270 - priv->dp_port_num = i; 1271 - priv->dp_out_buf_len = 0; 1272 - priv->dp_write_urb_in_use = 0; 1273 - priv->dp_modem_signals = 0; 1274 - init_waitqueue_head(&priv->dp_modem_change_wait); 1275 - priv->dp_transmit_idle = 0; 1276 - init_waitqueue_head(&priv->dp_transmit_idle_wait); 1277 - priv->dp_throttled = 0; 1278 - priv->dp_throttle_restart = 0; 1279 - init_waitqueue_head(&priv->dp_flush_wait); 1280 - init_waitqueue_head(&priv->dp_close_wait); 1281 - INIT_WORK(&priv->dp_wakeup_work, digi_wakeup_write_lock); 1282 - priv->dp_port = serial->port[i]; 1283 - /* initialize write wait queue for this port */ 1284 - init_waitqueue_head(&serial->port[i]->write_wait); 1285 - 1286 - usb_set_serial_port_data(serial->port[i], priv); 1287 - } 1288 - 1289 - /* allocate serial private structure */ 1290 - serial_priv = kmalloc(sizeof(struct digi_serial), GFP_KERNEL); 1291 - if (serial_priv == NULL) { 1292 - for (i = 0; i < serial->type->num_ports + 1; i++) 1293 - kfree(usb_get_serial_port_data(serial->port[i])); 1294 - return 1; /* error */ 1295 - } 1296 - 1297 - /* initialize serial private structure */ 1298 1276 spin_lock_init(&serial_priv->ds_serial_lock); 1299 1277 serial_priv->ds_oob_port_num = serial->type->num_ports; 1300 1278 serial_priv->ds_oob_port = serial->port[serial_priv->ds_oob_port_num]; 1301 - serial_priv->ds_device_started = 0; 1279 + 1280 + ret = digi_port_init(serial_priv->ds_oob_port, 1281 + serial_priv->ds_oob_port_num); 1282 + if (ret) { 1283 + kfree(serial_priv); 1284 + return ret; 1285 + } 1286 + 1302 1287 usb_set_serial_data(serial, serial_priv); 1303 1288 1304 1289 return 0; ··· 1310 1313 1311 1314 static void digi_release(struct usb_serial *serial) 1312 1315 { 1313 - int i; 1316 + struct digi_serial *serial_priv; 1317 + struct digi_port *priv; 1314 1318 1315 - /* free the private data structures for all ports */ 1316 - /* number of regular ports + 1 for the out-of-band port */ 1317 - for (i = 0; i < serial->type->num_ports + 1; i++) 1318 - kfree(usb_get_serial_port_data(serial->port[i])); 1319 - kfree(usb_get_serial_data(serial)); 1319 + serial_priv = usb_get_serial_data(serial); 1320 + 1321 + priv = usb_get_serial_port_data(serial_priv->ds_oob_port); 1322 + kfree(priv); 1323 + 1324 + kfree(serial_priv); 1320 1325 } 1321 1326 1327 + static int digi_port_probe(struct usb_serial_port *port) 1328 + { 1329 + unsigned port_num; 1330 + 1331 + port_num = port->number - port->serial->minor; 1332 + 1333 + return digi_port_init(port, port_num); 1334 + } 1335 + 1336 + static int digi_port_remove(struct usb_serial_port *port) 1337 + { 1338 + struct digi_port *priv; 1339 + 1340 + priv = usb_get_serial_port_data(port); 1341 + kfree(priv); 1342 + 1343 + return 0; 1344 + } 1322 1345 1323 1346 static void digi_read_bulk_callback(struct urb *urb) 1324 1347 {
+3 -4
drivers/usb/serial/ipw.c
··· 203 203 return 0; 204 204 } 205 205 206 - /* fake probe - only to allocate data structures */ 207 - static int ipw_probe(struct usb_serial *serial, const struct usb_device_id *id) 206 + static int ipw_attach(struct usb_serial *serial) 208 207 { 209 208 struct usb_wwan_intf_private *data; 210 209 ··· 302 303 .num_ports = 1, 303 304 .open = ipw_open, 304 305 .close = ipw_close, 305 - .probe = ipw_probe, 306 - .attach = usb_wwan_startup, 306 + .attach = ipw_attach, 307 307 .release = ipw_release, 308 + .port_probe = usb_wwan_port_probe, 308 309 .port_remove = usb_wwan_port_remove, 309 310 .dtr_rts = ipw_dtr_rts, 310 311 .write = usb_wwan_write,
+91 -96
drivers/usb/serial/keyspan.c
··· 1374 1374 data in device_details */ 1375 1375 static void keyspan_setup_urbs(struct usb_serial *serial) 1376 1376 { 1377 - int i, j; 1378 1377 struct keyspan_serial_private *s_priv; 1379 1378 const struct keyspan_device_details *d_details; 1380 - struct usb_serial_port *port; 1381 - struct keyspan_port_private *p_priv; 1382 1379 struct callbacks *cback; 1383 - int endp; 1384 1380 1385 1381 s_priv = usb_get_serial_data(serial); 1386 1382 d_details = s_priv->device_details; ··· 1400 1404 (serial, d_details->glocont_endpoint, USB_DIR_OUT, 1401 1405 serial, s_priv->glocont_buf, GLOCONT_BUFLEN, 1402 1406 cback->glocont_callback); 1403 - 1404 - /* Setup endpoints for each port specific thing */ 1405 - for (i = 0; i < d_details->num_ports; i++) { 1406 - port = serial->port[i]; 1407 - p_priv = usb_get_serial_port_data(port); 1408 - 1409 - /* Do indat endpoints first, once for each flip */ 1410 - endp = d_details->indat_endpoints[i]; 1411 - for (j = 0; j <= d_details->indat_endp_flip; ++j, ++endp) { 1412 - p_priv->in_urbs[j] = keyspan_setup_urb 1413 - (serial, endp, USB_DIR_IN, port, 1414 - p_priv->in_buffer[j], 64, 1415 - cback->indat_callback); 1416 - } 1417 - for (; j < 2; ++j) 1418 - p_priv->in_urbs[j] = NULL; 1419 - 1420 - /* outdat endpoints also have flip */ 1421 - endp = d_details->outdat_endpoints[i]; 1422 - for (j = 0; j <= d_details->outdat_endp_flip; ++j, ++endp) { 1423 - p_priv->out_urbs[j] = keyspan_setup_urb 1424 - (serial, endp, USB_DIR_OUT, port, 1425 - p_priv->out_buffer[j], 64, 1426 - cback->outdat_callback); 1427 - } 1428 - for (; j < 2; ++j) 1429 - p_priv->out_urbs[j] = NULL; 1430 - 1431 - /* inack endpoint */ 1432 - p_priv->inack_urb = keyspan_setup_urb 1433 - (serial, d_details->inack_endpoints[i], USB_DIR_IN, 1434 - port, p_priv->inack_buffer, 1, cback->inack_callback); 1435 - 1436 - /* outcont endpoint */ 1437 - p_priv->outcont_urb = keyspan_setup_urb 1438 - (serial, d_details->outcont_endpoints[i], USB_DIR_OUT, 1439 - port, p_priv->outcont_buffer, 64, 1440 - cback->outcont_callback); 1441 - } 1442 1407 } 1443 1408 1444 1409 /* usa19 function doesn't require prescaler */ ··· 2364 2407 static int keyspan_startup(struct usb_serial *serial) 2365 2408 { 2366 2409 int i, err; 2367 - struct usb_serial_port *port; 2368 2410 struct keyspan_serial_private *s_priv; 2369 - struct keyspan_port_private *p_priv; 2370 2411 const struct keyspan_device_details *d_details; 2371 2412 2372 2413 for (i = 0; (d_details = keyspan_devices[i]) != NULL; ++i) ··· 2387 2432 s_priv->device_details = d_details; 2388 2433 usb_set_serial_data(serial, s_priv); 2389 2434 2390 - /* Now setup per port private data */ 2391 - for (i = 0; i < serial->num_ports; i++) { 2392 - port = serial->port[i]; 2393 - p_priv = kzalloc(sizeof(struct keyspan_port_private), 2394 - GFP_KERNEL); 2395 - if (!p_priv) { 2396 - dev_dbg(&port->dev, "%s - kmalloc for keyspan_port_private (%d) failed!.\n", __func__, i); 2397 - return 1; 2398 - } 2399 - p_priv->device_details = d_details; 2400 - usb_set_serial_port_data(port, p_priv); 2401 - } 2402 - 2403 2435 keyspan_setup_urbs(serial); 2404 2436 2405 2437 if (s_priv->instat_urb != NULL) { ··· 2405 2463 2406 2464 static void keyspan_disconnect(struct usb_serial *serial) 2407 2465 { 2408 - int i, j; 2409 - struct usb_serial_port *port; 2410 - struct keyspan_serial_private *s_priv; 2411 - struct keyspan_port_private *p_priv; 2466 + struct keyspan_serial_private *s_priv; 2412 2467 2413 2468 s_priv = usb_get_serial_data(serial); 2414 2469 2415 - /* Stop reading/writing urbs */ 2416 2470 stop_urb(s_priv->instat_urb); 2417 2471 stop_urb(s_priv->glocont_urb); 2418 2472 stop_urb(s_priv->indat_urb); 2419 - for (i = 0; i < serial->num_ports; ++i) { 2420 - port = serial->port[i]; 2421 - p_priv = usb_get_serial_port_data(port); 2422 - stop_urb(p_priv->inack_urb); 2423 - stop_urb(p_priv->outcont_urb); 2424 - for (j = 0; j < 2; j++) { 2425 - stop_urb(p_priv->in_urbs[j]); 2426 - stop_urb(p_priv->out_urbs[j]); 2427 - } 2428 - } 2429 - 2430 - /* Now free them */ 2431 - usb_free_urb(s_priv->instat_urb); 2432 - usb_free_urb(s_priv->indat_urb); 2433 - usb_free_urb(s_priv->glocont_urb); 2434 - for (i = 0; i < serial->num_ports; ++i) { 2435 - port = serial->port[i]; 2436 - p_priv = usb_get_serial_port_data(port); 2437 - usb_free_urb(p_priv->inack_urb); 2438 - usb_free_urb(p_priv->outcont_urb); 2439 - for (j = 0; j < 2; j++) { 2440 - usb_free_urb(p_priv->in_urbs[j]); 2441 - usb_free_urb(p_priv->out_urbs[j]); 2442 - } 2443 - } 2444 2473 } 2445 2474 2446 2475 static void keyspan_release(struct usb_serial *serial) 2447 2476 { 2448 - int i; 2449 - struct usb_serial_port *port; 2450 - struct keyspan_serial_private *s_priv; 2477 + struct keyspan_serial_private *s_priv; 2451 2478 2452 2479 s_priv = usb_get_serial_data(serial); 2453 2480 2454 - kfree(s_priv); 2481 + usb_free_urb(s_priv->instat_urb); 2482 + usb_free_urb(s_priv->indat_urb); 2483 + usb_free_urb(s_priv->glocont_urb); 2455 2484 2456 - /* Now free per port private data */ 2457 - for (i = 0; i < serial->num_ports; i++) { 2458 - port = serial->port[i]; 2459 - kfree(usb_get_serial_port_data(port)); 2485 + kfree(s_priv); 2486 + } 2487 + 2488 + static int keyspan_port_probe(struct usb_serial_port *port) 2489 + { 2490 + struct usb_serial *serial = port->serial; 2491 + struct keyspan_port_private *s_priv; 2492 + struct keyspan_port_private *p_priv; 2493 + const struct keyspan_device_details *d_details; 2494 + struct callbacks *cback; 2495 + int endp; 2496 + int port_num; 2497 + int i; 2498 + 2499 + s_priv = usb_get_serial_data(serial); 2500 + d_details = s_priv->device_details; 2501 + 2502 + p_priv = kzalloc(sizeof(*p_priv), GFP_KERNEL); 2503 + if (!p_priv) 2504 + return -ENOMEM; 2505 + 2506 + s_priv = usb_get_serial_data(port->serial); 2507 + p_priv->device_details = d_details; 2508 + 2509 + /* Setup values for the various callback routines */ 2510 + cback = &keyspan_callbacks[d_details->msg_format]; 2511 + 2512 + port_num = port->number - port->serial->minor; 2513 + 2514 + /* Do indat endpoints first, once for each flip */ 2515 + endp = d_details->indat_endpoints[port_num]; 2516 + for (i = 0; i <= d_details->indat_endp_flip; ++i, ++endp) { 2517 + p_priv->in_urbs[i] = keyspan_setup_urb(serial, endp, 2518 + USB_DIR_IN, port, 2519 + p_priv->in_buffer[i], 64, 2520 + cback->indat_callback); 2460 2521 } 2522 + /* outdat endpoints also have flip */ 2523 + endp = d_details->outdat_endpoints[port_num]; 2524 + for (i = 0; i <= d_details->outdat_endp_flip; ++i, ++endp) { 2525 + p_priv->out_urbs[i] = keyspan_setup_urb(serial, endp, 2526 + USB_DIR_OUT, port, 2527 + p_priv->out_buffer[i], 64, 2528 + cback->outdat_callback); 2529 + } 2530 + /* inack endpoint */ 2531 + p_priv->inack_urb = keyspan_setup_urb(serial, 2532 + d_details->inack_endpoints[port_num], 2533 + USB_DIR_IN, port, 2534 + p_priv->inack_buffer, 1, 2535 + cback->inack_callback); 2536 + /* outcont endpoint */ 2537 + p_priv->outcont_urb = keyspan_setup_urb(serial, 2538 + d_details->outcont_endpoints[port_num], 2539 + USB_DIR_OUT, port, 2540 + p_priv->outcont_buffer, 64, 2541 + cback->outcont_callback); 2542 + 2543 + usb_set_serial_port_data(port, p_priv); 2544 + 2545 + return 0; 2546 + } 2547 + 2548 + static int keyspan_port_remove(struct usb_serial_port *port) 2549 + { 2550 + struct keyspan_port_private *p_priv; 2551 + int i; 2552 + 2553 + p_priv = usb_get_serial_port_data(port); 2554 + 2555 + stop_urb(p_priv->inack_urb); 2556 + stop_urb(p_priv->outcont_urb); 2557 + for (i = 0; i < 2; i++) { 2558 + stop_urb(p_priv->in_urbs[i]); 2559 + stop_urb(p_priv->out_urbs[i]); 2560 + } 2561 + 2562 + usb_free_urb(p_priv->inack_urb); 2563 + usb_free_urb(p_priv->outcont_urb); 2564 + for (i = 0; i < 2; i++) { 2565 + usb_free_urb(p_priv->in_urbs[i]); 2566 + usb_free_urb(p_priv->out_urbs[i]); 2567 + } 2568 + 2569 + kfree(p_priv); 2570 + 2571 + return 0; 2461 2572 } 2462 2573 2463 2574 MODULE_AUTHOR(DRIVER_AUTHOR);
+8
drivers/usb/serial/keyspan.h
··· 42 42 static int keyspan_startup (struct usb_serial *serial); 43 43 static void keyspan_disconnect (struct usb_serial *serial); 44 44 static void keyspan_release (struct usb_serial *serial); 45 + static int keyspan_port_probe(struct usb_serial_port *port); 46 + static int keyspan_port_remove(struct usb_serial_port *port); 45 47 static int keyspan_write_room (struct tty_struct *tty); 46 48 47 49 static int keyspan_write (struct tty_struct *tty, ··· 569 567 .attach = keyspan_startup, 570 568 .disconnect = keyspan_disconnect, 571 569 .release = keyspan_release, 570 + .port_probe = keyspan_port_probe, 571 + .port_remove = keyspan_port_remove, 572 572 }; 573 573 574 574 static struct usb_serial_driver keyspan_2port_device = { ··· 593 589 .attach = keyspan_startup, 594 590 .disconnect = keyspan_disconnect, 595 591 .release = keyspan_release, 592 + .port_probe = keyspan_port_probe, 593 + .port_remove = keyspan_port_remove, 596 594 }; 597 595 598 596 static struct usb_serial_driver keyspan_4port_device = { ··· 617 611 .attach = keyspan_startup, 618 612 .disconnect = keyspan_disconnect, 619 613 .release = keyspan_release, 614 + .port_probe = keyspan_port_probe, 615 + .port_remove = keyspan_port_remove, 620 616 }; 621 617 622 618 static struct usb_serial_driver * const serial_drivers[] = {
+34 -27
drivers/usb/serial/mct_u232.c
··· 49 49 * Function prototypes 50 50 */ 51 51 static int mct_u232_startup(struct usb_serial *serial); 52 - static void mct_u232_release(struct usb_serial *serial); 52 + static int mct_u232_port_probe(struct usb_serial_port *port); 53 + static int mct_u232_port_remove(struct usb_serial_port *remove); 53 54 static int mct_u232_open(struct tty_struct *tty, struct usb_serial_port *port); 54 55 static void mct_u232_close(struct usb_serial_port *port); 55 56 static void mct_u232_dtr_rts(struct usb_serial_port *port, int on); ··· 100 99 .tiocmget = mct_u232_tiocmget, 101 100 .tiocmset = mct_u232_tiocmset, 102 101 .attach = mct_u232_startup, 103 - .release = mct_u232_release, 102 + .port_probe = mct_u232_port_probe, 103 + .port_remove = mct_u232_port_remove, 104 104 .ioctl = mct_u232_ioctl, 105 105 .get_icount = mct_u232_get_icount, 106 106 }; ··· 390 388 391 389 static int mct_u232_startup(struct usb_serial *serial) 392 390 { 393 - struct mct_u232_private *priv; 394 391 struct usb_serial_port *port, *rport; 395 - 396 - priv = kzalloc(sizeof(struct mct_u232_private), GFP_KERNEL); 397 - if (!priv) 398 - return -ENOMEM; 399 - spin_lock_init(&priv->lock); 400 - init_waitqueue_head(&priv->msr_wait); 401 - usb_set_serial_port_data(serial->port[0], priv); 402 - 403 - init_waitqueue_head(&serial->port[0]->write_wait); 404 392 405 393 /* Puh, that's dirty */ 406 394 port = serial->port[0]; ··· 404 412 return 0; 405 413 } /* mct_u232_startup */ 406 414 407 - 408 - static void mct_u232_release(struct usb_serial *serial) 415 + static int mct_u232_port_probe(struct usb_serial_port *port) 409 416 { 410 417 struct mct_u232_private *priv; 411 - int i; 412 418 413 - for (i = 0; i < serial->num_ports; ++i) { 414 - /* My special items, the standard routines free my urbs */ 415 - priv = usb_get_serial_port_data(serial->port[i]); 416 - kfree(priv); 417 - } 418 - } /* mct_u232_release */ 419 + priv = kzalloc(sizeof(*priv), GFP_KERNEL); 420 + if (!priv) 421 + return -ENOMEM; 422 + 423 + spin_lock_init(&priv->lock); 424 + init_waitqueue_head(&priv->msr_wait); 425 + 426 + usb_set_serial_port_data(port, priv); 427 + 428 + return 0; 429 + } 430 + 431 + static int mct_u232_port_remove(struct usb_serial_port *port) 432 + { 433 + struct mct_u232_private *priv; 434 + 435 + priv = usb_get_serial_port_data(port); 436 + kfree(priv); 437 + 438 + return 0; 439 + } 419 440 420 441 static int mct_u232_open(struct tty_struct *tty, struct usb_serial_port *port) 421 442 { ··· 520 515 521 516 static void mct_u232_close(struct usb_serial_port *port) 522 517 { 523 - if (port->serial->dev) { 524 - /* shutdown our urbs */ 525 - usb_kill_urb(port->write_urb); 526 - usb_kill_urb(port->read_urb); 527 - usb_kill_urb(port->interrupt_in_urb); 528 - } 518 + /* 519 + * Must kill the read urb as it is actually an interrupt urb, which 520 + * generic close thus fails to kill. 521 + */ 522 + usb_kill_urb(port->read_urb); 523 + usb_kill_urb(port->interrupt_in_urb); 524 + 525 + usb_serial_generic_close(port); 529 526 } /* mct_u232_close */ 530 527 531 528
+21 -48
drivers/usb/serial/metro-usb.c
··· 179 179 { 180 180 dev_dbg(&port->dev, "%s\n", __func__); 181 181 182 - if (port->serial->dev) { 183 - /* Shutdown any interrupt in urbs. */ 184 - if (port->interrupt_in_urb) { 185 - usb_unlink_urb(port->interrupt_in_urb); 186 - usb_kill_urb(port->interrupt_in_urb); 187 - } 182 + usb_unlink_urb(port->interrupt_in_urb); 183 + usb_kill_urb(port->interrupt_in_urb); 188 184 189 - /* Send deactivate cmd to device */ 185 + mutex_lock(&port->serial->disc_mutex); 186 + if (!port->serial->disconnected) 190 187 metrousb_send_unidirectional_cmd(UNI_CMD_CLOSE, port); 191 - } 188 + mutex_unlock(&port->serial->disc_mutex); 192 189 } 193 190 194 191 static int metrousb_open(struct tty_struct *tty, struct usb_serial_port *port) ··· 268 271 return retval; 269 272 } 270 273 271 - static void metrousb_shutdown(struct usb_serial *serial) 272 - { 273 - int i = 0; 274 - 275 - dev_dbg(&serial->dev->dev, "%s\n", __func__); 276 - 277 - /* Stop reading and writing on all ports. */ 278 - for (i = 0; i < serial->num_ports; ++i) { 279 - /* Close any open urbs. */ 280 - metrousb_cleanup(serial->port[i]); 281 - 282 - /* Free memory. */ 283 - kfree(usb_get_serial_port_data(serial->port[i])); 284 - usb_set_serial_port_data(serial->port[i], NULL); 285 - 286 - dev_dbg(&serial->dev->dev, "%s - freed port number=%d\n", 287 - __func__, serial->port[i]->number); 288 - } 289 - } 290 - 291 - static int metrousb_startup(struct usb_serial *serial) 274 + static int metrousb_port_probe(struct usb_serial_port *port) 292 275 { 293 276 struct metrousb_private *metro_priv; 294 - struct usb_serial_port *port; 295 - int i = 0; 296 277 297 - dev_dbg(&serial->dev->dev, "%s\n", __func__); 278 + metro_priv = kzalloc(sizeof(*metro_priv), GFP_KERNEL); 279 + if (!metro_priv) 280 + return -ENOMEM; 298 281 299 - /* Loop through the serial ports setting up the private structures. 300 - * Currently we only use one port. */ 301 - for (i = 0; i < serial->num_ports; ++i) { 302 - port = serial->port[i]; 282 + spin_lock_init(&metro_priv->lock); 303 283 304 - /* Declare memory. */ 305 - metro_priv = kzalloc(sizeof(struct metrousb_private), GFP_KERNEL); 306 - if (!metro_priv) 307 - return -ENOMEM; 284 + usb_set_serial_port_data(port, metro_priv); 308 285 309 - /* Initialize memory. */ 310 - spin_lock_init(&metro_priv->lock); 311 - usb_set_serial_port_data(port, metro_priv); 286 + return 0; 287 + } 312 288 313 - dev_dbg(&serial->dev->dev, "%s - port number=%d\n ", 314 - __func__, port->number); 315 - } 289 + static int metrousb_port_remove(struct usb_serial_port *port) 290 + { 291 + struct metrousb_private *metro_priv; 292 + 293 + metro_priv = usb_get_serial_port_data(port); 294 + kfree(metro_priv); 316 295 317 296 return 0; 318 297 } ··· 387 414 .close = metrousb_cleanup, 388 415 .read_int_callback = metrousb_read_int_callback, 389 416 .write_int_callback = metrousb_write_int_callback, 390 - .attach = metrousb_startup, 391 - .release = metrousb_shutdown, 417 + .port_probe = metrousb_port_probe, 418 + .port_remove = metrousb_port_remove, 392 419 .throttle = metrousb_throttle, 393 420 .unthrottle = metrousb_unthrottle, 394 421 .tiocmget = metrousb_tiocmget,
+32 -30
drivers/usb/serial/mos7720.c
··· 1966 1966 1967 1967 static int mos7720_startup(struct usb_serial *serial) 1968 1968 { 1969 - struct moschip_port *mos7720_port; 1970 1969 struct usb_device *dev; 1971 - int i; 1972 1970 char data; 1973 1971 u16 product; 1974 1972 int ret_val; ··· 1997 1999 serial->port[1]->interrupt_in_buffer = NULL; 1998 2000 } 1999 2001 2000 - 2001 - /* set up serial port private structures */ 2002 - for (i = 0; i < serial->num_ports; ++i) { 2003 - mos7720_port = kzalloc(sizeof(struct moschip_port), GFP_KERNEL); 2004 - if (mos7720_port == NULL) { 2005 - dev_err(&dev->dev, "%s - Out of memory\n", __func__); 2006 - return -ENOMEM; 2007 - } 2008 - 2009 - /* Initialize all port interrupt end point to port 0 int 2010 - * endpoint. Our device has only one interrupt endpoint 2011 - * common to all ports */ 2012 - serial->port[i]->interrupt_in_endpointAddress = 2013 - serial->port[0]->interrupt_in_endpointAddress; 2014 - 2015 - mos7720_port->port = serial->port[i]; 2016 - usb_set_serial_port_data(serial->port[i], mos7720_port); 2017 - 2018 - dev_dbg(&dev->dev, "port number is %d\n", serial->port[i]->number); 2019 - dev_dbg(&dev->dev, "serial number is %d\n", serial->minor); 2020 - } 2021 - 2022 - 2023 2002 /* setting configuration feature to one */ 2024 2003 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 2025 2004 (__u8)0x03, 0x00, 0x01, 0x00, NULL, 0x00, 5*HZ); ··· 2024 2049 2025 2050 static void mos7720_release(struct usb_serial *serial) 2026 2051 { 2027 - int i; 2028 - 2029 2052 #ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT 2030 2053 /* close the parallel port */ 2031 2054 ··· 2062 2089 kref_put(&mos_parport->ref_count, destroy_mos_parport); 2063 2090 } 2064 2091 #endif 2065 - /* free private structure allocated for serial port */ 2066 - for (i = 0; i < serial->num_ports; ++i) 2067 - kfree(usb_get_serial_port_data(serial->port[i])); 2092 + } 2093 + 2094 + static int mos7720_port_probe(struct usb_serial_port *port) 2095 + { 2096 + struct moschip_port *mos7720_port; 2097 + 2098 + mos7720_port = kzalloc(sizeof(*mos7720_port), GFP_KERNEL); 2099 + if (!mos7720_port) 2100 + return -ENOMEM; 2101 + 2102 + /* Initialize all port interrupt end point to port 0 int endpoint. 2103 + * Our device has only one interrupt endpoint common to all ports. 2104 + */ 2105 + port->interrupt_in_endpointAddress = 2106 + port->serial->port[0]->interrupt_in_endpointAddress; 2107 + mos7720_port->port = port; 2108 + 2109 + usb_set_serial_port_data(port, mos7720_port); 2110 + 2111 + return 0; 2112 + } 2113 + 2114 + static int mos7720_port_remove(struct usb_serial_port *port) 2115 + { 2116 + struct moschip_port *mos7720_port; 2117 + 2118 + mos7720_port = usb_get_serial_port_data(port); 2119 + kfree(mos7720_port); 2120 + 2121 + return 0; 2068 2122 } 2069 2123 2070 2124 static struct usb_serial_driver moschip7720_2port_driver = { ··· 2109 2109 .probe = mos77xx_probe, 2110 2110 .attach = mos7720_startup, 2111 2111 .release = mos7720_release, 2112 + .port_probe = mos7720_port_probe, 2113 + .port_remove = mos7720_port_remove, 2112 2114 .ioctl = mos7720_ioctl, 2113 2115 .tiocmget = mos7720_tiocmget, 2114 2116 .tiocmset = mos7720_tiocmset,
+220 -301
drivers/usb/serial/mos7840.c
··· 218 218 int port_num; /*Actual port number in the device(1,2,etc) */ 219 219 struct urb *write_urb; /* write URB for this port */ 220 220 struct urb *read_urb; /* read URB for this port */ 221 - struct urb *int_urb; 222 221 __u8 shadowLCR; /* last LCR value received */ 223 222 __u8 shadowMCR; /* last MCR value received */ 224 223 char open; 225 224 char open_ports; 226 - char zombie; 227 225 wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */ 228 226 wait_queue_head_t delta_msr_wait; /* for handling sleeping while waiting for msr change to happen */ 229 227 int delta_msr_cond; ··· 476 478 struct moschip_port *mos7840_port; 477 479 struct device *dev = &urb->dev->dev; 478 480 __u8 regval = 0x0; 479 - int result = 0; 480 481 int status = urb->status; 481 482 482 483 mos7840_port = urb->context; ··· 492 495 return; 493 496 default: 494 497 dev_dbg(dev, "%s - nonzero urb status received: %d\n", __func__, status); 495 - goto exit; 498 + return; 496 499 } 497 500 498 501 dev_dbg(dev, "%s urb buffer size is %d\n", __func__, urb->actual_length); ··· 505 508 mos7840_handle_new_msr(mos7840_port, regval); 506 509 else if (mos7840_port->MsrLsr == 1) 507 510 mos7840_handle_new_lsr(mos7840_port, regval); 508 - 509 - exit: 510 - spin_lock(&mos7840_port->pool_lock); 511 - if (!mos7840_port->zombie) 512 - result = usb_submit_urb(mos7840_port->int_urb, GFP_ATOMIC); 513 - spin_unlock(&mos7840_port->pool_lock); 514 - if (result) { 515 - dev_err(dev, "%s - Error %d submitting interrupt urb\n", 516 - __func__, result); 517 - } 518 511 } 519 512 520 513 static int mos7840_get_reg(struct moschip_port *mcs, __u16 Wval, __u16 reg, ··· 673 686 wreg = MODEM_STATUS_REGISTER; 674 687 break; 675 688 } 676 - spin_lock(&mos7840_port->pool_lock); 677 - if (!mos7840_port->zombie) { 678 - rv = mos7840_get_reg(mos7840_port, wval, wreg, &Data); 679 - } else { 680 - spin_unlock(&mos7840_port->pool_lock); 681 - return; 682 - } 683 - spin_unlock(&mos7840_port->pool_lock); 689 + rv = mos7840_get_reg(mos7840_port, wval, wreg, &Data); 684 690 } 685 691 } 686 692 } ··· 2327 2347 return mos7840_num_ports; 2328 2348 } 2329 2349 2330 - /**************************************************************************** 2331 - * mos7840_startup 2332 - ****************************************************************************/ 2333 - 2334 - static int mos7840_startup(struct usb_serial *serial) 2350 + static int mos7840_port_probe(struct usb_serial_port *port) 2335 2351 { 2352 + struct usb_serial *serial = port->serial; 2336 2353 struct moschip_port *mos7840_port; 2337 - struct usb_device *dev; 2338 - int i, status; 2354 + int status; 2355 + int pnum; 2339 2356 __u16 Data; 2340 - 2341 - dev = serial->dev; 2342 2357 2343 2358 /* we set up the pointers to the endpoints in the mos7840_open * 2344 2359 * function, as the structures aren't created yet. */ 2345 2360 2346 - /* set up port private structures */ 2347 - for (i = 0; i < serial->num_ports; ++i) { 2348 - dev_dbg(&dev->dev, "mos7840_startup: configuring port %d............\n", i); 2349 - mos7840_port = kzalloc(sizeof(struct moschip_port), GFP_KERNEL); 2350 - if (mos7840_port == NULL) { 2351 - dev_err(&dev->dev, "%s - Out of memory\n", __func__); 2352 - status = -ENOMEM; 2353 - i--; /* don't follow NULL pointer cleaning up */ 2354 - goto error; 2355 - } 2361 + pnum = port->number - serial->minor; 2356 2362 2357 - /* Initialize all port interrupt end point to port 0 int 2358 - * endpoint. Our device has only one interrupt end point 2359 - * common to all port */ 2360 - 2361 - mos7840_port->port = serial->port[i]; 2362 - mos7840_set_port_private(serial->port[i], mos7840_port); 2363 - spin_lock_init(&mos7840_port->pool_lock); 2364 - 2365 - /* minor is not initialised until later by 2366 - * usb-serial.c:get_free_serial() and cannot therefore be used 2367 - * to index device instances */ 2368 - mos7840_port->port_num = i + 1; 2369 - dev_dbg(&dev->dev, "serial->port[i]->number = %d\n", serial->port[i]->number); 2370 - dev_dbg(&dev->dev, "serial->port[i]->serial->minor = %d\n", serial->port[i]->serial->minor); 2371 - dev_dbg(&dev->dev, "mos7840_port->port_num = %d\n", mos7840_port->port_num); 2372 - dev_dbg(&dev->dev, "serial->minor = %d\n", serial->minor); 2373 - 2374 - if (mos7840_port->port_num == 1) { 2375 - mos7840_port->SpRegOffset = 0x0; 2376 - mos7840_port->ControlRegOffset = 0x1; 2377 - mos7840_port->DcrRegOffset = 0x4; 2378 - } else if ((mos7840_port->port_num == 2) 2379 - && (serial->num_ports == 4)) { 2380 - mos7840_port->SpRegOffset = 0x8; 2381 - mos7840_port->ControlRegOffset = 0x9; 2382 - mos7840_port->DcrRegOffset = 0x16; 2383 - } else if ((mos7840_port->port_num == 2) 2384 - && (serial->num_ports == 2)) { 2385 - mos7840_port->SpRegOffset = 0xa; 2386 - mos7840_port->ControlRegOffset = 0xb; 2387 - mos7840_port->DcrRegOffset = 0x19; 2388 - } else if ((mos7840_port->port_num == 3) 2389 - && (serial->num_ports == 4)) { 2390 - mos7840_port->SpRegOffset = 0xa; 2391 - mos7840_port->ControlRegOffset = 0xb; 2392 - mos7840_port->DcrRegOffset = 0x19; 2393 - } else if ((mos7840_port->port_num == 4) 2394 - && (serial->num_ports == 4)) { 2395 - mos7840_port->SpRegOffset = 0xc; 2396 - mos7840_port->ControlRegOffset = 0xd; 2397 - mos7840_port->DcrRegOffset = 0x1c; 2398 - } 2399 - mos7840_dump_serial_port(serial->port[i], mos7840_port); 2400 - mos7840_set_port_private(serial->port[i], mos7840_port); 2401 - 2402 - /* enable rx_disable bit in control register */ 2403 - status = mos7840_get_reg_sync(serial->port[i], 2404 - mos7840_port->ControlRegOffset, &Data); 2405 - if (status < 0) { 2406 - dev_dbg(&dev->dev, "Reading ControlReg failed status-0x%x\n", status); 2407 - break; 2408 - } else 2409 - dev_dbg(&dev->dev, "ControlReg Reading success val is %x, status%d\n", Data, status); 2410 - Data |= 0x08; /* setting driver done bit */ 2411 - Data |= 0x04; /* sp1_bit to have cts change reflect in 2412 - modem status reg */ 2413 - 2414 - /* Data |= 0x20; //rx_disable bit */ 2415 - status = mos7840_set_reg_sync(serial->port[i], 2416 - mos7840_port->ControlRegOffset, Data); 2417 - if (status < 0) { 2418 - dev_dbg(&dev->dev, "Writing ControlReg failed(rx_disable) status-0x%x\n", status); 2419 - break; 2420 - } else 2421 - dev_dbg(&dev->dev, "ControlReg Writing success(rx_disable) status%d\n", status); 2422 - 2423 - /* Write default values in DCR (i.e 0x01 in DCR0, 0x05 in DCR2 2424 - and 0x24 in DCR3 */ 2425 - Data = 0x01; 2426 - status = mos7840_set_reg_sync(serial->port[i], 2427 - (__u16) (mos7840_port->DcrRegOffset + 0), Data); 2428 - if (status < 0) { 2429 - dev_dbg(&dev->dev, "Writing DCR0 failed status-0x%x\n", status); 2430 - break; 2431 - } else 2432 - dev_dbg(&dev->dev, "DCR0 Writing success status%d\n", status); 2433 - 2434 - Data = 0x05; 2435 - status = mos7840_set_reg_sync(serial->port[i], 2436 - (__u16) (mos7840_port->DcrRegOffset + 1), Data); 2437 - if (status < 0) { 2438 - dev_dbg(&dev->dev, "Writing DCR1 failed status-0x%x\n", status); 2439 - break; 2440 - } else 2441 - dev_dbg(&dev->dev, "DCR1 Writing success status%d\n", status); 2442 - 2443 - Data = 0x24; 2444 - status = mos7840_set_reg_sync(serial->port[i], 2445 - (__u16) (mos7840_port->DcrRegOffset + 2), Data); 2446 - if (status < 0) { 2447 - dev_dbg(&dev->dev, "Writing DCR2 failed status-0x%x\n", status); 2448 - break; 2449 - } else 2450 - dev_dbg(&dev->dev, "DCR2 Writing success status%d\n", status); 2451 - 2452 - /* write values in clkstart0x0 and clkmulti 0x20 */ 2453 - Data = 0x0; 2454 - status = mos7840_set_reg_sync(serial->port[i], 2455 - CLK_START_VALUE_REGISTER, Data); 2456 - if (status < 0) { 2457 - dev_dbg(&dev->dev, "Writing CLK_START_VALUE_REGISTER failed status-0x%x\n", status); 2458 - break; 2459 - } else 2460 - dev_dbg(&dev->dev, "CLK_START_VALUE_REGISTER Writing success status%d\n", status); 2461 - 2462 - Data = 0x20; 2463 - status = mos7840_set_reg_sync(serial->port[i], 2464 - CLK_MULTI_REGISTER, Data); 2465 - if (status < 0) { 2466 - dev_dbg(&dev->dev, "Writing CLK_MULTI_REGISTER failed status-0x%x\n", status); 2467 - goto error; 2468 - } else 2469 - dev_dbg(&dev->dev, "CLK_MULTI_REGISTER Writing success status%d\n", status); 2470 - 2471 - /* write value 0x0 to scratchpad register */ 2472 - Data = 0x00; 2473 - status = mos7840_set_uart_reg(serial->port[i], 2474 - SCRATCH_PAD_REGISTER, Data); 2475 - if (status < 0) { 2476 - dev_dbg(&dev->dev, "Writing SCRATCH_PAD_REGISTER failed status-0x%x\n", status); 2477 - break; 2478 - } else 2479 - dev_dbg(&dev->dev, "SCRATCH_PAD_REGISTER Writing success status%d\n", status); 2480 - 2481 - /* Zero Length flag register */ 2482 - if ((mos7840_port->port_num != 1) 2483 - && (serial->num_ports == 2)) { 2484 - 2485 - Data = 0xff; 2486 - status = mos7840_set_reg_sync(serial->port[i], 2487 - (__u16) (ZLP_REG1 + 2488 - ((__u16)mos7840_port->port_num)), Data); 2489 - dev_dbg(&dev->dev, "ZLIP offset %x\n", 2490 - (__u16)(ZLP_REG1 + ((__u16) mos7840_port->port_num))); 2491 - if (status < 0) { 2492 - dev_dbg(&dev->dev, "Writing ZLP_REG%d failed status-0x%x\n", i + 2, status); 2493 - break; 2494 - } else 2495 - dev_dbg(&dev->dev, "ZLP_REG%d Writing success status%d\n", i + 2, status); 2496 - } else { 2497 - Data = 0xff; 2498 - status = mos7840_set_reg_sync(serial->port[i], 2499 - (__u16) (ZLP_REG1 + 2500 - ((__u16)mos7840_port->port_num) - 0x1), Data); 2501 - dev_dbg(&dev->dev, "ZLIP offset %x\n", 2502 - (__u16)(ZLP_REG1 + ((__u16) mos7840_port->port_num) - 0x1)); 2503 - if (status < 0) { 2504 - dev_dbg(&dev->dev, "Writing ZLP_REG%d failed status-0x%x\n", i + 1, status); 2505 - break; 2506 - } else 2507 - dev_dbg(&dev->dev, "ZLP_REG%d Writing success status%d\n", i + 1, status); 2508 - 2509 - } 2510 - mos7840_port->control_urb = usb_alloc_urb(0, GFP_KERNEL); 2511 - mos7840_port->ctrl_buf = kmalloc(16, GFP_KERNEL); 2512 - mos7840_port->dr = kmalloc(sizeof(struct usb_ctrlrequest), 2513 - GFP_KERNEL); 2514 - if (!mos7840_port->control_urb || !mos7840_port->ctrl_buf || 2515 - !mos7840_port->dr) { 2516 - status = -ENOMEM; 2517 - goto error; 2518 - } 2519 - 2520 - mos7840_port->has_led = false; 2521 - 2522 - /* Initialize LED timers */ 2523 - if (device_type == MOSCHIP_DEVICE_ID_7810) { 2524 - mos7840_port->has_led = true; 2525 - 2526 - init_timer(&mos7840_port->led_timer1); 2527 - mos7840_port->led_timer1.function = mos7840_led_off; 2528 - mos7840_port->led_timer1.expires = 2529 - jiffies + msecs_to_jiffies(LED_ON_MS); 2530 - mos7840_port->led_timer1.data = 2531 - (unsigned long)mos7840_port; 2532 - 2533 - init_timer(&mos7840_port->led_timer2); 2534 - mos7840_port->led_timer2.function = 2535 - mos7840_led_flag_off; 2536 - mos7840_port->led_timer2.expires = 2537 - jiffies + msecs_to_jiffies(LED_OFF_MS); 2538 - mos7840_port->led_timer2.data = 2539 - (unsigned long)mos7840_port; 2540 - 2541 - mos7840_port->led_flag = false; 2542 - 2543 - /* Turn off LED */ 2544 - mos7840_set_led_sync(serial->port[i], 2545 - MODEM_CONTROL_REGISTER, 0x0300); 2546 - } 2363 + dev_dbg(&port->dev, "mos7840_startup: configuring port %d\n", pnum); 2364 + mos7840_port = kzalloc(sizeof(struct moschip_port), GFP_KERNEL); 2365 + if (mos7840_port == NULL) { 2366 + dev_err(&port->dev, "%s - Out of memory\n", __func__); 2367 + return -ENOMEM; 2547 2368 } 2548 2369 2549 - /* Zero Length flag enable */ 2550 - Data = 0x0f; 2551 - status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, Data); 2370 + /* Initialize all port interrupt end point to port 0 int 2371 + * endpoint. Our device has only one interrupt end point 2372 + * common to all port */ 2373 + 2374 + mos7840_port->port = port; 2375 + mos7840_set_port_private(port, mos7840_port); 2376 + spin_lock_init(&mos7840_port->pool_lock); 2377 + 2378 + /* minor is not initialised until later by 2379 + * usb-serial.c:get_free_serial() and cannot therefore be used 2380 + * to index device instances */ 2381 + mos7840_port->port_num = pnum + 1; 2382 + dev_dbg(&port->dev, "port->number = %d\n", port->number); 2383 + dev_dbg(&port->dev, "port->serial->minor = %d\n", port->serial->minor); 2384 + dev_dbg(&port->dev, "mos7840_port->port_num = %d\n", mos7840_port->port_num); 2385 + dev_dbg(&port->dev, "serial->minor = %d\n", serial->minor); 2386 + 2387 + if (mos7840_port->port_num == 1) { 2388 + mos7840_port->SpRegOffset = 0x0; 2389 + mos7840_port->ControlRegOffset = 0x1; 2390 + mos7840_port->DcrRegOffset = 0x4; 2391 + } else if ((mos7840_port->port_num == 2) && (serial->num_ports == 4)) { 2392 + mos7840_port->SpRegOffset = 0x8; 2393 + mos7840_port->ControlRegOffset = 0x9; 2394 + mos7840_port->DcrRegOffset = 0x16; 2395 + } else if ((mos7840_port->port_num == 2) && (serial->num_ports == 2)) { 2396 + mos7840_port->SpRegOffset = 0xa; 2397 + mos7840_port->ControlRegOffset = 0xb; 2398 + mos7840_port->DcrRegOffset = 0x19; 2399 + } else if ((mos7840_port->port_num == 3) && (serial->num_ports == 4)) { 2400 + mos7840_port->SpRegOffset = 0xa; 2401 + mos7840_port->ControlRegOffset = 0xb; 2402 + mos7840_port->DcrRegOffset = 0x19; 2403 + } else if ((mos7840_port->port_num == 4) && (serial->num_ports == 4)) { 2404 + mos7840_port->SpRegOffset = 0xc; 2405 + mos7840_port->ControlRegOffset = 0xd; 2406 + mos7840_port->DcrRegOffset = 0x1c; 2407 + } 2408 + mos7840_dump_serial_port(port, mos7840_port); 2409 + mos7840_set_port_private(port, mos7840_port); 2410 + 2411 + /* enable rx_disable bit in control register */ 2412 + status = mos7840_get_reg_sync(port, 2413 + mos7840_port->ControlRegOffset, &Data); 2552 2414 if (status < 0) { 2553 - dev_dbg(&dev->dev, "Writing ZLP_REG5 failed status-0x%x\n", status); 2415 + dev_dbg(&port->dev, "Reading ControlReg failed status-0x%x\n", status); 2416 + goto out; 2417 + } else 2418 + dev_dbg(&port->dev, "ControlReg Reading success val is %x, status%d\n", Data, status); 2419 + Data |= 0x08; /* setting driver done bit */ 2420 + Data |= 0x04; /* sp1_bit to have cts change reflect in 2421 + modem status reg */ 2422 + 2423 + /* Data |= 0x20; //rx_disable bit */ 2424 + status = mos7840_set_reg_sync(port, 2425 + mos7840_port->ControlRegOffset, Data); 2426 + if (status < 0) { 2427 + dev_dbg(&port->dev, "Writing ControlReg failed(rx_disable) status-0x%x\n", status); 2428 + goto out; 2429 + } else 2430 + dev_dbg(&port->dev, "ControlReg Writing success(rx_disable) status%d\n", status); 2431 + 2432 + /* Write default values in DCR (i.e 0x01 in DCR0, 0x05 in DCR2 2433 + and 0x24 in DCR3 */ 2434 + Data = 0x01; 2435 + status = mos7840_set_reg_sync(port, 2436 + (__u16) (mos7840_port->DcrRegOffset + 0), Data); 2437 + if (status < 0) { 2438 + dev_dbg(&port->dev, "Writing DCR0 failed status-0x%x\n", status); 2439 + goto out; 2440 + } else 2441 + dev_dbg(&port->dev, "DCR0 Writing success status%d\n", status); 2442 + 2443 + Data = 0x05; 2444 + status = mos7840_set_reg_sync(port, 2445 + (__u16) (mos7840_port->DcrRegOffset + 1), Data); 2446 + if (status < 0) { 2447 + dev_dbg(&port->dev, "Writing DCR1 failed status-0x%x\n", status); 2448 + goto out; 2449 + } else 2450 + dev_dbg(&port->dev, "DCR1 Writing success status%d\n", status); 2451 + 2452 + Data = 0x24; 2453 + status = mos7840_set_reg_sync(port, 2454 + (__u16) (mos7840_port->DcrRegOffset + 2), Data); 2455 + if (status < 0) { 2456 + dev_dbg(&port->dev, "Writing DCR2 failed status-0x%x\n", status); 2457 + goto out; 2458 + } else 2459 + dev_dbg(&port->dev, "DCR2 Writing success status%d\n", status); 2460 + 2461 + /* write values in clkstart0x0 and clkmulti 0x20 */ 2462 + Data = 0x0; 2463 + status = mos7840_set_reg_sync(port, CLK_START_VALUE_REGISTER, Data); 2464 + if (status < 0) { 2465 + dev_dbg(&port->dev, "Writing CLK_START_VALUE_REGISTER failed status-0x%x\n", status); 2466 + goto out; 2467 + } else 2468 + dev_dbg(&port->dev, "CLK_START_VALUE_REGISTER Writing success status%d\n", status); 2469 + 2470 + Data = 0x20; 2471 + status = mos7840_set_reg_sync(port, CLK_MULTI_REGISTER, Data); 2472 + if (status < 0) { 2473 + dev_dbg(&port->dev, "Writing CLK_MULTI_REGISTER failed status-0x%x\n", status); 2554 2474 goto error; 2555 2475 } else 2556 - dev_dbg(&dev->dev, "ZLP_REG5 Writing success status%d\n", status); 2476 + dev_dbg(&port->dev, "CLK_MULTI_REGISTER Writing success status%d\n", status); 2557 2477 2558 - /* setting configuration feature to one */ 2559 - usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 2560 - (__u8) 0x03, 0x00, 0x01, 0x00, NULL, 0x00, MOS_WDR_TIMEOUT); 2478 + /* write value 0x0 to scratchpad register */ 2479 + Data = 0x00; 2480 + status = mos7840_set_uart_reg(port, SCRATCH_PAD_REGISTER, Data); 2481 + if (status < 0) { 2482 + dev_dbg(&port->dev, "Writing SCRATCH_PAD_REGISTER failed status-0x%x\n", status); 2483 + goto out; 2484 + } else 2485 + dev_dbg(&port->dev, "SCRATCH_PAD_REGISTER Writing success status%d\n", status); 2486 + 2487 + /* Zero Length flag register */ 2488 + if ((mos7840_port->port_num != 1) && (serial->num_ports == 2)) { 2489 + Data = 0xff; 2490 + status = mos7840_set_reg_sync(port, 2491 + (__u16) (ZLP_REG1 + 2492 + ((__u16)mos7840_port->port_num)), Data); 2493 + dev_dbg(&port->dev, "ZLIP offset %x\n", 2494 + (__u16)(ZLP_REG1 + ((__u16) mos7840_port->port_num))); 2495 + if (status < 0) { 2496 + dev_dbg(&port->dev, "Writing ZLP_REG%d failed status-0x%x\n", pnum + 2, status); 2497 + goto out; 2498 + } else 2499 + dev_dbg(&port->dev, "ZLP_REG%d Writing success status%d\n", pnum + 2, status); 2500 + } else { 2501 + Data = 0xff; 2502 + status = mos7840_set_reg_sync(port, 2503 + (__u16) (ZLP_REG1 + 2504 + ((__u16)mos7840_port->port_num) - 0x1), Data); 2505 + dev_dbg(&port->dev, "ZLIP offset %x\n", 2506 + (__u16)(ZLP_REG1 + ((__u16) mos7840_port->port_num) - 0x1)); 2507 + if (status < 0) { 2508 + dev_dbg(&port->dev, "Writing ZLP_REG%d failed status-0x%x\n", pnum + 1, status); 2509 + goto out; 2510 + } else 2511 + dev_dbg(&port->dev, "ZLP_REG%d Writing success status%d\n", pnum + 1, status); 2512 + 2513 + } 2514 + mos7840_port->control_urb = usb_alloc_urb(0, GFP_KERNEL); 2515 + mos7840_port->ctrl_buf = kmalloc(16, GFP_KERNEL); 2516 + mos7840_port->dr = kmalloc(sizeof(struct usb_ctrlrequest), 2517 + GFP_KERNEL); 2518 + if (!mos7840_port->control_urb || !mos7840_port->ctrl_buf || 2519 + !mos7840_port->dr) { 2520 + status = -ENOMEM; 2521 + goto error; 2522 + } 2523 + 2524 + mos7840_port->has_led = false; 2525 + 2526 + /* Initialize LED timers */ 2527 + if (device_type == MOSCHIP_DEVICE_ID_7810) { 2528 + mos7840_port->has_led = true; 2529 + 2530 + init_timer(&mos7840_port->led_timer1); 2531 + mos7840_port->led_timer1.function = mos7840_led_off; 2532 + mos7840_port->led_timer1.expires = 2533 + jiffies + msecs_to_jiffies(LED_ON_MS); 2534 + mos7840_port->led_timer1.data = (unsigned long)mos7840_port; 2535 + 2536 + init_timer(&mos7840_port->led_timer2); 2537 + mos7840_port->led_timer2.function = mos7840_led_flag_off; 2538 + mos7840_port->led_timer2.expires = 2539 + jiffies + msecs_to_jiffies(LED_OFF_MS); 2540 + mos7840_port->led_timer2.data = (unsigned long)mos7840_port; 2541 + 2542 + mos7840_port->led_flag = false; 2543 + 2544 + /* Turn off LED */ 2545 + mos7840_set_led_sync(port, MODEM_CONTROL_REGISTER, 0x0300); 2546 + } 2547 + out: 2548 + if (pnum == serial->num_ports - 1) { 2549 + /* Zero Length flag enable */ 2550 + Data = 0x0f; 2551 + status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, Data); 2552 + if (status < 0) { 2553 + dev_dbg(&port->dev, "Writing ZLP_REG5 failed status-0x%x\n", status); 2554 + goto error; 2555 + } else 2556 + dev_dbg(&port->dev, "ZLP_REG5 Writing success status%d\n", status); 2557 + 2558 + /* setting configuration feature to one */ 2559 + usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 2560 + 0x03, 0x00, 0x01, 0x00, NULL, 0x00, 2561 + MOS_WDR_TIMEOUT); 2562 + } 2561 2563 return 0; 2562 2564 error: 2563 - for (/* nothing */; i >= 0; i--) { 2564 - mos7840_port = mos7840_get_port_private(serial->port[i]); 2565 + kfree(mos7840_port->dr); 2566 + kfree(mos7840_port->ctrl_buf); 2567 + usb_free_urb(mos7840_port->control_urb); 2568 + kfree(mos7840_port); 2565 2569 2566 - kfree(mos7840_port->dr); 2567 - kfree(mos7840_port->ctrl_buf); 2568 - usb_free_urb(mos7840_port->control_urb); 2569 - kfree(mos7840_port); 2570 - serial->port[i] = NULL; 2571 - } 2572 2570 return status; 2573 2571 } 2574 2572 2575 - /**************************************************************************** 2576 - * mos7840_disconnect 2577 - * This function is called whenever the device is removed from the usb bus. 2578 - ****************************************************************************/ 2579 - 2580 - static void mos7840_disconnect(struct usb_serial *serial) 2573 + static int mos7840_port_remove(struct usb_serial_port *port) 2581 2574 { 2582 - int i; 2583 - unsigned long flags; 2584 2575 struct moschip_port *mos7840_port; 2585 2576 2586 - /* check for the ports to be closed,close the ports and disconnect */ 2577 + mos7840_port = mos7840_get_port_private(port); 2587 2578 2588 - /* free private structure allocated for serial port * 2589 - * stop reads and writes on all ports */ 2579 + if (mos7840_port->has_led) { 2580 + /* Turn off LED */ 2581 + mos7840_set_led_sync(port, MODEM_CONTROL_REGISTER, 0x0300); 2590 2582 2591 - for (i = 0; i < serial->num_ports; ++i) { 2592 - mos7840_port = mos7840_get_port_private(serial->port[i]); 2593 - if (mos7840_port) { 2594 - spin_lock_irqsave(&mos7840_port->pool_lock, flags); 2595 - mos7840_port->zombie = 1; 2596 - spin_unlock_irqrestore(&mos7840_port->pool_lock, flags); 2597 - usb_kill_urb(mos7840_port->control_urb); 2598 - } 2583 + del_timer_sync(&mos7840_port->led_timer1); 2584 + del_timer_sync(&mos7840_port->led_timer2); 2599 2585 } 2600 - } 2586 + usb_kill_urb(mos7840_port->control_urb); 2587 + usb_free_urb(mos7840_port->control_urb); 2588 + kfree(mos7840_port->ctrl_buf); 2589 + kfree(mos7840_port->dr); 2590 + kfree(mos7840_port); 2601 2591 2602 - /**************************************************************************** 2603 - * mos7840_release 2604 - * This function is called when the usb_serial structure is freed. 2605 - ****************************************************************************/ 2606 - 2607 - static void mos7840_release(struct usb_serial *serial) 2608 - { 2609 - int i; 2610 - struct moschip_port *mos7840_port; 2611 - 2612 - /* check for the ports to be closed,close the ports and disconnect */ 2613 - 2614 - /* free private structure allocated for serial port * 2615 - * stop reads and writes on all ports */ 2616 - 2617 - for (i = 0; i < serial->num_ports; ++i) { 2618 - mos7840_port = mos7840_get_port_private(serial->port[i]); 2619 - if (mos7840_port) { 2620 - if (mos7840_port->has_led) { 2621 - /* Turn off LED */ 2622 - mos7840_set_led_sync(mos7840_port->port, 2623 - MODEM_CONTROL_REGISTER, 0x0300); 2624 - 2625 - del_timer_sync(&mos7840_port->led_timer1); 2626 - del_timer_sync(&mos7840_port->led_timer2); 2627 - } 2628 - kfree(mos7840_port->ctrl_buf); 2629 - kfree(mos7840_port->dr); 2630 - kfree(mos7840_port); 2631 - } 2632 - } 2592 + return 0; 2633 2593 } 2634 2594 2635 2595 static struct usb_serial_driver moschip7840_4port_device = { ··· 2597 2677 .tiocmget = mos7840_tiocmget, 2598 2678 .tiocmset = mos7840_tiocmset, 2599 2679 .get_icount = mos7840_get_icount, 2600 - .attach = mos7840_startup, 2601 - .disconnect = mos7840_disconnect, 2602 - .release = mos7840_release, 2680 + .port_probe = mos7840_port_probe, 2681 + .port_remove = mos7840_port_remove, 2603 2682 .read_bulk_callback = mos7840_bulk_in_callback, 2604 2683 .read_int_callback = mos7840_interrupt_callback, 2605 2684 };
+18 -18
drivers/usb/serial/omninet.c
··· 44 44 const unsigned char *buf, int count); 45 45 static int omninet_write_room(struct tty_struct *tty); 46 46 static void omninet_disconnect(struct usb_serial *serial); 47 - static void omninet_release(struct usb_serial *serial); 48 - static int omninet_attach(struct usb_serial *serial); 47 + static int omninet_port_probe(struct usb_serial_port *port); 48 + static int omninet_port_remove(struct usb_serial_port *port); 49 49 50 50 static const struct usb_device_id id_table[] = { 51 51 { USB_DEVICE(ZYXEL_VENDOR_ID, ZYXEL_OMNINET_ID) }, ··· 62 62 .description = "ZyXEL - omni.net lcd plus usb", 63 63 .id_table = id_table, 64 64 .num_ports = 1, 65 - .attach = omninet_attach, 65 + .port_probe = omninet_port_probe, 66 + .port_remove = omninet_port_remove, 66 67 .open = omninet_open, 67 68 .close = omninet_close, 68 69 .write = omninet_write, ··· 71 70 .read_bulk_callback = omninet_read_bulk_callback, 72 71 .write_bulk_callback = omninet_write_bulk_callback, 73 72 .disconnect = omninet_disconnect, 74 - .release = omninet_release, 75 73 }; 76 74 77 75 static struct usb_serial_driver * const serial_drivers[] = { ··· 112 112 __u8 od_outseq; /* Sequence number for bulk_out URBs */ 113 113 }; 114 114 115 - static int omninet_attach(struct usb_serial *serial) 115 + static int omninet_port_probe(struct usb_serial_port *port) 116 116 { 117 117 struct omninet_data *od; 118 - struct usb_serial_port *port = serial->port[0]; 119 118 120 119 od = kmalloc(sizeof(struct omninet_data), GFP_KERNEL); 121 - if (!od) { 122 - dev_err(&port->dev, "%s- kmalloc(%Zd) failed.\n", 123 - __func__, sizeof(struct omninet_data)); 120 + if (!od) 124 121 return -ENOMEM; 125 - } 122 + 126 123 usb_set_serial_port_data(port, od); 124 + 125 + return 0; 126 + } 127 + 128 + static int omninet_port_remove(struct usb_serial_port *port) 129 + { 130 + struct omninet_data *od; 131 + 132 + od = usb_get_serial_port_data(port); 133 + kfree(od); 134 + 127 135 return 0; 128 136 } 129 137 ··· 285 277 struct usb_serial_port *wport = serial->port[1]; 286 278 287 279 usb_kill_urb(wport->write_urb); 288 - } 289 - 290 - 291 - static void omninet_release(struct usb_serial *serial) 292 - { 293 - struct usb_serial_port *port = serial->port[0]; 294 - 295 - kfree(usb_get_serial_port_data(port)); 296 280 } 297 281 298 282 module_usb_serial_driver(serial_drivers, id_table);
+9 -2
drivers/usb/serial/opticon.c
··· 155 155 { 156 156 struct usb_serial *serial = port->serial; 157 157 int retval; 158 - u8 buffer[2]; 158 + u8 *buffer; 159 + 160 + buffer = kzalloc(1, GFP_KERNEL); 161 + if (!buffer) 162 + return -ENOMEM; 159 163 160 164 buffer[0] = val; 161 165 /* Send the message to the vendor control endpoint ··· 168 164 requesttype, 169 165 USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE, 170 166 0, 0, buffer, 1, 0); 167 + kfree(buffer); 171 168 172 169 return retval; 173 170 } ··· 286 281 if (!dr) { 287 282 dev_err(&port->dev, "out of memory\n"); 288 283 count = -ENOMEM; 289 - goto error; 284 + goto error_no_dr; 290 285 } 291 286 292 287 dr->bRequestType = USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT; ··· 316 311 317 312 return count; 318 313 error: 314 + kfree(dr); 315 + error_no_dr: 319 316 usb_free_urb(urb); 320 317 error_no_urb: 321 318 kfree(buffer);
+20 -3
drivers/usb/serial/option.c
··· 47 47 /* Function prototypes */ 48 48 static int option_probe(struct usb_serial *serial, 49 49 const struct usb_device_id *id); 50 + static int option_attach(struct usb_serial *serial); 50 51 static void option_release(struct usb_serial *serial); 51 52 static int option_send_setup(struct usb_serial_port *port); 52 53 static void option_instat_callback(struct urb *urb); ··· 1289 1288 .tiocmget = usb_wwan_tiocmget, 1290 1289 .tiocmset = usb_wwan_tiocmset, 1291 1290 .ioctl = usb_wwan_ioctl, 1292 - .attach = usb_wwan_startup, 1291 + .attach = option_attach, 1293 1292 .release = option_release, 1293 + .port_probe = usb_wwan_port_probe, 1294 1294 .port_remove = usb_wwan_port_remove, 1295 1295 .read_int_callback = option_instat_callback, 1296 1296 #ifdef CONFIG_PM ··· 1337 1335 static int option_probe(struct usb_serial *serial, 1338 1336 const struct usb_device_id *id) 1339 1337 { 1340 - struct usb_wwan_intf_private *data; 1341 - struct option_private *priv; 1342 1338 struct usb_interface_descriptor *iface_desc = 1343 1339 &serial->interface->cur_altsetting->desc; 1344 1340 struct usb_device_descriptor *dev_desc = &serial->dev->descriptor; ··· 1374 1374 iface_desc->bInterfaceClass != USB_CLASS_CDC_DATA) 1375 1375 return -ENODEV; 1376 1376 1377 + /* Store device id so we can use it during attach. */ 1378 + usb_set_serial_data(serial, (void *)id); 1379 + 1380 + return 0; 1381 + } 1382 + 1383 + static int option_attach(struct usb_serial *serial) 1384 + { 1385 + struct usb_interface_descriptor *iface_desc; 1386 + const struct usb_device_id *id; 1387 + struct usb_wwan_intf_private *data; 1388 + struct option_private *priv; 1389 + 1377 1390 data = kzalloc(sizeof(struct usb_wwan_intf_private), GFP_KERNEL); 1378 1391 if (!data) 1379 1392 return -ENOMEM; ··· 1396 1383 kfree(data); 1397 1384 return -ENOMEM; 1398 1385 } 1386 + 1387 + /* Retrieve device id stored at probe. */ 1388 + id = usb_get_serial_data(serial); 1389 + iface_desc = &serial->interface->cur_altsetting->desc; 1399 1390 1400 1391 priv->bInterfaceNumber = iface_desc->bInterfaceNumber; 1401 1392 data->private = priv;
+17 -16
drivers/usb/serial/qcserial.c
··· 138 138 139 139 static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id) 140 140 { 141 - struct usb_wwan_intf_private *data; 142 141 struct usb_host_interface *intf = serial->interface->cur_altsetting; 143 142 struct device *dev = &serial->dev->dev; 144 143 int retval = -ENODEV; ··· 152 153 dev_dbg(dev, "Num Interfaces = %d\n", nintf); 153 154 ifnum = intf->desc.bInterfaceNumber; 154 155 dev_dbg(dev, "This Interface = %d\n", ifnum); 155 - 156 - data = kzalloc(sizeof(struct usb_wwan_intf_private), 157 - GFP_KERNEL); 158 - if (!data) 159 - return -ENOMEM; 160 - 161 - spin_lock_init(&data->susp_lock); 162 156 163 157 if (nintf == 1) { 164 158 /* QDL mode */ ··· 245 253 } 246 254 } 247 255 248 - /* Set serial->private if not returning error */ 249 - if (retval == 0) 250 - usb_set_serial_data(serial, data); 251 - else 252 - kfree(data); 253 - 254 256 return retval; 257 + } 258 + 259 + static int qc_attach(struct usb_serial *serial) 260 + { 261 + struct usb_wwan_intf_private *data; 262 + 263 + data = kzalloc(sizeof(*data), GFP_KERNEL); 264 + if (!data) 265 + return -ENOMEM; 266 + 267 + spin_lock_init(&data->susp_lock); 268 + 269 + usb_set_serial_data(serial, data); 270 + 271 + return 0; 255 272 } 256 273 257 274 static void qc_release(struct usb_serial *serial) 258 275 { 259 276 struct usb_wwan_intf_private *priv = usb_get_serial_data(serial); 260 277 261 - /* Free the private data allocated in qcprobe */ 262 278 usb_set_serial_data(serial, NULL); 263 279 kfree(priv); 264 280 } ··· 285 285 .write = usb_wwan_write, 286 286 .write_room = usb_wwan_write_room, 287 287 .chars_in_buffer = usb_wwan_chars_in_buffer, 288 - .attach = usb_wwan_startup, 288 + .attach = qc_attach, 289 289 .release = qc_release, 290 + .port_probe = usb_wwan_port_probe, 290 291 .port_remove = usb_wwan_port_remove, 291 292 #ifdef CONFIG_PM 292 293 .suspend = usb_wwan_suspend,
+61 -74
drivers/usb/serial/quatech2.c
··· 143 143 144 144 static void qt2_release(struct usb_serial *serial) 145 145 { 146 - int i; 146 + struct qt2_serial_private *serial_priv; 147 147 148 - kfree(usb_get_serial_data(serial)); 148 + serial_priv = usb_get_serial_data(serial); 149 149 150 - for (i = 0; i < serial->num_ports; i++) 151 - kfree(usb_get_serial_port_data(serial->port[i])); 150 + usb_free_urb(serial_priv->read_urb); 151 + kfree(serial_priv); 152 152 } 153 153 154 154 static inline int calc_baud_divisor(int baudrate) ··· 423 423 port_priv->is_open = false; 424 424 425 425 spin_lock_irqsave(&port_priv->urb_lock, flags); 426 - if (port_priv->write_urb->status == -EINPROGRESS) 427 - usb_kill_urb(port_priv->write_urb); 426 + usb_kill_urb(port_priv->write_urb); 428 427 port_priv->urb_in_use = false; 429 428 spin_unlock_irqrestore(&port_priv->urb_lock, flags); 429 + 430 + mutex_lock(&port->serial->disc_mutex); 431 + if (port->serial->disconnected) { 432 + mutex_unlock(&port->serial->disc_mutex); 433 + return; 434 + } 430 435 431 436 /* flush the port transmit buffer */ 432 437 i = usb_control_msg(serial->dev, ··· 464 459 dev_err(&port->dev, "%s - close port failed %i\n", 465 460 __func__, i); 466 461 462 + mutex_unlock(&port->serial->disc_mutex); 467 463 } 468 464 469 465 static void qt2_disconnect(struct usb_serial *serial) 470 466 { 471 467 struct qt2_serial_private *serial_priv = usb_get_serial_data(serial); 472 - struct qt2_port_private *port_priv; 473 - int i; 474 468 475 - if (serial_priv->read_urb->status == -EINPROGRESS) 476 - usb_kill_urb(serial_priv->read_urb); 477 - 478 - usb_free_urb(serial_priv->read_urb); 479 - 480 - for (i = 0; i < serial->num_ports; i++) { 481 - port_priv = usb_get_serial_port_data(serial->port[i]); 482 - 483 - if (port_priv->write_urb->status == -EINPROGRESS) 484 - usb_kill_urb(port_priv->write_urb); 485 - usb_free_urb(port_priv->write_urb); 486 - } 469 + usb_kill_urb(serial_priv->read_urb); 487 470 } 488 471 489 472 static int get_serial_info(struct usb_serial_port *port, ··· 766 773 767 774 static int qt2_setup_urbs(struct usb_serial *serial) 768 775 { 769 - struct usb_serial_port *port; 770 776 struct usb_serial_port *port0; 771 777 struct qt2_serial_private *serial_priv; 772 - struct qt2_port_private *port_priv; 773 - int pcount, status; 778 + int status; 774 779 775 780 port0 = serial->port[0]; 776 781 ··· 786 795 sizeof(serial_priv->read_buffer), 787 796 qt2_read_bulk_callback, serial); 788 797 789 - /* setup write_urb for each port */ 790 - for (pcount = 0; pcount < serial->num_ports; pcount++) { 791 - 792 - port = serial->port[pcount]; 793 - port_priv = usb_get_serial_port_data(port); 794 - 795 - port_priv->write_urb = usb_alloc_urb(0, GFP_KERNEL); 796 - if (!port_priv->write_urb) { 797 - dev_err(&serial->dev->dev, 798 - "failed to alloc write_urb for port %i\n", 799 - pcount); 800 - return -ENOMEM; 801 - } 802 - 803 - usb_fill_bulk_urb(port_priv->write_urb, 804 - serial->dev, 805 - usb_sndbulkpipe(serial->dev, 806 - port0-> 807 - bulk_out_endpointAddress), 808 - port_priv->write_buffer, 809 - sizeof(port_priv->write_buffer), 810 - qt2_write_bulk_callback, port); 811 - } 812 - 813 798 status = usb_submit_urb(serial_priv->read_urb, GFP_KERNEL); 814 799 if (status != 0) { 815 800 dev_err(&serial->dev->dev, 816 801 "%s - submit read urb failed %i\n", __func__, status); 802 + usb_free_urb(serial_priv->read_urb); 817 803 return status; 818 804 } 819 805 820 806 return 0; 821 - 822 807 } 823 808 824 809 static int qt2_attach(struct usb_serial *serial) 825 810 { 826 811 struct qt2_serial_private *serial_priv; 827 - struct qt2_port_private *port_priv; 828 - int status, pcount; 812 + int status; 829 813 830 814 /* power on unit */ 831 815 status = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), ··· 820 854 821 855 usb_set_serial_data(serial, serial_priv); 822 856 823 - for (pcount = 0; pcount < serial->num_ports; pcount++) { 824 - port_priv = kzalloc(sizeof(*port_priv), GFP_KERNEL); 825 - if (!port_priv) { 826 - dev_err(&serial->dev->dev, 827 - "%s- kmalloc(%Zd) failed.\n", __func__, 828 - sizeof(*port_priv)); 829 - pcount--; 830 - status = -ENOMEM; 831 - goto attach_failed; 832 - } 833 - 834 - spin_lock_init(&port_priv->lock); 835 - spin_lock_init(&port_priv->urb_lock); 836 - init_waitqueue_head(&port_priv->delta_msr_wait); 837 - 838 - port_priv->port = serial->port[pcount]; 839 - 840 - usb_set_serial_port_data(serial->port[pcount], port_priv); 841 - } 842 - 843 857 status = qt2_setup_urbs(serial); 844 858 if (status != 0) 845 859 goto attach_failed; ··· 827 881 return 0; 828 882 829 883 attach_failed: 830 - for (/* empty */; pcount >= 0; pcount--) { 831 - port_priv = usb_get_serial_port_data(serial->port[pcount]); 832 - kfree(port_priv); 833 - } 834 884 kfree(serial_priv); 835 885 return status; 886 + } 887 + 888 + static int qt2_port_probe(struct usb_serial_port *port) 889 + { 890 + struct usb_serial *serial = port->serial; 891 + struct qt2_port_private *port_priv; 892 + u8 bEndpointAddress; 893 + 894 + port_priv = kzalloc(sizeof(*port_priv), GFP_KERNEL); 895 + if (!port_priv) 896 + return -ENOMEM; 897 + 898 + spin_lock_init(&port_priv->lock); 899 + spin_lock_init(&port_priv->urb_lock); 900 + init_waitqueue_head(&port_priv->delta_msr_wait); 901 + port_priv->port = port; 902 + 903 + port_priv->write_urb = usb_alloc_urb(0, GFP_KERNEL); 904 + if (!port_priv->write_urb) { 905 + kfree(port_priv); 906 + return -ENOMEM; 907 + } 908 + bEndpointAddress = serial->port[0]->bulk_out_endpointAddress; 909 + usb_fill_bulk_urb(port_priv->write_urb, serial->dev, 910 + usb_sndbulkpipe(serial->dev, bEndpointAddress), 911 + port_priv->write_buffer, 912 + sizeof(port_priv->write_buffer), 913 + qt2_write_bulk_callback, port); 914 + 915 + usb_set_serial_port_data(port, port_priv); 916 + 917 + return 0; 918 + } 919 + 920 + static int qt2_port_remove(struct usb_serial_port *port) 921 + { 922 + struct qt2_port_private *port_priv; 923 + 924 + port_priv = usb_get_serial_port_data(port); 925 + usb_free_urb(port_priv->write_urb); 926 + kfree(port_priv); 927 + 928 + return 0; 836 929 } 837 930 838 931 static int qt2_tiocmget(struct tty_struct *tty) ··· 1112 1127 .attach = qt2_attach, 1113 1128 .release = qt2_release, 1114 1129 .disconnect = qt2_disconnect, 1130 + .port_probe = qt2_port_probe, 1131 + .port_remove = qt2_port_remove, 1115 1132 .dtr_rts = qt2_dtr_rts, 1116 1133 .break_ctl = qt2_break_ctl, 1117 1134 .tiocmget = qt2_tiocmget,
+69 -66
drivers/usb/serial/sierra.c
··· 161 161 { 162 162 int result = 0; 163 163 struct usb_device *udev; 164 - struct sierra_intf_private *data; 165 164 u8 ifnum; 166 165 167 166 udev = serial->dev; ··· 186 187 "Ignoring blacklisted interface #%d\n", ifnum); 187 188 return -ENODEV; 188 189 } 189 - 190 - data = serial->private = kzalloc(sizeof(struct sierra_intf_private), GFP_KERNEL); 191 - if (!data) 192 - return -ENOMEM; 193 - spin_lock_init(&data->susp_lock); 194 190 195 191 return result; 196 192 } ··· 878 884 879 885 static int sierra_startup(struct usb_serial *serial) 880 886 { 881 - struct usb_serial_port *port; 882 - struct sierra_port_private *portdata; 883 - struct sierra_iface_info *himemoryp = NULL; 884 - int i; 885 - u8 ifnum; 887 + struct sierra_intf_private *intfdata; 888 + 889 + intfdata = kzalloc(sizeof(*intfdata), GFP_KERNEL); 890 + if (!intfdata) 891 + return -ENOMEM; 892 + 893 + spin_lock_init(&intfdata->susp_lock); 894 + 895 + usb_set_serial_data(serial, intfdata); 886 896 887 897 /* Set Device mode to D0 */ 888 898 sierra_set_power_state(serial->dev, 0x0000); ··· 895 897 if (nmea) 896 898 sierra_vsc_set_nmea(serial->dev, 1); 897 899 898 - /* Now setup per port private data */ 899 - for (i = 0; i < serial->num_ports; i++) { 900 - port = serial->port[i]; 901 - portdata = kzalloc(sizeof(*portdata), GFP_KERNEL); 902 - if (!portdata) { 903 - dev_dbg(&port->dev, "%s: kmalloc for " 904 - "sierra_port_private (%d) failed!\n", 905 - __func__, i); 906 - return -ENOMEM; 907 - } 908 - spin_lock_init(&portdata->lock); 909 - init_usb_anchor(&portdata->active); 910 - init_usb_anchor(&portdata->delayed); 911 - ifnum = i; 912 - /* Assume low memory requirements */ 913 - portdata->num_out_urbs = N_OUT_URB; 914 - portdata->num_in_urbs = N_IN_URB; 915 - 916 - /* Determine actual memory requirements */ 917 - if (serial->num_ports == 1) { 918 - /* Get interface number for composite device */ 919 - ifnum = sierra_calc_interface(serial); 920 - himemoryp = 921 - (struct sierra_iface_info *)&typeB_interface_list; 922 - if (is_himemory(ifnum, himemoryp)) { 923 - portdata->num_out_urbs = N_OUT_URB_HM; 924 - portdata->num_in_urbs = N_IN_URB_HM; 925 - } 926 - } 927 - else { 928 - himemoryp = 929 - (struct sierra_iface_info *)&typeA_interface_list; 930 - if (is_himemory(i, himemoryp)) { 931 - portdata->num_out_urbs = N_OUT_URB_HM; 932 - portdata->num_in_urbs = N_IN_URB_HM; 933 - } 934 - } 935 - dev_dbg(&serial->dev->dev, 936 - "Memory usage (urbs) interface #%d, in=%d, out=%d\n", 937 - ifnum,portdata->num_in_urbs, portdata->num_out_urbs ); 938 - /* Set the port private data pointer */ 939 - usb_set_serial_port_data(port, portdata); 940 - } 941 - 942 900 return 0; 943 901 } 944 902 945 903 static void sierra_release(struct usb_serial *serial) 946 904 { 947 - int i; 948 - struct usb_serial_port *port; 905 + struct sierra_intf_private *intfdata; 906 + 907 + intfdata = usb_get_serial_data(serial); 908 + kfree(intfdata); 909 + } 910 + 911 + static int sierra_port_probe(struct usb_serial_port *port) 912 + { 913 + struct usb_serial *serial = port->serial; 914 + struct sierra_port_private *portdata; 915 + const struct sierra_iface_info *himemoryp; 916 + u8 ifnum; 917 + 918 + portdata = kzalloc(sizeof(*portdata), GFP_KERNEL); 919 + if (!portdata) 920 + return -ENOMEM; 921 + 922 + spin_lock_init(&portdata->lock); 923 + init_usb_anchor(&portdata->active); 924 + init_usb_anchor(&portdata->delayed); 925 + 926 + /* Assume low memory requirements */ 927 + portdata->num_out_urbs = N_OUT_URB; 928 + portdata->num_in_urbs = N_IN_URB; 929 + 930 + /* Determine actual memory requirements */ 931 + if (serial->num_ports == 1) { 932 + /* Get interface number for composite device */ 933 + ifnum = sierra_calc_interface(serial); 934 + himemoryp = &typeB_interface_list; 935 + } else { 936 + /* This is really the usb-serial port number of the interface 937 + * rather than the interface number. 938 + */ 939 + ifnum = port->number - serial->minor; 940 + himemoryp = &typeA_interface_list; 941 + } 942 + 943 + if (is_himemory(ifnum, himemoryp)) { 944 + portdata->num_out_urbs = N_OUT_URB_HM; 945 + portdata->num_in_urbs = N_IN_URB_HM; 946 + } 947 + 948 + dev_dbg(&port->dev, 949 + "Memory usage (urbs) interface #%d, in=%d, out=%d\n", 950 + ifnum, portdata->num_in_urbs, portdata->num_out_urbs); 951 + 952 + usb_set_serial_port_data(port, portdata); 953 + 954 + return 0; 955 + } 956 + 957 + static int sierra_port_remove(struct usb_serial_port *port) 958 + { 949 959 struct sierra_port_private *portdata; 950 960 951 - for (i = 0; i < serial->num_ports; ++i) { 952 - port = serial->port[i]; 953 - if (!port) 954 - continue; 955 - portdata = usb_get_serial_port_data(port); 956 - if (!portdata) 957 - continue; 958 - kfree(portdata); 959 - } 961 + portdata = usb_get_serial_port_data(port); 962 + kfree(portdata); 963 + 964 + return 0; 960 965 } 961 966 962 967 #ifdef CONFIG_PM ··· 1063 1062 .tiocmset = sierra_tiocmset, 1064 1063 .attach = sierra_startup, 1065 1064 .release = sierra_release, 1065 + .port_probe = sierra_port_probe, 1066 + .port_remove = sierra_port_remove, 1066 1067 .suspend = sierra_suspend, 1067 1068 .resume = sierra_resume, 1068 1069 .read_int_callback = sierra_instat_callback,
+1 -1
drivers/usb/serial/usb-wwan.h
··· 8 8 extern void usb_wwan_dtr_rts(struct usb_serial_port *port, int on); 9 9 extern int usb_wwan_open(struct tty_struct *tty, struct usb_serial_port *port); 10 10 extern void usb_wwan_close(struct usb_serial_port *port); 11 - extern int usb_wwan_startup(struct usb_serial *serial); 11 + extern int usb_wwan_port_probe(struct usb_serial_port *port); 12 12 extern int usb_wwan_port_remove(struct usb_serial_port *port); 13 13 extern int usb_wwan_write_room(struct tty_struct *tty); 14 14 extern void usb_wwan_set_termios(struct tty_struct *tty,
+52 -76
drivers/usb/serial/usb_wwan.c
··· 447 447 EXPORT_SYMBOL(usb_wwan_close); 448 448 449 449 /* Helper functions used by usb_wwan_setup_urbs */ 450 - static struct urb *usb_wwan_setup_urb(struct usb_serial *serial, int endpoint, 450 + static struct urb *usb_wwan_setup_urb(struct usb_serial_port *port, 451 + int endpoint, 451 452 int dir, void *ctx, char *buf, int len, 452 453 void (*callback) (struct urb *)) 453 454 { 455 + struct usb_serial *serial = port->serial; 454 456 struct urb *urb; 455 457 456 458 if (endpoint == -1) ··· 474 472 return urb; 475 473 } 476 474 477 - /* Setup urbs */ 478 - static void usb_wwan_setup_urbs(struct usb_serial *serial) 475 + int usb_wwan_port_probe(struct usb_serial_port *port) 479 476 { 480 - int i, j; 481 - struct usb_serial_port *port; 482 477 struct usb_wwan_port_private *portdata; 483 - 484 - for (i = 0; i < serial->num_ports; i++) { 485 - port = serial->port[i]; 486 - portdata = usb_get_serial_port_data(port); 487 - 488 - /* Do indat endpoints first */ 489 - for (j = 0; j < N_IN_URB; ++j) { 490 - portdata->in_urbs[j] = usb_wwan_setup_urb(serial, 491 - port-> 492 - bulk_in_endpointAddress, 493 - USB_DIR_IN, 494 - port, 495 - portdata-> 496 - in_buffer[j], 497 - IN_BUFLEN, 498 - usb_wwan_indat_callback); 499 - } 500 - 501 - /* outdat endpoints */ 502 - for (j = 0; j < N_OUT_URB; ++j) { 503 - portdata->out_urbs[j] = usb_wwan_setup_urb(serial, 504 - port-> 505 - bulk_out_endpointAddress, 506 - USB_DIR_OUT, 507 - port, 508 - portdata-> 509 - out_buffer 510 - [j], 511 - OUT_BUFLEN, 512 - usb_wwan_outdat_callback); 513 - } 514 - } 515 - } 516 - 517 - int usb_wwan_startup(struct usb_serial *serial) 518 - { 519 - int i, j, err; 520 - struct usb_serial_port *port; 521 - struct usb_wwan_port_private *portdata; 478 + struct urb *urb; 522 479 u8 *buffer; 480 + int err; 481 + int i; 523 482 524 - /* Now setup per port private data */ 525 - for (i = 0; i < serial->num_ports; i++) { 526 - port = serial->port[i]; 527 - portdata = kzalloc(sizeof(*portdata), GFP_KERNEL); 528 - if (!portdata) { 529 - dev_dbg(&port->dev, "%s: kmalloc for usb_wwan_port_private (%d) failed!.\n", 530 - __func__, i); 531 - return 1; 532 - } 533 - init_usb_anchor(&portdata->delayed); 483 + portdata = kzalloc(sizeof(*portdata), GFP_KERNEL); 484 + if (!portdata) 485 + return -ENOMEM; 534 486 535 - for (j = 0; j < N_IN_URB; j++) { 536 - buffer = (u8 *) __get_free_page(GFP_KERNEL); 537 - if (!buffer) 538 - goto bail_out_error; 539 - portdata->in_buffer[j] = buffer; 540 - } 487 + init_usb_anchor(&portdata->delayed); 541 488 542 - for (j = 0; j < N_OUT_URB; j++) { 543 - buffer = kmalloc(OUT_BUFLEN, GFP_KERNEL); 544 - if (!buffer) 545 - goto bail_out_error2; 546 - portdata->out_buffer[j] = buffer; 547 - } 489 + for (i = 0; i < N_IN_URB; i++) { 490 + buffer = (u8 *)__get_free_page(GFP_KERNEL); 491 + if (!buffer) 492 + goto bail_out_error; 493 + portdata->in_buffer[i] = buffer; 548 494 549 - usb_set_serial_port_data(port, portdata); 495 + urb = usb_wwan_setup_urb(port, port->bulk_in_endpointAddress, 496 + USB_DIR_IN, port, 497 + buffer, IN_BUFLEN, 498 + usb_wwan_indat_callback); 499 + portdata->in_urbs[i] = urb; 500 + } 550 501 551 - if (!port->interrupt_in_urb) 502 + for (i = 0; i < N_OUT_URB; i++) { 503 + if (port->bulk_out_endpointAddress == -1) 552 504 continue; 505 + 506 + buffer = kmalloc(OUT_BUFLEN, GFP_KERNEL); 507 + if (!buffer) 508 + goto bail_out_error2; 509 + portdata->out_buffer[i] = buffer; 510 + 511 + urb = usb_wwan_setup_urb(port, port->bulk_out_endpointAddress, 512 + USB_DIR_OUT, port, 513 + buffer, OUT_BUFLEN, 514 + usb_wwan_outdat_callback); 515 + portdata->out_urbs[i] = urb; 516 + } 517 + 518 + usb_set_serial_port_data(port, portdata); 519 + 520 + if (port->interrupt_in_urb) { 553 521 err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 554 522 if (err) 555 523 dev_dbg(&port->dev, "%s: submit irq_in urb failed %d\n", 556 524 __func__, err); 557 525 } 558 - usb_wwan_setup_urbs(serial); 526 + 559 527 return 0; 560 528 561 529 bail_out_error2: 562 - for (j = 0; j < N_OUT_URB; j++) 563 - kfree(portdata->out_buffer[j]); 530 + for (i = 0; i < N_OUT_URB; i++) { 531 + usb_free_urb(portdata->out_urbs[i]); 532 + kfree(portdata->out_buffer[i]); 533 + } 564 534 bail_out_error: 565 - for (j = 0; j < N_IN_URB; j++) 566 - if (portdata->in_buffer[j]) 567 - free_page((unsigned long)portdata->in_buffer[j]); 535 + for (i = 0; i < N_IN_URB; i++) { 536 + usb_free_urb(portdata->in_urbs[i]); 537 + free_page((unsigned long)portdata->in_buffer[i]); 538 + } 568 539 kfree(portdata); 569 - return 1; 540 + 541 + return -ENOMEM; 570 542 } 571 - EXPORT_SYMBOL(usb_wwan_startup); 543 + EXPORT_SYMBOL_GPL(usb_wwan_port_probe); 572 544 573 545 int usb_wwan_port_remove(struct usb_serial_port *port) 574 546 {
+27 -33
drivers/usb/serial/whiteheat.c
··· 83 83 /* function prototypes for the Connect Tech WhiteHEAT serial converter */ 84 84 static int whiteheat_attach(struct usb_serial *serial); 85 85 static void whiteheat_release(struct usb_serial *serial); 86 + static int whiteheat_port_probe(struct usb_serial_port *port); 87 + static int whiteheat_port_remove(struct usb_serial_port *port); 86 88 static int whiteheat_open(struct tty_struct *tty, 87 89 struct usb_serial_port *port); 88 90 static void whiteheat_close(struct usb_serial_port *port); ··· 119 117 .num_ports = 4, 120 118 .attach = whiteheat_attach, 121 119 .release = whiteheat_release, 120 + .port_probe = whiteheat_port_probe, 121 + .port_remove = whiteheat_port_remove, 122 122 .open = whiteheat_open, 123 123 .close = whiteheat_close, 124 124 .ioctl = whiteheat_ioctl, ··· 222 218 { 223 219 struct usb_serial_port *command_port; 224 220 struct whiteheat_command_private *command_info; 225 - struct usb_serial_port *port; 226 - struct whiteheat_private *info; 227 221 struct whiteheat_hw_info *hw_info; 228 222 int pipe; 229 223 int ret; 230 224 int alen; 231 225 __u8 *command; 232 226 __u8 *result; 233 - int i; 234 227 235 228 command_port = serial->port[COMMAND_PORT]; 236 229 ··· 286 285 serial->type->description, 287 286 hw_info->sw_major_rev, hw_info->sw_minor_rev); 288 287 289 - for (i = 0; i < serial->num_ports; i++) { 290 - port = serial->port[i]; 291 - 292 - info = kmalloc(sizeof(struct whiteheat_private), GFP_KERNEL); 293 - if (info == NULL) { 294 - dev_err(&port->dev, 295 - "%s: Out of memory for port structures\n", 296 - serial->type->description); 297 - goto no_private; 298 - } 299 - 300 - info->mcr = 0; 301 - 302 - usb_set_serial_port_data(port, info); 303 - } 304 - 305 288 command_info = kmalloc(sizeof(struct whiteheat_command_private), 306 289 GFP_KERNEL); 307 290 if (command_info == NULL) { ··· 318 333 "%s: please contact support@connecttech.com\n", 319 334 serial->type->description); 320 335 kfree(result); 336 + kfree(command); 321 337 return -ENODEV; 322 338 323 339 no_command_private: 324 - for (i = serial->num_ports - 1; i >= 0; i--) { 325 - port = serial->port[i]; 326 - info = usb_get_serial_port_data(port); 327 - kfree(info); 328 - no_private: 329 - ; 330 - } 331 340 kfree(result); 332 341 no_result_buffer: 333 342 kfree(command); ··· 329 350 return -ENOMEM; 330 351 } 331 352 332 - 333 353 static void whiteheat_release(struct usb_serial *serial) 334 354 { 335 355 struct usb_serial_port *command_port; 336 - struct whiteheat_private *info; 337 - int i; 338 356 339 357 /* free up our private data for our command port */ 340 358 command_port = serial->port[COMMAND_PORT]; 341 359 kfree(usb_get_serial_port_data(command_port)); 360 + } 342 361 343 - for (i = 0; i < serial->num_ports; i++) { 344 - info = usb_get_serial_port_data(serial->port[i]); 345 - kfree(info); 346 - } 362 + static int whiteheat_port_probe(struct usb_serial_port *port) 363 + { 364 + struct whiteheat_private *info; 365 + 366 + info = kzalloc(sizeof(*info), GFP_KERNEL); 367 + if (!info) 368 + return -ENOMEM; 369 + 370 + usb_set_serial_port_data(port, info); 371 + 372 + return 0; 373 + } 374 + 375 + static int whiteheat_port_remove(struct usb_serial_port *port) 376 + { 377 + struct whiteheat_private *info; 378 + 379 + info = usb_get_serial_port_data(port); 380 + kfree(info); 381 + 382 + return 0; 347 383 } 348 384 349 385 static int whiteheat_open(struct tty_struct *tty, struct usb_serial_port *port)
+6
drivers/usb/storage/unusual_devs.h
··· 1004 1004 USB_SC_8070, USB_PR_CB, NULL, 1005 1005 US_FL_NEED_OVERRIDE | US_FL_FIX_INQUIRY ), 1006 1006 1007 + /* Submitted by Oleksandr Chumachenko <ledest@gmail.com> */ 1008 + UNUSUAL_DEV( 0x07cf, 0x1167, 0x0100, 0x0100, 1009 + "Casio", 1010 + "EX-N1 DigitalCamera", 1011 + USB_SC_8070, USB_PR_DEVICE, NULL, 0), 1012 + 1007 1013 /* Submitted by Hartmut Wahl <hwahl@hwahl.de>*/ 1008 1014 UNUSUAL_DEV( 0x0839, 0x000a, 0x0001, 0x0001, 1009 1015 "Samsung",