hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/usb/serial/generic.c
....@@ -106,12 +106,8 @@
106106 int usb_serial_generic_open(struct tty_struct *tty, struct usb_serial_port *port)
107107 {
108108 int result = 0;
109
- unsigned long flags;
110109
111
- spin_lock_irqsave(&port->lock, flags);
112
- port->throttled = 0;
113
- port->throttle_req = 0;
114
- spin_unlock_irqrestore(&port->lock, flags);
110
+ clear_bit(USB_SERIAL_THROTTLED, &port->flags);
115111
116112 if (port->bulk_in_size)
117113 result = usb_serial_generic_submit_read_urbs(port, GFP_KERNEL);
....@@ -349,7 +345,7 @@
349345 void usb_serial_generic_process_read_urb(struct urb *urb)
350346 {
351347 struct usb_serial_port *port = urb->context;
352
- char *ch = (char *)urb->transfer_buffer;
348
+ char *ch = urb->transfer_buffer;
353349 int i;
354350
355351 if (!urb->actual_length)
....@@ -359,13 +355,13 @@
359355 * stuff like 3G modems, so shortcircuit it in the 99.9999999% of
360356 * cases where the USB serial is not a console anyway.
361357 */
362
- if (!port->port.console || !port->sysrq) {
363
- tty_insert_flip_string(&port->port, ch, urb->actual_length);
364
- } else {
358
+ if (port->sysrq) {
365359 for (i = 0; i < urb->actual_length; i++, ch++) {
366360 if (!usb_serial_handle_sysrq_char(port, *ch))
367361 tty_insert_flip_char(&port->port, *ch, TTY_NORMAL);
368362 }
363
+ } else {
364
+ tty_insert_flip_string(&port->port, ch, urb->actual_length);
369365 }
370366 tty_flip_buffer_push(&port->port);
371367 }
....@@ -375,7 +371,6 @@
375371 {
376372 struct usb_serial_port *port = urb->context;
377373 unsigned char *data = urb->transfer_buffer;
378
- unsigned long flags;
379374 bool stopped = false;
380375 int status = urb->status;
381376 int i;
....@@ -422,22 +417,17 @@
422417 /*
423418 * Make sure URB is marked as free before checking the throttled flag
424419 * to avoid racing with unthrottle() on another CPU. Matches the
425
- * smp_mb() in unthrottle().
420
+ * smp_mb__after_atomic() in unthrottle().
426421 */
427422 smp_mb__after_atomic();
428423
429424 if (stopped)
430425 return;
431426
432
- /* Throttle the device if requested by tty */
433
- spin_lock_irqsave(&port->lock, flags);
434
- port->throttled = port->throttle_req;
435
- if (!port->throttled) {
436
- spin_unlock_irqrestore(&port->lock, flags);
437
- usb_serial_generic_submit_read_urb(port, i, GFP_ATOMIC);
438
- } else {
439
- spin_unlock_irqrestore(&port->lock, flags);
440
- }
427
+ if (test_bit(USB_SERIAL_THROTTLED, &port->flags))
428
+ return;
429
+
430
+ usb_serial_generic_submit_read_urb(port, i, GFP_ATOMIC);
441431 }
442432 EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback);
443433
....@@ -473,10 +463,9 @@
473463 default:
474464 dev_err_console(port, "%s - nonzero urb status: %d\n",
475465 __func__, status);
476
- goto resubmit;
466
+ break;
477467 }
478468
479
-resubmit:
480469 usb_serial_generic_write_start(port, GFP_ATOMIC);
481470 usb_serial_port_softint(port);
482471 }
....@@ -485,32 +474,24 @@
485474 void usb_serial_generic_throttle(struct tty_struct *tty)
486475 {
487476 struct usb_serial_port *port = tty->driver_data;
488
- unsigned long flags;
489477
490
- spin_lock_irqsave(&port->lock, flags);
491
- port->throttle_req = 1;
492
- spin_unlock_irqrestore(&port->lock, flags);
478
+ set_bit(USB_SERIAL_THROTTLED, &port->flags);
493479 }
494480 EXPORT_SYMBOL_GPL(usb_serial_generic_throttle);
495481
496482 void usb_serial_generic_unthrottle(struct tty_struct *tty)
497483 {
498484 struct usb_serial_port *port = tty->driver_data;
499
- int was_throttled;
500485
501
- spin_lock_irq(&port->lock);
502
- was_throttled = port->throttled;
503
- port->throttled = port->throttle_req = 0;
504
- spin_unlock_irq(&port->lock);
486
+ clear_bit(USB_SERIAL_THROTTLED, &port->flags);
505487
506488 /*
507489 * Matches the smp_mb__after_atomic() in
508490 * usb_serial_generic_read_bulk_callback().
509491 */
510
- smp_mb();
492
+ smp_mb__after_atomic();
511493
512
- if (was_throttled)
513
- usb_serial_generic_submit_read_urbs(port, GFP_KERNEL);
494
+ usb_serial_generic_submit_read_urbs(port, GFP_KERNEL);
514495 }
515496 EXPORT_SYMBOL_GPL(usb_serial_generic_unthrottle);
516497
....@@ -590,10 +571,10 @@
590571 }
591572 EXPORT_SYMBOL_GPL(usb_serial_generic_get_icount);
592573
593
-#ifdef CONFIG_MAGIC_SYSRQ
574
+#if defined(CONFIG_USB_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
594575 int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch)
595576 {
596
- if (port->sysrq && port->port.console) {
577
+ if (port->sysrq) {
597578 if (ch && time_before(jiffies, port->sysrq)) {
598579 handle_sysrq(ch);
599580 port->sysrq = 0;
....@@ -603,16 +584,13 @@
603584 }
604585 return 0;
605586 }
606
-#else
607
-int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch)
608
-{
609
- return 0;
610
-}
611
-#endif
612587 EXPORT_SYMBOL_GPL(usb_serial_handle_sysrq_char);
613588
614589 int usb_serial_handle_break(struct usb_serial_port *port)
615590 {
591
+ if (!port->port.console)
592
+ return 0;
593
+
616594 if (!port->sysrq) {
617595 port->sysrq = jiffies + HZ*5;
618596 return 1;
....@@ -621,6 +599,7 @@
621599 return 0;
622600 }
623601 EXPORT_SYMBOL_GPL(usb_serial_handle_break);
602
+#endif
624603
625604 /**
626605 * usb_serial_handle_dcd_change - handle a change of carrier detect state
....@@ -628,12 +607,10 @@
628607 * @tty: tty for the port
629608 * @status: new carrier detect status, nonzero if active
630609 */
631
-void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port,
610
+void usb_serial_handle_dcd_change(struct usb_serial_port *port,
632611 struct tty_struct *tty, unsigned int status)
633612 {
634
- struct tty_port *port = &usb_port->port;
635
-
636
- dev_dbg(&usb_port->dev, "%s - status %d\n", __func__, status);
613
+ dev_dbg(&port->dev, "%s - status %d\n", __func__, status);
637614
638615 if (tty) {
639616 struct tty_ldisc *ld = tty_ldisc_ref(tty);
....@@ -646,7 +623,7 @@
646623 }
647624
648625 if (status)
649
- wake_up_interruptible(&port->open_wait);
626
+ wake_up_interruptible(&port->port.open_wait);
650627 else if (tty && !C_CLOCAL(tty))
651628 tty_hangup(tty);
652629 }