generic.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. /*
  2. * USB Serial Converter Generic functions
  3. *
  4. * Copyright (C) 2010 - 2013 Johan Hovold (jhovold@gmail.com)
  5. * Copyright (C) 1999 - 2002 Greg Kroah-Hartman (greg@kroah.com)
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License version
  9. * 2 as published by the Free Software Foundation.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/sched/signal.h>
  13. #include <linux/errno.h>
  14. #include <linux/slab.h>
  15. #include <linux/sysrq.h>
  16. #include <linux/tty.h>
  17. #include <linux/tty_flip.h>
  18. #include <linux/module.h>
  19. #include <linux/moduleparam.h>
  20. #include <linux/usb.h>
  21. #include <linux/usb/serial.h>
  22. #include <linux/uaccess.h>
  23. #include <linux/kfifo.h>
  24. #include <linux/serial.h>
  25. #ifdef CONFIG_USB_SERIAL_GENERIC
  26. static __u16 vendor = 0x05f9;
  27. static __u16 product = 0xffff;
  28. module_param(vendor, ushort, 0);
  29. MODULE_PARM_DESC(vendor, "User specified USB idVendor");
  30. module_param(product, ushort, 0);
  31. MODULE_PARM_DESC(product, "User specified USB idProduct");
  32. static struct usb_device_id generic_device_ids[2]; /* Initially all zeroes. */
  33. static int usb_serial_generic_probe(struct usb_serial *serial,
  34. const struct usb_device_id *id)
  35. {
  36. struct device *dev = &serial->interface->dev;
  37. dev_info(dev, "The \"generic\" usb-serial driver is only for testing and one-off prototypes.\n");
  38. dev_info(dev, "Tell linux-usb@vger.kernel.org to add your device to a proper driver.\n");
  39. return 0;
  40. }
  41. static int usb_serial_generic_calc_num_ports(struct usb_serial *serial,
  42. struct usb_serial_endpoints *epds)
  43. {
  44. struct device *dev = &serial->interface->dev;
  45. int num_ports;
  46. num_ports = max(epds->num_bulk_in, epds->num_bulk_out);
  47. if (num_ports == 0) {
  48. dev_err(dev, "device has no bulk endpoints\n");
  49. return -ENODEV;
  50. }
  51. return num_ports;
  52. }
  53. static struct usb_serial_driver usb_serial_generic_device = {
  54. .driver = {
  55. .owner = THIS_MODULE,
  56. .name = "generic",
  57. },
  58. .id_table = generic_device_ids,
  59. .probe = usb_serial_generic_probe,
  60. .calc_num_ports = usb_serial_generic_calc_num_ports,
  61. .throttle = usb_serial_generic_throttle,
  62. .unthrottle = usb_serial_generic_unthrottle,
  63. .resume = usb_serial_generic_resume,
  64. };
  65. static struct usb_serial_driver * const serial_drivers[] = {
  66. &usb_serial_generic_device, NULL
  67. };
  68. #endif
  69. int usb_serial_generic_register(void)
  70. {
  71. int retval = 0;
  72. #ifdef CONFIG_USB_SERIAL_GENERIC
  73. generic_device_ids[0].idVendor = vendor;
  74. generic_device_ids[0].idProduct = product;
  75. generic_device_ids[0].match_flags =
  76. USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT;
  77. retval = usb_serial_register_drivers(serial_drivers,
  78. "usbserial_generic", generic_device_ids);
  79. #endif
  80. return retval;
  81. }
  82. void usb_serial_generic_deregister(void)
  83. {
  84. #ifdef CONFIG_USB_SERIAL_GENERIC
  85. usb_serial_deregister_drivers(serial_drivers);
  86. #endif
  87. }
  88. int usb_serial_generic_open(struct tty_struct *tty, struct usb_serial_port *port)
  89. {
  90. int result = 0;
  91. unsigned long flags;
  92. spin_lock_irqsave(&port->lock, flags);
  93. port->throttled = 0;
  94. port->throttle_req = 0;
  95. spin_unlock_irqrestore(&port->lock, flags);
  96. if (port->bulk_in_size)
  97. result = usb_serial_generic_submit_read_urbs(port, GFP_KERNEL);
  98. return result;
  99. }
  100. EXPORT_SYMBOL_GPL(usb_serial_generic_open);
  101. void usb_serial_generic_close(struct usb_serial_port *port)
  102. {
  103. unsigned long flags;
  104. int i;
  105. if (port->bulk_out_size) {
  106. for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i)
  107. usb_kill_urb(port->write_urbs[i]);
  108. spin_lock_irqsave(&port->lock, flags);
  109. kfifo_reset_out(&port->write_fifo);
  110. spin_unlock_irqrestore(&port->lock, flags);
  111. }
  112. if (port->bulk_in_size) {
  113. for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i)
  114. usb_kill_urb(port->read_urbs[i]);
  115. }
  116. }
  117. EXPORT_SYMBOL_GPL(usb_serial_generic_close);
  118. int usb_serial_generic_prepare_write_buffer(struct usb_serial_port *port,
  119. void *dest, size_t size)
  120. {
  121. return kfifo_out_locked(&port->write_fifo, dest, size, &port->lock);
  122. }
  123. /**
  124. * usb_serial_generic_write_start - start writing buffered data
  125. * @port: usb-serial port
  126. * @mem_flags: flags to use for memory allocations
  127. *
  128. * Serialised using USB_SERIAL_WRITE_BUSY flag.
  129. *
  130. * Return: Zero on success or if busy, otherwise a negative errno value.
  131. */
  132. int usb_serial_generic_write_start(struct usb_serial_port *port,
  133. gfp_t mem_flags)
  134. {
  135. struct urb *urb;
  136. int count, result;
  137. unsigned long flags;
  138. int i;
  139. if (test_and_set_bit_lock(USB_SERIAL_WRITE_BUSY, &port->flags))
  140. return 0;
  141. retry:
  142. spin_lock_irqsave(&port->lock, flags);
  143. if (!port->write_urbs_free || !kfifo_len(&port->write_fifo)) {
  144. clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags);
  145. spin_unlock_irqrestore(&port->lock, flags);
  146. return 0;
  147. }
  148. i = (int)find_first_bit(&port->write_urbs_free,
  149. ARRAY_SIZE(port->write_urbs));
  150. spin_unlock_irqrestore(&port->lock, flags);
  151. urb = port->write_urbs[i];
  152. count = port->serial->type->prepare_write_buffer(port,
  153. urb->transfer_buffer,
  154. port->bulk_out_size);
  155. urb->transfer_buffer_length = count;
  156. usb_serial_debug_data(&port->dev, __func__, count, urb->transfer_buffer);
  157. spin_lock_irqsave(&port->lock, flags);
  158. port->tx_bytes += count;
  159. spin_unlock_irqrestore(&port->lock, flags);
  160. clear_bit(i, &port->write_urbs_free);
  161. result = usb_submit_urb(urb, mem_flags);
  162. if (result) {
  163. dev_err_console(port, "%s - error submitting urb: %d\n",
  164. __func__, result);
  165. set_bit(i, &port->write_urbs_free);
  166. spin_lock_irqsave(&port->lock, flags);
  167. port->tx_bytes -= count;
  168. spin_unlock_irqrestore(&port->lock, flags);
  169. clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags);
  170. return result;
  171. }
  172. goto retry; /* try sending off another urb */
  173. }
  174. EXPORT_SYMBOL_GPL(usb_serial_generic_write_start);
  175. /**
  176. * usb_serial_generic_write - generic write function
  177. * @tty: tty for the port
  178. * @port: usb-serial port
  179. * @buf: data to write
  180. * @count: number of bytes to write
  181. *
  182. * Return: The number of characters buffered, which may be anything from
  183. * zero to @count, or a negative errno value.
  184. */
  185. int usb_serial_generic_write(struct tty_struct *tty,
  186. struct usb_serial_port *port, const unsigned char *buf, int count)
  187. {
  188. int result;
  189. if (!port->bulk_out_size)
  190. return -ENODEV;
  191. if (!count)
  192. return 0;
  193. count = kfifo_in_locked(&port->write_fifo, buf, count, &port->lock);
  194. result = usb_serial_generic_write_start(port, GFP_ATOMIC);
  195. if (result)
  196. return result;
  197. return count;
  198. }
  199. EXPORT_SYMBOL_GPL(usb_serial_generic_write);
  200. int usb_serial_generic_write_room(struct tty_struct *tty)
  201. {
  202. struct usb_serial_port *port = tty->driver_data;
  203. unsigned long flags;
  204. int room;
  205. if (!port->bulk_out_size)
  206. return 0;
  207. spin_lock_irqsave(&port->lock, flags);
  208. room = kfifo_avail(&port->write_fifo);
  209. spin_unlock_irqrestore(&port->lock, flags);
  210. dev_dbg(&port->dev, "%s - returns %d\n", __func__, room);
  211. return room;
  212. }
  213. int usb_serial_generic_chars_in_buffer(struct tty_struct *tty)
  214. {
  215. struct usb_serial_port *port = tty->driver_data;
  216. unsigned long flags;
  217. int chars;
  218. if (!port->bulk_out_size)
  219. return 0;
  220. spin_lock_irqsave(&port->lock, flags);
  221. chars = kfifo_len(&port->write_fifo) + port->tx_bytes;
  222. spin_unlock_irqrestore(&port->lock, flags);
  223. dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars);
  224. return chars;
  225. }
  226. EXPORT_SYMBOL_GPL(usb_serial_generic_chars_in_buffer);
  227. void usb_serial_generic_wait_until_sent(struct tty_struct *tty, long timeout)
  228. {
  229. struct usb_serial_port *port = tty->driver_data;
  230. unsigned int bps;
  231. unsigned long period;
  232. unsigned long expire;
  233. bps = tty_get_baud_rate(tty);
  234. if (!bps)
  235. bps = 9600; /* B0 */
  236. /*
  237. * Use a poll-period of roughly the time it takes to send one
  238. * character or at least one jiffy.
  239. */
  240. period = max_t(unsigned long, (10 * HZ / bps), 1);
  241. if (timeout)
  242. period = min_t(unsigned long, period, timeout);
  243. dev_dbg(&port->dev, "%s - timeout = %u ms, period = %u ms\n",
  244. __func__, jiffies_to_msecs(timeout),
  245. jiffies_to_msecs(period));
  246. expire = jiffies + timeout;
  247. while (!port->serial->type->tx_empty(port)) {
  248. schedule_timeout_interruptible(period);
  249. if (signal_pending(current))
  250. break;
  251. if (timeout && time_after(jiffies, expire))
  252. break;
  253. }
  254. }
  255. EXPORT_SYMBOL_GPL(usb_serial_generic_wait_until_sent);
  256. static int usb_serial_generic_submit_read_urb(struct usb_serial_port *port,
  257. int index, gfp_t mem_flags)
  258. {
  259. int res;
  260. if (!test_and_clear_bit(index, &port->read_urbs_free))
  261. return 0;
  262. dev_dbg(&port->dev, "%s - urb %d\n", __func__, index);
  263. res = usb_submit_urb(port->read_urbs[index], mem_flags);
  264. if (res) {
  265. if (res != -EPERM && res != -ENODEV) {
  266. dev_err(&port->dev,
  267. "%s - usb_submit_urb failed: %d\n",
  268. __func__, res);
  269. }
  270. set_bit(index, &port->read_urbs_free);
  271. return res;
  272. }
  273. return 0;
  274. }
  275. int usb_serial_generic_submit_read_urbs(struct usb_serial_port *port,
  276. gfp_t mem_flags)
  277. {
  278. int res;
  279. int i;
  280. for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) {
  281. res = usb_serial_generic_submit_read_urb(port, i, mem_flags);
  282. if (res)
  283. goto err;
  284. }
  285. return 0;
  286. err:
  287. for (; i >= 0; --i)
  288. usb_kill_urb(port->read_urbs[i]);
  289. return res;
  290. }
  291. EXPORT_SYMBOL_GPL(usb_serial_generic_submit_read_urbs);
  292. void usb_serial_generic_process_read_urb(struct urb *urb)
  293. {
  294. struct usb_serial_port *port = urb->context;
  295. char *ch = (char *)urb->transfer_buffer;
  296. int i;
  297. if (!urb->actual_length)
  298. return;
  299. /*
  300. * The per character mucking around with sysrq path it too slow for
  301. * stuff like 3G modems, so shortcircuit it in the 99.9999999% of
  302. * cases where the USB serial is not a console anyway.
  303. */
  304. if (!port->port.console || !port->sysrq) {
  305. tty_insert_flip_string(&port->port, ch, urb->actual_length);
  306. } else {
  307. for (i = 0; i < urb->actual_length; i++, ch++) {
  308. if (!usb_serial_handle_sysrq_char(port, *ch))
  309. tty_insert_flip_char(&port->port, *ch, TTY_NORMAL);
  310. }
  311. }
  312. tty_flip_buffer_push(&port->port);
  313. }
  314. EXPORT_SYMBOL_GPL(usb_serial_generic_process_read_urb);
  315. void usb_serial_generic_read_bulk_callback(struct urb *urb)
  316. {
  317. struct usb_serial_port *port = urb->context;
  318. unsigned char *data = urb->transfer_buffer;
  319. unsigned long flags;
  320. int status = urb->status;
  321. int i;
  322. for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) {
  323. if (urb == port->read_urbs[i])
  324. break;
  325. }
  326. set_bit(i, &port->read_urbs_free);
  327. dev_dbg(&port->dev, "%s - urb %d, len %d\n", __func__, i,
  328. urb->actual_length);
  329. switch (status) {
  330. case 0:
  331. break;
  332. case -ENOENT:
  333. case -ECONNRESET:
  334. case -ESHUTDOWN:
  335. dev_dbg(&port->dev, "%s - urb stopped: %d\n",
  336. __func__, status);
  337. return;
  338. case -EPIPE:
  339. dev_err(&port->dev, "%s - urb stopped: %d\n",
  340. __func__, status);
  341. return;
  342. default:
  343. dev_dbg(&port->dev, "%s - nonzero urb status: %d\n",
  344. __func__, status);
  345. goto resubmit;
  346. }
  347. usb_serial_debug_data(&port->dev, __func__, urb->actual_length, data);
  348. port->serial->type->process_read_urb(urb);
  349. resubmit:
  350. /* Throttle the device if requested by tty */
  351. spin_lock_irqsave(&port->lock, flags);
  352. port->throttled = port->throttle_req;
  353. if (!port->throttled) {
  354. spin_unlock_irqrestore(&port->lock, flags);
  355. usb_serial_generic_submit_read_urb(port, i, GFP_ATOMIC);
  356. } else {
  357. spin_unlock_irqrestore(&port->lock, flags);
  358. }
  359. }
  360. EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback);
  361. void usb_serial_generic_write_bulk_callback(struct urb *urb)
  362. {
  363. unsigned long flags;
  364. struct usb_serial_port *port = urb->context;
  365. int status = urb->status;
  366. int i;
  367. for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i) {
  368. if (port->write_urbs[i] == urb)
  369. break;
  370. }
  371. spin_lock_irqsave(&port->lock, flags);
  372. port->tx_bytes -= urb->transfer_buffer_length;
  373. set_bit(i, &port->write_urbs_free);
  374. spin_unlock_irqrestore(&port->lock, flags);
  375. switch (status) {
  376. case 0:
  377. break;
  378. case -ENOENT:
  379. case -ECONNRESET:
  380. case -ESHUTDOWN:
  381. dev_dbg(&port->dev, "%s - urb stopped: %d\n",
  382. __func__, status);
  383. return;
  384. case -EPIPE:
  385. dev_err_console(port, "%s - urb stopped: %d\n",
  386. __func__, status);
  387. return;
  388. default:
  389. dev_err_console(port, "%s - nonzero urb status: %d\n",
  390. __func__, status);
  391. goto resubmit;
  392. }
  393. resubmit:
  394. usb_serial_generic_write_start(port, GFP_ATOMIC);
  395. usb_serial_port_softint(port);
  396. }
  397. EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback);
  398. void usb_serial_generic_throttle(struct tty_struct *tty)
  399. {
  400. struct usb_serial_port *port = tty->driver_data;
  401. unsigned long flags;
  402. spin_lock_irqsave(&port->lock, flags);
  403. port->throttle_req = 1;
  404. spin_unlock_irqrestore(&port->lock, flags);
  405. }
  406. EXPORT_SYMBOL_GPL(usb_serial_generic_throttle);
  407. void usb_serial_generic_unthrottle(struct tty_struct *tty)
  408. {
  409. struct usb_serial_port *port = tty->driver_data;
  410. int was_throttled;
  411. spin_lock_irq(&port->lock);
  412. was_throttled = port->throttled;
  413. port->throttled = port->throttle_req = 0;
  414. spin_unlock_irq(&port->lock);
  415. if (was_throttled)
  416. usb_serial_generic_submit_read_urbs(port, GFP_KERNEL);
  417. }
  418. EXPORT_SYMBOL_GPL(usb_serial_generic_unthrottle);
  419. static bool usb_serial_generic_msr_changed(struct tty_struct *tty,
  420. unsigned long arg, struct async_icount *cprev)
  421. {
  422. struct usb_serial_port *port = tty->driver_data;
  423. struct async_icount cnow;
  424. unsigned long flags;
  425. bool ret;
  426. /*
  427. * Use tty-port initialised flag to detect all hangups including the
  428. * one generated at USB-device disconnect.
  429. */
  430. if (!tty_port_initialized(&port->port))
  431. return true;
  432. spin_lock_irqsave(&port->lock, flags);
  433. cnow = port->icount; /* atomic copy*/
  434. spin_unlock_irqrestore(&port->lock, flags);
  435. ret = ((arg & TIOCM_RNG) && (cnow.rng != cprev->rng)) ||
  436. ((arg & TIOCM_DSR) && (cnow.dsr != cprev->dsr)) ||
  437. ((arg & TIOCM_CD) && (cnow.dcd != cprev->dcd)) ||
  438. ((arg & TIOCM_CTS) && (cnow.cts != cprev->cts));
  439. *cprev = cnow;
  440. return ret;
  441. }
  442. int usb_serial_generic_tiocmiwait(struct tty_struct *tty, unsigned long arg)
  443. {
  444. struct usb_serial_port *port = tty->driver_data;
  445. struct async_icount cnow;
  446. unsigned long flags;
  447. int ret;
  448. spin_lock_irqsave(&port->lock, flags);
  449. cnow = port->icount; /* atomic copy */
  450. spin_unlock_irqrestore(&port->lock, flags);
  451. ret = wait_event_interruptible(port->port.delta_msr_wait,
  452. usb_serial_generic_msr_changed(tty, arg, &cnow));
  453. if (!ret && !tty_port_initialized(&port->port))
  454. ret = -EIO;
  455. return ret;
  456. }
  457. EXPORT_SYMBOL_GPL(usb_serial_generic_tiocmiwait);
  458. int usb_serial_generic_get_icount(struct tty_struct *tty,
  459. struct serial_icounter_struct *icount)
  460. {
  461. struct usb_serial_port *port = tty->driver_data;
  462. struct async_icount cnow;
  463. unsigned long flags;
  464. spin_lock_irqsave(&port->lock, flags);
  465. cnow = port->icount; /* atomic copy */
  466. spin_unlock_irqrestore(&port->lock, flags);
  467. icount->cts = cnow.cts;
  468. icount->dsr = cnow.dsr;
  469. icount->rng = cnow.rng;
  470. icount->dcd = cnow.dcd;
  471. icount->tx = cnow.tx;
  472. icount->rx = cnow.rx;
  473. icount->frame = cnow.frame;
  474. icount->parity = cnow.parity;
  475. icount->overrun = cnow.overrun;
  476. icount->brk = cnow.brk;
  477. icount->buf_overrun = cnow.buf_overrun;
  478. return 0;
  479. }
  480. EXPORT_SYMBOL_GPL(usb_serial_generic_get_icount);
  481. #ifdef CONFIG_MAGIC_SYSRQ
  482. int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch)
  483. {
  484. if (port->sysrq && port->port.console) {
  485. if (ch && time_before(jiffies, port->sysrq)) {
  486. handle_sysrq(ch);
  487. port->sysrq = 0;
  488. return 1;
  489. }
  490. port->sysrq = 0;
  491. }
  492. return 0;
  493. }
  494. #else
  495. int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch)
  496. {
  497. return 0;
  498. }
  499. #endif
  500. EXPORT_SYMBOL_GPL(usb_serial_handle_sysrq_char);
  501. int usb_serial_handle_break(struct usb_serial_port *port)
  502. {
  503. if (!port->sysrq) {
  504. port->sysrq = jiffies + HZ*5;
  505. return 1;
  506. }
  507. port->sysrq = 0;
  508. return 0;
  509. }
  510. EXPORT_SYMBOL_GPL(usb_serial_handle_break);
  511. /**
  512. * usb_serial_handle_dcd_change - handle a change of carrier detect state
  513. * @port: usb-serial port
  514. * @tty: tty for the port
  515. * @status: new carrier detect status, nonzero if active
  516. */
  517. void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port,
  518. struct tty_struct *tty, unsigned int status)
  519. {
  520. struct tty_port *port = &usb_port->port;
  521. dev_dbg(&usb_port->dev, "%s - status %d\n", __func__, status);
  522. if (tty) {
  523. struct tty_ldisc *ld = tty_ldisc_ref(tty);
  524. if (ld) {
  525. if (ld->ops->dcd_change)
  526. ld->ops->dcd_change(tty, status);
  527. tty_ldisc_deref(ld);
  528. }
  529. }
  530. if (status)
  531. wake_up_interruptible(&port->open_wait);
  532. else if (tty && !C_CLOCAL(tty))
  533. tty_hangup(tty);
  534. }
  535. EXPORT_SYMBOL_GPL(usb_serial_handle_dcd_change);
  536. int usb_serial_generic_resume(struct usb_serial *serial)
  537. {
  538. struct usb_serial_port *port;
  539. int i, c = 0, r;
  540. for (i = 0; i < serial->num_ports; i++) {
  541. port = serial->port[i];
  542. if (!tty_port_initialized(&port->port))
  543. continue;
  544. if (port->bulk_in_size) {
  545. r = usb_serial_generic_submit_read_urbs(port,
  546. GFP_NOIO);
  547. if (r < 0)
  548. c++;
  549. }
  550. if (port->bulk_out_size) {
  551. r = usb_serial_generic_write_start(port, GFP_NOIO);
  552. if (r < 0)
  553. c++;
  554. }
  555. }
  556. return c ? -EIO : 0;
  557. }
  558. EXPORT_SYMBOL_GPL(usb_serial_generic_resume);