generic.c 16 KB

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