mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-21 00:10:09 +00:00
mxser: simplify mxser_ioctl_op_mode
* ModeMask local array is just inverted OP_MODE_MASK shifted by shiftbit. Drop this array and use the value directly. * return from the if's true branch and drop 'else' branch by moving the code completely outside the if. Signed-off-by: Jiri Slaby <jslaby@suse.cz> Link: https://lore.kernel.org/r/20210618061516.662-40-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
9fae5f857e
commit
238d117d17
1 changed files with 10 additions and 17 deletions
|
@ -1411,10 +1411,9 @@ static int mxser_cflags_changed(struct mxser_port *info, unsigned long arg,
|
||||||
static int mxser_ioctl_op_mode(struct mxser_port *port, int index, bool set,
|
static int mxser_ioctl_op_mode(struct mxser_port *port, int index, bool set,
|
||||||
int __user *u_opmode)
|
int __user *u_opmode)
|
||||||
{
|
{
|
||||||
static const unsigned char ModeMask[] = { 0xfc, 0xf3, 0xcf, 0x3f };
|
|
||||||
int opmode, p = index % 4;
|
int opmode, p = index % 4;
|
||||||
int shiftbit = p * 2;
|
int shiftbit = p * 2;
|
||||||
unsigned char val, mask;
|
u8 val;
|
||||||
|
|
||||||
if (port->board->must_hwid != MOXA_MUST_MU860_HWID)
|
if (port->board->must_hwid != MOXA_MUST_MU860_HWID)
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
@ -1423,30 +1422,24 @@ static int mxser_ioctl_op_mode(struct mxser_port *port, int index, bool set,
|
||||||
if (get_user(opmode, u_opmode))
|
if (get_user(opmode, u_opmode))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
|
||||||
if (opmode != RS232_MODE && opmode != RS485_2WIRE_MODE &&
|
if (opmode & ~OP_MODE_MASK)
|
||||||
opmode != RS422_MODE &&
|
return -EINVAL;
|
||||||
opmode != RS485_4WIRE_MODE)
|
|
||||||
return -EFAULT;
|
|
||||||
|
|
||||||
mask = ModeMask[p];
|
|
||||||
|
|
||||||
spin_lock_irq(&port->slock);
|
spin_lock_irq(&port->slock);
|
||||||
val = inb(port->opmode_ioaddr);
|
val = inb(port->opmode_ioaddr);
|
||||||
val &= mask;
|
val &= ~(OP_MODE_MASK << shiftbit);
|
||||||
val |= (opmode << shiftbit);
|
val |= (opmode << shiftbit);
|
||||||
outb(val, port->opmode_ioaddr);
|
outb(val, port->opmode_ioaddr);
|
||||||
spin_unlock_irq(&port->slock);
|
spin_unlock_irq(&port->slock);
|
||||||
} else {
|
|
||||||
spin_lock_irq(&port->slock);
|
|
||||||
opmode = inb(port->opmode_ioaddr) >> shiftbit;
|
|
||||||
spin_unlock_irq(&port->slock);
|
|
||||||
|
|
||||||
opmode &= OP_MODE_MASK;
|
return 0;
|
||||||
if (put_user(opmode, u_opmode))
|
|
||||||
return -EFAULT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
spin_lock_irq(&port->slock);
|
||||||
|
opmode = inb(port->opmode_ioaddr) >> shiftbit;
|
||||||
|
spin_unlock_irq(&port->slock);
|
||||||
|
|
||||||
|
return put_user(opmode & OP_MODE_MASK, u_opmode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mxser_ioctl(struct tty_struct *tty,
|
static int mxser_ioctl(struct tty_struct *tty,
|
||||||
|
|
Loading…
Reference in a new issue