hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/drivers/usb/class/cdc-acm.c
....@@ -185,7 +185,7 @@
185185 for (;;) {
186186 wb = &acm->wb[wbn];
187187 if (!wb->use) {
188
- wb->use = 1;
188
+ wb->use = true;
189189 wb->len = 0;
190190 return wbn;
191191 }
....@@ -203,7 +203,8 @@
203203 n = ACM_NW;
204204 spin_lock_irqsave(&acm->write_lock, flags);
205205 for (i = 0; i < ACM_NW; i++)
206
- n -= acm->wb[i].use;
206
+ if(acm->wb[i].use)
207
+ n--;
207208 spin_unlock_irqrestore(&acm->write_lock, flags);
208209 return n;
209210 }
....@@ -213,7 +214,7 @@
213214 */
214215 static void acm_write_done(struct acm *acm, struct acm_wb *wb)
215216 {
216
- wb->use = 0;
217
+ wb->use = false;
217218 acm->transmitting--;
218219 usb_autopm_put_interface_async(acm->control);
219220 }
....@@ -494,7 +495,6 @@
494495 {
495496 struct acm_rb *rb = urb->context;
496497 struct acm *acm = rb->instance;
497
- unsigned long flags;
498498 int status = urb->status;
499499 bool stopped = false;
500500 bool stalled = false;
....@@ -558,15 +558,10 @@
558558 return;
559559 }
560560
561
- /* throttle device if requested by tty */
562
- spin_lock_irqsave(&acm->read_lock, flags);
563
- acm->throttled = acm->throttle_req;
564
- if (!acm->throttled) {
565
- spin_unlock_irqrestore(&acm->read_lock, flags);
566
- acm_submit_read_urb(acm, rb->index, GFP_ATOMIC);
567
- } else {
568
- spin_unlock_irqrestore(&acm->read_lock, flags);
569
- }
561
+ if (test_bit(ACM_THROTTLED, &acm->flags))
562
+ return;
563
+
564
+ acm_submit_read_urb(acm, rb->index, GFP_ATOMIC);
570565 }
571566
572567 /* data interface wrote those outgoing bytes */
....@@ -710,10 +705,7 @@
710705 /*
711706 * Unthrottle device in case the TTY was closed while throttled.
712707 */
713
- spin_lock_irq(&acm->read_lock);
714
- acm->throttled = 0;
715
- acm->throttle_req = 0;
716
- spin_unlock_irq(&acm->read_lock);
708
+ clear_bit(ACM_THROTTLED, &acm->flags);
717709
718710 retval = acm_submit_read_urbs(acm, GFP_KERNEL);
719711 if (retval)
....@@ -772,7 +764,7 @@
772764 if (!urb)
773765 break;
774766 wb = urb->context;
775
- wb->use = 0;
767
+ wb->use = false;
776768 usb_autopm_put_interface_async(acm->control);
777769 }
778770
....@@ -824,7 +816,7 @@
824816 wb = &acm->wb[wbn];
825817
826818 if (!acm->dev) {
827
- wb->use = 0;
819
+ wb->use = false;
828820 spin_unlock_irqrestore(&acm->write_lock, flags);
829821 return -ENODEV;
830822 }
....@@ -836,7 +828,7 @@
836828
837829 stat = usb_autopm_get_interface_async(acm->control);
838830 if (stat) {
839
- wb->use = 0;
831
+ wb->use = false;
840832 spin_unlock_irqrestore(&acm->write_lock, flags);
841833 return stat;
842834 }
....@@ -884,27 +876,19 @@
884876 {
885877 struct acm *acm = tty->driver_data;
886878
887
- spin_lock_irq(&acm->read_lock);
888
- acm->throttle_req = 1;
889
- spin_unlock_irq(&acm->read_lock);
879
+ set_bit(ACM_THROTTLED, &acm->flags);
890880 }
891881
892882 static void acm_tty_unthrottle(struct tty_struct *tty)
893883 {
894884 struct acm *acm = tty->driver_data;
895
- unsigned int was_throttled;
896885
897
- spin_lock_irq(&acm->read_lock);
898
- was_throttled = acm->throttled;
899
- acm->throttled = 0;
900
- acm->throttle_req = 0;
901
- spin_unlock_irq(&acm->read_lock);
886
+ clear_bit(ACM_THROTTLED, &acm->flags);
902887
903888 /* Matches the smp_mb__after_atomic() in acm_read_bulk_callback(). */
904889 smp_mb();
905890
906
- if (was_throttled)
907
- acm_submit_read_urbs(acm, GFP_KERNEL);
891
+ acm_submit_read_urbs(acm, GFP_KERNEL);
908892 }
909893
910894 static int acm_tty_break_ctl(struct tty_struct *tty, int state)
....@@ -950,51 +934,34 @@
950934 return acm_set_control(acm, acm->ctrlout = newctrl);
951935 }
952936
953
-static int get_serial_info(struct acm *acm, struct serial_struct __user *info)
937
+static int get_serial_info(struct tty_struct *tty, struct serial_struct *ss)
954938 {
955
- struct serial_struct tmp;
939
+ struct acm *acm = tty->driver_data;
956940
957
- memset(&tmp, 0, sizeof(tmp));
958
- tmp.xmit_fifo_size = acm->writesize;
959
- tmp.baud_base = le32_to_cpu(acm->line.dwDTERate);
960
- tmp.close_delay = jiffies_to_msecs(acm->port.close_delay) / 10;
961
- tmp.closing_wait = acm->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
941
+ ss->line = acm->minor;
942
+ ss->close_delay = jiffies_to_msecs(acm->port.close_delay) / 10;
943
+ ss->closing_wait = acm->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
962944 ASYNC_CLOSING_WAIT_NONE :
963945 jiffies_to_msecs(acm->port.closing_wait) / 10;
964
-
965
- if (copy_to_user(info, &tmp, sizeof(tmp)))
966
- return -EFAULT;
967
- else
968
- return 0;
946
+ return 0;
969947 }
970948
971
-static int set_serial_info(struct acm *acm,
972
- struct serial_struct __user *newinfo)
949
+static int set_serial_info(struct tty_struct *tty, struct serial_struct *ss)
973950 {
974
- struct serial_struct new_serial;
951
+ struct acm *acm = tty->driver_data;
975952 unsigned int closing_wait, close_delay;
976
- unsigned int old_closing_wait, old_close_delay;
977953 int retval = 0;
978954
979
- if (copy_from_user(&new_serial, newinfo, sizeof(new_serial)))
980
- return -EFAULT;
981
-
982
- close_delay = msecs_to_jiffies(new_serial.close_delay * 10);
983
- closing_wait = new_serial.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
955
+ close_delay = msecs_to_jiffies(ss->close_delay * 10);
956
+ closing_wait = ss->closing_wait == ASYNC_CLOSING_WAIT_NONE ?
984957 ASYNC_CLOSING_WAIT_NONE :
985
- msecs_to_jiffies(new_serial.closing_wait * 10);
986
-
987
- /* we must redo the rounding here, so that the values match */
988
- old_close_delay = jiffies_to_msecs(acm->port.close_delay) / 10;
989
- old_closing_wait = acm->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
990
- ASYNC_CLOSING_WAIT_NONE :
991
- jiffies_to_msecs(acm->port.closing_wait) / 10;
958
+ msecs_to_jiffies(ss->closing_wait * 10);
992959
993960 mutex_lock(&acm->port.mutex);
994961
995962 if (!capable(CAP_SYS_ADMIN)) {
996
- if ((new_serial.close_delay != old_close_delay) ||
997
- (new_serial.closing_wait != old_closing_wait))
963
+ if ((close_delay != acm->port.close_delay) ||
964
+ (closing_wait != acm->port.closing_wait))
998965 retval = -EPERM;
999966 } else {
1000967 acm->port.close_delay = close_delay;
....@@ -1071,12 +1038,6 @@
10711038 int rv = -ENOIOCTLCMD;
10721039
10731040 switch (cmd) {
1074
- case TIOCGSERIAL: /* gets serial port data */
1075
- rv = get_serial_info(acm, (struct serial_struct __user *) arg);
1076
- break;
1077
- case TIOCSSERIAL:
1078
- rv = set_serial_info(acm, (struct serial_struct __user *) arg);
1079
- break;
10801041 case TIOCMIWAIT:
10811042 rv = usb_autopm_get_interface(acm->control);
10821043 if (rv < 0) {
....@@ -1249,9 +1210,6 @@
12491210 return -EINVAL;
12501211 }
12511212
1252
- if (!intf->cur_altsetting)
1253
- return -EINVAL;
1254
-
12551213 if (!buflen) {
12561214 if (intf->cur_altsetting->endpoint &&
12571215 intf->cur_altsetting->endpoint->extralen &&
....@@ -1274,26 +1232,19 @@
12741232 call_intf_num = cmgmd->bDataInterface;
12751233
12761234 if (!union_header) {
1277
- if (call_intf_num > 0) {
1235
+ if (intf->cur_altsetting->desc.bNumEndpoints == 3) {
1236
+ dev_dbg(&intf->dev, "No union descriptor, assuming single interface\n");
1237
+ combined_interfaces = 1;
1238
+ control_interface = data_interface = intf;
1239
+ goto look_for_collapsed_interface;
1240
+ } else if (call_intf_num > 0) {
12781241 dev_dbg(&intf->dev, "No union descriptor, using call management descriptor\n");
1279
- /* quirks for Droids MuIn LCD */
1280
- if (quirks & NO_DATA_INTERFACE) {
1281
- data_interface = usb_ifnum_to_if(usb_dev, 0);
1282
- } else {
1283
- data_intf_num = call_intf_num;
1284
- data_interface = usb_ifnum_to_if(usb_dev, data_intf_num);
1285
- }
1242
+ data_intf_num = call_intf_num;
1243
+ data_interface = usb_ifnum_to_if(usb_dev, data_intf_num);
12861244 control_interface = intf;
12871245 } else {
1288
- if (intf->cur_altsetting->desc.bNumEndpoints != 3) {
1289
- dev_dbg(&intf->dev,"No union descriptor, giving up\n");
1290
- return -ENODEV;
1291
- } else {
1292
- dev_warn(&intf->dev,"No union descriptor, testing for castrated device\n");
1293
- combined_interfaces = 1;
1294
- control_interface = data_interface = intf;
1295
- goto look_for_collapsed_interface;
1296
- }
1246
+ dev_dbg(&intf->dev, "No union descriptor, giving up\n");
1247
+ return -ENODEV;
12971248 }
12981249 } else {
12991250 int class = -1;
....@@ -1317,8 +1268,6 @@
13171268 dev_dbg(&intf->dev, "no interfaces\n");
13181269 return -ENODEV;
13191270 }
1320
- if (!data_interface->cur_altsetting || !control_interface->cur_altsetting)
1321
- return -ENODEV;
13221271
13231272 if (data_intf_num != call_intf_num)
13241273 dev_dbg(&intf->dev, "Separate call control interface. That is not fully supported.\n");
....@@ -1345,10 +1294,8 @@
13451294 skip_normal_probe:
13461295
13471296 /*workaround for switched interfaces */
1348
- if (data_interface->cur_altsetting->desc.bInterfaceClass
1349
- != CDC_DATA_INTERFACE_TYPE) {
1350
- if (control_interface->cur_altsetting->desc.bInterfaceClass
1351
- == CDC_DATA_INTERFACE_TYPE) {
1297
+ if (data_interface->cur_altsetting->desc.bInterfaceClass != USB_CLASS_CDC_DATA) {
1298
+ if (control_interface->cur_altsetting->desc.bInterfaceClass == USB_CLASS_CDC_DATA) {
13521299 dev_dbg(&intf->dev,
13531300 "Your device has switched interfaces.\n");
13541301 swap(control_interface, data_interface);
....@@ -1883,6 +1830,9 @@
18831830 { USB_DEVICE(0x09d8, 0x0320), /* Elatec GmbH TWN3 */
18841831 .driver_info = NO_UNION_NORMAL, /* has misplaced union descriptor */
18851832 },
1833
+ { USB_DEVICE(0x0c26, 0x0020), /* Icom ICF3400 Serie */
1834
+ .driver_info = NO_UNION_NORMAL, /* reports zero length descriptor */
1835
+ },
18861836 { USB_DEVICE(0x0ca6, 0xa050), /* Castles VEGA3000 */
18871837 .driver_info = NO_UNION_NORMAL, /* reports zero length descriptor */
18881838 },
....@@ -1960,16 +1910,17 @@
19601910
19611911 /* NOTE: non-Nokia COMM/ACM/0xff is likely MSFT RNDIS... NOT a modem! */
19621912
1963
- /* Support for Droids MuIn LCD */
1964
- { USB_DEVICE(0x04d8, 0x000b),
1965
- .driver_info = NO_DATA_INTERFACE,
1966
- },
1967
-
19681913 #if IS_ENABLED(CONFIG_INPUT_IMS_PCU)
19691914 { USB_DEVICE(0x04d8, 0x0082), /* Application mode */
19701915 .driver_info = IGNORE_DEVICE,
19711916 },
19721917 { USB_DEVICE(0x04d8, 0x0083), /* Bootloader mode */
1918
+ .driver_info = IGNORE_DEVICE,
1919
+ },
1920
+#endif
1921
+
1922
+#if IS_ENABLED(CONFIG_IR_TOY)
1923
+ { USB_DEVICE(0x04d8, 0xfd08),
19731924 .driver_info = IGNORE_DEVICE,
19741925 },
19751926
....@@ -2080,6 +2031,8 @@
20802031 .set_termios = acm_tty_set_termios,
20812032 .tiocmget = acm_tty_tiocmget,
20822033 .tiocmset = acm_tty_tiocmset,
2034
+ .get_serial = get_serial_info,
2035
+ .set_serial = set_serial_info,
20832036 .get_icount = acm_tty_get_icount,
20842037 };
20852038