For two cases (beginning and end of the patch) I opted to create small
functions instead of breaking the the lines in a weird way.
The other changes are simple ones: either by breaking the line when
appropriate or by turning a comment into a multi-line one.
Signed-off-by: Fernando Apesteguia <[email protected]>
---
Changes from V2 include the addition of a new function to wake up
processes waiting in a printer/terminal unit. This avoids code
duplication and reduces line length.
drivers/staging/dgnc/dgnc_tty.c | 64 +++++++++++++++++++++++++----------------
1 file changed, 39 insertions(+), 25 deletions(-)
diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c
index af4bc86..37795a0 100644
--- a/drivers/staging/dgnc/dgnc_tty.c
+++ b/drivers/staging/dgnc/dgnc_tty.c
@@ -102,6 +102,8 @@ static int dgnc_tty_write(struct tty_struct *tty, const unsigned char *buf,
static void dgnc_tty_set_termios(struct tty_struct *tty,
struct ktermios *old_termios);
static void dgnc_tty_send_xchar(struct tty_struct *tty, char ch);
+static void dgnc_set_signal_low(struct channel_t *ch, const unsigned char line);
+static void dgnc_wake_up_unit(struct un_t *unit);
static const struct tty_operations dgnc_tty_ops = {
.open = dgnc_tty_open,
@@ -786,6 +788,12 @@ void dgnc_check_queue_flow_control(struct channel_t *ch)
}
}
+static void dgnc_set_signal_low(struct channel_t *ch, const unsigned char sig)
+{
+ ch->ch_mostat &= ~(sig);
+ ch->ch_bd->bd_ops->assert_modem_signals(ch);
+}
+
void dgnc_wakeup_writes(struct channel_t *ch)
{
int qlen = 0;
@@ -823,19 +831,15 @@ void dgnc_wakeup_writes(struct channel_t *ch)
* If RTS Toggle mode is on, whenever
* the queue and UART is empty, keep RTS low.
*/
- if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) {
- ch->ch_mostat &= ~(UART_MCR_RTS);
- ch->ch_bd->bd_ops->assert_modem_signals(ch);
- }
+ if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
+ dgnc_set_signal_low(ch, UART_MCR_RTS);
/*
* If DTR Toggle mode is on, whenever
* the queue and UART is empty, keep DTR low.
*/
- if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) {
- ch->ch_mostat &= ~(UART_MCR_DTR);
- ch->ch_bd->bd_ops->assert_modem_signals(ch);
- }
+ if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
+ dgnc_set_signal_low(ch, UART_MCR_DTR);
}
}
@@ -969,8 +973,9 @@ static int dgnc_tty_open(struct tty_struct *tty, struct file *file)
* touched safely, the close routine will signal the
* ch_flags_wait to wake us back up.
*/
- rc = wait_event_interruptible(ch->ch_flags_wait, (((ch->ch_tun.un_flags |
- ch->ch_pun.un_flags) & UN_CLOSING) == 0));
+ rc = wait_event_interruptible(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)
@@ -1188,11 +1193,12 @@ static int dgnc_block_til_ready(struct tty_struct *tty,
*/
if (sleep_on_un_flags)
retval = wait_event_interruptible
- (un->un_flags_wait, (old_flags != (ch->ch_tun.un_flags |
- ch->ch_pun.un_flags)));
+ (un->un_flags_wait,
+ (old_flags != (ch->ch_tun.un_flags |
+ ch->ch_pun.un_flags)));
else
retval = wait_event_interruptible(ch->ch_flags_wait,
- (old_flags != ch->ch_flags));
+ (old_flags != ch->ch_flags));
/*
* We got woken up for some reason.
@@ -2326,6 +2332,17 @@ static void dgnc_tty_flush_buffer(struct tty_struct *tty)
spin_unlock_irqrestore(&ch->ch_lock, flags);
}
+/*
+ * dgnc_wake_up_unit()
+ *
+ * Wakes up processes waiting in the unit's (teminal/printer) wait queue
+ */
+static void dgnc_wake_up_unit(struct un_t *unit)
+{
+ unit->un_flags &= ~(UN_LOW | UN_EMPTY);
+ wake_up_interruptible(&unit->un_flags_wait);
+}
+
/* The IOCTL function and all of its helpers */
/*
@@ -2508,17 +2525,11 @@ static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
ch->ch_w_head = ch->ch_w_tail;
ch_bd_ops->flush_uart_write(ch);
- if (ch->ch_tun.un_flags & (UN_LOW | UN_EMPTY)) {
- ch->ch_tun.un_flags &=
- ~(UN_LOW | UN_EMPTY);
- wake_up_interruptible(&ch->ch_tun.un_flags_wait);
- }
-
- if (ch->ch_pun.un_flags & (UN_LOW | UN_EMPTY)) {
- ch->ch_pun.un_flags &=
- ~(UN_LOW | UN_EMPTY);
- wake_up_interruptible(&ch->ch_pun.un_flags_wait);
- }
+ if (ch->ch_tun.un_flags & (UN_LOW | UN_EMPTY))
+ dgnc_wake_up_unit(&ch->ch_tun);
+
+ if (ch->ch_pun.un_flags & (UN_LOW | UN_EMPTY))
+ dgnc_wake_up_unit(&ch->ch_pun);
}
}
@@ -2737,7 +2748,10 @@ static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
buf.rxbuf = (ch->ch_r_head - ch->ch_r_tail) & RQUEUEMASK;
buf.txbuf = (ch->ch_w_head - ch->ch_w_tail) & WQUEUEMASK;
- /* Is the UART empty? Add that value to whats in our TX queue. */
+ /*
+ * Is the UART empty?
+ * Add that value to whats in our TX queue.
+ */
count = buf.txbuf + ch_bd_ops->get_uart_bytes_left(ch);
--
2.7.4