|
@@ -221,8 +221,8 @@ static int MoxaPortRxQueue(struct moxa_port *);
|
|
|
static int MoxaPortTxFree(struct moxa_port *);
|
|
|
static void MoxaPortTxDisable(struct moxa_port *);
|
|
|
static void MoxaPortTxEnable(struct moxa_port *);
|
|
|
-static int moxa_get_serial_info(struct moxa_port *, struct serial_struct __user *);
|
|
|
-static int moxa_set_serial_info(struct moxa_port *, struct serial_struct __user *);
|
|
|
+static int moxa_get_serial_info(struct tty_struct *, struct serial_struct *);
|
|
|
+static int moxa_set_serial_info(struct tty_struct *, struct serial_struct *);
|
|
|
static void MoxaSetFifo(struct moxa_port *port, int enable);
|
|
|
|
|
|
/*
|
|
@@ -375,16 +375,6 @@ copy:
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
- case TIOCGSERIAL:
|
|
|
- mutex_lock(&ch->port.mutex);
|
|
|
- ret = moxa_get_serial_info(ch, argp);
|
|
|
- mutex_unlock(&ch->port.mutex);
|
|
|
- break;
|
|
|
- case TIOCSSERIAL:
|
|
|
- mutex_lock(&ch->port.mutex);
|
|
|
- ret = moxa_set_serial_info(ch, argp);
|
|
|
- mutex_unlock(&ch->port.mutex);
|
|
|
- break;
|
|
|
default:
|
|
|
ret = -ENOIOCTLCMD;
|
|
|
}
|
|
@@ -415,6 +405,8 @@ static const struct tty_operations moxa_ops = {
|
|
|
.break_ctl = moxa_break_ctl,
|
|
|
.tiocmget = moxa_tiocmget,
|
|
|
.tiocmset = moxa_tiocmset,
|
|
|
+ .set_serial = moxa_set_serial_info,
|
|
|
+ .get_serial = moxa_get_serial_info,
|
|
|
};
|
|
|
|
|
|
static const struct tty_port_operations moxa_port_ops = {
|
|
@@ -2034,46 +2026,55 @@ static void MoxaPortTxEnable(struct moxa_port *port)
|
|
|
moxafunc(port->tableAddr, FC_SetXonState, Magic_code);
|
|
|
}
|
|
|
|
|
|
-static int moxa_get_serial_info(struct moxa_port *info,
|
|
|
- struct serial_struct __user *retinfo)
|
|
|
+static int moxa_get_serial_info(struct tty_struct *tty,
|
|
|
+ struct serial_struct *ss)
|
|
|
{
|
|
|
- struct serial_struct tmp = {
|
|
|
- .type = info->type,
|
|
|
- .line = info->port.tty->index,
|
|
|
- .flags = info->port.flags,
|
|
|
- .baud_base = 921600,
|
|
|
- .close_delay = info->port.close_delay
|
|
|
- };
|
|
|
- return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0;
|
|
|
+ struct moxa_port *info = tty->driver_data;
|
|
|
+
|
|
|
+ if (tty->index == MAX_PORTS)
|
|
|
+ return -EINVAL;
|
|
|
+ if (!info)
|
|
|
+ return -ENODEV;
|
|
|
+ mutex_lock(&info->port.mutex);
|
|
|
+ ss->type = info->type,
|
|
|
+ ss->line = info->port.tty->index,
|
|
|
+ ss->flags = info->port.flags,
|
|
|
+ ss->baud_base = 921600,
|
|
|
+ ss->close_delay = info->port.close_delay;
|
|
|
+ mutex_unlock(&info->port.mutex);
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
-static int moxa_set_serial_info(struct moxa_port *info,
|
|
|
- struct serial_struct __user *new_info)
|
|
|
+static int moxa_set_serial_info(struct tty_struct *tty,
|
|
|
+ struct serial_struct *ss)
|
|
|
{
|
|
|
- struct serial_struct new_serial;
|
|
|
+ struct moxa_port *info = tty->driver_data;
|
|
|
|
|
|
- if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
|
|
|
- return -EFAULT;
|
|
|
+ if (tty->index == MAX_PORTS)
|
|
|
+ return -EINVAL;
|
|
|
+ if (!info)
|
|
|
+ return -ENODEV;
|
|
|
|
|
|
- if (new_serial.irq != 0 || new_serial.port != 0 ||
|
|
|
- new_serial.custom_divisor != 0 ||
|
|
|
- new_serial.baud_base != 921600)
|
|
|
+ if (ss->irq != 0 || ss->port != 0 ||
|
|
|
+ ss->custom_divisor != 0 ||
|
|
|
+ ss->baud_base != 921600)
|
|
|
return -EPERM;
|
|
|
|
|
|
+ mutex_lock(&info->port.mutex);
|
|
|
if (!capable(CAP_SYS_ADMIN)) {
|
|
|
- if (((new_serial.flags & ~ASYNC_USR_MASK) !=
|
|
|
- (info->port.flags & ~ASYNC_USR_MASK)))
|
|
|
+ if (((ss->flags & ~ASYNC_USR_MASK) !=
|
|
|
+ (info->port.flags & ~ASYNC_USR_MASK))) {
|
|
|
+ mutex_unlock(&info->port.mutex);
|
|
|
return -EPERM;
|
|
|
- } else
|
|
|
- info->port.close_delay = new_serial.close_delay * HZ / 100;
|
|
|
-
|
|
|
- new_serial.flags = (new_serial.flags & ~ASYNC_FLAGS);
|
|
|
- new_serial.flags |= (info->port.flags & ASYNC_FLAGS);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ info->port.close_delay = ss->close_delay * HZ / 100;
|
|
|
|
|
|
- MoxaSetFifo(info, new_serial.type == PORT_16550A);
|
|
|
+ MoxaSetFifo(info, ss->type == PORT_16550A);
|
|
|
|
|
|
- info->type = new_serial.type;
|
|
|
+ info->type = ss->type;
|
|
|
+ mutex_unlock(&info->port.mutex);
|
|
|
return 0;
|
|
|
}
|
|
|
|