TTY_DRIVER_REAL_RAW |
TTY_DRIVER_DYNAMIC_DEV |
TTY_DRIVER_HARDWARE_BREAK);
-
if (IS_ERR(brd->serial_driver))
return PTR_ERR(brd->serial_driver);
TTY_DRIVER_REAL_RAW |
TTY_DRIVER_DYNAMIC_DEV |
TTY_DRIVER_HARDWARE_BREAK);
-
if (IS_ERR(brd->print_driver)) {
rc = PTR_ERR(brd->print_driver);
goto unregister_serial_driver;
tty_unregister_driver(brd->serial_driver);
free_serial_driver:
put_tty_driver(brd->serial_driver);
-
return rc;
}
int dgnc_tty_init(struct dgnc_board *brd)
{
int i;
+ int rc;
void __iomem *vaddr;
struct channel_t *ch;
*/
brd->channels[i] = kzalloc(sizeof(*brd->channels[i]),
GFP_KERNEL);
- if (!brd->channels[i])
+ if (!brd->channels[i]) {
+ rc = -ENOMEM;
goto err_free_channels;
+ }
}
ch = brd->channels[0];
kfree(brd->channels[i]);
brd->channels[i] = NULL;
}
- return -ENOMEM;
+ return rc;
}
/*
*/
rc = wait_event_interruptible(brd->state_wait,
(brd->state & BOARD_READY));
-
if (rc)
return rc;
/* If opened device is greater than our number of ports, bail. */
if (PORT_NUM(minor) >= brd->nasync) {
- spin_unlock_irqrestore(&brd->bd_lock, flags);
- return -ENXIO;
+ rc = -ENXIO;
+ goto err_brd_unlock;
}
ch = brd->channels[PORT_NUM(minor)];
if (!ch) {
- spin_unlock_irqrestore(&brd->bd_lock, flags);
- return -ENXIO;
+ rc = -ENXIO;
+ goto err_brd_unlock;
}
/* Drop board lock */
un = &brd->channels[PORT_NUM(minor)]->ch_pun;
un->un_type = DGNC_PRINT;
} else {
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return -ENXIO;
+ rc = -ENXIO;
+ goto err_ch_unlock;
}
/*
rc = wait_event_interruptible(ch->ch_flags_wait,
((ch->ch_flags & CH_OPENING) == 0));
-
/* If ret is non-zero, user ctrl-c'ed us */
if (rc)
return -EINTR;
ch->ch_flags_wait,
(((ch->ch_tun.un_flags |
ch->ch_pun.un_flags) & UN_CLOSING) == 0));
-
/* If ret is non-zero, user ctrl-c'ed us */
if (rc)
return -EINTR;
kfree(ch->ch_rqueue);
kfree(ch->ch_equeue);
kfree(ch->ch_wqueue);
-
return -ENOMEM;
}
spin_unlock_irqrestore(&ch->ch_lock, flags);
return rc;
+
+err_brd_unlock:
+ spin_unlock_irqrestore(&brd->bd_lock, flags);
+ return rc;
+err_ch_unlock:
+ spin_unlock_irqrestore(&ch->ch_lock, flags);
+ return rc;
+
}
/*
struct file *file,
struct channel_t *ch)
{
- int retval = 0;
+ int rc = 0;
struct un_t *un = tty->driver_data;
unsigned long flags;
uint old_flags = 0;
* bail with error.
*/
if (ch->ch_bd->state == BOARD_FAILED) {
- retval = -ENXIO;
+ rc = -ENXIO;
break;
}
/* If tty was hung up, break out of loop and set error. */
if (tty_hung_up_p(file)) {
- retval = -EAGAIN;
+ rc = -EAGAIN;
break;
}
break;
if (tty_io_error(tty)) {
- retval = -EIO;
+ rc = -EIO;
break;
}
* Leave loop with error set.
*/
if (signal_pending(current)) {
- retval = -ERESTARTSYS;
+ rc = -ERESTARTSYS;
break;
}
* from the current value.
*/
if (sleep_on_un_flags)
- retval = wait_event_interruptible
+ rc = wait_event_interruptible
(un->un_flags_wait,
(old_flags != (ch->ch_tun.un_flags |
ch->ch_pun.un_flags)));
else
- retval = wait_event_interruptible(
+ rc = wait_event_interruptible(
ch->ch_flags_wait,
(old_flags != ch->ch_flags));
ch->ch_wopen--;
spin_unlock_irqrestore(&ch->ch_lock, flags);
-
- return retval;
+ return rc;
}
/*
ushort thead;
ushort ttail;
uint tmask;
- uint chars = 0;
+ uint chars;
unsigned long flags;
if (!tty)
spin_unlock_irqrestore(&ch->ch_lock, flags);
- if (ttail == thead) {
+ if (ttail == thead)
chars = 0;
- } else {
- if (thead >= ttail)
- chars = thead - ttail;
- else
- chars = thead - ttail + WQUEUESIZE;
- }
+ else if (thead > ttail)
+ chars = thead - ttail;
+ else
+ chars = thead - ttail + WQUEUESIZE;
- return chars;
+ return (int)chars;
}
/*
*/
static int dgnc_maxcps_room(struct channel_t *ch, int bytes_available)
{
+ int rc = bytes_available;
+
if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
int cps_limit = 0;
unsigned long current_time = jiffies;
cps_limit = 0;
}
- bytes_available = min(cps_limit, bytes_available);
+ rc = min(cps_limit, bytes_available);
}
- return bytes_available;
+ return rc;
}
/*
* dgnc_tty_write_room()
*
- * Return space available in Tx buffer
+ * Return room available in Tx buffer
*/
static int dgnc_tty_write_room(struct tty_struct *tty)
{
ushort head;
ushort tail;
ushort tmask;
- int ret = 0;
+ int room = 0;
unsigned long flags;
if (!tty)
head = (ch->ch_w_head) & tmask;
tail = (ch->ch_w_tail) & tmask;
- ret = tail - head - 1;
- if (ret < 0)
- ret += WQUEUESIZE;
+ room = tail - head - 1;
+ if (room < 0)
+ room += WQUEUESIZE;
/* Limit printer to maxcps */
if (un->un_type != DGNC_PRINT)
- ret = dgnc_maxcps_room(ch, ret);
+ room = dgnc_maxcps_room(ch, room);
/*
- * If we are printer device, leave space for
+ * If we are printer device, leave room for
* possibly both the on and off strings.
*/
if (un->un_type == DGNC_PRINT) {
if (!(ch->ch_flags & CH_PRON))
- ret -= ch->ch_digi.digi_onlen;
- ret -= ch->ch_digi.digi_offlen;
+ room -= ch->ch_digi.digi_onlen;
+ room -= ch->ch_digi.digi_offlen;
} else {
if (ch->ch_flags & CH_PRON)
- ret -= ch->ch_digi.digi_offlen;
+ room -= ch->ch_digi.digi_offlen;
}
- if (ret < 0)
- ret = 0;
+ if (room < 0)
+ room = 0;
spin_unlock_irqrestore(&ch->ch_lock, flags);
-
- return ret;
+ return room;
}
/*
return count;
exit_retry:
-
spin_unlock_irqrestore(&ch->ch_lock, flags);
return 0;
}
{
struct channel_t *ch;
struct un_t *un;
- int result = -EIO;
+ int rc = -EIO;
unsigned char mstat = 0;
unsigned long flags;
if (!tty || tty->magic != TTY_MAGIC)
- return result;
+ return rc;
un = tty->driver_data;
if (!un || un->magic != DGNC_UNIT_MAGIC)
- return result;
+ return rc;
ch = un->un_ch;
if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return result;
+ return rc;
spin_lock_irqsave(&ch->ch_lock, flags);
spin_unlock_irqrestore(&ch->ch_lock, flags);
- result = 0;
+ rc = 0;
if (mstat & UART_MCR_DTR)
- result |= TIOCM_DTR;
+ rc |= TIOCM_DTR;
if (mstat & UART_MCR_RTS)
- result |= TIOCM_RTS;
+ rc |= TIOCM_RTS;
if (mstat & UART_MSR_CTS)
- result |= TIOCM_CTS;
+ rc |= TIOCM_CTS;
if (mstat & UART_MSR_DSR)
- result |= TIOCM_DSR;
+ rc |= TIOCM_DSR;
if (mstat & UART_MSR_RI)
- result |= TIOCM_RI;
+ rc |= TIOCM_RI;
if (mstat & UART_MSR_DCD)
- result |= TIOCM_CD;
+ rc |= TIOCM_CD;
- return result;
+ return rc;
}
/*
struct dgnc_board *bd;
struct channel_t *ch;
struct un_t *un;
- int ret = -EIO;
+ int rc = -EIO;
unsigned long flags;
if (!tty || tty->magic != TTY_MAGIC)
- return ret;
+ return rc;
un = tty->driver_data;
if (!un || un->magic != DGNC_UNIT_MAGIC)
- return ret;
+ return rc;
ch = un->un_ch;
if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return ret;
+ return rc;
bd = ch->ch_bd;
if (!bd || bd->magic != DGNC_BOARD_MAGIC)
- return ret;
+ return rc;
spin_lock_irqsave(&ch->ch_lock, flags);
struct dgnc_board *bd;
struct channel_t *ch;
struct un_t *un;
- int ret = -EIO;
+ int rc = -EIO;
unsigned long flags;
if (!tty || tty->magic != TTY_MAGIC)
- return ret;
+ return rc;
un = tty->driver_data;
if (!un || un->magic != DGNC_UNIT_MAGIC)
- return ret;
+ return rc;
ch = un->un_ch;
if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return ret;
+ return rc;
bd = ch->ch_bd;
if (!bd || bd->magic != DGNC_BOARD_MAGIC)
- return ret;
+ return rc;
switch (msec) {
case -1:
static inline int dgnc_get_mstat(struct channel_t *ch)
{
unsigned char mstat;
- int result = 0;
+ int rc = -ENXIO;
unsigned long flags;
if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return -ENXIO;
+ return rc;
spin_lock_irqsave(&ch->ch_lock, flags);
spin_unlock_irqrestore(&ch->ch_lock, flags);
+ rc = 0;
+
if (mstat & UART_MCR_DTR)
- result |= TIOCM_DTR;
+ rc |= TIOCM_DTR;
if (mstat & UART_MCR_RTS)
- result |= TIOCM_RTS;
+ rc |= TIOCM_RTS;
if (mstat & UART_MSR_CTS)
- result |= TIOCM_CTS;
+ rc |= TIOCM_CTS;
if (mstat & UART_MSR_DSR)
- result |= TIOCM_DSR;
+ rc |= TIOCM_DSR;
if (mstat & UART_MSR_RI)
- result |= TIOCM_RI;
+ rc |= TIOCM_RI;
if (mstat & UART_MSR_DCD)
- result |= TIOCM_CD;
+ rc |= TIOCM_CD;
- return result;
+ return rc;
}
/* Return modem signals to ld. */
unsigned int command,
unsigned int __user *value)
{
- int ret = -ENXIO;
+ int rc;
unsigned int arg = 0;
unsigned long flags;
- ret = get_user(arg, value);
- if (ret)
- return ret;
+ rc = get_user(arg, value);
+ if (rc)
+ return rc;
switch (command) {
case TIOCMBIS:
struct un_t *un;
struct digi_t tmp;
unsigned long flags;
+ int rc = -EFAULT;
if (!retinfo)
- return -EFAULT;
+ return rc;
if (!tty || tty->magic != TTY_MAGIC)
- return -EFAULT;
+ return rc;
un = tty->driver_data;
if (!un || un->magic != DGNC_UNIT_MAGIC)
- return -EFAULT;
+ return rc;
ch = un->un_ch;
if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return -EFAULT;
+ return rc;
memset(&tmp, 0, sizeof(tmp));
spin_unlock_irqrestore(&ch->ch_lock, flags);
if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
- return -EFAULT;
+ return rc;
return 0;
}
struct un_t *un;
struct digi_t new_digi;
unsigned long flags;
+ int rc = -EFAULT;
if (!tty || tty->magic != TTY_MAGIC)
- return -EFAULT;
+ return rc;
un = tty->driver_data;
if (!un || un->magic != DGNC_UNIT_MAGIC)
- return -EFAULT;
+ return rc;
ch = un->un_ch;
if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return -EFAULT;
+ return rc;
bd = ch->ch_bd;
if (!bd || bd->magic != DGNC_BOARD_MAGIC)
- return -EFAULT;
+ return rc;
if (copy_from_user(&new_digi, new_info, sizeof(new_digi)))
- return -EFAULT;
+ return rc;
spin_lock_irqsave(&ch->ch_lock, flags);
struct board_ops *ch_bd_ops;
struct channel_t *ch;
struct un_t *un;
- int rc;
+ int rc = -ENODEV;
unsigned long flags;
void __user *uarg = (void __user *)arg;
if (!tty || tty->magic != TTY_MAGIC)
- return -ENODEV;
+ return rc;
un = tty->driver_data;
if (!un || un->magic != DGNC_UNIT_MAGIC)
- return -ENODEV;
+ return rc;
ch = un->un_ch;
if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
- return -ENODEV;
+ return rc;
bd = ch->ch_bd;
if (!bd || bd->magic != DGNC_BOARD_MAGIC)
- return -ENODEV;
+ return rc;
ch_bd_ops = bd->bd_ops;
spin_lock_irqsave(&ch->ch_lock, flags);
if (un->un_open_count <= 0) {
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return -EIO;
+ rc = -EIO;
+ goto err_unlock;
}
switch (cmd) {
* also.
*/
rc = tty_check_change(tty);
- if (rc) {
- spin_unlock_irqrestore(&ch->ch_lock, flags);
- return rc;
- }
+ if (rc)
+ goto err_unlock;
if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
ch->ch_r_head = ch->ch_r_tail;
if (cmd == (DIGI_SETAW)) {
spin_unlock_irqrestore(&ch->ch_lock, flags);
rc = ch_bd_ops->drain(tty, 0);
-
if (rc)
return -EINTR;
return -ENOIOCTLCMD;
}
+err_unlock:
+ spin_unlock_irqrestore(&ch->ch_lock, flags);
+ return rc;
}