forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-02-19 1c055e55a242a33e574e48be530e06770a210dcd
kernel/drivers/tty/mxser.c
....@@ -638,16 +638,15 @@
638638 * This routine is called to set the UART divisor registers to match
639639 * the specified baud rate for a serial port.
640640 */
641
-static int mxser_change_speed(struct tty_struct *tty)
641
+static void mxser_change_speed(struct tty_struct *tty)
642642 {
643643 struct mxser_port *info = tty->driver_data;
644644 unsigned cflag, cval, fcr;
645
- int ret = 0;
646645 unsigned char status;
647646
648647 cflag = tty->termios.c_cflag;
649648 if (!info->ioaddr)
650
- return ret;
649
+ return;
651650
652651 if (mxser_set_baud_method[tty->index] == 0)
653652 mxser_set_baud(tty, tty_get_baud_rate(tty));
....@@ -803,8 +802,6 @@
803802
804803 outb(fcr, info->ioaddr + UART_FCR); /* set fcr */
805804 outb(cval, info->ioaddr + UART_LCR);
806
-
807
- return ret;
808805 }
809806
810807 static void mxser_check_modem_status(struct tty_struct *tty,
....@@ -861,6 +858,7 @@
861858 struct mxser_port *info = container_of(port, struct mxser_port, port);
862859 unsigned long page;
863860 unsigned long flags;
861
+ int ret;
864862
865863 page = __get_free_page(GFP_KERNEL);
866864 if (!page)
....@@ -870,9 +868,9 @@
870868
871869 if (!info->ioaddr || !info->type) {
872870 set_bit(TTY_IO_ERROR, &tty->flags);
873
- free_page(page);
874871 spin_unlock_irqrestore(&info->slock, flags);
875
- return 0;
872
+ ret = 0;
873
+ goto err_free_xmit;
876874 }
877875 info->port.xmit_buf = (unsigned char *) page;
878876
....@@ -898,8 +896,10 @@
898896 if (capable(CAP_SYS_ADMIN)) {
899897 set_bit(TTY_IO_ERROR, &tty->flags);
900898 return 0;
901
- } else
902
- return -ENODEV;
899
+ }
900
+
901
+ ret = -ENODEV;
902
+ goto err_free_xmit;
903903 }
904904
905905 /*
....@@ -944,6 +944,10 @@
944944 spin_unlock_irqrestore(&info->slock, flags);
945945
946946 return 0;
947
+err_free_xmit:
948
+ free_page(page);
949
+ info->port.xmit_buf = NULL;
950
+ return ret;
947951 }
948952
949953 /*
....@@ -1207,76 +1211,90 @@
12071211 * ------------------------------------------------------------
12081212 */
12091213 static int mxser_get_serial_info(struct tty_struct *tty,
1210
- struct serial_struct __user *retinfo)
1214
+ struct serial_struct *ss)
12111215 {
12121216 struct mxser_port *info = tty->driver_data;
1213
- struct serial_struct tmp = {
1214
- .type = info->type,
1215
- .line = tty->index,
1216
- .port = info->ioaddr,
1217
- .irq = info->board->irq,
1218
- .flags = info->port.flags,
1219
- .baud_base = info->baud_base,
1220
- .close_delay = info->port.close_delay,
1221
- .closing_wait = info->port.closing_wait,
1222
- .custom_divisor = info->custom_divisor,
1223
- };
1224
- if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
1225
- return -EFAULT;
1217
+ struct tty_port *port = &info->port;
1218
+
1219
+ if (tty->index == MXSER_PORTS)
1220
+ return -ENOTTY;
1221
+
1222
+ mutex_lock(&port->mutex);
1223
+ ss->type = info->type,
1224
+ ss->line = tty->index,
1225
+ ss->port = info->ioaddr,
1226
+ ss->irq = info->board->irq,
1227
+ ss->flags = info->port.flags,
1228
+ ss->baud_base = info->baud_base,
1229
+ ss->close_delay = info->port.close_delay,
1230
+ ss->closing_wait = info->port.closing_wait,
1231
+ ss->custom_divisor = info->custom_divisor,
1232
+ mutex_unlock(&port->mutex);
12261233 return 0;
12271234 }
12281235
12291236 static int mxser_set_serial_info(struct tty_struct *tty,
1230
- struct serial_struct __user *new_info)
1237
+ struct serial_struct *ss)
12311238 {
12321239 struct mxser_port *info = tty->driver_data;
12331240 struct tty_port *port = &info->port;
1234
- struct serial_struct new_serial;
12351241 speed_t baud;
12361242 unsigned long sl_flags;
12371243 unsigned int flags;
12381244 int retval = 0;
12391245
1240
- if (!new_info || !info->ioaddr)
1241
- return -ENODEV;
1242
- if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
1243
- return -EFAULT;
1246
+ if (tty->index == MXSER_PORTS)
1247
+ return -ENOTTY;
1248
+ if (tty_io_error(tty))
1249
+ return -EIO;
12441250
1245
- if (new_serial.irq != info->board->irq ||
1246
- new_serial.port != info->ioaddr)
1251
+ mutex_lock(&port->mutex);
1252
+ if (!info->ioaddr) {
1253
+ mutex_unlock(&port->mutex);
1254
+ return -ENODEV;
1255
+ }
1256
+
1257
+ if (ss->irq != info->board->irq ||
1258
+ ss->port != info->ioaddr) {
1259
+ mutex_unlock(&port->mutex);
12471260 return -EINVAL;
1261
+ }
12481262
12491263 flags = port->flags & ASYNC_SPD_MASK;
12501264
12511265 if (!capable(CAP_SYS_ADMIN)) {
1252
- if ((new_serial.baud_base != info->baud_base) ||
1253
- (new_serial.close_delay != info->port.close_delay) ||
1254
- ((new_serial.flags & ~ASYNC_USR_MASK) != (info->port.flags & ~ASYNC_USR_MASK)))
1266
+ if ((ss->baud_base != info->baud_base) ||
1267
+ (ss->close_delay != info->port.close_delay) ||
1268
+ ((ss->flags & ~ASYNC_USR_MASK) != (info->port.flags & ~ASYNC_USR_MASK))) {
1269
+ mutex_unlock(&port->mutex);
12551270 return -EPERM;
1271
+ }
12561272 info->port.flags = ((info->port.flags & ~ASYNC_USR_MASK) |
1257
- (new_serial.flags & ASYNC_USR_MASK));
1273
+ (ss->flags & ASYNC_USR_MASK));
12581274 } else {
12591275 /*
12601276 * OK, past this point, all the error checking has been done.
12611277 * At this point, we start making changes.....
12621278 */
12631279 port->flags = ((port->flags & ~ASYNC_FLAGS) |
1264
- (new_serial.flags & ASYNC_FLAGS));
1265
- port->close_delay = new_serial.close_delay * HZ / 100;
1266
- port->closing_wait = new_serial.closing_wait * HZ / 100;
1280
+ (ss->flags & ASYNC_FLAGS));
1281
+ port->close_delay = ss->close_delay * HZ / 100;
1282
+ port->closing_wait = ss->closing_wait * HZ / 100;
12671283 port->low_latency = (port->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
12681284 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST &&
1269
- (new_serial.baud_base != info->baud_base ||
1270
- new_serial.custom_divisor !=
1285
+ (ss->baud_base != info->baud_base ||
1286
+ ss->custom_divisor !=
12711287 info->custom_divisor)) {
1272
- if (new_serial.custom_divisor == 0)
1288
+ if (ss->custom_divisor == 0) {
1289
+ mutex_unlock(&port->mutex);
12731290 return -EINVAL;
1274
- baud = new_serial.baud_base / new_serial.custom_divisor;
1291
+ }
1292
+ baud = ss->baud_base / ss->custom_divisor;
12751293 tty_encode_baud_rate(tty, baud, baud);
12761294 }
12771295 }
12781296
1279
- info->type = new_serial.type;
1297
+ info->type = ss->type;
12801298
12811299 process_txrx_fifo(info);
12821300
....@@ -1291,6 +1309,7 @@
12911309 if (retval == 0)
12921310 tty_port_set_initialized(port, 1);
12931311 }
1312
+ mutex_unlock(&port->mutex);
12941313 return retval;
12951314 }
12961315
....@@ -1660,11 +1679,9 @@
16601679 unsigned int cmd, unsigned long arg)
16611680 {
16621681 struct mxser_port *info = tty->driver_data;
1663
- struct tty_port *port = &info->port;
16641682 struct async_icount cnow;
16651683 unsigned long flags;
16661684 void __user *argp = (void __user *)arg;
1667
- int retval;
16681685
16691686 if (tty->index == MXSER_PORTS)
16701687 return mxser_ioctl_special(cmd, argp);
....@@ -1708,20 +1725,10 @@
17081725 return 0;
17091726 }
17101727
1711
- if (cmd != TIOCGSERIAL && cmd != TIOCMIWAIT && tty_io_error(tty))
1728
+ if (cmd != TIOCMIWAIT && tty_io_error(tty))
17121729 return -EIO;
17131730
17141731 switch (cmd) {
1715
- case TIOCGSERIAL:
1716
- mutex_lock(&port->mutex);
1717
- retval = mxser_get_serial_info(tty, argp);
1718
- mutex_unlock(&port->mutex);
1719
- return retval;
1720
- case TIOCSSERIAL:
1721
- mutex_lock(&port->mutex);
1722
- retval = mxser_set_serial_info(tty, argp);
1723
- mutex_unlock(&port->mutex);
1724
- return retval;
17251732 case TIOCSERGETLSR: /* Get line status register */
17261733 return mxser_get_lsr_info(info, argp);
17271734 /*
....@@ -2325,6 +2332,8 @@
23252332 .wait_until_sent = mxser_wait_until_sent,
23262333 .tiocmget = mxser_tiocmget,
23272334 .tiocmset = mxser_tiocmset,
2335
+ .set_serial = mxser_set_serial_info,
2336
+ .get_serial = mxser_get_serial_info,
23282337 .get_icount = mxser_get_icount,
23292338 };
23302339