From: Alan Cox Date: Wed, 16 Jul 2008 20:56:54 +0000 (+0100) Subject: tty: Clean up tiocmset X-Git-Tag: v2.6.27-rc1~1007 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae67751785dae388beb31fc24d14870d0d4669d9;p=linux-2.6 tty: Clean up tiocmset Reverse the order of one test and it gets much more readable Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c index 739c9c59fc..a8cc416a23 100644 --- a/drivers/char/tty_io.c +++ b/drivers/char/tty_io.c @@ -3515,35 +3515,31 @@ static int tty_tiocmget(struct tty_struct *tty, struct file *file, int __user *p static int tty_tiocmset(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned __user *p) { - int retval = -EINVAL; - - if (tty->ops->tiocmset) { - unsigned int set, clear, val; - - retval = get_user(val, p); - if (retval) - return retval; - - set = clear = 0; - switch (cmd) { - case TIOCMBIS: - set = val; - break; - case TIOCMBIC: - clear = val; - break; - case TIOCMSET: - set = val; - clear = ~val; - break; - } + int retval; + unsigned int set, clear, val; - set &= TIOCM_DTR|TIOCM_RTS|TIOCM_OUT1|TIOCM_OUT2|TIOCM_LOOP; - clear &= TIOCM_DTR|TIOCM_RTS|TIOCM_OUT1|TIOCM_OUT2|TIOCM_LOOP; + if (tty->ops->tiocmset == NULL) + return -EINVAL; - retval = tty->ops->tiocmset(tty, file, set, clear); + retval = get_user(val, p); + if (retval) + return retval; + set = clear = 0; + switch (cmd) { + case TIOCMBIS: + set = val; + break; + case TIOCMBIC: + clear = val; + break; + case TIOCMSET: + set = val; + clear = ~val; + break; } - return retval; + set &= TIOCM_DTR|TIOCM_RTS|TIOCM_OUT1|TIOCM_OUT2|TIOCM_LOOP; + clear &= TIOCM_DTR|TIOCM_RTS|TIOCM_OUT1|TIOCM_OUT2|TIOCM_LOOP; + return tty->ops->tiocmset(tty, file, set, clear); } /*