forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-02-19 1c055e55a242a33e574e48be530e06770a210dcd
kernel/drivers/usb/serial/ti_usb_3410_5052.c
....@@ -220,7 +220,7 @@
220220 u8 bDataCounter;
221221 __be16 wBaseAddrHi;
222222 __be16 wBaseAddrLo;
223
- u8 bData[0];
223
+ u8 bData[];
224224 } __packed;
225225
226226 struct ti_read_data_request {
....@@ -235,7 +235,7 @@
235235 __u8 bCmdCode;
236236 __u8 bModuleId;
237237 __u8 bErrorCode;
238
- __u8 bData[0];
238
+ __u8 bData[];
239239 } __packed;
240240
241241 /* Interrupt struct */
....@@ -314,8 +314,6 @@
314314 static bool ti_tx_empty(struct usb_serial_port *port);
315315 static void ti_throttle(struct tty_struct *tty);
316316 static void ti_unthrottle(struct tty_struct *tty);
317
-static int ti_ioctl(struct tty_struct *tty,
318
- unsigned int cmd, unsigned long arg);
319317 static void ti_set_termios(struct tty_struct *tty,
320318 struct usb_serial_port *port, struct ktermios *old_termios);
321319 static int ti_tiocmget(struct tty_struct *tty);
....@@ -331,10 +329,10 @@
331329 static void ti_send(struct ti_port *tport);
332330 static int ti_set_mcr(struct ti_port *tport, unsigned int mcr);
333331 static int ti_get_lsr(struct ti_port *tport, u8 *lsr);
334
-static int ti_get_serial_info(struct ti_port *tport,
335
- struct serial_struct __user *ret_arg);
336
-static int ti_set_serial_info(struct tty_struct *tty, struct ti_port *tport,
337
- struct serial_struct __user *new_arg);
332
+static int ti_get_serial_info(struct tty_struct *tty,
333
+ struct serial_struct *ss);
334
+static int ti_set_serial_info(struct tty_struct *tty,
335
+ struct serial_struct *ss);
338336 static void ti_handle_new_msr(struct ti_port *tport, u8 msr);
339337
340338 static void ti_stop_read(struct ti_port *tport, struct tty_struct *tty);
....@@ -439,7 +437,8 @@
439437 .tx_empty = ti_tx_empty,
440438 .throttle = ti_throttle,
441439 .unthrottle = ti_unthrottle,
442
- .ioctl = ti_ioctl,
440
+ .get_serial = ti_get_serial_info,
441
+ .set_serial = ti_set_serial_info,
443442 .set_termios = ti_set_termios,
444443 .tiocmget = ti_tiocmget,
445444 .tiocmset = ti_tiocmset,
....@@ -472,7 +471,8 @@
472471 .tx_empty = ti_tx_empty,
473472 .throttle = ti_throttle,
474473 .unthrottle = ti_unthrottle,
475
- .ioctl = ti_ioctl,
474
+ .get_serial = ti_get_serial_info,
475
+ .set_serial = ti_set_serial_info,
476476 .set_termios = ti_set_termios,
477477 .tiocmget = ti_tiocmget,
478478 .tiocmset = ti_tiocmset,
....@@ -803,8 +803,8 @@
803803 , __func__, status);
804804
805805 mutex_lock(&tdev->td_open_close_lock);
806
- --tport->tp_tdev->td_open_port_count;
807
- if (tport->tp_tdev->td_open_port_count == 0) {
806
+ --tdev->td_open_port_count;
807
+ if (tdev->td_open_port_count == 0) {
808808 /* last port is closed, shut down interrupt urb */
809809 usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
810810 }
....@@ -900,24 +900,6 @@
900900 __func__, status);
901901 }
902902 }
903
-
904
-static int ti_ioctl(struct tty_struct *tty,
905
- unsigned int cmd, unsigned long arg)
906
-{
907
- struct usb_serial_port *port = tty->driver_data;
908
- struct ti_port *tport = usb_get_serial_port_data(port);
909
-
910
- switch (cmd) {
911
- case TIOCGSERIAL:
912
- return ti_get_serial_info(tport,
913
- (struct serial_struct __user *)arg);
914
- case TIOCSSERIAL:
915
- return ti_set_serial_info(tty, tport,
916
- (struct serial_struct __user *)arg);
917
- }
918
- return -ENOIOCTLCMD;
919
-}
920
-
921903
922904 static void ti_set_termios(struct tty_struct *tty,
923905 struct usb_serial_port *port, struct ktermios *old_termios)
....@@ -1416,47 +1398,44 @@
14161398 }
14171399
14181400
1419
-static int ti_get_serial_info(struct ti_port *tport,
1420
- struct serial_struct __user *ret_arg)
1401
+static int ti_get_serial_info(struct tty_struct *tty,
1402
+ struct serial_struct *ss)
14211403 {
1422
- struct usb_serial_port *port = tport->tp_port;
1423
- struct serial_struct ret_serial;
1404
+ struct usb_serial_port *port = tty->driver_data;
1405
+ struct ti_port *tport = usb_get_serial_port_data(port);
14241406 unsigned cwait;
14251407
14261408 cwait = port->port.closing_wait;
14271409 if (cwait != ASYNC_CLOSING_WAIT_NONE)
14281410 cwait = jiffies_to_msecs(cwait) / 10;
14291411
1430
- memset(&ret_serial, 0, sizeof(ret_serial));
1431
-
1432
- ret_serial.type = PORT_16550A;
1433
- ret_serial.line = port->minor;
1434
- ret_serial.port = port->port_number;
1435
- ret_serial.xmit_fifo_size = kfifo_size(&port->write_fifo);
1436
- ret_serial.baud_base = tport->tp_tdev->td_is_3410 ? 921600 : 460800;
1437
- ret_serial.closing_wait = cwait;
1438
-
1439
- if (copy_to_user(ret_arg, &ret_serial, sizeof(*ret_arg)))
1440
- return -EFAULT;
1441
-
1412
+ ss->type = PORT_16550A;
1413
+ ss->line = port->minor;
1414
+ ss->port = port->port_number;
1415
+ ss->xmit_fifo_size = kfifo_size(&port->write_fifo);
1416
+ ss->baud_base = tport->tp_tdev->td_is_3410 ? 921600 : 460800;
1417
+ ss->closing_wait = cwait;
14421418 return 0;
14431419 }
14441420
14451421
1446
-static int ti_set_serial_info(struct tty_struct *tty, struct ti_port *tport,
1447
- struct serial_struct __user *new_arg)
1422
+static int ti_set_serial_info(struct tty_struct *tty,
1423
+ struct serial_struct *ss)
14481424 {
1449
- struct serial_struct new_serial;
1425
+ struct usb_serial_port *port = tty->driver_data;
1426
+ struct tty_port *tport = &port->port;
14501427 unsigned cwait;
14511428
1452
- if (copy_from_user(&new_serial, new_arg, sizeof(new_serial)))
1453
- return -EFAULT;
1454
-
1455
- cwait = new_serial.closing_wait;
1429
+ cwait = ss->closing_wait;
14561430 if (cwait != ASYNC_CLOSING_WAIT_NONE)
1457
- cwait = msecs_to_jiffies(10 * new_serial.closing_wait);
1431
+ cwait = msecs_to_jiffies(10 * ss->closing_wait);
14581432
1459
- tport->tp_port->port.closing_wait = cwait;
1433
+ if (!capable(CAP_SYS_ADMIN)) {
1434
+ if (cwait != tport->closing_wait)
1435
+ return -EPERM;
1436
+ }
1437
+
1438
+ tport->closing_wait = cwait;
14601439
14611440 return 0;
14621441 }