diff options
author | Jiri Slaby <jslaby@suse.cz> | 2012-04-02 07:53:52 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-04-09 14:16:54 -0400 |
commit | 37630f406338de4a5f72a42c0b6a034657dce383 (patch) | |
tree | 11212fa0f1b2481e60af871b0bb77e483adf5963 /drivers/isdn | |
parent | ce93d33cf45db9893cfc725a2b470da15bfe4435 (diff) |
TTY: isdn, make some functions readable
Huh, this was a mess.
* Remove the 5 indent levels by just returning from isdn_tty_try_read
when the conditions there are not satisfied.
* Use 'continue' in loop in isdn_tty_readmodem to save 2 levels.
* Chain 'if's in isdn_tty_modem_escape.
* Use 'continue' in loop in isdn_tty_carrier_timeout to save 1 level.
Better to look at this patch with -w -b.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Karsten Keil <isdn@linux-pingi.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/isdn')
-rw-r--r-- | drivers/isdn/i4l/isdn_tty.c | 178 |
1 files changed, 93 insertions, 85 deletions
diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c index 1ff307276d2d..74b05188c18f 100644 --- a/drivers/isdn/i4l/isdn_tty.c +++ b/drivers/isdn/i4l/isdn_tty.c | |||
@@ -65,49 +65,54 @@ isdn_tty_try_read(modem_info *info, struct sk_buff *skb) | |||
65 | struct tty_struct *tty; | 65 | struct tty_struct *tty; |
66 | char last; | 66 | char last; |
67 | 67 | ||
68 | if (info->online) { | 68 | if (!info->online) |
69 | if ((tty = info->tty)) { | 69 | return 0; |
70 | if (info->mcr & UART_MCR_RTS) { | 70 | |
71 | len = skb->len | 71 | tty = info->tty; |
72 | if (!tty) | ||
73 | return 0; | ||
74 | |||
75 | if (!(info->mcr & UART_MCR_RTS)) | ||
76 | return 0; | ||
77 | |||
78 | len = skb->len | ||
72 | #ifdef CONFIG_ISDN_AUDIO | 79 | #ifdef CONFIG_ISDN_AUDIO |
73 | + ISDN_AUDIO_SKB_DLECOUNT(skb) | 80 | + ISDN_AUDIO_SKB_DLECOUNT(skb) |
74 | #endif | 81 | #endif |
75 | ; | 82 | ; |
83 | |||
84 | c = tty_buffer_request_room(tty, len); | ||
85 | if (c < len) | ||
86 | return 0; | ||
76 | 87 | ||
77 | c = tty_buffer_request_room(tty, len); | ||
78 | if (c >= len) { | ||
79 | #ifdef CONFIG_ISDN_AUDIO | ||
80 | if (ISDN_AUDIO_SKB_DLECOUNT(skb)) { | ||
81 | int l = skb->len; | ||
82 | unsigned char *dp = skb->data; | ||
83 | while (--l) { | ||
84 | if (*dp == DLE) | ||
85 | tty_insert_flip_char(tty, DLE, 0); | ||
86 | tty_insert_flip_char(tty, *dp++, 0); | ||
87 | } | ||
88 | if (*dp == DLE) | ||
89 | tty_insert_flip_char(tty, DLE, 0); | ||
90 | last = *dp; | ||
91 | } else { | ||
92 | #endif | ||
93 | if (len > 1) | ||
94 | tty_insert_flip_string(tty, skb->data, len - 1); | ||
95 | last = skb->data[len - 1]; | ||
96 | #ifdef CONFIG_ISDN_AUDIO | 88 | #ifdef CONFIG_ISDN_AUDIO |
97 | } | 89 | if (ISDN_AUDIO_SKB_DLECOUNT(skb)) { |
90 | int l = skb->len; | ||
91 | unsigned char *dp = skb->data; | ||
92 | while (--l) { | ||
93 | if (*dp == DLE) | ||
94 | tty_insert_flip_char(tty, DLE, 0); | ||
95 | tty_insert_flip_char(tty, *dp++, 0); | ||
96 | } | ||
97 | if (*dp == DLE) | ||
98 | tty_insert_flip_char(tty, DLE, 0); | ||
99 | last = *dp; | ||
100 | } else { | ||
98 | #endif | 101 | #endif |
99 | if (info->emu.mdmreg[REG_CPPP] & BIT_CPPP) | 102 | if (len > 1) |
100 | tty_insert_flip_char(tty, last, 0xFF); | 103 | tty_insert_flip_string(tty, skb->data, len - 1); |
101 | else | 104 | last = skb->data[len - 1]; |
102 | tty_insert_flip_char(tty, last, TTY_NORMAL); | 105 | #ifdef CONFIG_ISDN_AUDIO |
103 | tty_flip_buffer_push(tty); | ||
104 | kfree_skb(skb); | ||
105 | return 1; | ||
106 | } | ||
107 | } | ||
108 | } | ||
109 | } | 106 | } |
110 | return 0; | 107 | #endif |
108 | if (info->emu.mdmreg[REG_CPPP] & BIT_CPPP) | ||
109 | tty_insert_flip_char(tty, last, 0xFF); | ||
110 | else | ||
111 | tty_insert_flip_char(tty, last, TTY_NORMAL); | ||
112 | tty_flip_buffer_push(tty); | ||
113 | kfree_skb(skb); | ||
114 | |||
115 | return 1; | ||
111 | } | 116 | } |
112 | 117 | ||
113 | /* isdn_tty_readmodem() is called periodically from within timer-interrupt. | 118 | /* isdn_tty_readmodem() is called periodically from within timer-interrupt. |
@@ -125,35 +130,39 @@ isdn_tty_readmodem(void) | |||
125 | modem_info *info; | 130 | modem_info *info; |
126 | 131 | ||
127 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) { | 132 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) { |
128 | if ((midx = dev->m_idx[i]) >= 0) { | 133 | midx = dev->m_idx[i]; |
129 | info = &dev->mdm.info[midx]; | 134 | if (midx < 0) |
130 | if (info->online) { | 135 | continue; |
131 | r = 0; | 136 | |
137 | info = &dev->mdm.info[midx]; | ||
138 | if (!info->online) | ||
139 | continue; | ||
140 | |||
141 | r = 0; | ||
132 | #ifdef CONFIG_ISDN_AUDIO | 142 | #ifdef CONFIG_ISDN_AUDIO |
133 | isdn_audio_eval_dtmf(info); | 143 | isdn_audio_eval_dtmf(info); |
134 | if ((info->vonline & 1) && (info->emu.vpar[1])) | 144 | if ((info->vonline & 1) && (info->emu.vpar[1])) |
135 | isdn_audio_eval_silence(info); | 145 | isdn_audio_eval_silence(info); |
136 | #endif | 146 | #endif |
137 | if ((tty = info->tty)) { | 147 | tty = info->tty; |
138 | if (info->mcr & UART_MCR_RTS) { | 148 | if (tty) { |
139 | /* CISCO AsyncPPP Hack */ | 149 | if (info->mcr & UART_MCR_RTS) { |
140 | if (!(info->emu.mdmreg[REG_CPPP] & BIT_CPPP)) | 150 | /* CISCO AsyncPPP Hack */ |
141 | r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, tty, 0); | 151 | if (!(info->emu.mdmreg[REG_CPPP] & BIT_CPPP)) |
142 | else | 152 | r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, tty, 0); |
143 | r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, tty, 1); | 153 | else |
144 | if (r) | 154 | r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, tty, 1); |
145 | tty_flip_buffer_push(tty); | 155 | if (r) |
146 | } else | 156 | tty_flip_buffer_push(tty); |
147 | r = 1; | 157 | } else |
148 | } else | 158 | r = 1; |
149 | r = 1; | 159 | } else |
150 | if (r) { | 160 | r = 1; |
151 | info->rcvsched = 0; | 161 | if (r) { |
152 | resched = 1; | 162 | info->rcvsched = 0; |
153 | } else | 163 | resched = 1; |
154 | info->rcvsched = 1; | 164 | } else |
155 | } | 165 | info->rcvsched = 1; |
156 | } | ||
157 | } | 166 | } |
158 | if (!resched) | 167 | if (!resched) |
159 | isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 0); | 168 | isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 0); |
@@ -3769,19 +3778,19 @@ isdn_tty_modem_escape(void) | |||
3769 | int midx; | 3778 | int midx; |
3770 | 3779 | ||
3771 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) | 3780 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) |
3772 | if (USG_MODEM(dev->usage[i])) | 3781 | if (USG_MODEM(dev->usage[i]) && (midx = dev->m_idx[i]) >= 0) { |
3773 | if ((midx = dev->m_idx[i]) >= 0) { | 3782 | modem_info *info = &dev->mdm.info[midx]; |
3774 | modem_info *info = &dev->mdm.info[midx]; | 3783 | if (info->online) { |
3775 | if (info->online) { | 3784 | ton = 1; |
3776 | ton = 1; | 3785 | if ((info->emu.pluscount == 3) && |
3777 | if ((info->emu.pluscount == 3) && | 3786 | time_after(jiffies, |
3778 | time_after(jiffies , info->emu.lastplus + PLUSWAIT2)) { | 3787 | info->emu.lastplus + PLUSWAIT2)) { |
3779 | info->emu.pluscount = 0; | 3788 | info->emu.pluscount = 0; |
3780 | info->online = 0; | 3789 | info->online = 0; |
3781 | isdn_tty_modem_result(RESULT_OK, info); | 3790 | isdn_tty_modem_result(RESULT_OK, info); |
3782 | } | ||
3783 | } | 3791 | } |
3784 | } | 3792 | } |
3793 | } | ||
3785 | isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS, ton); | 3794 | isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS, ton); |
3786 | } | 3795 | } |
3787 | 3796 | ||
@@ -3839,15 +3848,14 @@ isdn_tty_carrier_timeout(void) | |||
3839 | 3848 | ||
3840 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) { | 3849 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) { |
3841 | modem_info *info = &dev->mdm.info[i]; | 3850 | modem_info *info = &dev->mdm.info[i]; |
3842 | if (info->dialing) { | 3851 | if (!info->dialing) |
3843 | if (info->emu.carrierwait++ > info->emu.mdmreg[REG_WAITC]) { | 3852 | continue; |
3844 | info->dialing = 0; | 3853 | if (info->emu.carrierwait++ > info->emu.mdmreg[REG_WAITC]) { |
3845 | isdn_tty_modem_result(RESULT_NO_CARRIER, info); | 3854 | info->dialing = 0; |
3846 | isdn_tty_modem_hup(info, 1); | 3855 | isdn_tty_modem_result(RESULT_NO_CARRIER, info); |
3847 | } | 3856 | isdn_tty_modem_hup(info, 1); |
3848 | else | 3857 | } else |
3849 | ton = 1; | 3858 | ton = 1; |
3850 | } | ||
3851 | } | 3859 | } |
3852 | isdn_timer_ctrl(ISDN_TIMER_CARRIER, ton); | 3860 | isdn_timer_ctrl(ISDN_TIMER_CARRIER, ton); |
3853 | } | 3861 | } |